From 35ed5d4c759df4fb4046e126096812edbfae3aa2 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Wed, 14 Jun 2017 01:26:46 +0200 Subject: [PATCH] Portability, some corrections. --- include/libcasio.h | 14 +-- include/libcasio/builtin.h | 65 +++++----- include/libcasio/cdefs.h | 49 +++----- include/libcasio/cdefs/endian.h | 26 ++-- include/libcasio/cdefs/integers.h | 2 +- include/libcasio/date.h | 13 +- include/libcasio/encoding.h | 12 +- include/libcasio/error.h | 11 +- include/libcasio/file.h | 58 +++++---- include/libcasio/format.h | 15 +-- include/libcasio/format/cas.h | 15 ++- include/libcasio/format/cas/backup.h | 1 + include/libcasio/format/cas/cell.h | 1 + include/libcasio/format/cas/gmem.h | 3 +- include/libcasio/format/cas/graph.h | 1 + include/libcasio/format/cas/picture.h | 3 +- include/libcasio/format/cas/program.h | 3 +- include/libcasio/format/casemul.h | 5 +- include/libcasio/format/fxi.h.draft | 3 +- include/libcasio/format/mcs/cells.h | 5 +- include/libcasio/format/mcs/picture.h | 3 +- include/libcasio/format/mcs/program.h | 3 +- include/libcasio/format/mcs/setup.h | 3 +- include/libcasio/format/mcs/spreadsheet.h | 5 +- include/libcasio/format/std.h | 15 ++- include/libcasio/format/std/addin.h | 3 +- include/libcasio/format/std/eact.h | 3 +- include/libcasio/format/std/fkey.h | 3 +- include/libcasio/format/std/lang.h | 3 +- include/libcasio/format/std/mcs.h | 13 +- include/libcasio/format/std/picture.h | 3 +- include/libcasio/format/storage.h | 5 +- include/libcasio/{filesystem.h => fs.h} | 23 ++-- include/libcasio/link.h | 66 +++++----- include/libcasio/log.h | 20 ++-- include/libcasio/mcs.h | 26 ++++ include/libcasio/mcsfile.h | 67 ++++++----- include/libcasio/number.h | 31 +++-- include/libcasio/picture.h | 25 ++-- include/libcasio/protocol/legacy.h | 2 +- include/libcasio/protocol/seven.h | 105 ++++++++-------- include/libcasio/protocol/seven/commands.h | 30 +++-- include/libcasio/protocol/typz.h | 2 +- include/libcasio/stream.h | 133 ++++++++++++--------- include/libcasio/utils.h | 15 ++- include/libcasio/version.h | 13 +- src/errors.c | 14 +++ src/file/decode/std/mcs.c | 6 +- src/file/manage.c | 9 +- src/internals.h | 8 +- src/link/seven/receive.c | 2 +- src/link/seven/send.c | 2 +- src/mcsfile/decode/cas.c | 8 +- src/mcsfile/decode/cas/cell.c | 8 +- src/mcsfile/decode/cas/program.c | 2 +- src/mcsfile/decode/mcs/setup.c | 15 +-- src/mcsfile/manage.c | 2 +- src/stream/open.c | 1 - src/utils/checksum.c | 25 +++- 59 files changed, 564 insertions(+), 463 deletions(-) rename include/libcasio/{filesystem.h => fs.h} (89%) create mode 100644 include/libcasio/mcs.h diff --git a/include/libcasio.h b/include/libcasio.h index c9e78c8..10ebfff 100644 --- a/include/libcasio.h +++ b/include/libcasio.h @@ -18,13 +18,13 @@ * ************************************************************************* */ #ifndef LIBCASIO_H # define LIBCASIO_H -# include -# include +# include "libcasio/cdefs.h" +# include "libcasio/error.h" -# include -# include +# include "libcasio/log.h" +# include "libcasio/number.h" -# include -# include -# include +# include "libcasio/link.h" +# include "libcasio/file.h" +# include "libcasio/utils.h" #endif /* LIBCASIO_H */ diff --git a/include/libcasio/builtin.h b/include/libcasio/builtin.h index 2100286..78c4974 100644 --- a/include/libcasio/builtin.h +++ b/include/libcasio/builtin.h @@ -18,53 +18,54 @@ * ************************************************************************* */ #ifndef LIBCASIO_BUILTIN_H # define LIBCASIO_BUILTIN_H -# include -# include +# include "cdefs.h" +# include "stream.h" # ifndef LIBCASIO_DISABLED_FILE # include # endif CASIO_BEGIN_NAMESPACE CASIO_BEGIN_DECLS -/* Microsoft Windows thingies */ -# if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) \ - && !defined(__WINDOWS__) -# define __WINDOWS__ -# endif /* ************************************************************************* */ /* Built-in streams */ /* ************************************************************************* */ /* Make a stream using the standard FILE interface. */ # ifndef LIBCASIO_DISABLED_FILE -extern int casio_open_stream_file OF((casio_stream_t **casio__stream, - FILE *casio__readstream, FILE *casio__writestream, - int casio__close_readstream, int casio__close_writestream)); +CASIO_EXTERN int CASIO_EXPORT casio_open_stream_file + OF((casio_stream_t **casio__stream, + FILE *casio__readstream, FILE *casio__writestream, + int casio__close_readstream, int casio__close_writestream)); # endif /* Make a stream using the POSIX STREAMS interface. */ # if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) -extern int casio_opencom_streams OF((casio_stream_t **casio__stream, - const char *casio__path)); +CASIO_EXTERN int CASIO_EXPORT casio_opencom_streams + OF((casio_stream_t **casio__stream, const char *casio__path)); -extern int casio_open_stream_streams OF((casio_stream_t **casio__stream, - const char *casio__path, casio_openmode_t casio__mode)); -extern int casio_open_stream_fd OF((casio_stream_t **casio__stream, - int casio__readfd, int casio__writefd, - int casio__closeread, int casio__closewrite)); +CASIO_EXTERN int CASIO_EXPORT casio_open_stream_streams + OF((casio_stream_t **casio__stream, + const char *casio__path, casio_openmode_t casio__mode)); +CASIO_EXTERN int CASIO_EXPORT casio_open_stream_fd + OF((casio_stream_t **casio__stream, + int casio__readfd, int casio__writefd, + int casio__closeread, int casio__closewrite)); # else # define LIBCASIO_DISABLED_STREAMS # endif /* Make a stream using libusb. */ # ifndef LIBCASIO_DISABLED_LIBUSB -extern int casio_openusb_libusb OF((casio_stream_t **casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_openusb_libusb + OF((casio_stream_t **casio__stream)); # endif /* Make a stream using the Microsoft Windows API. */ -# ifdef __WINDOWS__ -extern int casio_openusb_windows OF((casio_stream_t **casio__stream)); -extern int casio_opencom_windows OF((casio_stream_t **casio__stream, - const char *casio__path)); +# if defined(_WIN16) || defined(_WIN32) || defined(_WIN64) \ + || defined(__WINDOWS__) +CASIO_EXTERN int CASIO_EXPORT casio_openusb_windows + OF((casio_stream_t **casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_opencom_windows + OF((casio_stream_t **casio__stream, const char *casio__path)); # else # define LIBCASIO_DISABLED_WINDOWS # endif @@ -73,20 +74,20 @@ extern int casio_opencom_windows OF((casio_stream_t **casio__stream, /* ************************************************************************* */ /* List serial devices on Linux. */ # ifdef __linux__ -extern int casio_comlist_linux OF((casio_list_com_t *casio__callback, - void *casio__cookie)); +CASIO_EXTERN int CASIO_EXPORT casio_comlist_linux + OF((casio_list_com_t *casio__callback, void *casio__cookie)); # endif /* List serial devices on MacOS/OS X. */ # if defined(__APPLE__) && defined(__MACH__) -extern int casio_comlist_macos OF((casio_list_com_t *casio__callback, - void *casio__cookie)); +CASIO_EXTERN int CASIO_EXPORT casio_comlist_macos + OF((casio_list_com_t *casio__callback, void *casio__cookie)); # endif /* List serial devices on Microsoft Windows. */ -# ifdef __WINDOWS__ -extern int casio_comlist_windows OF((casio_list_com_t *casio__callback, - void *casio__cookie)); +# ifndef LIBCASIO_DISABLED_WINDOWS +CASIO_EXTERN int CASIO_EXPORT casio_comlist_windows + OF((casio_list_com_t *casio__callback, void *casio__cookie)); # endif /* ************************************************************************* */ /* Built-in sleep function */ @@ -96,8 +97,10 @@ extern int casio_comlist_windows OF((casio_list_com_t *casio__callback, typedef void casio_sleep_t OF((unsigned long casio__ms)); -extern void casio_set_sleep OF((casio_sleep_t *casio__func)); -extern int casio_sleep OF((unsigned long casio__ms)); +CASIO_EXTERN void CASIO_EXPORT casio_set_sleep + OF((casio_sleep_t *casio__func)); +CASIO_EXTERN int CASIO_EXPORT casio_sleep + OF((unsigned long casio__ms)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/cdefs.h b/include/libcasio/cdefs.h index 147644b..e564918 100644 --- a/include/libcasio/cdefs.h +++ b/include/libcasio/cdefs.h @@ -18,17 +18,17 @@ * ************************************************************************* */ #ifndef LIBCASIO_CDEFS_H # define LIBCASIO_CDEFS_H -# include +# include "config.h" +# include +# include /* ************************************************************************* */ /* Check for compilers */ /* ************************************************************************* */ /* First, GCC. */ -# ifdef CASIO_GNUC_PREREQ -# undef CASIO_GNUC_PREREQ -# endif -# if defined(__GNUC__) && defined(__GNUC_MINOR__) +# if defined(CASIO_GNUC_PREREQ) +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) # define CASIO_GNUC_PREREQ(CASIO__MAJ, CASIO__MIN) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((CASIO__MAJ) << 16) + (CASIO__MIN)) # else @@ -37,25 +37,28 @@ /* Then, Microsoft's Compiler. */ -# ifdef CASIO_MSC_PREREQ -# undef CASIO_MSC_PREREQ -# endif -# if defined(_MSC_VER) +# if defined(CASIO_MSC_PREREQ) || defined(_MSC_VER) # define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) \ (_MSC_VER >= (CASIO__MAJ) * 1000 + (CASIO__MIN)) # else # define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) 0 # endif /* ************************************************************************* */ +/* Extern functions */ +/* ************************************************************************* */ +/* Some platforms require more than simply 'extern'. + * Here are macros to control this. */ + +# define CASIO_EXTERN extern +# define CASIO_EXPORT +/* ************************************************************************* */ /* Function declaration arguments */ /* ************************************************************************* */ /* Pre-ANSI C compilers don't support arguments (and argument types) in * function declarations. This macro is inspired from zlib. */ -# ifdef OF -# undef OF -# endif -# if defined(__STDC__) && __STDC__ +# if defined(OF) +# elif defined(__STDC__) && __STDC__ # define OF(CASIO_ARGS) CASIO_ARGS # else # define OF(CASIO_ARGS) () @@ -65,19 +68,6 @@ /* ************************************************************************* */ /* libcasio is made in C. */ -# ifdef CASIO_BEGIN_DECLS -# undef CASIO_BEGIN_DECLS -# endif -# ifdef CASIO_END_DECLS -# undef CASIO_END_DECLS -# endif -# ifdef CASIO_BEGIN_NAMESPACE -# undef CASIO_BEGIN_NAMESPACE -# endif -# ifdef CASIO_END_NAMESPACE -# undef CASIO_END_NAMESPACE -# endif - # if 0 /* hey, what about this? */ # define CASIO_BEGIN_NAMESPACE namespace casio { # define CASIO_END_NAMESPACE } @@ -99,9 +89,6 @@ /* ************************************************************************* */ /* That's pretty much all of it. */ -# ifdef casio_attr_wur -# undef casio_attr_wur -# endif # if CASIO_GNUC_PREREQ(4, 0) # define casio_attr_wur __attribute__((warn_unused_result)) # elif CASIO_MSC_PREREQ(17, 0) @@ -109,6 +96,6 @@ # define casio_attr_wur _Check_return_ # endif -# include -# include +# include "cdefs/integers.h" +# include "cdefs/endian.h" #endif /* LIBCASIO_CDEFS_H */ diff --git a/include/libcasio/cdefs/endian.h b/include/libcasio/cdefs/endian.h index d553b99..3ccee5a 100644 --- a/include/libcasio/cdefs/endian.h +++ b/include/libcasio/cdefs/endian.h @@ -18,21 +18,29 @@ * ************************************************************************* */ #ifndef LIBCASIO_CDEFS_ENDIAN_H # define LIBCASIO_CDEFS_ENDIAN_H -# include +# include "../cdefs.h" /* These function always exist. They are the default ones, if the platform * does not have any equivalent function (or has one but indicates that * fact badly). */ -extern casio_uint16_t casio_be16toh OF((casio_uint16_t casio__x)); -extern casio_uint16_t casio_le16toh OF((casio_uint16_t casio__x)); -extern casio_uint32_t casio_be32toh OF((casio_uint32_t casio__x)); -extern casio_uint32_t casio_le32toh OF((casio_uint32_t casio__x)); +CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_be16toh + OF((casio_uint16_t casio__x)); +CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_le16toh + OF((casio_uint16_t casio__x)); +CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_be32toh + OF((casio_uint32_t casio__x)); +CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_le32toh + OF((casio_uint32_t casio__x)); -extern casio_uint16_t casio_htobe16 OF((casio_uint16_t casio__x)); -extern casio_uint16_t casio_htole16 OF((casio_uint16_t casio__x)); -extern casio_uint32_t casio_htobe32 OF((casio_uint32_t casio__x)); -extern casio_uint32_t casio_htole32 OF((casio_uint32_t casio__x)); +CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_htobe16 + OF((casio_uint16_t casio__x)); +CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_htole16 + OF((casio_uint16_t casio__x)); +CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_htobe32 + OF((casio_uint32_t casio__x)); +CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_htole32 + OF((casio_uint32_t casio__x)); # if defined(__APPLE__) # include diff --git a/include/libcasio/cdefs/integers.h b/include/libcasio/cdefs/integers.h index 7c1b87f..f0f5447 100644 --- a/include/libcasio/cdefs/integers.h +++ b/include/libcasio/cdefs/integers.h @@ -18,7 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_CDEFS_INTEGERS_H # define LIBCASIO_CDEFS_INTEGERS_H 1 -# include +# include "../cdefs.h" CASIO_BEGIN_NAMESPACE # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L diff --git a/include/libcasio/date.h b/include/libcasio/date.h index d350747..c8db4b2 100644 --- a/include/libcasio/date.h +++ b/include/libcasio/date.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_DATE_H # define LIBCASIO_DATE_H -# include -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE /* CASIO's dates look like 'YYYY.MMDD.HHmm', where 'YYYY' is the major, @@ -27,10 +26,12 @@ CASIO_BEGIN_NAMESPACE * minutes. The date is considered UTC. */ CASIO_BEGIN_DECLS -extern int casio_decode_date OF((time_t *casio__date, - const char *casio__raw)); -extern int casio_encode_date OF((char *casio__raw, - const time_t *casio__date)); + +CASIO_EXTERN int CASIO_EXPORT casio_decode_date + OF((time_t *casio__date, const char *casio__raw)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_date + OF((char *casio__raw, const time_t *casio__date)); + CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/encoding.h b/include/libcasio/encoding.h index 4e5bc62..119b67c 100644 --- a/include/libcasio/encoding.h +++ b/include/libcasio/encoding.h @@ -18,15 +18,17 @@ * ************************************************************************* */ #ifndef LIBCASIO_ENCODING_H # define LIBCASIO_ENCODING_H -# include +# include "cdefs.h" typedef int casio_encode_string_t OF((void *casio__dest, const void *casio__data, size_t *casio__size)); -extern int casio_register_conv OF((const char *casio__to, - const char *casio__from, casio_encode_t *casio__encode_from)); +CASIO_EXTERN int CASIO_EXPORT casio_register_conv + OF((const char *casio__to, const char *casio__from, + casio_encode_t *casio__encode_from)); -extern int casio_encode_string OF((void *casio__dest, const void *casio__data, - size_t *casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_string + OF((void *casio__dest, const void *casio__data, + size_t *casio__size)); #endif /* LIBCASIO_ENCODING_H */ diff --git a/include/libcasio/error.h b/include/libcasio/error.h index d0a38a8..b3ad16b 100644 --- a/include/libcasio/error.h +++ b/include/libcasio/error.h @@ -18,7 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_ERROR_H # define LIBCASIO_ERROR_H -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE /* ************************************************************************* */ @@ -84,10 +84,13 @@ typedef enum casio_error_e { } casio_error_t; /* Get a string describing the error. */ -extern const char *casio_error_strings[]; +CASIO_EXTERN const char* CASIO_EXPORT casio_error_strings[]; +CASIO_EXTERN const char* CASIO_EXPORT casio_strerror + OF((int casio__error)); -# define casio_strerror(CASIO_N) casio_error_strings[(CASIO_N)] -# define casio_geterror(CASIO_N) casio_error_strings[(CASIO_N)] +# ifndef LIBCASIO_NO_STRERROR +# define casio_strerror(CASIO_N) casio_error_strings[(CASIO_N)] +# endif CASIO_END_NAMESPACE #endif /* LIBCASIO_ERROR_H */ diff --git a/include/libcasio/file.h b/include/libcasio/file.h index c8ad891..8ce1bda 100644 --- a/include/libcasio/file.h +++ b/include/libcasio/file.h @@ -18,9 +18,10 @@ * ************************************************************************* */ #ifndef LIBCASIO_FILE_H # define LIBCASIO_FILE_H -# include -# include -# include +# include "cdefs.h" +# include "mcsfile.h" +# include "version.h" +# include "date.h" /* ************************************************************************* */ /* Description */ @@ -94,38 +95,47 @@ typedef struct casio_file_s { /* ************************************************************************* */ /* Make a file. */ -extern int casio_make_picture OF((casio_file_t **casio__handle, - unsigned int casio__width, unsigned int casio__height)); -extern int casio_make_mcs OF((casio_file_t **casio__handle, - int casio__count)); -extern int casio_make_fkey OF((casio_file_t **casio__handle, - casio_filefor_t casio__for, int casio__count)); -extern int casio_make_lang OF((casio_file_t **casio__handle, - casio_filefor_t casio__for, int casio__count)); -extern int casio_make_addin OF((casio_file_t **casio__handle, - casio_filefor_t casio__for, size_t casio__size, - const char *casio__name, const char *casio__internal, - const casio_version_t *casio__version, const time_t *casio__created)); +CASIO_EXTERN int CASIO_EXPORT casio_make_picture + OF((casio_file_t **casio__handle, + unsigned int casio__width, unsigned int casio__height)); +CASIO_EXTERN int CASIO_EXPORT casio_make_mcs + OF((casio_file_t **casio__handle, int casio__count)); +CASIO_EXTERN int CASIO_EXPORT casio_make_fkey + OF((casio_file_t **casio__handle, + casio_filefor_t casio__for, int casio__count)); +CASIO_EXTERN int CASIO_EXPORT casio_make_lang + OF((casio_file_t **casio__handle, + casio_filefor_t casio__for, int casio__count)); +CASIO_EXTERN int CASIO_EXPORT casio_make_addin + OF((casio_file_t **casio__handle, + casio_filefor_t casio__for, size_t casio__size, + const char *casio__name, const char *casio__internal, + const casio_version_t *casio__version, const time_t *casio__created)); /* Manage an MCS archive. */ -extern int casio_mcs_insert OF((casio_file_t *handle, casio_mcsfile_t **tofile, - const casio_mcshead_t *head)); -extern int casio_mcs_sort OF((casio_file_t *handle)); +CASIO_EXTERN int CASIO_EXPORT casio_mcs_insert + OF((casio_file_t *handle, casio_mcsfile_t **tofile, + const casio_mcshead_t *head)); +CASIO_EXTERN int CASIO_EXPORT casio_mcs_sort + OF((casio_file_t *handle)); /* Free a file. */ -extern void casio_free_file OF((casio_file_t *casio__handle)); +CASIO_EXTERN void CASIO_EXPORT casio_free_file + OF((casio_file_t *casio__handle)); /* Decode a file. */ -extern int casio_decode OF((casio_file_t **casio__handle, - const char *casio__path, casio_stream_t *casio__buffer, - casio_filetype_t casio__expected_types)); +CASIO_EXTERN int CASIO_EXPORT casio_decode + OF((casio_file_t **casio__handle, + const char *casio__path, casio_stream_t *casio__buffer, + casio_filetype_t casio__expected_types)); /* Open and decode a file. */ -extern int casio_open_file OF((casio_file_t **casio__handle, - const char *casio__path, casio_filetype_t casio__expected_types)); +CASIO_EXTERN int CASIO_EXPORT casio_open_file + OF((casio_file_t **casio__handle, + const char *casio__path, casio_filetype_t casio__expected_types)); #endif /* LIBCASIO_FILE_H */ diff --git a/include/libcasio/format.h b/include/libcasio/format.h index e60ef15..5049626 100644 --- a/include/libcasio/format.h +++ b/include/libcasio/format.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_H # define LIBCASIO_FORMAT_H -# include -# include +# include "cdefs.h" /* Welcome on this new episode of the Monster Circus show! Today we'll present * to you the different formats surrounding CASIO calculators: open or closed, @@ -38,7 +37,7 @@ * * You can find its description in the following header: */ -# include +# include "format/cas.h" /* ************************************************************************* */ /* The GraphCard (GRC) format */ /* ************************************************************************* */ @@ -66,7 +65,9 @@ /* Followed by loads of zero, then, the content. The description of the rest * of the format is described in this header: */ -/*# include -- TODO */ +# if 0 +# include "format/fxi.h" -- TODO */ +# endif /* ************************************************************************* */ /* The Casemul format */ /* ************************************************************************* */ @@ -84,7 +85,7 @@ /* Discover the rest in its dedicated header: */ -# include +# include "format/casemul.h" /* ************************************************************************* */ /* The G1S format */ /* ************************************************************************* */ @@ -92,7 +93,7 @@ * It won't work with fx-CP or fx-CG calculators, as the storage memory * has changed since. */ -# include +# include "format/storage.h" /* ************************************************************************* */ /* The standard format */ /* ************************************************************************* */ @@ -105,5 +106,5 @@ * It doesn't have one single magic string, but a few, although the standard * header has the same format, so we consider it as the same format. */ -# include +# include "format/std.h" #endif /* LIBCASIO_FORMAT_H */ diff --git a/include/libcasio/format/cas.h b/include/libcasio/format/cas.h index 6426443..cd16c34 100644 --- a/include/libcasio/format/cas.h +++ b/include/libcasio/format/cas.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_H # define LIBCASIO_FORMAT_CAS_H -# include -# include +# include "../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE @@ -231,10 +230,10 @@ typedef struct casio_cas100info_s { CASIO_END_NAMESPACE # pragma pack() -# include /* programs, f-mem */ -# include /* list, matrix, variable */ -# include -# include -# include -# include +# include "cas/program.h" /* programs, f-mem */ +# include "cas/cell.h" /* lists, matrixes, variables */ +# include "cas/backup.h" +# include "cas/picture.h" +# include "cas/graph.h" +# include "cas/gmem.h" #endif /* LIBCASIO_FORMAT_CAS_H */ diff --git a/include/libcasio/format/cas/backup.h b/include/libcasio/format/cas/backup.h index 4163b90..00d3d34 100644 --- a/include/libcasio/format/cas/backup.h +++ b/include/libcasio/format/cas/backup.h @@ -18,6 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_BACKUP_H # define LIBCASIO_FORMAT_CAS_BACKUP_H +# include "../../cdefs.h" /* Backups are raw backups from the calculator. * diff --git a/include/libcasio/format/cas/cell.h b/include/libcasio/format/cas/cell.h index f47c18f..ef71376 100644 --- a/include/libcasio/format/cas/cell.h +++ b/include/libcasio/format/cas/cell.h @@ -18,6 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_CELL_H # define LIBCASIO_FORMAT_CAS_CELL_H +# include "../../cdefs.h" /* Lists, matrixes and variables are sent/stored the same way. * Variables are either 1*1 matrixes, or 0*0 matrixes if unused. diff --git a/include/libcasio/format/cas/gmem.h b/include/libcasio/format/cas/gmem.h index 32682a9..fc99253 100644 --- a/include/libcasio/format/cas/gmem.h +++ b/include/libcasio/format/cas/gmem.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_GMEM_H # define LIBCASIO_FORMAT_CAS_GMEM_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/cas/graph.h b/include/libcasio/format/cas/graph.h index 447ed9e..8a0a538 100644 --- a/include/libcasio/format/cas/graph.h +++ b/include/libcasio/format/cas/graph.h @@ -18,6 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_GRAPH_H # define LIBCASIO_FORMAT_CAS_GRAPH_H +# include "../../cdefs.h" /* This is the data type used for the expression of each function which can be * used to draw a graph. They are sent when you select 'Y=Data' in the diff --git a/include/libcasio/format/cas/picture.h b/include/libcasio/format/cas/picture.h index ef44526..6801cf2 100644 --- a/include/libcasio/format/cas/picture.h +++ b/include/libcasio/format/cas/picture.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_PICTURE_H # define LIBCASIO_FORMAT_CAS_PICTURE_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/cas/program.h b/include/libcasio/format/cas/program.h index ac421ca..27b341a 100644 --- a/include/libcasio/format/cas/program.h +++ b/include/libcasio/format/cas/program.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CAS_PROGRAM_H # define LIBCASIO_FORMAT_CAS_PROGRAM_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/casemul.h b/include/libcasio/format/casemul.h index 33582bc..fefc2d0 100644 --- a/include/libcasio/format/casemul.h +++ b/include/libcasio/format/casemul.h @@ -18,9 +18,8 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_CASEMUL_H # define LIBCASIO_FORMAT_CASEMUL_H -# include -# include -# include +# include "../cdefs.h" +# include "../number.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/fxi.h.draft b/include/libcasio/format/fxi.h.draft index bfd2263..438a94f 100644 --- a/include/libcasio/format/fxi.h.draft +++ b/include/libcasio/format/fxi.h.draft @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_FXI_H # define LIBCASIO_FORMAT_FXI_H -# include -# include +# include "../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/mcs/cells.h b/include/libcasio/format/mcs/cells.h index 9386681..aab59e9 100644 --- a/include/libcasio/format/mcs/cells.h +++ b/include/libcasio/format/mcs/cells.h @@ -18,9 +18,8 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_MCS_CELLS_H # define LIBCASIO_FORMAT_MCS_CELLS_H -# include -# include -# include +# include "../../cdefs.h" +# include "../../number.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/mcs/picture.h b/include/libcasio/format/mcs/picture.h index f784966..ad57a57 100644 --- a/include/libcasio/format/mcs/picture.h +++ b/include/libcasio/format/mcs/picture.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_MCS_PICTURE_H # define LIBCASIO_FORMAT_MCS_PICTURE_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/mcs/program.h b/include/libcasio/format/mcs/program.h index 2287ab2..b1d62c4 100644 --- a/include/libcasio/format/mcs/program.h +++ b/include/libcasio/format/mcs/program.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_MCS_PROGRAM_H # define LIBCASIO_FORMAT_MCS_PROGRAM_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/mcs/setup.h b/include/libcasio/format/mcs/setup.h index c55632f..53c22c6 100644 --- a/include/libcasio/format/mcs/setup.h +++ b/include/libcasio/format/mcs/setup.h @@ -18,9 +18,10 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_MCS_SETUP_H # define LIBCASIO_FORMAT_MCS_SETUP_H +# include "../../cdefs.h" /* Setup files have no headers, they are just a bunch of bytes you can copy. - * Legacy fx setup files have 100 entries (100 bytes), fx-CG setup files + * Legacy fx setup files have 0x64 (100) byte entries, fx-CG setup files * have twice as much (even though the first 100 entries have the same * signification in the two). * diff --git a/include/libcasio/format/mcs/spreadsheet.h b/include/libcasio/format/mcs/spreadsheet.h index 8b42d75..ad907c1 100644 --- a/include/libcasio/format/mcs/spreadsheet.h +++ b/include/libcasio/format/mcs/spreadsheet.h @@ -18,9 +18,8 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_MCS_SPREADSHEET_H # define LIBCASIO_FORMAT_MCS_SPREADSHEET_H -# include -# include -# include +# include "../../cdefs.h" +# include "../../number.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/std.h b/include/libcasio/format/std.h index 54c805b..afd75ff 100644 --- a/include/libcasio/format/std.h +++ b/include/libcasio/format/std.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_H # define LIBCASIO_FORMAT_STD_H -# include -# include +# include "../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE @@ -251,10 +250,10 @@ typedef struct casio_standard_picheader_s { CASIO_END_NAMESPACE # pragma pack() -# include -# include -# include -# include -# include -# include +# include "std/addin.h" +# include "std/eact.h" +# include "std/mcs.h" +# include "std/picture.h" +# include "std/lang.h" +# include "std/fkey.h" #endif /* LIBCASIO_FORMAT_STD_H */ diff --git a/include/libcasio/format/std/addin.h b/include/libcasio/format/std/addin.h index aaa5f4e..93c1856 100644 --- a/include/libcasio/format/std/addin.h +++ b/include/libcasio/format/std/addin.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_ADDIN_H # define LIBCASIO_FORMAT_STD_ADDIN_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/std/eact.h b/include/libcasio/format/std/eact.h index ab667b3..9cf854a 100644 --- a/include/libcasio/format/std/eact.h +++ b/include/libcasio/format/std/eact.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_EACT_H # define LIBCASIO_FORMAT_STD_EACT_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/std/fkey.h b/include/libcasio/format/std/fkey.h index 97eecc5..5fde382 100644 --- a/include/libcasio/format/std/fkey.h +++ b/include/libcasio/format/std/fkey.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_FKEY_H # define LIBCASIO_FORMAT_STD_FKEY_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/std/lang.h b/include/libcasio/format/std/lang.h index d11e9b8..88a7176 100644 --- a/include/libcasio/format/std/lang.h +++ b/include/libcasio/format/std/lang.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_LANG_H # define LIBCASIO_FORMAT_STD_LANG_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/std/mcs.h b/include/libcasio/format/std/mcs.h index a23c906..da8f834 100644 --- a/include/libcasio/format/std/mcs.h +++ b/include/libcasio/format/std/mcs.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_MCS_H # define LIBCASIO_FORMAT_STD_MCS_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE @@ -76,9 +75,9 @@ CASIO_END_NAMESPACE /* Beneath the file header, the file have different structures according to * their group name and MCS type. Pick your poison, once again! */ -# include -# include -# include -# include -# include +# include "../mcs/cells.h" +# include "../mcs/picture.h" +# include "../mcs/program.h" +# include "../mcs/setup.h" +# include "../mcs/spreadsheet.h" #endif /* LIBCASIO_FORMAT_STD_MCS_H */ diff --git a/include/libcasio/format/std/picture.h b/include/libcasio/format/std/picture.h index f8e2bc7..109c043 100644 --- a/include/libcasio/format/std/picture.h +++ b/include/libcasio/format/std/picture.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STD_PICTURE_H # define LIBCASIO_FORMAT_STD_PICTURE_H -# include -# include +# include "../../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE diff --git a/include/libcasio/format/storage.h b/include/libcasio/format/storage.h index 2472b2b..689a588 100644 --- a/include/libcasio/format/storage.h +++ b/include/libcasio/format/storage.h @@ -18,8 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_FORMAT_STORAGE_H # define LIBCASIO_FORMAT_STORAGE_H -# include -# include +# include "../cdefs.h" # pragma pack(1) CASIO_BEGIN_NAMESPACE @@ -109,7 +108,7 @@ typedef struct casio_storage_sector_s { /* ************************************************************************* */ /* After the sectors come the directories. * - * Their special nibble is either 0x05 if active or 0x00 if deleted. + * Their spec# include "../cdefs.h"ial nibble is either 0x05 if active or 0x00 if deleted. * Here is their subheader structure: */ typedef struct casio_storage_directory_s { diff --git a/include/libcasio/filesystem.h b/include/libcasio/fs.h similarity index 89% rename from include/libcasio/filesystem.h rename to include/libcasio/fs.h index 1fe6240..51f4c4e 100644 --- a/include/libcasio/filesystem.h +++ b/include/libcasio/fs.h @@ -1,5 +1,5 @@ /* **************************************************************************** - * libcasio/filesystem.h -- libcasio filesystems. + * libcasio/fs.h -- libcasio filesystems. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libcasio. @@ -16,10 +16,10 @@ * You should have received a copy of the GNU Lesser General Public License * along with libcasio; if not, see . * ************************************************************************* */ -#ifndef LIBCASIO_FILESYSTEM_H -# define LIBCASIO_FILESYSTEM_H -# include -# include +#ifndef LIBCASIO_FS_H +# define LIBCASIO_FS_H +# include "cdefs.h" +# include "stream.h" CASIO_BEGIN_NAMESPACE /* forward structure declarations (don't mind) */ @@ -92,13 +92,14 @@ struct casio_fsfuncs_s { /* ************************************************************************* */ CASIO_BEGIN_DECLS -extern int casio_open_fs OF((casio_filesystem_t **casio__fs, - void *casio__cookie, const char *casio__dirsep, - const casio_fsfuncs_t *casio__funcs)); +CASIO_EXTERN int CASIO_EXPORT casio_open_fs + OF((casio_filesystem_t **casio__fs, + void *casio__cookie, const char *casio__dirsep, + const casio_fsfuncs_t *casio__funcs)); -extern int casio_makedir OF((casio_filesystem_t *casio__fs, - const char *casio__path)); +CASIO_EXTERN int CASIO_EXPORT casio_makedir + OF((casio_filesystem_t *casio__fs, const char *casio__path)); CASIO_END_DECLS CASIO_END_NAMESPACE -#endif /* LIBCASIO_FILESYSTEM_H */ +#endif /* LIBCASIO_FS_H */ diff --git a/include/libcasio/link.h b/include/libcasio/link.h index ac28f2d..0a11e77 100644 --- a/include/libcasio/link.h +++ b/include/libcasio/link.h @@ -18,11 +18,11 @@ * ************************************************************************* */ #ifndef LIBCASIO_LINK_H # define LIBCASIO_LINK_H -# include -# include -# include -# include -# include +# include "cdefs.h" +# include "stream.h" +# include "fs.h" +# include "version.h" +# include "picture.h" CASIO_BEGIN_NAMESPACE /* ************************************************************************* */ @@ -109,24 +109,24 @@ typedef void casio_link_list_t OF((void *casio__cookie, CASIO_BEGIN_DECLS /* Cross-platform initialization. */ -extern int casio_open_usb OF((casio_link_t **casio__h, +CASIO_EXTERN int casio_open_usb OF((casio_link_t **casio__h, unsigned long casio__flags)); -extern int casio_open_com OF((casio_link_t **casio__h, +CASIO_EXTERN int casio_open_com OF((casio_link_t **casio__h, unsigned long casio__flags, const char *casio__path, const casio_streamattrs_t *casio__attributes)); /* Initialize a handle using a custom stream. */ -extern int casio_open_link OF((casio_link_t **casio__h, +CASIO_EXTERN int casio_open_link OF((casio_link_t **casio__h, unsigned long casio__flags, casio_stream_t *casio__stream, const casio_streamattrs_t *casio__attributes)); /* Get things. */ -extern const casio_link_info_t *casio_get_link_info OF(( +CASIO_EXTERN const casio_link_info_t *casio_get_link_info OF(( casio_link_t *casio__handle)); /* De-initialize. */ -extern void casio_close_link OF((casio_link_t *casio__h)); +CASIO_EXTERN void casio_close_link OF((casio_link_t *casio__h)); /* ************************************************************************* */ /* Run servers. */ /* ************************************************************************* */ @@ -135,49 +135,53 @@ extern void casio_close_link OF((casio_link_t *casio__h)); typedef int casio_seven_server_func_t OF((void *casio__cookie, casio_link_t *casio__handle)); -extern int casio_seven_serve OF((casio_link_t *casio__handle, +CASIO_EXTERN int casio_seven_serve OF((casio_link_t *casio__handle, casio_seven_server_func_t **casio__callbacks, void *casio__cookie)); /* ************************************************************************* */ /* General-purpose link operations */ /* ************************************************************************* */ /* Set the link settings. */ -extern int casio_setlink OF((casio_link_t *casio__handle, - const casio_streamattrs_t *casio__attrs)); +CASIO_EXTERN int CASIO_EXPORT casio_setlink + OF((casio_link_t *casio__handle, const casio_streamattrs_t *casio__attrs)); /* Set up a screen streaming receiver. */ -extern int casio_getscreen OF((casio_link_t *casio__handle, - casio_link_screen_t *casio__callback, void *casio__scookie)); +CASIO_EXTERN int CASIO_EXPORT casio_getscreen + OF((casio_link_t *casio__handle, + casio_link_screen_t *casio__callback, void *casio__scookie)); /* Backup the ROM. */ -extern int casio_backup_rom OF((casio_link_t *casio__handle, - casio_stream_t *casio__buffer, casio_link_progress_t *casio__progress, - void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_backup_rom + OF((casio_link_t *casio__handle, + casio_stream_t *casio__buffer, casio_link_progress_t *casio__progress, + void *casio__pcookie)); # ifndef LIBCASIO_DISABLED_FILE -extern int casio_backup_rom_file OF((casio_link_t *casio__handle, - FILE *casio__file, casio_link_progress_t *casio__progress, - void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_backup_rom_file + OF((casio_link_t *casio__handle, + FILE *casio__file, casio_link_progress_t *casio__progress, + void *casio__pcookie)); # endif /* Upload and run an executable. */ -extern int casio_upload_and_run OF((casio_link_t *casio__handle, - casio_stream_t *casio__buffer, casio_off_t casio__size, - unsigned long casio__loadaddr, unsigned long casio__straddr, - casio_link_progress_t *casio__disp, void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_upload_and_run + OF((casio_link_t *casio__handle, + casio_stream_t *casio__buffer, casio_off_t casio__size, + unsigned long casio__loadaddr, unsigned long casio__straddr, + casio_link_progress_t *casio__disp, void *casio__pcookie)); # ifndef LIBCASIO_DISABLED_FILE -extern int casio_upload_and_run_file OF(( - casio_link_t *casio__handle, FILE *casio__program, - unsigned long casio__loadaddr, unsigned long casio__straddr, - casio_link_progress_t *casio__disp, void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_upload_and_run_file + OF((casio_link_t *casio__handle, FILE *casio__program, + unsigned long casio__loadaddr, unsigned long casio__straddr, + casio_link_progress_t *casio__disp, void *casio__pcookie)); # endif CASIO_END_DECLS CASIO_END_NAMESPACE -# include -# include +# include "protocol/legacy.h" +# include "protocol/seven.h" #endif /* LIBCASIO_LINK_H */ diff --git a/include/libcasio/log.h b/include/libcasio/log.h index b95c7d1..37459bb 100644 --- a/include/libcasio/log.h +++ b/include/libcasio/log.h @@ -18,7 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_LOG_H # define LIBCASIO_LOG_H -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE /* Log levels -- prefer the functions to these values, that can change! */ @@ -32,22 +32,24 @@ typedef int casio_loglevel_t; CASIO_BEGIN_DECLS /* Get and set the log level at runtime */ -extern void casio_setlog OF((casio_loglevel_t casio__level)); -extern casio_loglevel_t casio_getlog OF((void)); +CASIO_EXTERN void CASIO_EXPORT casio_setlog + OF((casio_loglevel_t casio__level)); +CASIO_EXTERN casio_loglevel_t CASIO_EXPORT casio_getlog + OF((void)); /* Get, set and list log level strings */ -extern const char *casio_loglevel_tostring OF(( - casio_loglevel_t casio__level)); -extern casio_loglevel_t casio_loglevel_fromstring OF(( - const char *casio__string)); +CASIO_EXTERN const char* CASIO_EXPORT casio_loglevel_tostring + OF((casio_loglevel_t casio__level)); +CASIO_EXTERN casio_loglevel_t CASIO_EXPORT casio_loglevel_fromstring + OF((const char *casio__string)); /* List log levels */ typedef void casio_log_list_t OF((void *casio__cookie, const char *casio__str)); -extern void casio_listlog OF((casio_log_list_t *casio__callback, - void *casio__cookie)); +CASIO_EXTERN void CASIO_EXPORT casio_listlog + OF((casio_log_list_t *casio__callback, void *casio__cookie)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/mcs.h b/include/libcasio/mcs.h new file mode 100644 index 0000000..351e3d4 --- /dev/null +++ b/include/libcasio/mcs.h @@ -0,0 +1,26 @@ +/* **************************************************************************** + * libcasio/mcs.h -- libcasio RAM filesystem. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of libcasio. + * libcasio is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcasio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libcasio; if not, see . + * ************************************************************************* */ +#ifndef LIBCASIO_MCS_H +# define LIBCASIO_MCS_H +# include "cdefs.h" +# include "mcsfile.h" + +/* TODO: something similar to `fs.h`, but for MCS. */ + +#endif /* LIBCASIO_MCS_H */ diff --git a/include/libcasio/mcsfile.h b/include/libcasio/mcsfile.h index 745c08e..98e6bb8 100644 --- a/include/libcasio/mcsfile.h +++ b/include/libcasio/mcsfile.h @@ -18,9 +18,10 @@ * ************************************************************************* */ #ifndef LIBCASIO_MCSFILE_H # define LIBCASIO_MCSFILE_H -# include -# include -# include +# include "cdefs.h" +# include "number.h" +# include "picture.h" + # define casio_theta 27 # define casio_r 28 # define casio_ans 29 @@ -279,47 +280,55 @@ typedef struct casio_mcsfile_s { CASIO_BEGIN_DECLS /* Manage a main memory file from a head, and free a main memory file. */ -extern int casio_make_mcsfile OF((casio_mcsfile_t **casio__handle, - const casio_mcshead_t *casio__head)); -extern void casio_free_mcsfile OF((casio_mcsfile_t *casio__handle)); +CASIO_EXTERN int CASIO_EXPORT casio_make_mcsfile + OF((casio_mcsfile_t **casio__handle, const casio_mcshead_t *casio__head)); +CASIO_EXTERN void CASIO_EXPORT casio_free_mcsfile + OF((casio_mcsfile_t *casio__handle)); /* Decode and encode an MCS file from an MCS archive. */ -extern int casio_decode_mcsfile_head OF((casio_mcshead_t *casio__head, - int casio__raw_type, const unsigned char *casio__groupname, - const unsigned char *casio__dirname, const unsigned char *casio__filename, - unsigned long filesize)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_mcsfile_head + OF((casio_mcshead_t *casio__head, int casio__raw_type, + const unsigned char *casio__groupname, + const unsigned char *casio__dirname, + const unsigned char *casio__filename, + unsigned long casio__filesize)); -extern int casio_decode_mcsfile OF((casio_mcsfile_t **casio__handle, - const casio_mcshead_t *casio__head, casio_stream_t *casio__buffer)); -extern int casio_decode_mcsfile_data OF((casio_mcsfile_t **casio__handle, - const casio_mcshead_t *casio__head, - const void *casio__data, size_t casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_mcsfile + OF((casio_mcsfile_t **casio__handle, + const casio_mcshead_t *casio__head, + casio_stream_t *casio__buffer)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_mcsfile_data + OF((casio_mcsfile_t **casio__handle, + const casio_mcshead_t *casio__head, + const void *casio__data, size_t casio__size)); -extern int casio_encode_mcsfile OF((casio_mcsfile_t *casio__handle, - casio_stream_t *casio__buffer)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_mcsfile + OF((casio_mcsfile_t *casio__handle, casio_stream_t *casio__buffer)); /* Decode and encode an MCS file from a CASIOLINK environment. */ -extern int casio_decode_casfile_head OF((casio_mcshead_t *casio__head, - casio_stream_t *casio__buffer)); -extern int casio_decode_casfile_part OF((casio_mcsfile_t *casio__file, - casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_casfile_head + OF((casio_mcshead_t *casio__head, casio_stream_t *casio__buffer)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_casfile_part + OF((casio_mcsfile_t *casio__file, casio_stream_t *casio__stream)); -extern int casio_encode_casfile_head OF((casio_mcshead_t *casio__head, - casio_stream_t *casio__buffer)); -extern int casio_encode_casfile_part OF((casio_mcsfile_t *casio__file, - casio_stream_t *casio__buffer)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_casfile_head + OF((casio_mcshead_t *casio__head, casio_stream_t *casio__buffer)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_casfile_part + OF((casio_mcsfile_t *casio__file, casio_stream_t *casio__buffer)); /* Correct a head (add raw data). */ -extern int casio_correct_mcsfile_head OF((casio_mcshead_t *casio__head)); -extern int casio_correct_casfile_head OF((casio_mcshead_t *casio__head)); +CASIO_EXTERN int CASIO_EXPORT casio_correct_mcsfile_head + OF((casio_mcshead_t *casio__head)); +CASIO_EXTERN int CASIO_EXPORT casio_correct_casfile_head + OF((casio_mcshead_t *casio__head)); /* Compare MCS files (for ordering). */ -extern int casio_compare_mcsfiles OF((const casio_mcsfile_t *first, - const casio_mcsfile_t *second)); +CASIO_EXTERN int CASIO_EXPORT casio_compare_mcsfiles + OF((const casio_mcsfile_t *first, const casio_mcsfile_t *second)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/number.h b/include/libcasio/number.h index 9458b54..45b2ea1 100644 --- a/include/libcasio/number.h +++ b/include/libcasio/number.h @@ -24,8 +24,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_NUMBER_H # define LIBCASIO_NUMBER_H -# include -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE # define CASIO_BCD_MANTISSA_SIZE 16 @@ -39,7 +38,6 @@ CASIO_BEGIN_NAMESPACE # define CASIO_BCD_GOODBUFSIZE \ (2 + CASIO_BCD_MANTISSA_SIZE + 4 + 2 + 1) - /* ************************************************************************* */ /* Main type */ /* ************************************************************************* */ @@ -117,25 +115,26 @@ typedef struct casio_mcsbcd_s { CASIO_BEGIN_DECLS /* From and to MCS BCD. */ -extern int casio_bcd_frommcs OF((casio_bcd_t *casio__bcd, - const casio_mcsbcd_t *casio__raw)); -extern int casio_bcd_tomcs OF((casio_mcsbcd_t *casio__raw, - const casio_bcd_t *casio__bcd)); +CASIO_EXTERN int CASIO_EXPORT casio_bcd_frommcs + OF((casio_bcd_t *casio__bcd, const casio_mcsbcd_t *casio__raw)); +CASIO_EXTERN int CASIO_EXPORT casio_bcd_tomcs + OF((casio_mcsbcd_t *casio__raw, const casio_bcd_t *casio__bcd)); /* From and to CAS BCD. */ -extern int casio_bcd_fromcas OF((casio_bcd_t *casio__bcd, - const casio_casbcd_t *casio__raw)); -extern int casio_bcd_tocas OF((casio_casbcd_t *casio__raw, - const casio_bcd_t *casio__bcd)); +CASIO_EXTERN int CASIO_EXPORT casio_bcd_fromcas + OF((casio_bcd_t *casio__bcd, const casio_casbcd_t *casio__raw)); +CASIO_EXTERN int CASIO_EXPORT casio_bcd_tocas + OF((casio_casbcd_t *casio__raw, const casio_bcd_t *casio__bcd)); /* From and to C-double */ -extern void casio_bcd_fromdouble OF((casio_bcd_t *casio__bcd, - double casio__raw)); -extern double casio_bcd_todouble OF((const casio_bcd_t *casio__bcd)); +CASIO_EXTERN void CASIO_EXPORT casio_bcd_fromdouble + OF((casio_bcd_t *casio__bcd, double casio__raw)); +CASIO_EXTERN double CASIO_EXPORT casio_bcd_todouble + OF((const casio_bcd_t *casio__bcd)); /* Make a string out of a BCD */ -extern size_t casio_bcdtoa OF((char *casio__buf, size_t casio__len, - const casio_bcd_t *casio__bcd)); +CASIO_EXTERN size_t CASIO_EXPORT casio_bcdtoa + OF((char *casio__buf, size_t casio__len, const casio_bcd_t *casio__bcd)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/picture.h b/include/libcasio/picture.h index a8c280e..0db47bf 100644 --- a/include/libcasio/picture.h +++ b/include/libcasio/picture.h @@ -18,7 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_PICTURE_H # define LIBCASIO_PICTURE_H -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE /* This file describes the picture formats CASIO has used for various purposes @@ -38,7 +38,7 @@ typedef casio_uint32_t casio_pixel_t; * Do not use the format described above other than to define your own * formats, as it might change! */ -typedef enum casio_pictureformat_s { +typedef enum casio_pictureformat_e { /* ************************************************************************* */ /* Monochrome pictures with fill bits */ /* ************************************************************************* */ @@ -170,17 +170,20 @@ typedef enum casio_pictureformat_s { CASIO_BEGIN_DECLS -extern size_t casio_get_picture_size OF((casio_pixel_t **casio__pixels, - casio_pictureformat_t casio__format, - unsigned int casio__width, unsigned int casio__height)); +CASIO_EXTERN size_t CASIO_EXPORT casio_get_picture_size + OF((casio_pixel_t **casio__pixels, + casio_pictureformat_t casio__format, + unsigned int casio__width, unsigned int casio__height)); -extern int casio_decode_picture OF((casio_pixel_t **casio__pixels, - const void *casio__raw, casio_pictureformat_t casio__format, - unsigned int casio__width, unsigned casio__height)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_picture + OF((casio_pixel_t **casio__pixels, + const void *casio__raw, casio_pictureformat_t casio__format, + unsigned int casio__width, unsigned casio__height)); -extern int casio_encode_picture OF((void *casio__raw, - const casio_pixel_t **casio__pixels, casio_pictureformat_t casio__format, - unsigned int casio__width, unsigned casio__height)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_picture + OF((void *casio__raw, const casio_pixel_t **casio__pixels, + casio_pictureformat_t casio__format, + unsigned int casio__width, unsigned casio__height)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/protocol/legacy.h b/include/libcasio/protocol/legacy.h index 7511d6e..c1d2e8a 100644 --- a/include/libcasio/protocol/legacy.h +++ b/include/libcasio/protocol/legacy.h @@ -23,7 +23,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_PROTOCOL_LEGACY_H # define LIBCASIO_PROTOCOL_LEGACY_H -# include +# include "../cdefs.h" /* In these protocols, there are two types of packets: one-byte packets, * and multi-byte packets (headers, headers data, data). diff --git a/include/libcasio/protocol/seven.h b/include/libcasio/protocol/seven.h index 8c267f8..5076797 100644 --- a/include/libcasio/protocol/seven.h +++ b/include/libcasio/protocol/seven.h @@ -18,9 +18,9 @@ * ************************************************************************* */ #ifndef LIBCASIO_PROTOCOL_SEVEN_H # define LIBCASIO_PROTOCOL_SEVEN_H -# include -# include -# include +# include "../cdefs.h" +# include "../link.h" +# include "typz.h" CASIO_BEGIN_NAMESPACE /* ************************************************************************* */ @@ -178,8 +178,8 @@ CASIO_BEGIN_DECLS * to checksums; for example, in the screenstreaming packet flow, where the * receiver should not send anything. */ -extern int casio_seven_receive OF((casio_link_t *casio__handle, - int casio__care_about_checksums)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_receive + OF((casio_link_t *casio__handle, int casio__care_about_checksums)); /* These are the base functions to send a packet. * Unless `resp` is zero, it will also get the response to the packet, @@ -187,13 +187,15 @@ extern int casio_seven_receive OF((casio_link_t *casio__handle, * * You shouldn't use them directly to send a packet, but here they are: */ -extern int casio_seven_send_basic OF((casio_link_t *casio__handle, - casio_seven_type_t casio__type, unsigned int casio__subtype, - int casio__resp)); -extern int casio_seven_send_ext OF((casio_link_t *casio__handle, - casio_seven_type_t casio__type, unsigned int casio__subtype, - const void *casio__data, unsigned int casio__size, - int casio__resp)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_basic + OF((casio_link_t *casio__handle, + casio_seven_type_t casio__type, unsigned int casio__subtype, + int casio__resp)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_ext + OF((casio_link_t *casio__handle, + casio_seven_type_t casio__type, unsigned int casio__subtype, + const void *casio__data, unsigned int casio__size, + int casio__resp)); /* Send checks. * Initial checks are useful to check if there is another device speaking @@ -219,8 +221,8 @@ extern int casio_seven_send_ext OF((casio_link_t *casio__handle, 0x00, (CASIO__R))) # define casio_seven_confirm_ow(CASIO__H) \ (casio_seven_send_basic((CASIO__H), casio_seven_type_ack, 0x01, 1)) -extern int casio_seven_send_eack OF((casio_link_t *casio__handle, - casio_link_info_t *casio__info)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_eack + OF((casio_link_t *casio__handle, casio_link_info_t *casio__info)); /* Send negative acknowledgements (NAK packets). * These are used to report errors. */ @@ -250,14 +252,16 @@ extern int casio_seven_send_eack OF((casio_link_t *casio__handle, * There are specific command-sending in `libcasio/protocol/seven/commands.h`, * so if you're using a classical command, you should use them instead. */ -extern int casio_seven_send_cmd OF((casio_link_t *casio__handle, - unsigned int casio__subtype)); -extern int casio_seven_send_cmd_data OF((casio_link_t *casio__handle, - unsigned int casio__subtype, int casio__overwrite, - unsigned int casio__datatype, unsigned long casio__filesize, - const char *casio__arg0, const char *casio__arg1, - const char *casio__arg2, const char *casio__arg3, - const char *casio__arg4, const char *casio__arg5)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_cmd + OF((casio_link_t *casio__handle, + unsigned int casio__subtype)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_cmd_data + OF((casio_link_t *casio__handle, + unsigned int casio__subtype, int casio__overwrite, + unsigned int casio__datatype, unsigned long casio__filesize, + const char *casio__arg0, const char *casio__arg1, + const char *casio__arg2, const char *casio__arg3, + const char *casio__arg4, const char *casio__arg5)); CASIO_END_DECLS CASIO_END_NAMESPACE @@ -279,10 +283,10 @@ typedef struct casio_seven_env_s { CASIO_BEGIN_DECLS /* And here is everything you need lol. */ -extern int casio_seven_getenv OF((casio_seven_env_t *casio__env, - const char *casio__id)); -extern int casio_seven_command_is_supported OF(( - const casio_seven_env_t *casio__env, unsigned int casio__code)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_getenv + OF((casio_seven_env_t *casio__env, const char *casio__id)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_command_is_supported + OF((const casio_seven_env_t *casio__env, unsigned int casio__code)); CASIO_END_DECLS /* ************************************************************************* */ @@ -364,8 +368,10 @@ CASIO_BEGIN_DECLS * you shouldn't use them unless you know what you're doing * (and you probably don't if you actually want to use them). */ -extern int casio_seven_start OF((casio_link_t *casio__handle)); -extern int casio_seven_end OF((casio_link_t *casio__handle)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_start + OF((casio_link_t *casio__handle)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_end + OF((casio_link_t *casio__handle)); /* Send and receive data, using buffers. * This will automatically divide your data into packets, or make up the @@ -377,36 +383,41 @@ extern int casio_seven_end OF((casio_link_t *casio__handle)); * It is advised not to use it for receiving data, or for sensitive * data. */ -extern int casio_seven_send_buffer OF((casio_link_t *casio__handle, - casio_stream_t *casio__stream, casio_off_t casio__size, - int casio__shift, casio_link_progress_t *casio__progress, - void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_buffer + OF((casio_link_t *casio__handle, + casio_stream_t *casio__stream, casio_off_t casio__size, + int casio__shift, casio_link_progress_t *casio__progress, + void *casio__pcookie)); -extern int casio_seven_get_buffer OF((casio_link_t *casio__handle, - casio_stream_t *casio__stream, casio_off_t casio__size, - int casio__shift, casio_link_progress_t *casio__progress, - void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_get_buffer + OF((casio_link_t *casio__handle, + casio_stream_t *casio__stream, casio_off_t casio__size, + int casio__shift, casio_link_progress_t *casio__progress, + void *casio__pcookie)); /* Send and receive data, using memory areas. * Beyond the buffer/memory difference, those and the previous ones are * basically the same thing. */ -extern int casio_seven_send_data OF((casio_link_t *casio__handle, - const void *casio__buf, casio_off_t casio__size, - int casio__shift, casio_link_progress_t *casio__progress, - void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_data + OF((casio_link_t *casio__handle, + const void *casio__buf, casio_off_t casio__size, + int casio__shift, casio_link_progress_t *casio__progress, + void *casio__pcookie)); -extern int casio_seven_get_data OF((casio_link_t *casio__handle, - void *casio__buf, casio_off_t casio__size, - int casio__shift, casio_link_progress_t *casio__progress, - void *casio__pcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_get_data + OF((casio_link_t *casio__handle, + void *casio__buf, casio_off_t casio__size, + int casio__shift, casio_link_progress_t *casio__progress, + void *casio__pcookie)); /* Send and receive data, using a stream. * This is practicle when you want to encode and write on the fly. */ -extern int casio_seven_open_data_stream OF((casio_stream_t **casio__stream, - casio_link_t *casio__link, casio_off_t casio__size, - casio_link_progress_t *casio__disp, void *casio__dcookie)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_open_data_stream + OF((casio_stream_t **casio__stream, + casio_link_t *casio__link, casio_off_t casio__size, + casio_link_progress_t *casio__disp, void *casio__dcookie)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/protocol/seven/commands.h b/include/libcasio/protocol/seven/commands.h index bc7ab9a..dae5ff5 100644 --- a/include/libcasio/protocol/seven/commands.h +++ b/include/libcasio/protocol/seven/commands.h @@ -16,21 +16,19 @@ * You should have received a copy of the GNU Lesser General Public License * along with libcasio; if not, see . * ************************************************************************* */ -#ifndef LIBCASIO_PROTOCOL_SEVEN_H -# include -#endif #ifndef LIBCASIO_PROTOCOL_SEVEN_COMMANDS_H # define LIBCASIO_PROTOCOL_SEVEN_COMMANDS_H -# include +# include "../seven.h" +# include "../../mcsfile.h" CASIO_BEGIN_NAMESPACE CASIO_BEGIN_DECLS /* Utility for MCS commands */ -extern int casio_seven_send_typical_mcs_command OF(( - casio_link_t *casio__handle, - int casio__code, casio_mcshead_t *casio__head, - casio_mcsfile_t *casio__file, - int casio__ow)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_typical_mcs_command + OF((casio_link_t *casio__handle, + int casio__code, casio_mcshead_t *casio__head, + casio_mcsfile_t *casio__file, + int casio__ow)); /* size_t sz = casio__file ? get_the_file_size(casio__file) : 0; return (casio_seven_send_cmd_data(casio__handle, casio__code, casio__ow, @@ -50,9 +48,9 @@ extern int casio_seven_send_typical_mcs_command OF(( /* Set the link settings */ # define casio_seven_cmdsys_setlink 0x02 -extern int casio_seven_send_cmdsys_setlink OF(( - casio_link_t *casio__handle, - int casio__baudrate, int casio__parity, int casio__stopbits)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_cmdsys_setlink + OF((casio_link_t *casio__handle, + int casio__baudrate, int casio__parity, int casio__stopbits)); /* ************************************************************************* */ /* Backup commands */ /* ************************************************************************* */ @@ -210,10 +208,10 @@ extern int casio_seven_send_cmdsys_setlink OF(( /* ************************************************************************* */ /* Upload and run */ # define casio_seven_cmdosu_upandrun 0x56 -extern int casio_seven_send_cmdosu_upandrun OF(( - casio_link_t *casio__handle, - unsigned long casio__upsize, unsigned long casio__loadaddr, - unsigned long casio__straddr)); +CASIO_EXTERN int CASIO_EXPORT casio_seven_send_cmdosu_upandrun + OF((casio_link_t *casio__handle, + unsigned long casio__upsize, unsigned long casio__loadaddr, + unsigned long casio__straddr)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/include/libcasio/protocol/typz.h b/include/libcasio/protocol/typz.h index bfc602f..cfeb547 100644 --- a/include/libcasio/protocol/typz.h +++ b/include/libcasio/protocol/typz.h @@ -18,7 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_PROTOCOL_TYPZ_H # define LIBCASIO_PROTOCOL_TYPZ_H -# include +# include "../cdefs.h" CASIO_BEGIN_NAMESPACE /* In both Protocol 7.00 and extended SCSI protocols, recent CASIO diff --git a/include/libcasio/stream.h b/include/libcasio/stream.h index 8bd5f43..803d368 100644 --- a/include/libcasio/stream.h +++ b/include/libcasio/stream.h @@ -26,8 +26,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_STREAM_H # define LIBCASIO_STREAM_H -# include -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE /* forward structure declarations (don't mind) */ @@ -263,91 +262,110 @@ struct casio_scsi_s { CASIO_BEGIN_DECLS /* Default stream serial settings utilities. */ -extern int casio_make_attrs OF((casio_streamattrs_t *casio__attrs, - const char *casio__raw)); +CASIO_EXTERN int CASIO_EXPORT casio_make_attrs + OF((casio_streamattrs_t *casio__attrs, const char *casio__raw)); /* List serial devices (platform agnostic). */ typedef void casio_list_com_t OF((void *casio__cookie, const char *casio__str)); -extern int casio_comlist OF((casio_list_com_t *casio__callback, - void *casio__cookie)); +CASIO_EXTERN int CASIO_EXPORT casio_comlist + OF((casio_list_com_t *casio__callback, void *casio__cookie)); /* Open and close a stream. */ -extern int casio_open OF((casio_stream_t **casio__stream, - casio_openmode_t mode, - casio_streamtype_t casio__type, void *casio__cookie, - const casio_streamfuncs_t *casio__callbacks)); -extern int casio_close OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_open + OF((casio_stream_t **casio__stream, casio_openmode_t mode, + casio_streamtype_t casio__type, void *casio__cookie, + const casio_streamfuncs_t *casio__callbacks)); +CASIO_EXTERN int CASIO_EXPORT casio_close + OF((casio_stream_t *casio__stream)); /* Get stream various data. */ -extern int casio_isreadable OF((casio_stream_t *casio__stream)); -extern int casio_iswritable OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_isreadable + OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_iswritable + OF((casio_stream_t *casio__stream)); # define casio_isreadable(CASIO__STREAM) \ (casio_get_openmode(CASIO__STREAM) & CASIO_OPENMODE_READ) # define casio_iswritable(CASIO__STREAM) \ (casio_get_openmode(CASIO__STREAM) & CASIO_OPENMODE_WRITE) -extern casio_streamtype_t casio_get_type OF((casio_stream_t *casio__stream)); -extern casio_openmode_t casio_get_openmode OF((casio_stream_t *casio__stream)); -extern void *casio_get_cookie OF((casio_stream_t *casio__stream)); -extern int casio_get_lasterr OF((casio_stream_t *casio__stream)); +CASIO_EXTERN casio_streamtype_t CASIO_EXPORT casio_get_type + OF((casio_stream_t *casio__stream)); +CASIO_EXTERN casio_openmode_t CASIO_EXPORT casio_get_openmode + OF((casio_stream_t *casio__stream)); +CASIO_EXTERN void* CASIO_EXPORT casio_get_cookie + OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_get_lasterr + OF((casio_stream_t *casio__stream)); /* Read and write data from and to a stream. */ -extern int casio_read OF((casio_stream_t *casio__stream, - void *casio__dest, size_t casio__size)); -extern int casio_write OF((casio_stream_t *casio__stream, - const void *casio__data, size_t casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_read + OF((casio_stream_t *casio__stream, + void *casio__dest, size_t casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_write + OF((casio_stream_t *casio__stream, + const void *casio__data, size_t casio__size)); -extern int casio_write_char OF((casio_stream_t *casio__stream, - int casio__char)); +CASIO_EXTERN int CASIO_EXPORT casio_write_char + OF((casio_stream_t *casio__stream, int casio__char)); /* Skip bytes from a stream. */ -extern int casio_skip OF((casio_stream_t *casio__stream, size_t casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_skip + OF((casio_stream_t *casio__stream, size_t casio__size)); /* Set and get the attributes of a stream. */ -extern int casio_init_attrs OF((casio_stream_t *stream)); -extern int casio_set_attrs OF((casio_stream_t *casio__stream, - const casio_streamattrs_t *casio__attrs)); -extern int casio_get_attrs OF((casio_stream_t *casio__stream, - casio_streamattrs_t *casio__attrs)); +CASIO_EXTERN int CASIO_EXPORT casio_init_attrs + OF((casio_stream_t *stream)); +CASIO_EXTERN int CASIO_EXPORT casio_set_attrs + OF((casio_stream_t *casio__stream, + const casio_streamattrs_t *casio__attrs)); +CASIO_EXTERN int CASIO_EXPORT casio_get_attrs + OF((casio_stream_t *casio__stream, casio_streamattrs_t *casio__attrs)); /* Set and get the timeouts of a stream. */ -extern int casio_init_timeouts OF((casio_stream_t *casio__stream)); -extern int casio_set_timeouts OF((casio_stream_t *casio__stream, - const casio_timeouts_t *casio__timeouts)); -extern int casio_get_timeouts OF((casio_stream_t *casio__stream, - casio_timeouts_t *casio__timeouts)); +CASIO_EXTERN int CASIO_EXPORT casio_init_timeouts + OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_set_timeouts + OF((casio_stream_t *casio__stream, + const casio_timeouts_t *casio__timeouts)); +CASIO_EXTERN int CASIO_EXPORT casio_get_timeouts + OF((casio_stream_t *casio__stream, casio_timeouts_t *casio__timeouts)); /* Move in a file. */ -extern int casio_seek OF((casio_stream_t *casio__stream, - casio_off_t casio__offset, casio_whence_t casio__whence)); -extern casio_off_t casio_tell OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_seek + OF((casio_stream_t *casio__stream, + casio_off_t casio__offset, casio_whence_t casio__whence)); +CASIO_EXTERN casio_off_t CASIO_EXPORT casio_tell + OF((casio_stream_t *casio__stream)); /* Make out the size of a file (shortcut for making out the size). */ -extern int casio_getsize OF((casio_stream_t *casio__stream, - casio_off_t *casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_getsize + OF((casio_stream_t *casio__stream, casio_off_t *casio__size)); /* Make a stream out of memory. */ -extern int casio_open_memory OF((casio_stream_t **casio__stream, - const void *casio__memory, size_t casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_open_memory + OF((casio_stream_t **casio__stream, + const void *casio__memory, size_t casio__size)); /* Make a stream out of another, with a limit (and empty it). */ -extern int casio_open_limited OF((casio_stream_t **casio__stream, - casio_stream_t *casio__original, size_t casio__size)); -extern int casio_empty_limited OF((casio_stream_t *casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_open_limited + OF((casio_stream_t **casio__stream, + casio_stream_t *casio__original, size_t casio__size)); +CASIO_EXTERN int CASIO_EXPORT casio_empty_limited + OF((casio_stream_t *casio__stream)); /* ************************************************************************* */ /* USB or serial stream opening management */ /* ************************************************************************* */ @@ -356,30 +374,33 @@ extern int casio_empty_limited OF((casio_stream_t *casio__stream)); * * Communication port listing. */ -typedef int casio_comlist_t OF((casio_list_com_t *casio__callback, +typedef int casio_comlist_t OF((casio_list_com_t *casio__callback, void *casio__cookie)); -extern int casio_add_default_comlist OF((casio_comlist_t *casio__function)); +CASIO_EXTERN int CASIO_EXPORT casio_add_default_comlist + OF((casio_comlist_t *casio__function)); /* Serial communication stream opening. */ -typedef int casio_opencomstream_t OF((casio_stream_t **casio__stream, +typedef int casio_opencomstream_t OF((casio_stream_t **casio__stream, const char *casio__path)); -extern int casio_open_com_stream OF((casio_stream_t **casio__stream, - const char *casio__path)); -extern int casio_add_default_com_stream OF(( - casio_opencomstream_t *casio__function)); +CASIO_EXTERN int CASIO_EXPORT casio_open_com_stream + OF((casio_stream_t **casio__stream, + const char *casio__path)); +CASIO_EXTERN int CASIO_EXPORT casio_add_default_com_stream + OF((casio_opencomstream_t *casio__function)); /* USB stream opening. */ -typedef int casio_openusbstream_t OF((casio_stream_t **casio__stream)); +typedef int casio_openusbstream_t OF((casio_stream_t **casio__stream)); -extern int casio_open_usb_stream OF((casio_stream_t **casio__stream)); -extern int casio_add_default_usb_stream OF(( - casio_openusbstream_t *casio__function)); +CASIO_EXTERN int CASIO_EXPORT casio_open_usb_stream + OF((casio_stream_t **casio__stream)); +CASIO_EXTERN int CASIO_EXPORT casio_add_default_usb_stream + OF((casio_openusbstream_t *casio__function)); CASIO_END_DECLS CASIO_END_NAMESPACE -# include +# include "builtin.h" #endif /* LIBCASIO_STREAM_H */ diff --git a/include/libcasio/utils.h b/include/libcasio/utils.h index 77276db..fdc319f 100644 --- a/include/libcasio/utils.h +++ b/include/libcasio/utils.h @@ -18,14 +18,17 @@ * ************************************************************************* */ #ifndef LIBCASIO_UTILS_H # define LIBCASIO_UTILS_H 1 +# include "cdefs.h" /* ASCII-HEX, ASCII-DEC utilities */ -extern void casio_putascii OF((unsigned char *casio__p, - unsigned long casio__i, int casio__n)); -extern unsigned long casio_getascii OF((const unsigned char *casio__p, - int casio__n)); +CASIO_EXTERN void CASIO_EXPORT casio_putascii + OF((unsigned char *casio__p, unsigned long casio__i, int casio__n)); +CASIO_EXTERN unsigned long CASIO_EXPORT casio_getascii + OF((const unsigned char *casio__p, int casio__n)); -extern unsigned long casio_getdec OF((unsigned long casio__h)); -extern unsigned long casio_gethex OF((unsigned long casio__d)); +CASIO_EXTERN unsigned long CASIO_EXPORT casio_getdec + OF((unsigned long casio__h)); +CASIO_EXTERN unsigned long CASIO_EXPORT casio_gethex + OF((unsigned long casio__d)); #endif /* LIBCASIO_UTILS_H */ diff --git a/include/libcasio/version.h b/include/libcasio/version.h index e3cad5c..1f21829 100644 --- a/include/libcasio/version.h +++ b/include/libcasio/version.h @@ -18,7 +18,7 @@ * ************************************************************************* */ #ifndef LIBCASIO_VERSION_H # define LIBCASIO_VERSION_H -# include +# include "cdefs.h" CASIO_BEGIN_NAMESPACE /* CASIO's versions look like 'MM.mm.ABCD', where 'MM' is the major, 'mm' is @@ -70,11 +70,12 @@ CASIO_BEGIN_DECLS * right format (for user interface, such as command-line argument checking), * and to decode/encode a version. */ -extern int casio_check_version OF((const char *casio__raw)); -extern int casio_decode_version OF((casio_version_t *casio__version, - const char *casio__raw)); -extern int casio_encode_version OF((char *casio__raw, - const casio_version_t *casio__version)); +CASIO_EXTERN int CASIO_EXPORT casio_check_version + OF((const char *casio__raw)); +CASIO_EXTERN int CASIO_EXPORT casio_decode_version + OF((casio_version_t *casio__version, const char *casio__raw)); +CASIO_EXTERN int CASIO_EXPORT casio_encode_version + OF((char *casio__raw, const casio_version_t *casio__version)); CASIO_END_DECLS CASIO_END_NAMESPACE diff --git a/src/errors.c b/src/errors.c index 9be6a5b..2db01d7 100644 --- a/src/errors.c +++ b/src/errors.c @@ -16,6 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with libcasio; if not, see . * ************************************************************************* */ +#define LIBCASIO_NO_STRERROR #include "internals.h" const char *casio_error_strings[128] = { @@ -69,3 +70,16 @@ const char *casio_error_strings[128] = { "invalid checksum", "was recognized but not one of the allowed file types." }; + +/** + * casio_strerror: + * Get the error string. + * + * @arg error the error code. + * @return the error string. + */ + +const char *casio_strerror(int error) +{ + return (casio_error_strings[error]); +} diff --git a/src/file/decode/std/mcs.c b/src/file/decode/std/mcs.c index 76dec8a..b17463b 100644 --- a/src/file/decode/std/mcs.c +++ b/src/file/decode/std/mcs.c @@ -63,9 +63,11 @@ int casio_decode_std_mcs(casio_file_t **h, casio_stream_t *buffer, /* foreach subpart */ for (i = 0; i < hd.casio_mcs_subheader_subcount; i++) { casio_mcs_fileheader_t fhd; + casio_uint32_t datalength; /* get the part header */ GDREAD(fhd) + datalength = be32toh(fhd.casio_mcs_fileheader_datalength); /* log info about the subpart */ msg((ll_info, "[%lu] directory name is '%.8s'", @@ -73,7 +75,7 @@ int casio_decode_std_mcs(casio_file_t **h, casio_stream_t *buffer, msg((ll_info, "[%lu] filename is '%.8s'", i, fhd.casio_mcs_fileheader_filename)); msg((ll_info, "[%lu] data length is %" CASIO_PRIu32, - i, fhd.casio_mcs_fileheader_datalength)); + i, datalength)); /* decode the head */ casio_decode_mcsfile_head(&head, @@ -81,7 +83,7 @@ int casio_decode_std_mcs(casio_file_t **h, casio_stream_t *buffer, hd.casio_mcs_subheader_intname, fhd.casio_mcs_fileheader_dirname, fhd.casio_mcs_fileheader_filename, - be32toh(fhd.casio_mcs_fileheader_datalength)); + datalength); /* decode */ handle->casio_file_mcsfiles[handle->casio_file_count] = NULL; diff --git a/src/file/manage.c b/src/file/manage.c index 03206b9..695ee6c 100644 --- a/src/file/manage.c +++ b/src/file/manage.c @@ -258,7 +258,6 @@ fail: casio_free_file(*h); *h = NULL; return (casio_error_alloc); } - /* ************************************************************************* */ /* Free a handle */ /* ************************************************************************* */ @@ -285,15 +284,13 @@ void casio_free_file(casio_file_t *handle) /* mcs time! */ if (handle->casio_file_type & casio_filetype_mcs) { - casio_mcsfile_t **files; + casio_mcsfile_t **files = handle->casio_file_mcsfiles; /* check if mcs */ - if (!handle->casio_file_mcsfiles) - return ; + if (!files) return ; /* foreach file in mcs */ - files = handle->casio_file_mcsfiles; - for (i = handle->casio_file_count; i >= 0; i--) { + for (i = handle->casio_file_count - 1; i >= 0; i--) { /* free the file if exists */ if (files[i]) casio_free_mcsfile(files[i]); } diff --git a/src/internals.h b/src/internals.h index 6734691..cd931b2 100644 --- a/src/internals.h +++ b/src/internals.h @@ -51,9 +51,11 @@ /* Checksum. */ -extern unsigned char casio_checksum8 OF((void *casio__mem, - size_t casio__size, unsigned char casio__current)); -extern casio_uint32_t casio_checksum32 OF((void *casio__mem, +extern int casio_checksum_cas OF((void *casio__mem, + size_t casio__size, int casio__current)); +extern int casio_checksum_sub OF((void *casio__mem, + size_t casio__size, int casio__current)); +extern casio_uint32_t casio_checksum32 OF((void *casio__mem, size_t casio__size, casio_uint32_t casio__current)); /* Extension. */ diff --git a/src/link/seven/receive.c b/src/link/seven/receive.c index 8c005bc..f2f9f74 100644 --- a/src/link/seven/receive.c +++ b/src/link/seven/receive.c @@ -23,7 +23,7 @@ #include #include #define checksub8(BUF, SIZE, INI) \ - casio_checksum8(&((char*)(BUF))[1], (SIZE) - 3, (INI)) + casio_checksum_sub(&((char*)(BUF))[1], (SIZE) - 3, (INI)) /* ************************************************************************* */ /* Logging */ diff --git a/src/link/seven/send.c b/src/link/seven/send.c index 612a062..082e765 100644 --- a/src/link/seven/send.c +++ b/src/link/seven/send.c @@ -22,7 +22,7 @@ #include #include #define checksub8(BUF, SIZE) \ - casio_checksum8(&((char*)(BUF))[1], (SIZE) - 3, 0) + casio_checksum_sub(&((char*)(BUF))[1], (SIZE) - 3, 0) /* Internal macros. */ #define buffer \ diff --git a/src/mcsfile/decode/cas.c b/src/mcsfile/decode/cas.c index 477611a..7f0ad13 100644 --- a/src/mcsfile/decode/cas.c +++ b/src/mcsfile/decode/cas.c @@ -97,7 +97,7 @@ static int decode_cas50(casio_mcshead_t *head, casio_stream_t *buffer, mem((ll_info, &hd, sizeof(casio_cas50_t))); /* check the checksum */ - csum = casio_checksum8(&hd, sizeof(casio_cas50_t) - 1, 0); + csum = casio_checksum_cas(&hd, sizeof(casio_cas50_t) - 1, 0); if (csum != hd.casio_cas50_checksum) { msg((ll_error, "Checksum mismatch: expected 0x%02X, got 0x%02X", hd.casio_cas50_checksum, csum)); @@ -153,14 +153,14 @@ int casio_decode_casfile_head(casio_mcshead_t *head, casio_stream_t *buffer) { unsigned char buf[39], csum; casio_casdyn_t *dhd = (void*)buf; - casio_cas40_t *hd = (void*)buf; + casio_cas40_t *hd = (void*)buf; /* check that the head exists */ if (!head) return (-1); memset(head, 0, sizeof(casio_mcshead_t)); /* read beginning of the header, check if is an extended header */ - READ(buf, 4) csum = casio_checksum8(buf, 4, 0); + READ(buf, 4) csum = casio_checksum_cas(buf, 4, 0); if (!casio_maketype_casapp(head, dhd->casio_casdyn_ext, (char*)dhd->casio_casdyn_app)) switch (head->casio_mcshead_info) { @@ -176,7 +176,7 @@ int casio_decode_casfile_head(casio_mcshead_t *head, casio_stream_t *buffer) /* is a CAS40 head, read it. */ READ(&buf[4], 35) - csum = casio_checksum8(&buf[4], 34, csum); + csum = casio_checksum_cas(&buf[4], 34, csum); msg((ll_info, "Raw CAS40 (CAS) header:")); mem((ll_info, hd, sizeof(casio_cas40_t))); if (casio_maketype_cas(head, (char*)hd->casio_cas40_data)) diff --git a/src/mcsfile/decode/cas/cell.c b/src/mcsfile/decode/cas/cell.c index bc2182c..8931feb 100644 --- a/src/mcsfile/decode/cas/cell.c +++ b/src/mcsfile/decode/cas/cell.c @@ -44,15 +44,15 @@ static int decode_cell(casio_stream_t *buffer, casio_mcscell_t *cell, /* read position */ DREAD(fx) *x = be16toh(fx) - 1; DREAD(fy) *y = be16toh(fy) - 1; - csum = casio_checksum8(&fx, sizeof(uint16_t), csum); - csum = casio_checksum8(&fy, sizeof(uint16_t), csum); + csum = casio_checksum_cas(&fx, sizeof(uint16_t), csum); + csum = casio_checksum_cas(&fy, sizeof(uint16_t), csum); /* read the parts */ DREAD(wkg) - csum = casio_checksum8(&wkg, sizeof(casio_casbcd_t), csum); + csum = casio_checksum_cas(&wkg, sizeof(casio_casbcd_t), csum); if (casio_bcd_fromcas(&cell->casio_mcscell_real, &wkg)) { READ(&wkg, sizeof(casio_casbcd_t)) - csum = casio_checksum8(&wkg, sizeof(casio_casbcd_t), csum); + csum = casio_checksum_cas(&wkg, sizeof(casio_casbcd_t), csum); casio_bcd_fromcas(&cell->casio_mcscell_imgn, &wkg); } diff --git a/src/mcsfile/decode/cas/program.c b/src/mcsfile/decode/cas/program.c index f46059b..0ad96f8 100644 --- a/src/mcsfile/decode/cas/program.c +++ b/src/mcsfile/decode/cas/program.c @@ -41,7 +41,7 @@ int casio_decode_caspart_program(casio_mcsfile_t *handle, /* check the sum */ DREAD(checksum) - csum = casio_checksum8(handle->casio_mcsfile_content, + csum = casio_checksum_cas(handle->casio_mcsfile_content, handle->casio_mcsfile_head.casio_mcshead_size, 0); if (checksum != csum) { msg((ll_error, "Checksum mismatch: expected 0x%02X, got 0x%02X", diff --git a/src/mcsfile/decode/mcs/setup.c b/src/mcsfile/decode/mcs/setup.c index 5fa40eb..84e9771 100644 --- a/src/mcsfile/decode/mcs/setup.c +++ b/src/mcsfile/decode/mcs/setup.c @@ -31,15 +31,11 @@ int casio_decode_mcs_setup(casio_mcsfile_t **h, casio_stream_t *buffer, casio_mcshead_t *head) { - int err; - unsigned char *content = NULL; + int err; unsigned char content[100]; casio_setup_t *sp; /* read content */ - err = casio_error_alloc; - content = malloc(head->casio_mcshead_size); - if (!content) goto fail; - GREAD(content, head->casio_mcshead_size) + READ(content, 100) /* make final head and file */ err = casio_make_mcsfile(h, head); @@ -64,12 +60,5 @@ int casio_decode_mcs_setup(casio_mcsfile_t **h, casio_stream_t *buffer, /* TODO: decode more options! */ /* no error! */ - err = 0; -fail: - free(content); - if (err) { - casio_free_mcsfile(*h); - *h = NULL; - } return (0); } diff --git a/src/mcsfile/manage.c b/src/mcsfile/manage.c index ea0d266..8e7cd0c 100644 --- a/src/mcsfile/manage.c +++ b/src/mcsfile/manage.c @@ -42,7 +42,7 @@ int casio_make_mcsfile(casio_mcsfile_t **h, const casio_mcshead_t *rawhead) if (!handle) return (casio_error_alloc); /* initialize the handle, copy the head */ - memset(h, 0, sizeof(casio_mcsfile_t)); + memset(handle, 0, sizeof(casio_mcsfile_t)); memcpy(&handle->casio_mcsfile_head, rawhead, sizeof(casio_mcshead_t)); head = &handle->casio_mcsfile_head; diff --git a/src/stream/open.c b/src/stream/open.c index 4c01942..7760c68 100644 --- a/src/stream/open.c +++ b/src/stream/open.c @@ -70,7 +70,6 @@ int casio_open(casio_stream_t **pstream, casio_openmode_t mode, casio_init_timeouts(stream); /* no error! */ - msg((ll_info, "Stream successfully created!")); err = 0; fail: if (err) { diff --git a/src/utils/checksum.c b/src/utils/checksum.c index 5fc85e4..1966828 100644 --- a/src/utils/checksum.c +++ b/src/utils/checksum.c @@ -19,7 +19,7 @@ #include "../internals.h" /** - * casio_checksum8: + * casio_checksum_cas: * Make checksums great again. * * @arg mem the memory zone. @@ -28,12 +28,31 @@ * @return the new checksum. */ -unsigned char casio_checksum8(void *mem, size_t size, unsigned char cs) +int casio_checksum_cas(void *mem, size_t size, int cs) { unsigned char *m = mem; while (size--) - cs -= *m++; + cs = (cs - *m++) & 255; + return (cs); +} + +/** + * casio_checksum_sub: + * Make the CASIOWIN type of checksums. + * + * @arg mem the memory zone. + * @arg size the memory zone size. + * @arg cs the current checksum. + * @return the new checksum. + */ + +int casio_checksum_sub(void *mem, size_t size, int cs) +{ + unsigned char *m = mem; + + while (size--) + cs = (cs - *m++) & 255; return (cs); }