From 658e70d5f9580c2af8215286f3c5b7f889f7a0e4 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Thu, 23 Mar 2017 16:41:27 +0100 Subject: [PATCH] g1m_t -> g1m_handle_t. --- include/libg1m.h | 34 ++++++++++---------- include/libg1m/buffer.h | 6 ++-- include/libg1m/eact.h | 8 ++--- include/libg1m/formatutils.h | 2 +- include/libg1m/handle.h | 34 ++++++++++---------- include/libg1m/internals.h | 25 ++++++++------- include/libg1m/mcs.h | 14 ++++----- src/decode/cas.c | 6 ++-- src/decode/casemul.c | 4 +-- src/decode/main.c | 4 +-- src/decode/std.c | 3 +- src/decode/std/addin.c | 12 ++++---- src/decode/std/eact.c | 8 ++--- src/decode/std/fkey.c | 8 ++--- src/decode/std/lang.c | 8 ++--- src/decode/std/mcs.c | 4 +-- src/decode/std/picture.c | 6 ++-- src/decode/storage.c.draft | 4 +-- src/encode/addin.c | 4 +-- src/encode/main.c | 6 ++-- src/manage/handle.c | 60 ++++++++++++------------------------ src/manage/mcs.c | 4 +-- src/utils/file.c | 8 ++--- 23 files changed, 128 insertions(+), 144 deletions(-) diff --git a/include/libg1m.h b/include/libg1m.h index c0b4cf5..97cc8ff 100644 --- a/include/libg1m.h +++ b/include/libg1m.h @@ -80,35 +80,37 @@ extern const char *g1m_error_strings[]; /* Main functions */ /* ************************************************************************** */ /* open and free a handle */ -extern int g1m_decode(g1m_t **handle, const char *path, g1m_buffer_t *buffer, - g1m_type_t allowed_types); -extern void g1m_free(g1m_t *handle); +extern int g1m_decode(g1m_handle_t **handle, const char *path, + g1m_buffer_t *buffer, g1m_type_t allowed_types); +extern void g1m_free(g1m_handle_t *handle); /* open a handle using FILEs */ #ifndef G1M_DISABLED_FILE -extern int g1m_open(g1m_t **handle, const char *path, +extern int g1m_open(g1m_handle_t **handle, const char *path, g1m_type_t allowed_types); -extern int g1m_fopen(g1m_t **handle, const char *path, FILE *stream, +extern int g1m_fopen(g1m_handle_t **handle, const char *path, FILE *stream, g1m_type_t allowed_types); #endif /* Make a handle */ -extern int g1m_make_mcs(g1m_t **handle, int count); -extern int g1m_make_fkey(g1m_t **handle, g1m_platform_t platform, int count); -extern int g1m_make_lang(g1m_t **handle, g1m_platform_t platform, int count); -extern int g1m_make_picture(g1m_t **handle, +extern int g1m_make_mcs(g1m_handle_t **handle, int count); +extern int g1m_make_fkey(g1m_handle_t **handle, g1m_platform_t platform, + int count); +extern int g1m_make_lang(g1m_handle_t **handle, g1m_platform_t platform, + int count); +extern int g1m_make_picture(g1m_handle_t **handle, unsigned int width, unsigned int height); -extern int g1m_make_addin(g1m_t **h, g1m_platform_t platform, size_t size, - const char *name, const char *internal_name, +extern int g1m_make_addin(g1m_handle_t **h, g1m_platform_t platform, + size_t size, const char *name, const char *internal_name, const g1m_version_t *version, const time_t *created); /* encode a handle, get the extension */ -extern int g1m_encode(g1m_t *handle, g1m_buffer_t *buffer); +extern int g1m_encode(g1m_handle_t *handle, g1m_buffer_t *buffer); /* put into a FILE */ #ifndef G1M_DISABLED_FILE -extern int g1m_write(g1m_t *handle, const char *path); -extern int g1m_fwrite(g1m_t *handle, FILE *stream); +extern int g1m_write(g1m_handle_t *handle, const char *path); +extern int g1m_fwrite(g1m_handle_t *handle, FILE *stream); #endif /* ************************************************************************** */ /* Main MCS functions */ @@ -148,12 +150,12 @@ extern int g1m_decode_casfile_part(g1m_mcsfile_t *file, g1m_buffer_t *buffer); /* MCS archive management */ /* ************************************************************************** */ /* create and insert an MCS file into a MCS archive */ -extern int g1m_mcs_insert(g1m_t *handle, g1m_mcsfile_t **tofile, +extern int g1m_mcs_insert(g1m_handle_t *handle, g1m_mcsfile_t **tofile, const g1m_mcshead_t *head); /* sort an MCS archive for encoding, * compare two MCS files (utility function used by the first) */ -extern int g1m_mcs_sort(g1m_t *handle); +extern int g1m_mcs_sort(g1m_handle_t *handle); extern int g1m_compare_mcsfiles(const g1m_mcsfile_t *first_file, const g1m_mcsfile_t *second_file); /* ************************************************************************** */ diff --git a/include/libg1m/buffer.h b/include/libg1m/buffer.h index 080e697..1d54f68 100644 --- a/include/libg1m/buffer.h +++ b/include/libg1m/buffer.h @@ -38,9 +38,9 @@ /* General definition */ /* ************************************************************************** */ /* The callbacks types... */ -typedef int (*g1m_buffer_read_t)(void*, unsigned char*, size_t); -typedef int (*g1m_buffer_write_t)(void*, const unsigned char*, size_t); -typedef int (*g1m_buffer_announce_t)(void*, size_t); +typedef int (*g1m_buffer_read_t)(void*, unsigned char*, size_t); +typedef int (*g1m_buffer_write_t)(void*, const unsigned char*, size_t); +typedef int (*g1m_buffer_announce_t)(void*, size_t); typedef void (*g1m_buffer_unannounce_t)(void*); /* ... and the structure of a buffer. */ diff --git a/include/libg1m/eact.h b/include/libg1m/eact.h index 8c108d2..0c6bbc7 100644 --- a/include/libg1m/eact.h +++ b/include/libg1m/eact.h @@ -24,10 +24,10 @@ /* E-activities line types */ /* ************************************************************************** */ typedef unsigned int g1m_eact_line_type_t; -# define g1m_linetype_title 0x01 -# define g1m_linetype_text 0x02 -# define g1m_linetype_picture 0x04 -# define g1m_linetype_eact 0x08 +# define g1m_linetype_title 0x01 /* title */ +# define g1m_linetype_text 0x02 /* text */ +# define g1m_linetype_picture 0x04 /* (link to) picture */ +# define g1m_linetype_eact 0x08 /* sub e-activity */ /* Line type aliases */ # define g1m_linetype_pict g1m_linetype_picture diff --git a/include/libg1m/formatutils.h b/include/libg1m/formatutils.h index 55c11ab..0c2d730 100644 --- a/include/libg1m/formatutils.h +++ b/include/libg1m/formatutils.h @@ -32,7 +32,7 @@ extern "C" { # endif /* ************************************************************************** */ -/* General types (`g1m_t`) */ +/* General types (`g1m_handle_t`) */ /* ************************************************************************** */ /* Standard header */ # define g1m_stdflag_check1 0x0001 /* check first control value */ diff --git a/include/libg1m/handle.h b/include/libg1m/handle.h index 75336d5..d226ac4 100644 --- a/include/libg1m/handle.h +++ b/include/libg1m/handle.h @@ -27,27 +27,27 @@ /* ************************************************************************** */ /* General type */ typedef unsigned int g1m_type_t; -# define g1m_type_addin 0x0001 -# define g1m_type_mcs 0x0002 -# define g1m_type_eact 0x0004 -# define g1m_type_picture 0x0008 -# define g1m_type_lang 0x0010 -# define g1m_type_fkey 0x0020 -# define g1m_type_storage 0x0040 +# define g1m_type_addin 0x0001 +# define g1m_type_mcs 0x0002 +# define g1m_type_eact 0x0004 +# define g1m_type_picture 0x0008 +# define g1m_type_lang 0x0010 +# define g1m_type_fkey 0x0020 +# define g1m_type_storage 0x0040 /* General type aliases */ -# define g1m_type_pict g1m_type_picture -# define g1m_type_eactivity g1m_type_eact -# define g1m_type_add_in g1m_type_addin +# define g1m_type_pict g1m_type_picture +# define g1m_type_eactivity g1m_type_eact +# define g1m_type_add_in g1m_type_addin /* Platform */ typedef unsigned int g1m_platform_t; -# define g1m_platform_none 0x0000 -# define g1m_platform_fx 0x0001 -# define g1m_platform_cp 0x0002 -# define g1m_platform_cg 0x0004 -# define g1m_platform_cas 0x0008 -# define g1m_platform_casemul 0x0010 +# define g1m_platform_none 0x0000 +# define g1m_platform_fx 0x0001 +# define g1m_platform_cp 0x0002 +# define g1m_platform_cg 0x0004 +# define g1m_platform_cas 0x0008 +# define g1m_platform_casemul 0x0010 /* ************************************************************************** */ /* Helpers */ /* ************************************************************************** */ @@ -87,6 +87,6 @@ typedef struct { /* E-activities related data */ g1m_line_t *line; g1m_line_t _linedata; -} g1m_t; +} g1m_handle_t; #endif /* LIBG1M_HANDLE_H */ diff --git a/include/libg1m/internals.h b/include/libg1m/internals.h index 4a8c7a7..c6d9c1d 100644 --- a/include/libg1m/internals.h +++ b/include/libg1m/internals.h @@ -101,31 +101,34 @@ /* Decoding functions */ /* ************************************************************************** */ /* with expected types */ -extern int g1m_decode_std(g1m_t **handle, const char *path, +extern int g1m_decode_std(g1m_handle_t **handle, const char *path, g1m_buffer_t *buffer, struct standard_header*, g1m_type_t expected_types); /* w/o expected types */ -int g1m_decode_casemul(g1m_t **handle, g1m_buffer_t *buffer, int big_endian); -int g1m_decode_storage(g1m_t **handle, g1m_buffer_t *buffer); -int g1m_decode_cas(g1m_t **handle, g1m_buffer_t *buffer); -int g1m_decode_grc(g1m_t **handle, g1m_buffer_t *buffer); +int g1m_decode_casemul(g1m_handle_t **handle, g1m_buffer_t *buffer, + int big_endian); +int g1m_decode_storage(g1m_handle_t **handle, g1m_buffer_t *buffer); +int g1m_decode_cas(g1m_handle_t **handle, g1m_buffer_t *buffer); +int g1m_decode_grc(g1m_handle_t **handle, g1m_buffer_t *buffer); /* ************************************************************************** */ /* "Std"-specific decoding functions */ /* ************************************************************************** */ # define G1M_STDFUNC(NAME) \ -extern int g1m_decode_std_##NAME(g1m_t **handle, g1m_buffer_t *buffer, \ +extern int g1m_decode_std_##NAME(g1m_handle_t **handle, g1m_buffer_t *buffer, \ struct standard_header *std); # define G1M_PRIZMFUNC(NAME) \ -extern int g1m_decode_std_cg_##NAME(g1m_t **handle, g1m_buffer_t *buffer, \ +extern int g1m_decode_std_cg_##NAME(g1m_handle_t **handle, \ + g1m_buffer_t *buffer, \ struct standard_header *std, struct standard_subheader *sub, \ struct _prizm_subheader *pzm, uint32_t *check); # define G1M_CPFUNC(NAME) \ -extern int g1m_decode_std_cp_##NAME(g1m_t **handle, g1m_buffer_t *buffer, \ +extern int g1m_decode_std_cp_##NAME(g1m_handle_t **handle, \ + g1m_buffer_t *buffer, \ struct standard_header *std, struct standard_subheader *sub, \ struct _classpad_subheader *cp, uint32_t *check); # define G1M_PICFUNC(NAME) \ -extern int g1m_decode_std_##NAME(g1m_t **handle, g1m_buffer_t *buffer, \ +extern int g1m_decode_std_##NAME(g1m_handle_t **handle, g1m_buffer_t *buffer, \ struct standard_header *std, struct standard_picheader *pic); /* standard funcs */ @@ -180,8 +183,8 @@ G1M_CASFUNC(capture) /* Handle encoding functions */ /* ************************************************************************** */ # define G1M_ENCFUNC(NAME) \ -extern int g1m_announce_##NAME(g1m_t *handle, size_t *size); \ -extern int g1m_encode_##NAME(g1m_t *handle, g1m_buffer_t *buffer); +extern int g1m_announce_##NAME(g1m_handle_t *handle, size_t *size); \ +extern int g1m_encode_##NAME(g1m_handle_t *handle, g1m_buffer_t *buffer); G1M_ENCFUNC(addin) /* ************************************************************************** */ diff --git a/include/libg1m/mcs.h b/include/libg1m/mcs.h index 93f95eb..a2afad1 100644 --- a/include/libg1m/mcs.h +++ b/include/libg1m/mcs.h @@ -22,8 +22,8 @@ # include # include # define g1m_theta 27 -# define g1m_r 28 -# define g1m_ans 29 +# define g1m_r 28 +# define g1m_ans 29 /* ************************************************************************** */ /* Main Memory Types */ @@ -90,11 +90,11 @@ typedef struct g1m_mcs_cell_s { /* mcs file type -- what type of raw information is there * e.g. `head.flags & g1m_mcsmask_info == g1m_mcsinfo_g1m` */ # define g1m_mcsinfo(H) ((H)->flags & g1m_mcsmask_info) -# define g1m_mcsmask_info 0x0600 -# define g1m_mcsinfo_none 0x0000 -# define g1m_mcsinfo_mcs 0x0200 -# define g1m_mcsinfo_cas 0x0400 -# define g1m_mcsinfo_caspro 0x0600 +# define g1m_mcsmask_info 0x0600 +# define g1m_mcsinfo_none 0x0000 +# define g1m_mcsinfo_mcs 0x0200 +# define g1m_mcsinfo_cas 0x0400 +# define g1m_mcsinfo_caspro 0x0600 /* mcs file head */ typedef struct g1m_mcshead_s { diff --git a/src/decode/cas.c b/src/decode/cas.c index 86fdc80..62b3e38 100644 --- a/src/decode/cas.c +++ b/src/decode/cas.c @@ -245,12 +245,12 @@ int g1m_decode_casfile_part(g1m_mcsfile_t *file, g1m_buffer_t *buffer) * @return the libg1m error. */ -int g1m_decode_cas(g1m_t **h, g1m_buffer_t *buffer) +int g1m_decode_cas(g1m_handle_t **h, g1m_buffer_t *buffer) { /* make the handle */ int err = g1m_make_mcs(h, 0); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* read each */ for (handle->count = 0;;) { @@ -319,7 +319,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_decode_grc(g1m_t **handle, g1m_buffer_t *buffer) +int g1m_decode_grc(g1m_handle_t **handle, g1m_buffer_t *buffer) { uint8_t intro[2]; READ(intro, 2) /* probably the file count? */ uint8_t colon; READ(&colon, 1) /* read first colon */ diff --git a/src/decode/casemul.c b/src/decode/casemul.c index f6593b3..9d13e4f 100644 --- a/src/decode/casemul.c +++ b/src/decode/casemul.c @@ -306,7 +306,7 @@ static int read_list(g1m_mcsfile_t **pfile, g1m_buffer_t *buffer, * @return the error code (0 if ok). */ -int g1m_decode_casemul(g1m_t **h, g1m_buffer_t *buffer, int big_endian) +int g1m_decode_casemul(g1m_handle_t **h, g1m_buffer_t *buffer, int big_endian) { int err; @@ -338,7 +338,7 @@ int g1m_decode_casemul(g1m_t **h, g1m_buffer_t *buffer, int big_endian) err = g1m_make_mcs(h, /* src.programs + */ src.pictures + src.matrixes + src.lists); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* read each program; TODO: put this in a function when token parsing * is managed. */ diff --git a/src/decode/main.c b/src/decode/main.c index 4af3ce1..6b50dfc 100644 --- a/src/decode/main.c +++ b/src/decode/main.c @@ -22,7 +22,7 @@ /* Check using extensions */ /* ************************************************************************** */ /* Decode function */ -typedef int (*decode_func)(g1m_t**, g1m_buffer_t*); +typedef int (*decode_func)(g1m_handle_t**, g1m_buffer_t*); /* Correspondance type */ struct corresp { @@ -90,7 +90,7 @@ static int lookup_extension(const char *path, g1m_type_t types, * @return the error code (0 if ok). */ -int g1m_decode(g1m_t **handle, const char *path, g1m_buffer_t *buffer, +int g1m_decode(g1m_handle_t **handle, const char *path, g1m_buffer_t *buffer, g1m_type_t expected_types) { /* match using extension */ diff --git a/src/decode/std.c b/src/decode/std.c index 504d69f..0f662bf 100644 --- a/src/decode/std.c +++ b/src/decode/std.c @@ -104,7 +104,8 @@ static int find_decode_function(g1m_platform_t platform, g1m_type_t type, * @return the error code (0 if ok). */ -int g1m_decode_std(g1m_t **handle, const char *path, g1m_buffer_t *buffer, +int g1m_decode_std(g1m_handle_t **handle, const char *path, + g1m_buffer_t *buffer, struct standard_header *std, g1m_type_t expected_types) { int err; diff --git a/src/decode/std/addin.c b/src/decode/std/addin.c index 890262f..9203a03 100644 --- a/src/decode/std/addin.c +++ b/src/decode/std/addin.c @@ -30,7 +30,7 @@ * @return the error code (0 if ok). */ -int g1m_decode_std_addin(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_addin(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std) { int err = 0; @@ -49,7 +49,7 @@ int g1m_decode_std_addin(g1m_t **h, g1m_buffer_t *buffer, err = g1m_make_addin(h, g1m_platform_fx, content_size, (char*)hd.title, (char*)hd.internal_name, &version, &created); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* log info about the subheader */ log_info("title is '%s'", handle->title); @@ -91,7 +91,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_decode_std_cp_addin(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_cp_addin(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std, struct standard_subheader *sub, struct _classpad_subheader *cp, uint32_t *check) { @@ -109,7 +109,7 @@ int g1m_decode_std_cp_addin(g1m_t **h, g1m_buffer_t *buffer, err = g1m_make_addin(h, g1m_platform_cp, content_size, (char*)sub->title, (char*)sub->internal_name, &version, &created); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* decode pictures */ g1m_decode_picture(handle->icon_unsel, g1m_pictureformat_1bit_packed, @@ -151,7 +151,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_decode_std_cg_addin(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_cg_addin(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std, struct standard_subheader *sub, struct _prizm_subheader *prizm, uint32_t *check) { @@ -174,7 +174,7 @@ int g1m_decode_std_cg_addin(g1m_t **h, g1m_buffer_t *buffer, err = g1m_make_addin(h, g1m_platform_cg, content_size, (char*)sub->internal_name, (char*)sub->title, &version, &created); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* decode pictures */ g1m_decode_picture(handle->icon_unsel, g1m_pictureformat_16bit, diff --git a/src/decode/std/eact.c b/src/decode/std/eact.c index c8847d7..a3a6751 100644 --- a/src/decode/std/eact.c +++ b/src/decode/std/eact.c @@ -438,7 +438,7 @@ static int eact_decode_line(g1m_line_t *handle, uint8_t *buf, size_t size, * @return the error code (0 if ok). */ -int g1m_decode_std_eact(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_eact(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std) { (void)std; int err; @@ -457,10 +457,10 @@ int g1m_decode_std_eact(g1m_t **h, g1m_buffer_t *buffer, hd.setup_area_size); /* allocate handle */ - *h = malloc(sizeof(g1m_t)); + *h = malloc(sizeof(g1m_handle_t)); if (!*h) return (g1m_error_alloc); - g1m_t *handle = *h; - memset(handle, 0, sizeof(g1m_t)); + g1m_handle_t *handle = *h; + memset(handle, 0, sizeof(g1m_handle_t)); /* skip the setup area */ SKIP(hd.setup_area_size) diff --git a/src/decode/std/fkey.c b/src/decode/std/fkey.c index 5f2df92..daf7030 100644 --- a/src/decode/std/fkey.c +++ b/src/decode/std/fkey.c @@ -72,7 +72,7 @@ static uint32_t **fkeydup3(uint8_t *fkey) * @return the error code (0 if ok). */ -int g1m_decode_std_fkey(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_fkey(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std) { int err; (void)std; @@ -89,7 +89,7 @@ int g1m_decode_std_fkey(g1m_t **h, g1m_buffer_t *buffer, /* prepare the handle */ err = g1m_make_fkey(h, g1m_platform_fx, num); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* get the offset table */ uint16_t *offsets = (uint16_t*)data; @@ -136,7 +136,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_decode_std_cg_fkey(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_cg_fkey(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std, struct standard_subheader *sub, struct _prizm_subheader *prizm, uint32_t *check) { @@ -159,7 +159,7 @@ int g1m_decode_std_cg_fkey(g1m_t **h, g1m_buffer_t *buffer, int num = be32toh(lhd.num); err = g1m_make_fkey(h, g1m_platform_cg, num); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* setup the pointers */ uint32_t *offsets = (void*)data; diff --git a/src/decode/std/lang.c b/src/decode/std/lang.c index e1afff6..f884a0f 100644 --- a/src/decode/std/lang.c +++ b/src/decode/std/lang.c @@ -30,7 +30,7 @@ * @return the error code (0 if ok). */ -int g1m_decode_std_lang(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_lang(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std) { (void)std; int err; @@ -51,7 +51,7 @@ int g1m_decode_std_lang(g1m_t **h, g1m_buffer_t *buffer, /* make the handle */ err = g1m_make_lang(h, g1m_platform_fx, num); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* get the offset table */ uint16_t *offsets = (uint16_t*)data; @@ -101,7 +101,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_decode_std_cg_lang(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_cg_lang(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std, struct standard_subheader *sub, struct _prizm_subheader *prizm, uint32_t *check) { @@ -124,7 +124,7 @@ int g1m_decode_std_cg_lang(g1m_t **h, g1m_buffer_t *buffer, int num = be32toh(lhd.num); err = g1m_make_lang(h, g1m_platform_cg, num); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* setup the pointers */ uint32_t *offsets = (void*)data; diff --git a/src/decode/std/mcs.c b/src/decode/std/mcs.c index 66eb030..7c6d743 100644 --- a/src/decode/std/mcs.c +++ b/src/decode/std/mcs.c @@ -207,7 +207,7 @@ int g1m_decode_mcsfile_data(g1m_mcsfile_t **handle, * @return the error code (0 if ok). */ -int g1m_decode_std_mcs(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_mcs(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std) { int err = g1m_error_alloc; @@ -217,7 +217,7 @@ int g1m_decode_std_mcs(g1m_t **h, g1m_buffer_t *buffer, /* make the handle */ err = g1m_make_mcs(h, num); if (err) return (err); - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* read all of the parts */ log_info("%" PRIuFAST16 " total mcs files to browse", num); diff --git a/src/decode/std/picture.c b/src/decode/std/picture.c index e46c4d7..150b729 100644 --- a/src/decode/std/picture.c +++ b/src/decode/std/picture.c @@ -52,7 +52,7 @@ static void g3p_deobfuscate(uint8_t *buf, size_t n) * @return the error code (0 if ok). */ -int g1m_decode_std_g3p(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_g3p(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std, struct standard_picheader *pic) { int err; *h = NULL; @@ -123,7 +123,7 @@ int g1m_decode_std_g3p(g1m_t **h, g1m_buffer_t *buffer, /* make the handle */ err = g1m_make_picture(h, ihd.width, ihd.height); if (err) goto fail; - g1m_t *handle = *h; + g1m_handle_t *handle = *h; /* then store it */ g1m_decode_picture(handle->pixels, picfmt, @@ -154,7 +154,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_decode_std_c2p(g1m_t **h, g1m_buffer_t *buffer, +int g1m_decode_std_c2p(g1m_handle_t **h, g1m_buffer_t *buffer, struct standard_header *std, struct standard_picheader *pic) { (void)h; (void)buffer; diff --git a/src/decode/storage.c.draft b/src/decode/storage.c.draft index 4d588f1..118294d 100644 --- a/src/decode/storage.c.draft +++ b/src/decode/storage.c.draft @@ -29,12 +29,12 @@ * g1m_decode_storage: * Decode storage files. * - * @arg handle the libg1m handle. + * @arg handle the libg1m handle to make. * @arg buffer the buffer to read from. * @return the error code (0 if ok). */ -int g1m_decode_storage(g1m_t *handle, g1m_buffer_t *buffer) +int g1m_decode_storage(g1m_handle_t **h, g1m_buffer_t *buffer) { (void)std; int err, ret = 0; handle->type = 0x00; diff --git a/src/encode/addin.c b/src/encode/addin.c index 797994b..b0e4b24 100644 --- a/src/encode/addin.c +++ b/src/encode/addin.c @@ -27,7 +27,7 @@ * @return the error code (0 if ok). */ -int g1m_announce_addin(g1m_t *handle, size_t *size) +int g1m_announce_addin(g1m_handle_t *handle, size_t *size) { *size += sizeof(struct standard_header) + sizeof(struct g1a_subheader); *size += handle->size; @@ -43,7 +43,7 @@ int g1m_announce_addin(g1m_t *handle, size_t *size) * @return the error code (0 if ok). */ -int g1m_encode_addin(g1m_t *handle, g1m_buffer_t *buffer) +int g1m_encode_addin(g1m_handle_t *handle, g1m_buffer_t *buffer) { /* make the StandardHeader up */ size_t filesize; g1m_announce_addin(handle, &filesize); diff --git a/src/encode/main.c b/src/encode/main.c index 11cc0f2..27b958c 100644 --- a/src/encode/main.c +++ b/src/encode/main.c @@ -23,8 +23,8 @@ /* Correspondances */ /* ************************************************************************** */ /* Types */ -typedef int (*announce_t)(g1m_t*, size_t*); -typedef int (*encode_t)(g1m_t*, g1m_buffer_t*); +typedef int (*announce_t)(g1m_handle_t*, size_t*); +typedef int (*encode_t)(g1m_handle_t*, g1m_buffer_t*); struct corresp { /* 'identification' */ g1m_type_t types; @@ -56,7 +56,7 @@ static const struct corresp encodings[] = { * @return the error code (0 if ok). */ -int g1m_encode(g1m_t *handle, g1m_buffer_t *buffer) +int g1m_encode(g1m_handle_t *handle, g1m_buffer_t *buffer) { int err; diff --git a/src/manage/handle.c b/src/manage/handle.c index a5d1e01..cb660cb 100644 --- a/src/manage/handle.c +++ b/src/manage/handle.c @@ -18,6 +18,9 @@ * ************************************************************************** */ #include #include +#define mkhandle() \ + if (!(*(h) = malloc(sizeof(g1m_handle_t)))) return (g1m_error_alloc); \ + g1m_handle_t *handle = *h; memset(handle, 0, sizeof(g1m_handle_t)) /* ************************************************************************** */ /* Make a handle */ @@ -32,15 +35,10 @@ * @return the error code (0 if ok). */ -int g1m_make_picture(g1m_t **h, unsigned int width, unsigned int height) +int g1m_make_picture(g1m_handle_t **h, unsigned int width, unsigned int height) { - /* allocate the handle */ - *h = malloc(sizeof(g1m_t)); - if (!*h) return (g1m_error_alloc); - g1m_t *handle = *h; - memset(handle, 0, sizeof(g1m_t)); - - /* allocate the pixels */ + /* make the handle */ + mkhandle(); handle->type = g1m_type_picture; handle->width = width; handle->height = height; @@ -61,15 +59,10 @@ int g1m_make_picture(g1m_t **h, unsigned int width, unsigned int height) * @return the error code (0 if ok). */ -int g1m_make_mcs(g1m_t **h, int count) +int g1m_make_mcs(g1m_handle_t **h, int count) { - /* allocate the handle */ - *h = malloc(sizeof(g1m_t)); - if (!*h) return (g1m_error_alloc); - g1m_t *handle = *h; - memset(handle, 0, sizeof(g1m_t)); - - /* initialize it */ + /* make the handle */ + mkhandle(); handle->type = g1m_type_mcs; handle->platform = g1m_platform_fx; handle->count = 0; handle->_size = 0; @@ -100,15 +93,10 @@ fail: * @return the error code (0 if ok). */ -int g1m_make_fkey(g1m_t **h, g1m_platform_t pf, int count) +int g1m_make_fkey(g1m_handle_t **h, g1m_platform_t pf, int count) { - /* allocate the handle */ - *h = malloc(sizeof(g1m_t)); - if (!*h) return (g1m_error_alloc); - g1m_t *handle = *h; - memset(handle, 0, sizeof(g1m_t)); - - /* initialize it */ + /* make the handle */ + mkhandle(); handle->type = g1m_type_fkey; handle->platform = pf; handle->count = 0; handle->_size = 0; @@ -139,15 +127,10 @@ fail: * @return the error code (0 if ok). */ -int g1m_make_lang(g1m_t **h, g1m_platform_t platform, int count) +int g1m_make_lang(g1m_handle_t **h, g1m_platform_t platform, int count) { - /* allocate the handle */ - *h = malloc(sizeof(g1m_t)); - if (!*h) return (g1m_error_alloc); - g1m_t *handle = *h; - memset(handle, 0, sizeof(g1m_t)); - - /* initialize it */ + /* make the handle */ + mkhandle(); handle->type = g1m_type_lang; handle->platform = platform; handle->count = 0; handle->_size = 0; @@ -182,7 +165,7 @@ fail: * @return the error code (0 if ok). */ -int g1m_make_addin(g1m_t **h, g1m_platform_t platform, size_t size, +int g1m_make_addin(g1m_handle_t **h, g1m_platform_t platform, size_t size, const char *name, const char *internal, const g1m_version_t *version, const time_t *created) { @@ -197,13 +180,8 @@ int g1m_make_addin(g1m_t **h, g1m_platform_t platform, size_t size, if (!isupper(name[0]) || internal[0] != '@' || !isupper(internal[1])) return (g1m_error_op); - /* allocate the handle */ - *h = malloc(sizeof(g1m_t)); - if (!*h) return (g1m_error_alloc); - g1m_t *handle = *h; - memset(handle, 0, sizeof(g1m_t)); - - /* set basic options */ + /* make the handle */ + mkhandle(); handle->type = g1m_type_addin; handle->platform = platform; handle->version = *version; @@ -271,7 +249,7 @@ fail: * @arg handle the handle. */ -void g1m_free(g1m_t *handle) +void g1m_free(g1m_handle_t *handle) { /* check if there is something to free */ if (!handle) return ; diff --git a/src/manage/mcs.c b/src/manage/mcs.c index db08a55..e8195ef 100644 --- a/src/manage/mcs.c +++ b/src/manage/mcs.c @@ -33,7 +33,7 @@ * @return the mcs file (NULL if allocation error). */ -int g1m_mcs_insert(g1m_t *handle, g1m_mcsfile_t **tofile, +int g1m_mcs_insert(g1m_handle_t *handle, g1m_mcsfile_t **tofile, const g1m_mcshead_t *head) { g1m_mcsfile_t **pfile = NULL; *tofile = NULL; @@ -124,7 +124,7 @@ found:; */ typedef int (*g1m_compare_mcsfiles_t)(const void*, const void*); -int g1m_mcs_sort(g1m_t *handle) +int g1m_mcs_sort(g1m_handle_t *handle) { if (handle->type != g1m_type_mcs) return (g1m_error_op); if (handle->platform != g1m_platform_fx) return (g1m_error_op); diff --git a/src/utils/file.c b/src/utils/file.c index 301a5fa..1f578d6 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -34,7 +34,7 @@ * @return the error code (0 if ok). */ -int g1m_open(g1m_t **handle, const char *path, +int g1m_open(g1m_handle_t **handle, const char *path, g1m_type_t expected) { /* open stream and decode */ @@ -60,7 +60,7 @@ int g1m_open(g1m_t **handle, const char *path, * @return the error code (0 if ok) */ -int g1m_fopen(g1m_t **handle, const char *path, FILE *stream, +int g1m_fopen(g1m_handle_t **handle, const char *path, FILE *stream, g1m_type_t expected) { /* check stream */ @@ -89,7 +89,7 @@ int g1m_fopen(g1m_t **handle, const char *path, FILE *stream, * @return the error code (0 if ok). */ -int g1m_write(g1m_t *handle, const char *path) +int g1m_write(g1m_handle_t *handle, const char *path) { /* open the stream and write */ FILE *f = fopen(path, "w"); @@ -110,7 +110,7 @@ int g1m_write(g1m_t *handle, const char *path) * @return the error code (0 if ok). */ -int g1m_fwrite(g1m_t *handle, FILE *stream) +int g1m_fwrite(g1m_handle_t *handle, FILE *stream) { /* check stream */ if (!stream) return (g1m_error_nostream);