cake
/
libg1m
Archived
1
0
Fork 0

g1m_t -> g1m_handle_t.

This commit is contained in:
Thomas Touhey 2017-03-23 16:41:27 +01:00
parent c101c21a7e
commit 658e70d5f9
23 changed files with 128 additions and 144 deletions

View File

@ -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);
/* ************************************************************************** */

View File

@ -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. */

View File

@ -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

View File

@ -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 */

View File

@ -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 */

View File

@ -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)
/* ************************************************************************** */

View File

@ -22,8 +22,8 @@
# include <libg1m/picture.h>
# include <inttypes.h>
# 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 {

View File

@ -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 */

View File

@ -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. */

View File

@ -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 */

View File

@ -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;

View File

@ -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,

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -18,6 +18,9 @@
* ************************************************************************** */
#include <libg1m/internals.h>
#include <ctype.h>
#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 ;

View File

@ -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);

View File

@ -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);