From: handa Date: Fri, 2 Oct 2009 03:59:15 +0000 (+0000) Subject: (OTF_ApplicationData_): New type. X-Git-Tag: REL-0-9-11~59 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=b7e3344e95c45b90d17f260e62b513fbef86864a;p=m17n%2Flibotf.git (OTF_ApplicationData_): New type. (OTF_InternalData): New member app_data. (OTF_close): Free OTF_InternalData->app_data. (OTF_put_data, OTF_get_data): New functions. --- diff --git a/src/otfopen.c b/src/otfopen.c index af85fa5..6f137df 100644 --- a/src/otfopen.c +++ b/src/otfopen.c @@ -299,6 +299,16 @@ struct _OTF_TableInfo OTF_Stream *stream; }; +struct _OTF_ApplicationData +{ + char *id; + void *data; + void (*freer) (void *data); + struct _OTF_ApplicationData *next; +}; + +typedef struct _OTF_ApplicationData OTF_ApplicationData; + struct OTF_InternalData { /* Information about each OTF table. */ @@ -309,6 +319,9 @@ struct OTF_InternalData /* Records of allocated memories. */ OTF_MemoryRecord *memory_record; + + /* Root of application data chain. */ + OTF_ApplicationData *app_data; }; @@ -3004,6 +3017,7 @@ OTF_close (OTF *otf) if (internal_data) { OTF_MemoryRecord *memrec = internal_data->memory_record; + OTF_ApplicationData *app_data = internal_data->app_data; if (internal_data->header_stream) free_stream (internal_data->header_stream); @@ -3021,6 +3035,10 @@ OTF_close (OTF *otf) free (memrec); memrec = next; } + + for (; app_data; app_data = app_data->next) + if (app_data->data && app_data->freer) + app_data->freer (app_data->data); free (internal_data); } if (otf->filename) @@ -3216,3 +3234,44 @@ OTF_tag_name (OTF_Tag tag, char *name) name[3] = (char) (tag & 0xFF); name[4] = '\0'; } + +int +OTF_put_data (OTF *otf, char *id, void *data, void (*freer) (void *data)) +{ + char *errfmt = "appdata %s"; + int errret = -1; + OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data; + OTF_ApplicationData *app_data = internal_data->app_data; + int len = strlen (id) + 1; + + for (; app_data; app_data = app_data->next) + if (memcmp (app_data->id, id, len) == 0) + { + if (app_data->data && app_data->freer) + app_data->freer (app_data->data); + break; + } + if (! app_data) + { + OTF_MALLOC (app_data, sizeof (OTF_ApplicationData), id); + app_data->next = internal_data->app_data; + internal_data->app_data = app_data; + OTF_MALLOC (app_data->id, len, id); + memcpy (app_data->id, id, len); + } + app_data->data = data; + app_data->freer = freer; + return 0; +} + +void * +OTF_get_data (OTF *otf, char *id) +{ + OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data; + OTF_ApplicationData *app_data = internal_data->app_data; + + for (; app_data; app_data = app_data->next) + if (strcmp (app_data->id, id) == 0) + return app_data->data; + return NULL; +}