diff --git a/legacy/eet/src/bin/eet_bench_main.c b/legacy/eet/src/bin/eet_bench_main.c index 88aa364b93..cc13da36ef 100644 --- a/legacy/eet/src/bin/eet_bench_main.c +++ b/legacy/eet/src/bin/eet_bench_main.c @@ -1,3 +1,6 @@ +/* strdup requires BSD source */ +#define _BSD_SOURCE + #include "Eet.h" #include #include @@ -16,7 +19,7 @@ double get_time(void) { struct timeval timev; - + gettimeofday(&timev, NULL); return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); } @@ -30,7 +33,10 @@ main(int argc, char **argv) int items_num; int i; double t1, t2; - + + if (argc < 2) + exit(-1); + file = argv[1]; ef = eet_open(file, EET_FILE_MODE_READ); if (ef) @@ -45,16 +51,17 @@ main(int argc, char **argv) printf("EEK. cannot load %s\n", file); exit(-1); } - + t1 = get_time(); ef = eet_open(file, EET_FILE_MODE_READ); if (ef) { for (i = 0; i < items_num; i++) { - int w, h, alpha, compress, quality, lossy; + int alpha, compress, quality, lossy; + unsigned int w, h; void *data; - + if (eet_data_image_header_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy)) { data = eet_data_image_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy); @@ -81,9 +88,10 @@ main(int argc, char **argv) t1 = get_time(); for (i = 0; i < items_num; i++) { - int w, h, alpha, compress, quality, lossy; + int alpha, compress, quality, lossy; + unsigned int w, h; void *data; - + ef = eet_open(file, EET_FILE_MODE_READ); if (ef) { diff --git a/legacy/eet/src/bin/eet_main.c b/legacy/eet/src/bin/eet_main.c index f0fb86f2c5..e2a69cbc32 100644 --- a/legacy/eet/src/bin/eet_main.c +++ b/legacy/eet/src/bin/eet_main.c @@ -1,3 +1,6 @@ +/* PATH_MAX requires POSIX source */ +#define _POSIX_SOURCE + #include "Eet.h" #include #include @@ -51,31 +54,31 @@ encdectest(void) int size; FILE *f; Blah *blah_in; - + edd3 = eet_data_descriptor_new("blah3", sizeof(Blah3), - evas_list_next, - evas_list_append, - evas_list_data, + evas_list_next, + evas_list_append, + evas_list_data, evas_list_free, evas_hash_foreach, evas_hash_add, evas_hash_free); EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING); - + edd2 = eet_data_descriptor_new("blah2", sizeof(Blah2), - evas_list_next, - evas_list_append, - evas_list_data, + evas_list_next, + evas_list_append, + evas_list_data, evas_list_free, evas_hash_foreach, evas_hash_add, evas_hash_free); EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING); - + edd = eet_data_descriptor_new("blah", sizeof(Blah), - evas_list_next, - evas_list_append, - evas_list_data, + evas_list_next, + evas_list_append, + evas_list_data, evas_list_free, evas_hash_foreach, evas_hash_add, @@ -91,9 +94,9 @@ encdectest(void) EET_DATA_DESCRIPTOR_ADD_LIST (edd, Blah, "blah3", blah3, edd3); blah3.string="PANTS"; - + blah2.string="subtype string here!"; - + blah.character='7'; blah.sixteen=0x7777; blah.integer=0xc0def00d; @@ -109,14 +112,14 @@ encdectest(void) blah.blah3 = evas_list_append(blah.blah3, &blah3); blah.blah3 = evas_list_append(blah.blah3, &blah3); blah.blah3 = evas_list_append(blah.blah3, &blah3); - + data = eet_data_descriptor_encode(edd, &blah, &size); f = fopen("out", "wb"); if (f) { fwrite(data, size, 1, f); fclose(f); - } + } printf("-----DECODING\n"); blah_in = eet_data_descriptor_decode(edd, data, size); printf("-----DECODED!\n"); @@ -131,11 +134,11 @@ encdectest(void) printf(" %s\n", blah_in->blah2->string); { Evas_List *l; - + for (l = blah_in->blah3; l; l = l->next) { Blah3 *blah3_in; - + blah3_in = l->data; printf("%p\n", blah3_in); printf(" %s\n", blah3_in->string); @@ -144,7 +147,7 @@ encdectest(void) eet_data_descriptor_free(edd); eet_data_descriptor_free(edd2); eet_data_descriptor_free(edd3); - + exit(0); } #endif @@ -181,7 +184,7 @@ eet_mkdirs(char *s) { char ss[PATH_MAX]; int i, ii; - + i = 0; ii = 0; while (s[i]) @@ -199,14 +202,14 @@ depak_file(Eet_File *ef, char *file) void *data; int size; char *last; - + data = eet_read(ef, file, &size); if (data) { FILE *f; char buf[PATH_MAX]; int len; - + strncpy(buf, file, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; if (buf[0] == '/') return; @@ -219,12 +222,12 @@ depak_file(Eet_File *ef, char *file) if (!strcmp(&(buf[len - 3]), "/..")) return; } last = strrchr(buf, '/'); - if (last) + if (last) { last[1] = 0; eet_mkdirs(buf); } - + f = fopen(file, "wb"); if (f) { @@ -248,8 +251,8 @@ depack(char *pak_file) int i, num; char **list; Eet_File *ef; - - ef = eet_open(pak_file, EET_FILE_MODE_READ); + + ef = eet_open(pak_file, EET_FILE_MODE_READ); if (!ef) { printf("cannot open for reading: %s\n", pak_file); @@ -262,7 +265,7 @@ depack(char *pak_file) depak_file(ef, list[i]); free(list); } - eet_close(ef); + eet_close(ef); } void @@ -271,8 +274,8 @@ list(char *pak_file) int i, num; char **list; Eet_File *ef; - - ef = eet_open(pak_file, EET_FILE_MODE_READ); + + ef = eet_open(pak_file, EET_FILE_MODE_READ); if (!ef) { printf("cannot open for reading: %s\n", pak_file); @@ -285,29 +288,29 @@ list(char *pak_file) printf("%s\n",list[i]); free(list); } - eet_close(ef); + eet_close(ef); } void pak_file(Eet_File *ef, char *file, char **noz, int noz_num) { struct stat st; - + if (stat(file, &st) >= 0) { void *buf; - + buf = malloc(st.st_size); if (buf) { FILE *f; - + f = fopen(file, "rb"); if (f) { int compress = 1; int i; - + for (i = 0; i < noz_num; i++) { if (!fnmatch(noz[i], file, 0)) @@ -347,7 +350,7 @@ pak_dir(Eet_File *ef, char *dir, char **noz, int noz_num) while ((dp = readdir(dirp))) { char buf[PATH_MAX]; - + if ((!strcmp(".", dp->d_name)) || (!strcmp("..", dp->d_name))) { } @@ -365,7 +368,7 @@ pack(char *pak_file, char **files, int count, char **noz, int noz_num) { Eet_File *ef; int i; - + ef = eet_open(pak_file, EET_FILE_MODE_WRITE); if (!ef) { @@ -379,7 +382,7 @@ pack(char *pak_file, char **files, int count, char **noz, int noz_num) int main(int argc, char **argv) -{ +{ if (argc == 3) { if (!strcmp(argv[1], "-d")) @@ -397,11 +400,11 @@ main(int argc, char **argv) { char **noz = NULL; int noz_num = 0; - + if (!strcmp(argv[1], "-c")) { int i; - + for (i = 3; i < argc; i++) { if (!strcmp(argv[i], "-nz")) diff --git a/legacy/eet/src/lib/Eet.h b/legacy/eet/src/lib/Eet.h index 182f30a30d..9f4923f0d5 100644 --- a/legacy/eet/src/lib/Eet.h +++ b/legacy/eet/src/lib/Eet.h @@ -54,9 +54,9 @@ extern "C" { EET_FILE_MODE_WRITE, EET_FILE_MODE_READ_WRITE }; - + typedef enum _Eet_File_Mode Eet_File_Mode; - + typedef struct _Eet_File Eet_File; typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor; @@ -81,36 +81,36 @@ extern "C" { * @param file The file path to the eet file. eg: "/tmp/file.eet". * @param mode The mode for opening. Either EET_FILE_MODE_READ or EET_FILE_MODE_WRITE, but not both. * @return An opened eet file handle. - * + * * This function will open an exiting eet file for reading, and build * the directory table in memory and return a handle to the file, if it * exists and can be read, and no memory errors occur on the way, otherwise * NULL will be returned. - * + * * It will also open an eet file for writing. This will, if successful, * delete the original file and replace it with a new empty file, till * the eet file handle is closed or flushed. If it cannot be opened for * writing or a memory error occurs, NULL is returned. - * + * * Example: * @code * #include - * + * * int * main(int argc, char **argv) * { * Eet_File *ef; * char buf[1024], *ret, **list; * int size, num, i; - * + * * strcpy(buf, "Here is a string of data to save!"); - * + * * ef = eet_open("/tmp/my_file.eet, EET_FILE_MODE_WRITE); * if (!ef) return -1; * if (!eet_write(ef, "/key/to_store/at", buf, 1024, 1)) * fprintf("Error writing data!\n"); * eet_close(ef); - * + * * ef = eet_open("/tmp/my_file.eet, EET_FILE_MODE_READ); * if (!ef) return -1; * list = eet_list(ef, "*", &num); @@ -127,11 +127,11 @@ extern "C" { * free(ret); * } * eet_close(ef); - * + * * return 0; * } * @endcode - */ + */ EAPI Eet_File *eet_open (const char *file, Eet_File_Mode mode); /** @@ -140,33 +140,33 @@ extern "C" { * @return The mode ef was opened with. */ EAPI Eet_File_Mode eet_mode_get (Eet_File *ef); - + /** * Close an eet file handle and flush and writes pending. * @param ef A valid eet file handle. - * + * * This function will flush any pending writes to disk if the eet file * was opened for write, and free all data associated with the file handle * and file, and close the file. - * + * * If the eet file handle is not valid nothing will be done. */ EAPI void eet_close (Eet_File *ef); - + /** * Read a specified entry from an eet file and return data * @param ef A valid eet file handle opened for reading. * @param name Name of the entry. eg: "/base/file_i_want". * @param size_ret Number of bytes read from entry and returned. * @return The data stored in that entry in the eet file. - * + * * This function finds an entry in the eet file that is stored under the * name specified, and returns that data, decompressed, if successful. * NULL is returned if the lookup fails or if memory errors are * encountered. It is the job of the calling program to call free() on * the returned data. The number of bytes in the returned data chunk are * placed in size_ret. - * + * * If the eet file handle is not valid NULL is returned and size_ret is * filled with 0. */ @@ -180,17 +180,17 @@ extern "C" { * @param size Length in bytes in the data to be stored. * @param compress Compression flags (1 == compress, 0 = don't compress). * @return Success or failure of the write. - * + * * This function will write the specified chunk of data to the eet file * and return greater than 0 on success. 0 will be returned on failure. - * - * The eet file handle must be a valid file handle for an eet file opened + * + * The eet file handle must be a valid file handle for an eet file opened * for writing. If it is not, 0 will be returned and no action will be * performed. - * + * * Name, and data must not be NULL, and size must be > 0. If these * conditions are not met, 0 will be returned. - * + * * The data will be copied (and optionally compressed) in ram, pending * a flush to disk (it will stay in ram till the eet file handle is * closed though). @@ -202,42 +202,42 @@ extern "C" { * @param ef A valid eet file handle opened for writing. * @param name Name of the entry. eg: "/base/file_i_want". * @return Success or failure of the delete. - * + * * This function will delete the specified chunk of data from the eet file * and return greater than 0 on success. 0 will be returned on failure. - * - * The eet file handle must be a valid file handle for an eet file opened + * + * The eet file handle must be a valid file handle for an eet file opened * for writing. If it is not, 0 will be returned and no action will be * performed. - * + * * Name, must not be NULL, otherwise 0 will be returned. */ EAPI int eet_delete(Eet_File *ef, char *name); - + /** * List all entries in eet file matching shell glob. * @param ef A valid eet file handle. * @param glob A shell glob to match against. * @param count_ret Number of entries found to match. * @return Pointer to an array of strings. - * + * * This function will list all entries in the eet file matching the * supplied shell glob and return an allocated list of their names, if * there are any, and if no memory errors occur. - * + * * The eet file handle must be valid and glob must not be NULL, or NULL * will be returned and count_ret will be filled with 0. - * + * * The calling program must call free() on the array returned, but NOT * on the string pointers in the array. They are taken as read-only * internals from the eet file handle. They are only valid as long as * the file handle is not closed. When it is closed those pointers in the * array are now not valid and should not be used. - * + * * On success the array returned will have a list of string pointers * that are the names of the entries that matched, and count_ret will have * the number of entries in this array placed in it. - * + * * Hint: an easy way to list all entries in an eet file is to use a glob * value of "*". */ @@ -249,20 +249,20 @@ extern "C" { * Read just the header data for an image and dont decode the pixels. * @param ef A valid eet file handle opened for reading. * @param name Name of the entry. eg: "/base/file_i_want". - * @param w A pointer to the int to hold the width in pixels. - * @param h A pointer to the int to hold the height in pixels. + * @param w A pointer to the unsigned int to hold the width in pixels. + * @param h A pointer to the unsigned int to hold the height in pixels. * @param alpha A pointer to the int to hold the alpha flag. * @param compress A pointer to the int to hold the compression amount. * @param quality A pointer to the int to hold the quality amount. * @param lossy A pointer to the int to hold the lossiness flag. * @return 1 on successfull decode, 0 otherwise - * + * * This function reads an image from an eet file stored under the named * key in the eet file and return a pointer to the decompressed pixel data. - * + * * The other parameters of the image (width, height etc.) are placed into * the values pointed to (they must be supplied). The pixel data is a linear - * array of pixels starting from the top-left of the image scanning row by + * array of pixels starting from the top-left of the image scanning row by * row from left to right. Each pile is a 32bit value, with the high byte * being the alpha channel, the next being red, then green, and the low byte * being blue. The width and height are measured in pixels and will be @@ -272,30 +272,30 @@ extern "C" { * stored with. The quality value is filled with the quality encoding of * the image file (0 - 100). The lossy flags is either 0 or 1 as to if * the image was encoded lossily or not. - * + * * On success the function returns 1 indicating the header was read and * decoded properly, or 0 on failure. */ - EAPI int eet_data_image_header_read(Eet_File *ef, char *name, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy); - + EAPI int eet_data_image_header_read(Eet_File *ef, char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); + /** * Read image data from the named key in the eet file. * @param ef A valid eet file handle opened for reading. * @param name Name of the entry. eg: "/base/file_i_want". - * @param w A pointer to the int to hold the width in pixels. - * @param h A pointer to the int to hold the height in pixels. + * @param w A pointer to the unsigned int to hold the width in pixels. + * @param h A pointer to the unsigned int to hold the height in pixels. * @param alpha A pointer to the int to hold the alpha flag. * @param compress A pointer to the int to hold the compression amount. * @param quality A pointer to the int to hold the quality amount. * @param lossy A pointer to the int to hold the lossiness flag. * @return The image pixel data decoded - * + * * This function reads an image from an eet file stored under the named * key in the eet file and return a pointer to the decompressed pixel data. - * + * * The other parameters of the image (width, height etc.) are placed into * the values pointed to (they must be supplied). The pixel data is a linear - * array of pixels starting from the top-left of the image scanning row by + * array of pixels starting from the top-left of the image scanning row by * row from left to right. Each pile is a 32bit value, with the high byte * being the alpha channel, the next being red, then green, and the low byte * being blue. The width and height are measured in pixels and will be @@ -305,14 +305,14 @@ extern "C" { * stored with. The quality value is filled with the quality encoding of * the image file (0 - 100). The lossy flags is either 0 or 1 as to if * the image was encoded lossily or not. - * + * * On success the function returns a pointer to the image data decoded. The * calling application is responsible for calling free() on the image data * when it is done with it. On failure NULL is returned and the parameter * values may not contain any sensible data. */ - EAPI void *eet_data_image_read(Eet_File *ef, char *name, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy); - + EAPI void *eet_data_image_read(Eet_File *ef, char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); + /** * Write image data to the named key in an eet file. * @param ef A valid eet file handle opened for writing. @@ -325,11 +325,11 @@ extern "C" { * @param quality The quality encoding amount. * @param lossy The lossiness flag. * @return Success if the data was encoded and written or not. - * + * * This function takes image pixel data and encodes it in an eet file * stored under the supplied name key, and returns how many bytes were * actually written to encode the image data. - * + * * The data expected is the same format as returned by eet_data_image_read. * If this is not the case weird things may happen. Width and height must * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning @@ -339,30 +339,30 @@ extern "C" { * lossy compression and should be a value from 0 to 100. The lossy flag * can be 0 or 1. 0 means encode losslessly and 1 means to encode with * image quality loss (but then have a much smaller encoding). - * + * * On success this function returns the number of bytes that were required * to encode the image data, or on failure it returns 0. - */ - EAPI int eet_data_image_write(Eet_File *ef, char *name, void *data, int w, int h, int alpha, int compress, int quality, int lossy); - + */ + EAPI int eet_data_image_write(Eet_File *ef, char *name, void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy); + /** * Decode Image data header only to get information. * @param data The encoded pixel data. * @param size The size, in bytes, of the encoded pixel data. - * @param w A pointer to the int to hold the width in pixels. - * @param h A pointer to the int to hold the height in pixels. + * @param w A pointer to the unsigned int to hold the width in pixels. + * @param h A pointer to the unsigned int to hold the height in pixels. * @param alpha A pointer to the int to hold the alpha flag. * @param compress A pointer to the int to hold the compression amount. * @param quality A pointer to the int to hold the quality amount. * @param lossy A pointer to the int to hold the lossiness flag. * @return 1 on success, 0 on failure. - * + * * This function takes encoded pixel data and decodes it into raw RGBA * pixels on success. - * + * * The other parameters of the image (width, height etc.) are placed into * the values pointed to (they must be supplied). The pixel data is a linear - * array of pixels starting from the top-left of the image scanning row by + * array of pixels starting from the top-left of the image scanning row by * row from left to right. Each pixel is a 32bit value, with the high byte * being the alpha channel, the next being red, then green, and the low byte * being blue. The width and height are measured in pixels and will be @@ -372,30 +372,30 @@ extern "C" { * stored with. The quality value is filled with the quality encoding of * the image file (0 - 100). The lossy flags is either 0 or 1 as to if * the image was encoded lossily or not. - * + * * On success the function returns 1 indicating the header was read and * decoded properly, or 0 on failure. */ - EAPI int eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy); + EAPI int eet_data_image_header_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); /** * Decode Image data into pixel data. * @param data The encoded pixel data. * @param size The size, in bytes, of the encoded pixel data. - * @param w A pointer to the int to hold the width in pixels. - * @param h A pointer to the int to hold the height in pixels. + * @param w A pointer to the unsigned int to hold the width in pixels. + * @param h A pointer to the unsigned int to hold the height in pixels. * @param alpha A pointer to the int to hold the alpha flag. * @param compress A pointer to the int to hold the compression amount. * @param quality A pointer to the int to hold the quality amount. * @param lossy A pointer to the int to hold the lossiness flag. * @return The image pixel data decoded - * + * * This function takes encoded pixel data and decodes it into raw RGBA * pixels on success. - * + * * The other parameters of the image (width, height etc.) are placed into * the values pointed to (they must be supplied). The pixel data is a linear - * array of pixels starting from the top-left of the image scanning row by + * array of pixels starting from the top-left of the image scanning row by * row from left to right. Each pixel is a 32bit value, with the high byte * being the alpha channel, the next being red, then green, and the low byte * being blue. The width and height are measured in pixels and will be @@ -405,13 +405,13 @@ extern "C" { * stored with. The quality value is filled with the quality encoding of * the image file (0 - 100). The lossy flags is either 0 or 1 as to if * the image was encoded lossily or not. - * + * * On success the function returns a pointer to the image data decoded. The * calling application is responsible for calling free() on the image data * when it is done with it. On failure NULL is returned and the parameter * values may not contain any sensible data. */ - EAPI void *eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy); + EAPI void *eet_data_image_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); /** * Encode image data for storage or transmission. @@ -424,11 +424,11 @@ extern "C" { * @param quality The quality encoding amount. * @param lossy The lossiness flag. * @return The encoded image data. - * + * * This function stakes image pixel data and encodes it with compression and * possible loss of quality (as a trade off for size) for storage or * transmission to another system. - * + * * The data expected is the same format as returned by eet_data_image_read. * If this is not the case weird things may happen. Width and height must * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning @@ -438,14 +438,14 @@ extern "C" { * lossy compression and should be a value from 0 to 100. The lossy flag * can be 0 or 1. 0 means encode losslessly and 1 means to encode with * image quality loss (but then have a much smaller encoding). - * + * * On success this function returns a pointer to the encoded data that you * can free with free() when no longer needed. - */ - EAPI void *eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int compress, int quality, int lossy); + */ + EAPI void *eet_data_image_encode(void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy); /***************************************************************************/ - + /** * Create a new empty data structure descriptor. * @param name The string name of this data structure. @@ -458,39 +458,39 @@ extern "C" { * @param func_hash_add The function to add a member to a hash table. * @param func_hash_free The function to free an entire hash table. * @return A new empty data descriptor. - * + * * This function creates a new data descriptore and returns a handle to the * new data descriptor. On creation it will be empty, containing no contents * describing anything other than the shell of the data structure. - * + * * You add structure members to the data descriptor using the macros * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are * adding to the description. - * + * * Once you have described all the members of a struct you want loaded, or * saved eet can load and save those members for you, encode them into * endian-independant serialised data chunks for transmission across a * a network or more. - * + * * Example: - * + * * @code * #include * #include - * + * * typedef struct _blah2 * { * char *string; * } * Blah2; - * + * * typedef struct _blah3 * { * char *string; * } * Blah3; - * + * * typedef struct _blah * { * char character; @@ -504,7 +504,7 @@ extern "C" { * Evas_List *blah3; * } * Blah; - * + * * int * main(int argc, char **argv) * { @@ -516,7 +516,7 @@ extern "C" { * int size; * FILE *f; * Blah *blah_in; - * + * * edd3 = eet_data_descriptor_new("blah3", sizeof(Blah3), * evas_list_next, * evas_list_append, @@ -526,7 +526,7 @@ extern "C" { * evas_hash_add, * evas_hash_free); * EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING); - * + * * edd2 = eet_data_descriptor_new("blah2", sizeof(Blah2), * evas_list_next, * evas_list_append, @@ -536,7 +536,7 @@ extern "C" { * evas_hash_add, * evas_hash_free); * EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING); - * + * * edd = eet_data_descriptor_new("blah", sizeof(Blah), * evas_list_next, * evas_list_append, @@ -554,11 +554,11 @@ extern "C" { * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "string", string, EET_T_STRING); * EET_DATA_DESCRIPTOR_ADD_SUB(edd, Blah, "blah2", blah2, edd2); * EET_DATA_DESCRIPTOR_ADD_LIST(edd, Blah, "blah3", blah3, edd3); - * + * * blah3.string="PANTS"; - * + * * blah2.string="subtype string here!"; - * + * * blah.character='7'; * blah.sixteen=0x7777; * blah.integer=0xc0def00d; @@ -574,7 +574,7 @@ extern "C" { * blah.blah3 = evas_list_append(blah.blah3, &blah3); * blah.blah3 = evas_list_append(blah.blah3, &blah3); * blah.blah3 = evas_list_append(blah.blah3, &blah3); - * + * * data = eet_data_descriptor_encode(edd, &blah, &size); * f = fopen("out", "w"); * if (f) @@ -584,7 +584,7 @@ extern "C" { * } * printf("-----DECODING\n"); * blah_in = eet_data_descriptor_decode(edd, data, size); - * + * * printf("-----DECODED!\n"); * printf("%c\n", blah_in->character); * printf("%x\n", (int)blah_in->sixteen); @@ -597,11 +597,11 @@ extern "C" { * printf(" %s\n", blah_in->blah2->string); * { * Evas_List *l; - * + * * for (l = blah_in->blah3; l; l = l->next) * { * Blah3 *blah3_in; - * + * * blah3_in = l->data; * printf("%p\n", blah3_in); * printf(" %s\n", blah3_in->string); @@ -610,15 +610,15 @@ extern "C" { * eet_data_descriptor_free(edd); * eet_data_descriptor_free(edd2); * eet_data_descriptor_free(edd3); - * + * * return 0; * } - * + * * @endcode - * + * */ EAPI Eet_Data_Descriptor *eet_data_descriptor_new(char *name, int size, void *(*func_list_next) (void *l), void *(*func_list_append) (void *l, void *d), void *(*func_list_data) (void *l), void *(*func_list_free) (void *l), void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt), void *(*func_hash_add) (void *h, const char *k, void *d), void (*func_hash_free) (void *h)); - + /** * This function frees a data descriptor when it is not needed anymore. * @param edd The data descriptor to free. @@ -626,10 +626,10 @@ extern "C" { * This function takes a data descriptor handle as a parameter and frees all * data allocated for the data descriptor and the handle itself. After this * call the descriptor is no longer valid. - * + * */ EAPI void eet_data_descriptor_free(Eet_Data_Descriptor *edd); - + /** * This function is an internal used by macros. * @@ -637,17 +637,17 @@ extern "C" { * EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is * complex to use by hand and should be left to be used by the macros, and * thus is not documented. - * + * */ EAPI void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type, int group_type, int offset, int count, char *counter_name, Eet_Data_Descriptor *subtype); - + /** * Read a data structure from an eet file and decodes it. * @param ef The eet file handle to read from. * @param edd The data descriptor handle to use when decoding. * @param name The key the data is stored under in the eet file. * @return A pointer to the decoded data structure. - * + * * This function decodes a data structure stored in an eet file, returning * a pointer to it if it decoded successfully, or NULL on failure. This * can save a programmer dozens of hours of work in writing configuration @@ -657,15 +657,15 @@ extern "C" { * storage and safely zero-fills unfilled members if they were not found * in the data. It checks sizes and headers whenever it reads data, allowing * the programmer to not worry about corrupt data. - * + * * Once a data structure has been described by the programmer with the * fields they wish to save or load, storing or retrieving a data structure * from an eet file, or from a chunk of memory is as simple as a single * function call. - * + * */ EAPI void *eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name); - + /** * Write a data structure from memory and store in an eet file. * @param ef The eet file handle to write to. @@ -674,38 +674,38 @@ extern "C" { * @param data A pointer to the data structure to ssave and encode. * @param compress Compression flags for storage. * @return 1 on successful write, 0 on failure. - * + * * This function is the reverse of eet_data_read(), saving a data structure * to an eet file. - * + * */ EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, char *name, void *data, int compress); - + /** * Decode a data structure from an arbitary location in memory. * @param edd The data descriptor to use when decoding. * @param data_in The pointer to the data to decode into a struct. * @param size_in The size of the data pointed to in bytes. * @return NULL on failure, or a valid decoded struct pointer on success. - * + * * This function will decode a data structure that has been encoded using * eet_data_descriptor_encode(), and return a data structure with all its * elements filled out, if successful, or NULL on failure. - * + * * The data to be decoded is stored at the memory pointed to by @p data_in, * and is described by the descriptor pointed to by @p edd. The data size is * passed in as the value to @p size_in, ande must be greater than 0 to * succeed. - * + * * This function is useful for decoding data structures delivered to the * application by means other than an eet file, such as an IPC or socket * connection, raw files, shared memory etc. - * + * * Please see eet_data_read() for more information. - * - */ + * + */ EAPI void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd, void *data_in, int size_in); - + /** * Encode a dsata struct to memory and return that encoded data. * @param edd The data descriptor to use when encoding. @@ -714,22 +714,22 @@ extern "C" { * @return NULL on failure, or a valid encoded data chunk on success. * * This function takes a data structutre in memory and encodes it into a - * serialised chunk of data that can be decoded again by + * serialised chunk of data that can be decoded again by * eet_data_descriptor_decode(). This is useful for being able to transmit * data structures across sockets, pipes, IPC or shared file mechanisms, * without having to worry about memory space, machine type, endianess etc. - * + * * The parameter @p edd must point to a valid data descriptor, and * @p data_in must point to the right data structure to encode. If not, the * encoding may fail. - * + * * On success a non NULL valid pointer is returned and what @p size_ret * points to is set to the size of this decoded data, in bytes. When the * encoded data is no longer needed, call free() on it. On failure NULL is * returned and what @p size_ret points to is set to 0. - * + * * Please see eet_data_write() for more information. - * + * */ EAPI void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd, void *data_in, int *size_ret); @@ -740,7 +740,7 @@ extern "C" { * @param name The string name to use to encode/decode this member. * @param member The struct member itself to be encoded. * @param type The type of the member to encode. - * + * * This macro is a convenience macro provided to add a member to the data * descriptor @p edd. The type of the structure is provided as the * @p struct_type parameter (for example: struct my_struct). The @p name @@ -751,7 +751,7 @@ extern "C" { * must be one of: EET_T_CHAR, EET_T_SHORT, EET_T_INT, EET_T_LONG_LONG, * EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR, EET_T_USHORT, EET_T_UINT, * EET_T_ULONG_LONG or EET_T_STRING. - * + * */ #define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \ { \ @@ -761,7 +761,7 @@ extern "C" { (char *)(&(___ett.member)) - (char *)(&(___ett)), \ 0, NULL, NULL); \ } - + /** * Add a sub-element type to a data descriptor * @param edd The data descriptor to add the type to. @@ -769,13 +769,13 @@ extern "C" { * @param name The string name to use to encode/decode this member. * @param member The struct member itself to be encoded. * @param subtype The type of sub-type struct to add. - * + * * This macro lets you easily add a sub-type (a struct that's pointed to - * by this one). All the parameters are the same as for + * by this one). All the parameters are the same as for * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception. * This must be the data descriptor of the struct that is pointed to by * this element. - * + * */ #define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype) \ { \ @@ -785,7 +785,7 @@ extern "C" { (char *)(&(___ett.member)) - (char *)(&(___ett)), \ 0, NULL, subtype); \ } - + /** * Add a linked list type to a data descriptor * @param edd The data descriptor to add the type to. @@ -793,12 +793,12 @@ extern "C" { * @param name The string name to use to encode/decode this member. * @param member The struct member itself to be encoded. * @param subtype The type of linked list member to add. - * - * This macro lets you easily add a linked list of other data types. All the - * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the + * + * This macro lets you easily add a linked list of other data types. All the + * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the * @p subtype being the exception. This must be the data descriptor of the * element that is in each member of the linked list to be stored. - * + * */ #define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \ { \ diff --git a/legacy/eet/src/lib/eet_data.c b/legacy/eet/src/lib/eet_data.c index 28f1c143eb..7c6ec7a24d 100644 --- a/legacy/eet/src/lib/eet_data.c +++ b/legacy/eet/src/lib/eet_data.c @@ -3,12 +3,12 @@ /* * rotuines for doing data -> struct and struct -> data conversion - * + * * types: - * + * * basic types: * a sequence of... - * + * * char * short * int @@ -20,23 +20,23 @@ * unsigned int * unsgined long long * string - * + * * groupings: * multiple entries ordered as... - * + * * fixed size array [ of basic types ] * variable size array [ of basic types ] * linked list [ of basic types ] * hash table [ of basic types ] - * + * * need to provide builder/accessor funcs for: - * + * * list_next * list_append - * + * * hash_foreach * hash_add - * + * */ /*---*/ @@ -131,7 +131,7 @@ static void eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream /*---*/ -const Eet_Data_Basic_Type_Decoder eet_coder[] = +const Eet_Data_Basic_Type_Decoder eet_coder[] = { {sizeof(char), eet_data_get_char, eet_data_put_char }, {sizeof(short), eet_data_get_short, eet_data_put_short }, @@ -180,7 +180,7 @@ static int eet_data_get_char(void *src, void *src_end, void *dst) { char *s, *d; - + if (((char *)src + sizeof(char)) > (char *)src_end) return -1; s = (char *)src; d = (char *)dst; @@ -193,7 +193,7 @@ static void * eet_data_put_char(void *src, int *size_ret) { char *s, *d; - + d = (char *)malloc(sizeof(char)); if (!d) return NULL; s = (char *)src; @@ -208,7 +208,7 @@ static int eet_data_get_short(void *src, void *src_end, void *dst) { short *d; - + if (((char *)src + sizeof(short)) > (char *)src_end) return -1; memcpy(dst, src, sizeof(short)); d = (short *)dst; @@ -220,7 +220,7 @@ static void * eet_data_put_short(void *src, int *size_ret) { short *s, *d; - + d = (short *)malloc(sizeof(short)); if (!d) return NULL; s = (short *)src; @@ -235,7 +235,7 @@ static int eet_data_get_int(void *src, void *src_end, void *dst) { int *d; - + if (((char *)src + sizeof(int)) > (char *)src_end) return -1; memcpy(dst, src, sizeof(int)); d = (int *)dst; @@ -247,7 +247,7 @@ static void * eet_data_put_int(void *src, int *size_ret) { int *s, *d; - + d = (int *)malloc(sizeof(int)); if (!d) return NULL; s = (int *)src; @@ -262,7 +262,7 @@ static int eet_data_get_long_long(void *src, void *src_end, void *dst) { unsigned long long *d; - + if (((char *)src + sizeof(unsigned long long)) > (char *)src_end) return -1; memcpy(dst, src, sizeof(unsigned long long)); d = (unsigned long long *)dst; @@ -274,7 +274,7 @@ static void * eet_data_put_long_long(void *src, int *size_ret) { unsigned long long *s, *d; - + d = (unsigned long long *)malloc(sizeof(unsigned long long)); if (!d) return NULL; s = (unsigned long long *)src; @@ -290,7 +290,7 @@ eet_data_get_string(void *src, void *src_end, void *dst) { char *s, **d, *p; int len; - + s = (char *)src; d = (char **)dst; p = s; @@ -309,7 +309,7 @@ eet_data_put_string(void *src, int *size_ret) char *s, *d; int len; const char *empty_s = ""; - + s = (char *)(*((char **)src)); if (!s) s = (char *)empty_s; len = strlen(s); @@ -327,7 +327,7 @@ eet_data_get_float(void *src, void *src_end, void *dst) float *d; char *s, *str, *p, *prev_locale; int len; - + s = (char *)src; d = (float *)dst; p = s; @@ -337,11 +337,11 @@ eet_data_get_float(void *src, void *src_end, void *dst) if (!str) return -1; memcpy(str, s, len); str[len] = 0; - + prev_locale = setlocale(LC_NUMERIC, "C"); *d = (float)atof(str); if (prev_locale) setlocale(LC_NUMERIC, prev_locale); - + free(str); return len + 1; } @@ -352,7 +352,7 @@ eet_data_put_float(void *src, int *size_ret) float *s; char *d, buf[64], *prev_locale; int len; - + s = (float *)src; prev_locale = setlocale(LC_NUMERIC, "C"); snprintf(buf, sizeof(buf), "%a", (double)(*s)); @@ -372,7 +372,7 @@ eet_data_get_double(void *src, void *src_end, void *dst) double *d; char *s, *str, *p, *prev_locale; int len; - + s = (char *)src; d = (double *)dst; p = s; @@ -382,11 +382,11 @@ eet_data_get_double(void *src, void *src_end, void *dst) if (!str) return -1; memcpy(str, s, len); str[len] = 0; - + prev_locale = setlocale(LC_NUMERIC, "C"); *d = (double)atof(str); if (prev_locale) setlocale(LC_NUMERIC, prev_locale); - + free(str); return len + 1; } @@ -397,7 +397,7 @@ eet_data_put_double(void *src, int *size_ret) double *s; char *d, buf[128], *prev_locale; int len; - + s = (double *)src; prev_locale = setlocale(LC_NUMERIC, "C"); snprintf(buf, sizeof(buf), "%a", (double)(*s)); @@ -414,7 +414,7 @@ static int eet_data_get_type(int type, void *src, void *src_end, void *dest) { int ret; - + ret = eet_coder[type - 1].get(src, src_end, dest); return ret; } @@ -423,20 +423,20 @@ static void * eet_data_put_type(int type, void *src, int *size_ret) { void *ret; - + ret = eet_coder[type - 1].put(src, size_ret); return ret; } /* chunk format... - * + * * char[4] = "CHnK"; * int = chunk size (including magic string); * char[] = chuck magic/name string (0 byte terminated); * ... sub-chunks (a chunk can contain chuncks recusrively) ... * or * ... payload data ... - * + * */ static Eet_Data_Chunk * @@ -445,13 +445,13 @@ eet_data_chunk_get(void *src, int size) Eet_Data_Chunk *chnk; char *s; int ret1, ret2; - + if (!src) return NULL; if (size <= 8) return NULL; - + chnk = calloc(1, sizeof(Eet_Data_Chunk)); if (!chnk) return NULL; - + s = src; if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K')) { @@ -462,18 +462,18 @@ eet_data_chunk_get(void *src, int size) if (ret1 <= 0) { free(chnk); - return NULL; + return NULL; } if ((chnk->size < 0) || ((chnk->size + 8) > size)) { free(chnk); - return NULL; + return NULL; } ret2 = eet_data_get_type(EET_T_STRING, (void *)(s + 8), (void *)(s + size), &(chnk->name)); if (ret2 <= 0) { free(chnk); - return NULL; + return NULL; } chnk->data = (char *)src + 4 + ret1 + ret2; chnk->size -= ret2; @@ -484,15 +484,15 @@ static Eet_Data_Chunk * eet_data_chunk_new(void *data, int size, char *name) { Eet_Data_Chunk *chnk; - + if (!name) return NULL; chnk = calloc(1, sizeof(Eet_Data_Chunk)); if (!chnk) return NULL; - + chnk->name = strdup(name); chnk->size = size; chnk->data = data; - + return chnk; } @@ -507,7 +507,7 @@ static Eet_Data_Stream * eet_data_stream_new(void) { Eet_Data_Stream *ds; - + ds = calloc(1, sizeof(Eet_Data_Stream)); if (!ds) return NULL; return ds; @@ -524,7 +524,7 @@ static void eet_data_stream_write(Eet_Data_Stream *ds, void *data, int size) { char *p; - + if ((ds->pos + size) > ds->size) { ds->data = realloc(ds->data, ds->size + size + 256); @@ -598,7 +598,7 @@ void eet_data_descriptor_free(Eet_Data_Descriptor *edd) { int i; - + if (edd->name) free(edd->name); for (i = 0; i < edd->elements.num; i++) { @@ -610,14 +610,14 @@ eet_data_descriptor_free(Eet_Data_Descriptor *edd) } void -eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type, - int group_type, - int offset, - int count, char *counter_name, +eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type, + int group_type, + int offset, + int count, char *counter_name, Eet_Data_Descriptor *subtype) { Eet_Data_Element *ede; - + edd->elements.num++; edd->elements.set = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element)); if (!edd->elements.set) return; @@ -639,7 +639,7 @@ eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name) void *data_dec; void *data; int size; - + data = eet_read(ef, name, &size); if (!data) return NULL; data_dec = eet_data_descriptor_decode(edd, data, size); @@ -653,7 +653,7 @@ eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, char *name, void *data, i void *data_enc; int size; int val; - + data_enc = eet_data_descriptor_encode(edd, data, &size); if (!data_enc) return 0; val = eet_write(ef, name, data_enc, size, compress); @@ -720,7 +720,7 @@ static void _eet_freelist_list_add(void **data) { int i; - + for (i = 0; i < freelist_list_num; i++) { if (freelist_list[i] == data) return; @@ -748,7 +748,7 @@ static void _eet_freelist_list_free(Eet_Data_Descriptor *edd) { int i; - + if (freelist_list_ref > 0) return; for (i = 0; i < freelist_list_num; i++) edd->func.list_free(*(freelist_list[i])); @@ -776,7 +776,7 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, char *p; int size; Eet_Data_Chunk *chnk; - + if (words_bigendian == -1) { unsigned long int v; @@ -785,7 +785,7 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, if (v == 0x12345678) words_bigendian = 1; else words_bigendian = 0; } - + data = calloc(1, edd->size); if (!data) return NULL; _eet_freelist_ref(); @@ -815,7 +815,7 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, { Eet_Data_Chunk *echnk; int i; - + /* get next data chunk */ echnk = eet_data_chunk_get(p, size); if (!echnk) @@ -830,7 +830,7 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, for (i = 0; i < edd->elements.num; i++) { Eet_Data_Element *ede; - + ede = &(edd->elements.set[i]); if (!strcmp(echnk->name, ede->name)) { @@ -838,8 +838,8 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, { int ret; void *data_ret; - - if ((ede->type >= EET_T_CHAR) && + + if ((ede->type >= EET_T_CHAR) && (ede->type <= EET_T_STRING)) { ret = eet_data_get_type(ede->type, @@ -850,7 +850,7 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, else if (ede->subtype) { void **ptr; - + data_ret = eet_data_descriptor_decode(ede->subtype, echnk->data, echnk->size); @@ -883,7 +883,7 @@ eet_data_descriptor_decode(Eet_Data_Descriptor *edd, void *list = NULL; void **ptr; void *data_ret; - + ptr = (void **)(((char *)data) + ede->offset); list = *ptr; data_ret = NULL; @@ -974,7 +974,7 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, int i; void *cdata; int csize; - + if (words_bigendian == -1) { unsigned long int v; @@ -983,7 +983,7 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, if (v == 0x12345678) words_bigendian = 1; else words_bigendian = 0; } - + ds = eet_data_stream_new(); for (i = 0; i < edd->elements.num; i++) { @@ -991,24 +991,24 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, Eet_Data_Chunk *echnk; void *data; int size; - + ede = &(edd->elements.set[i]); data = NULL; if (ede->group_type == EET_G_UNKNOWN) { - if ((ede->type >= EET_T_CHAR) && + if ((ede->type >= EET_T_CHAR) && (ede->type <= EET_T_STRING)) - data = eet_data_put_type(ede->type, - ((char *)data_in) + ede->offset, + data = eet_data_put_type(ede->type, + ((char *)data_in) + ede->offset, &size); else if (ede->subtype) { if (*((char **)(((char *)data_in) + ede->offset))) - data = eet_data_descriptor_encode(ede->subtype, + data = eet_data_descriptor_encode(ede->subtype, *((char **)(((char *)data_in) + ede->offset)), &size); } - if (data) + if (data) { echnk = eet_data_chunk_new(data, size, ede->name); eet_data_chunk_put(echnk, ds); @@ -1030,7 +1030,7 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, case EET_G_LIST: { void *l; - + l = *((void **)(((char *)data_in) + ede->offset)); for (; l; l = edd->func.list_next(l)) { @@ -1045,7 +1045,7 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, &size); if (data) { - echnk = eet_data_chunk_new(data, size, ede->name); + echnk = eet_data_chunk_new(data, size, ede->name); eet_data_chunk_put(echnk, ds); eet_data_chunk_free(echnk); free(data); @@ -1068,7 +1068,7 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, ds->data = NULL; ds->size = 0; eet_data_stream_free(ds); - + ds = eet_data_stream_new(); eet_data_chunk_put(chnk, ds); cdata = ds->data; @@ -1078,9 +1078,9 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd, ds->size = 0; eet_data_stream_free(ds); *size_ret = csize; - + free(chnk->data); eet_data_chunk_free(chnk); - + return cdata; } diff --git a/legacy/eet/src/lib/eet_image.c b/legacy/eet/src/lib/eet_image.c index 5c6da893f5..62cb9ad59c 100644 --- a/legacy/eet/src/lib/eet_image.c +++ b/legacy/eet/src/lib/eet_image.c @@ -19,13 +19,13 @@ static void _JPEGFatalErrorHandler(j_common_ptr cinfo); static void _JPEGErrorHandler(j_common_ptr cinfo); static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level); -static int eet_data_image_jpeg_header_decode(void *data, int size, int *w, int *h); -static void *eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h); -static void *eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, int *h); -static void *eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha); -static void *eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int alpha, int compression); -static void *eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int quality); -static void *eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha, int quality); +static int eet_data_image_jpeg_header_decode(void *data, int size, unsigned int *w, unsigned int *h); +static void *eet_data_image_jpeg_rgb_decode(void *data, int size, unsigned int *w, unsigned int *h); +static void *eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, unsigned int *w, unsigned int *h); +static void *eet_data_image_lossless_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha); +static void *eet_data_image_lossless_compressed_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int compression); +static void *eet_data_image_jpeg_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality); +static void *eet_data_image_jpeg_alpha_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality); /*---*/ @@ -62,29 +62,29 @@ static void _JPEGFatalErrorHandler(j_common_ptr cinfo) { emptr errmgr; - + errmgr = (emptr) cinfo->err; /* cinfo->err->output_message(cinfo);*/ longjmp(errmgr->setjmp_buffer, 1); return; } - + static void _JPEGErrorHandler(j_common_ptr cinfo) { emptr errmgr; - + errmgr = (emptr) cinfo->err; /* cinfo->err->output_message(cinfo);*/ /* longjmp(errmgr->setjmp_buffer, 1);*/ return; } - + static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level) { emptr errmgr; - + errmgr = (emptr) cinfo->err; /* cinfo->err->output_message(cinfo);*/ /* longjmp(errmgr->setjmp_buffer, 1);*/ @@ -93,12 +93,12 @@ _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level) } static int -eet_data_image_jpeg_header_decode(void *data, int size, int *w, int *h) +eet_data_image_jpeg_header_decode(void *data, int size, unsigned int *w, unsigned int *h) { struct jpeg_decompress_struct cinfo; struct _JPEG_error_mgr jerr; FILE *f; - + f = _eet_memfile_read_open(data, (size_t)size); if (!f) return 0; cinfo.err = jpeg_std_error(&(jerr.pub)); @@ -117,7 +117,7 @@ eet_data_image_jpeg_header_decode(void *data, int size, int *w, int *h) cinfo.do_fancy_upsampling = FALSE; cinfo.do_block_smoothing = FALSE; jpeg_start_decompress(&cinfo); - + /* head decoding */ *w = cinfo.output_width; *h = cinfo.output_height; @@ -128,16 +128,17 @@ eet_data_image_jpeg_header_decode(void *data, int size, int *w, int *h) } static void * -eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h) +eet_data_image_jpeg_rgb_decode(void *data, int size, unsigned int *w, unsigned int *h) { unsigned int *d; struct jpeg_decompress_struct cinfo; struct _JPEG_error_mgr jerr; unsigned char *ptr, *line[16], *tdata = NULL; unsigned int *ptr2; - int x, y, l, i, scans, count, prevy; + unsigned int x, y, l, scans; + int i, count, prevy; FILE *f; - + f = _eet_memfile_read_open(data, (size_t)size); if (!f) return NULL; cinfo.err = jpeg_std_error(&(jerr.pub)); @@ -158,7 +159,7 @@ eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h) cinfo.do_fancy_upsampling = FALSE; cinfo.do_block_smoothing = FALSE; jpeg_start_decompress(&cinfo); - + /* head decoding */ *w = cinfo.output_width; *h = cinfo.output_height; @@ -241,22 +242,23 @@ eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h) } static void * -eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, int *h) +eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, unsigned int *w, unsigned int *h) { struct jpeg_decompress_struct cinfo; struct _JPEG_error_mgr jerr; unsigned char *ptr, *line[16], *tdata = NULL; unsigned int *ptr2; - int x, y, l, i, scans, count, prevy; + unsigned int x, y, l, scans; + int i, count, prevy; FILE *f; - + f = _eet_memfile_read_open(data, (size_t)size); if (!f) return NULL; if (0) { char buf[1]; - + while (fread(buf, 1, 1, f)); _eet_memfile_read_close(f); return d; @@ -279,19 +281,19 @@ eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, cinfo.do_fancy_upsampling = FALSE; cinfo.do_block_smoothing = FALSE; jpeg_start_decompress(&cinfo); - + /* head decoding */ if ((*w) != cinfo.output_width) { jpeg_destroy_decompress(&cinfo); _eet_memfile_read_close(f); - return NULL; + return NULL; } if ((*h) != cinfo.output_height) { jpeg_destroy_decompress(&cinfo); _eet_memfile_read_close(f); - return NULL; + return NULL; } *w = cinfo.output_width; *h = cinfo.output_height; @@ -368,7 +370,7 @@ eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, } static void * -eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha) +eet_data_image_lossless_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha) { if (words_bigendian == -1) { @@ -381,7 +383,7 @@ eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha) { unsigned char *d; int *header; - + d = malloc((w * h * 4) + (8 * 4)); if (!d) return NULL; @@ -394,11 +396,11 @@ eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha) header[3] = alpha; memcpy(d + 32, data, w * h * 4); - + if (words_bigendian) { - int i; - + unsigned int i; + for (i = 0; i < ((w * h) + 8); i++) SWAP32(header[i]); } *size = ((w * h * 4) + (8 * 4)); @@ -407,7 +409,7 @@ eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha) } static void * -eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int alpha, int compression) +eet_data_image_lossless_compressed_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int compression) { if (words_bigendian == -1) { @@ -424,7 +426,7 @@ eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int *header; int ret; uLongf buflen; - + d = malloc((w * h * 4) + (8 * 4)); if (!d) return NULL; buflen = (((w * h * 101) / 100) + 3) * 4; @@ -443,11 +445,11 @@ eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, header[3] = alpha; header[4] = compression; memcpy(d + 32, data, w * h * 4); - + if (words_bigendian) { - int i; - + unsigned int i; + for (i = 0; i < ((w * h) + 8); i++) SWAP32(header[i]); } ret = compress2((Bytef *)comp, &buflen, @@ -468,7 +470,7 @@ eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, } static void * -eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int quality) +eet_data_image_jpeg_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality) { int *ptr; void *d = NULL; @@ -479,17 +481,19 @@ eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int FILE *f; unsigned char *buf; + (void) alpha; /* unused */ + f =_eet_memfile_write_open(&d, &sz); if (!f) return NULL; - + buf = malloc(3 * w); - if (!buf) + if (!buf) { _eet_memfile_write_close(f); if (d) free(d); return NULL; } - + cinfo.err = jpeg_std_error(&(jerr.pub)); jerr.pub.error_exit = _JPEGFatalErrorHandler; jerr.pub.emit_message = _JPEGErrorHandler2; @@ -524,8 +528,8 @@ eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int ptr = data; while (cinfo.next_scanline < cinfo.image_height) { - int i, j; - + unsigned int i, j; + /* convert scaline from ARGB to RGB packed */ for (j = 0, i = 0; i < w; i++) { @@ -535,26 +539,28 @@ eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int ptr++; } jbuf = (JSAMPROW *) (&buf); - jpeg_write_scanlines(&cinfo, jbuf, 1); + jpeg_write_scanlines(&cinfo, jbuf, 1); } - + jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - + _eet_memfile_write_close(f); *size = sz; - if (buf) free(buf); + if (buf) free(buf); return d; } static void * -eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha, int quality) +eet_data_image_jpeg_alpha_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality) { unsigned char *d1, *d2; unsigned char *d; int *header; int sz1, sz2; + (void) alpha; /* unused */ + if (words_bigendian == -1) { unsigned long int v; @@ -563,7 +569,7 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha if (v == 0x12345678) words_bigendian = 1; else words_bigendian = 0; } - + { int *ptr; void *d = NULL; @@ -573,18 +579,18 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha struct jpeg_compress_struct cinfo; FILE *f; unsigned char *buf; - + f = _eet_memfile_write_open(&d, &sz); if (!f) return NULL; - + buf = malloc(3 * w); - if (!buf) + if (!buf) { _eet_memfile_write_close(f); if (d) free(d); return NULL; } - + cinfo.err = jpeg_std_error(&(jerr.pub)); jerr.pub.error_exit = _JPEGFatalErrorHandler; jerr.pub.emit_message = _JPEGErrorHandler2; @@ -615,12 +621,12 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha cinfo.comp_info[2].v_samp_factor = 1; } jpeg_start_compress(&cinfo, TRUE); - + ptr = data; while (cinfo.next_scanline < cinfo.image_height) { - int i, j; - + unsigned int i, j; + /* convert scaline from ARGB to RGB packed */ for (j = 0, i = 0; i < w; i++) { @@ -630,13 +636,13 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha ptr++; } jbuf = (JSAMPROW *) (&buf); - jpeg_write_scanlines(&cinfo, jbuf, 1); + jpeg_write_scanlines(&cinfo, jbuf, 1); } - + jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - - if (buf) free(buf); + + if (buf) free(buf); _eet_memfile_write_close(f); d1 = d; sz1 = sz; @@ -650,23 +656,23 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha struct jpeg_compress_struct cinfo; FILE *f; unsigned char *buf; - + f = _eet_memfile_write_open(&d, &sz); - if (!f) + if (!f) { free(d1); return NULL; } - + buf = malloc(3 * w); - if (!buf) + if (!buf) { _eet_memfile_write_close(f); if (d) free(d); free(d1); return NULL; } - + cinfo.err = jpeg_std_error(&(jerr.pub)); jerr.pub.error_exit = _JPEGFatalErrorHandler; jerr.pub.emit_message = _JPEGErrorHandler2; @@ -698,12 +704,12 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha cinfo.comp_info[2].v_samp_factor = 1; } jpeg_start_compress(&cinfo, TRUE); - + ptr = data; while (cinfo.next_scanline < cinfo.image_height) { - int i, j; - + unsigned int i, j; + /* convert scaline from ARGB to RGB packed */ for (j = 0, i = 0; i < w; i++) { @@ -711,13 +717,13 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha ptr++; } jbuf = (JSAMPROW *) (&buf); - jpeg_write_scanlines(&cinfo, jbuf, 1); + jpeg_write_scanlines(&cinfo, jbuf, 1); } - + jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - - if (buf) free(buf); + + if (buf) free(buf); _eet_memfile_write_close(f); d2 = d; sz2 = sz; @@ -736,21 +742,21 @@ eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha if (words_bigendian) { int i; - + for (i = 0; i < 3; i++) SWAP32(header[i]); } memcpy(d + 12, d1, sz1); memcpy(d + 12 + sz1, d2, sz2); - + free(d1); free(d2); *size = 12 + sz1 + sz2; - return d; + return d; } int eet_data_image_write(Eet_File *ef, char *name, - void *data, int w, int h, int alpha, + void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy) { void *d = NULL; @@ -760,7 +766,7 @@ eet_data_image_write(Eet_File *ef, char *name, if (d) { int v; - + v = eet_write(ef, name, d, size, 0); free(d); return v; @@ -770,13 +776,13 @@ eet_data_image_write(Eet_File *ef, char *name, void * eet_data_image_read(Eet_File *ef, char *name, - int *w, int *h, int *alpha, + unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy) { void *data; int size; unsigned int *d = NULL; - + data = eet_read(ef, name, &size); if (!data) return NULL; d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy); @@ -786,13 +792,13 @@ eet_data_image_read(Eet_File *ef, char *name, int eet_data_image_header_read(Eet_File *ef, char *name, - int *w, int *h, int *alpha, + unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy) { void *data; int size; int d; - + data = eet_read(ef, name, &size); if (!data) return 0; d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy); @@ -801,11 +807,11 @@ eet_data_image_header_read(Eet_File *ef, char *name, } void * -eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int compress, int quality, int lossy) +eet_data_image_encode(void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy) { void *d = NULL; int size = 0; - + if (lossy == 0) { if (compress <= 0) @@ -825,10 +831,10 @@ eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int co } int -eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy) +eet_data_image_header_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy) { int header[8]; - + if (words_bigendian == -1) { unsigned long int v; @@ -837,20 +843,20 @@ eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, i if (v == 0x12345678) words_bigendian = 1; else words_bigendian = 0; } - + if (size < 32) return 0; memcpy(header, data, 32); if (words_bigendian) { int i; - - for (i = 0; i < 8; i++) SWAP32(header[i]); + + for (i = 0; i < 8; i++) SWAP32(header[i]); } - if (header[0] == 0xac1dfeed) + if ((unsigned)header[0] == 0xac1dfeed) { int iw, ih, al, cp; - + iw = header[1]; ih = header[2]; al = header[3]; @@ -865,13 +871,13 @@ eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, i if (quality) *quality = 100; return 1; } - else if (header[0] == 0xbeeff00d) + else if ((unsigned)header[0] == 0xbeeff00d) { - int iw = 0, ih = 0; - int sz1, sz2; + unsigned int iw = 0, ih = 0; unsigned char *dt; + int sz1, sz2; int ok; - + sz1 = header[1]; sz2 = header[2]; dt = data; @@ -890,9 +896,9 @@ eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, i } else { - int iw = 0, ih = 0; + unsigned int iw = 0, ih = 0; int ok; - + ok = eet_data_image_jpeg_header_decode(data, size, &iw, &ih); if (ok) { @@ -909,11 +915,11 @@ eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, i } void * -eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy) +eet_data_image_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy) { unsigned int *d = NULL; int header[8]; - + if (words_bigendian == -1) { unsigned long int v; @@ -922,21 +928,21 @@ eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *com if (v == 0x12345678) words_bigendian = 1; else words_bigendian = 0; } - + if (size < 32) return NULL; memcpy(header, data, 32); if (words_bigendian) { int i; - - for (i = 0; i < 8; i++) SWAP32(header[i]); + + for (i = 0; i < 8; i++) SWAP32(header[i]); } - if (header[0] == 0xac1dfeed) + if ((unsigned)header[0] == 0xac1dfeed) { int iw, ih, al, cp; unsigned int *body; - + iw = header[1]; ih = header[2]; al = header[3]; @@ -945,28 +951,28 @@ eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *com if ((cp == 0) && (size < ((iw * ih * 4) + 32))) return NULL; body = ((unsigned int *)data) + 8; d = malloc(iw * ih * 4); - if (!d) return NULL; + if (!d) return NULL; if (!cp) { memcpy(d, body, iw * ih * 4); if (words_bigendian) { int x; - + for (x = 0; x < (iw * ih); x++) SWAP32(d[x]); } } else { uLongf dlen; - + dlen = iw * ih * 4; uncompress((Bytef *)d, &dlen, (Bytef *)body, (uLongf)(size - 32)); if (words_bigendian) { int x; - + for (x = 0; x < (iw * ih); x++) SWAP32(d[x]); } } @@ -978,14 +984,14 @@ eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *com if (compress) *compress = cp; if (lossy) *lossy = 0; if (quality) *quality = 100; - } + } } - else if (header[0] == 0xbeeff00d) + else if ((unsigned)header[0] == 0xbeeff00d) { - int iw = 0, ih = 0; - int sz1, sz2; + unsigned int iw = 0, ih = 0; unsigned char *dt; - + int sz1, sz2; + sz1 = header[1]; sz2 = header[2]; dt = data; @@ -1008,8 +1014,8 @@ eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *com } else { - int iw = 0, ih = 0; - + unsigned int iw = 0, ih = 0; + d = eet_data_image_jpeg_rgb_decode(data, size, &iw, &ih); if (d) { diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c index 417753d076..6fab64f431 100644 --- a/legacy/eet/src/lib/eet_lib.c +++ b/legacy/eet/src/lib/eet_lib.c @@ -13,7 +13,7 @@ #define EET_MAGIC_FILE_HEADER 0x1ee7ff01 #define EET_MAGIC_FILE_NODE 0x1ee7ff02 #define EET_MAGIC_FILE_DIRECTORY 0x1ee7ff03 -#define EET_MAGIC_FILE_DIRECTORY_HASH 0x1ee7ff04 +#define EET_MAGIC_FILE_DIRECTORY_HASH 0x1ee7ff04 typedef struct _Eet_File_Header Eet_File_Header; typedef struct _Eet_File_Node Eet_File_Node; @@ -24,15 +24,15 @@ struct _Eet_File { int magic; int references; - + char *path; char *real_path; - + FILE *fp; Eet_File_Mode mode; - + int writes_pending : 1; - + Eet_File_Header *header; }; @@ -70,7 +70,7 @@ struct _Eet_File_Directory_Hash int magic; /* magic number ie 0x1ee7ff00 */ int num_directory_entries; /* number of directory entries to follow */ int bytes_directory_entries; /* bytes of directory entries to follow */ -struct +struct { int offset; /* bytes offset into file for data chunk */ int flags; /* flags - for now 0 = uncompressed, 1 = compressed */ @@ -80,7 +80,7 @@ struct char name[name_size]; /* name string (variable length) */ } directory[num_directory_entries]; /* and now startes the data stream... */ -#endif +#endif /* prototypes of internal calls */ static Eet_File *eet_cache_find(char *real_path, Eet_File **cache, int cache_num); @@ -102,7 +102,7 @@ static Eet_File * eet_cache_find(char *real_path, Eet_File **cache, int cache_num) { int i; - + /* walk list */ for (i = 0; i < cache_num; i++) { @@ -119,7 +119,7 @@ eet_cache_add(Eet_File *ef, Eet_File ***cache, int *cache_num) { Eet_File **new_cache; int new_cache_num; - + new_cache_num = *cache_num; new_cache = *cache; new_cache_num++; @@ -132,7 +132,7 @@ eet_cache_add(Eet_File *ef, Eet_File ***cache, int *cache_num) if (!new_cache) return; new_cache[new_cache_num - 1] = ef; *cache = new_cache; - *cache_num = new_cache_num; + *cache_num = new_cache_num; } /* delete from cache */ @@ -158,7 +158,7 @@ eet_cache_del(Eet_File *ef, Eet_File ***cache, int *cache_num) return; } new_cache_num--; - for (j = i; j < new_cache_num; j++) new_cache[j] = new_cache[j + 1]; + for (j = i; j < new_cache_num; j++) new_cache[j] = new_cache[j + 1]; if (new_cache_num > 0) { new_cache = realloc(new_cache, new_cache_num * sizeof(Eet_File *)); @@ -173,7 +173,7 @@ eet_cache_del(Eet_File *ef, Eet_File ***cache, int *cache_num) free(new_cache); new_cache = NULL; } - *cache_num = new_cache_num; + *cache_num = new_cache_num; *cache = new_cache; } @@ -190,7 +190,7 @@ eet_string_match(char *s1, char *s2) if (*s1 != *s2) return 0; s1++; s2++; - } + } while ((*s1) || (*s2)); /* got this far. match */ return 1; @@ -214,13 +214,14 @@ eet_hash_gen(char *key, int hash_size) 0x7f, 0xff }; - + /* no string - index 0 */ if (!key) return 0; - + /* calc hash num */ - for (ptr = key; *ptr; ptr++) hash_num ^= (int)(*ptr); - + for (ptr = (unsigned char *)key; *ptr; ptr++) + hash_num ^= (int)(*ptr); + /* mask it */ hash_num &= masks[hash_size]; /* return it */ @@ -234,8 +235,8 @@ eet_flush(Eet_File *ef) int i, j, count, size, num, offset; int head[3]; unsigned long int i1, i2; - - /* check to see its' an eet file pointer */ + + /* check to see its' an eet file pointer */ if ((!ef) || (ef->magic != EET_MAGIC_FILE)) return; if (!ef->header) return; @@ -252,7 +253,7 @@ eet_flush(Eet_File *ef) for (j = 0; j < ef->header->directory->hash[i].size; j++) { if (ef->header->directory->hash[i].node[j].compression >= 0) - { + { size += 20 + strlen(ef->header->directory->hash[i].node[j].name); count++; } @@ -314,7 +315,7 @@ eet_flush(Eet_File *ef) i2 = htonl(i1); *((int *)(buf + 16)) = (int)i2; memcpy(buf + 20, ef->header->directory->hash[i].node[j].name, name_size); - if (fwrite(buf, buf_size, 1, ef->fp) != 1) + if (fwrite(buf, buf_size, 1, ef->fp) != 1) { free(buf); return; @@ -331,7 +332,7 @@ eet_flush(Eet_File *ef) { if (ef->header->directory->hash[i].node[j].compression >= 0) { - if (fwrite(ef->header->directory->hash[i].node[j].data, + if (fwrite(ef->header->directory->hash[i].node[j].data, ef->header->directory->hash[i].node[j].size, 1, ef->fp) != 1) return; @@ -353,7 +354,7 @@ eet_open(const char *file, Eet_File_Mode mode) // printf("open %s\n", file); #ifdef HAVE_REALPATH /* in case this is a symlink... find out where it REALLY points */ - if (!realpath(file, buf)) + if (!realpath(file, buf)) { if (mode == EET_FILE_MODE_READ) return NULL; } @@ -375,11 +376,11 @@ eet_open(const char *file, Eet_File_Mode mode) ef->references++; return ef; } - + /* allocate struct for eet file and have it zero'd out */ ef = calloc(sizeof(Eet_File), 1); if (!ef) return NULL; - + /* fill some of the members */ ef->path = strdup(file); ef->real_path = strdup(buf); @@ -401,14 +402,14 @@ eet_open(const char *file, Eet_File_Mode mode) eet_close(ef); return NULL; } - + /* if we can't open - bail out */ if (!ef->fp) { eet_close(ef); return NULL; } - + /* if we opened for read or read-write */ if ((mode == EET_FILE_MODE_READ) || (mode == EET_FILE_MODE_READ_WRITE)) { @@ -417,14 +418,14 @@ eet_open(const char *file, Eet_File_Mode mode) unsigned long int i1, i2; int num_entries, byte_entries, i; size_t count; - + /* build header table if read mode */ /* geat header */ count = fread(buf, 12, 1, ef->fp); if (count != 1) { eet_close(ef); - return NULL; + return NULL; } /* get magic no */ memcpy(&i1, buf + 0, sizeof(int)); @@ -432,7 +433,7 @@ eet_open(const char *file, Eet_File_Mode mode) if (i2 != EET_MAGIC_FILE) { eet_close(ef); - return NULL; + return NULL; } /* get entries count and byte count */ memcpy(&i1, buf + 4, sizeof(int)); @@ -445,20 +446,20 @@ eet_open(const char *file, Eet_File_Mode mode) if ((num_entries <= 0) || (byte_entries <= 0)) { eet_close(ef); - return NULL; + return NULL; } /* we can't have more entires than minimum bytes for those! invalid! */ if ((num_entries * 20) > byte_entries) { eet_close(ef); - return NULL; + return NULL; } /* allocate dynamic buffer for entire directory block */ dyn_buf = malloc(byte_entries); if (!dyn_buf) { eet_close(ef); - return NULL; + return NULL; } /* allocate header */ ef->header = calloc(sizeof(Eet_File_Header), 1); @@ -509,9 +510,9 @@ eet_open(const char *file, Eet_File_Mode mode) Eet_File_Node *node; int node_size; void *data = NULL; - + /* out directory block is inconsistent - we have oveerun our */ - /* dynamic block buffer before we finished scanning dir entries */ + /* dynamic block buffer before we finished scanning dir entries */ if (p >= (dyn_buf + byte_entries)) { free(dyn_buf); @@ -539,21 +540,21 @@ eet_open(const char *file, Eet_File_Mode mode) { free(dyn_buf); eet_close(ef); - return NULL; + return NULL; } /* invalid name_size */ if (name_size <= 0) { free(dyn_buf); eet_close(ef); - return NULL; + return NULL; } /* reading name would mean falling off end of dyn_buf - invalid */ if ((p + 16 + name_size) > (dyn_buf + byte_entries)) { free(dyn_buf); eet_close(ef); - return NULL; + return NULL; } /* allocate name string */ name = malloc(name_size + 1); @@ -561,16 +562,16 @@ eet_open(const char *file, Eet_File_Mode mode) { free(dyn_buf); eet_close(ef); - return NULL; + return NULL; } /* copy name in and terminate it */ - strncpy(name, p + 20, name_size); + strncpy(name, (char *)p + 20, name_size); name[name_size] = 0; /* get hask bucket it should go in */ hash = eet_hash_gen(name, ef->header->directory->size); /* resize hask bucket */ - node = realloc(ef->header->directory->hash[hash].node, - (ef->header->directory->hash[hash].size + 1) * + node = realloc(ef->header->directory->hash[hash].node, + (ef->header->directory->hash[hash].size + 1) * sizeof(Eet_File_Node)); if (!node) { @@ -615,7 +616,7 @@ eet_open(const char *file, Eet_File_Mode mode) break; } } - + ef->header->directory->hash[hash].node[node_size].data = data; } @@ -647,7 +648,7 @@ eet_open(const char *file, Eet_File_Mode mode) Eet_File_Mode eet_mode_get(Eet_File *ef) { - /* check to see its' an eet file pointer */ + /* check to see its' an eet file pointer */ if ((!ef) || (ef->magic != EET_MAGIC_FILE)) return EET_FILE_MODE_INVALID; else @@ -657,7 +658,7 @@ eet_mode_get(Eet_File *ef) void eet_close(Eet_File *ef) { - /* check to see its' an eet file pointer */ + /* check to see its' an eet file pointer */ if ((!ef) || (ef->magic != EET_MAGIC_FILE)) return; /* deref */ @@ -678,14 +679,14 @@ eet_close(Eet_File *ef) if (ef->real_path) free(ef->real_path); /* free up data */ - if (ef->header) + if (ef->header) { if (ef->header->directory) { if (ef->header->directory->hash) { int i, num; - + num = (1 << (ef->header->directory->size - 1)); for (i = 0; i < num; i++) { @@ -693,7 +694,7 @@ eet_close(Eet_File *ef) { int j; int num2; - + num2 = ef->header->directory->hash[i].size; for (j = 0; j < num2; j++) { @@ -711,7 +712,7 @@ eet_close(Eet_File *ef) } free(ef->header); } - + /* zero out ram for struct - caution tactic against stale memory use */ memset(ef, 0, sizeof(Eet_File)); /* free it */ @@ -758,8 +759,8 @@ eet_read(Eet_File *ef, char *name, int *size_ret) { /* if we alreayd have the data in ram... copy that */ if (ef->header->directory->hash[hash].node[i].data) - memcpy(data, - ef->header->directory->hash[hash].node[i].data, + memcpy(data, + ef->header->directory->hash[hash].node[i].data, ef->header->directory->hash[hash].node[i].size); /* or get data from disk */ else @@ -786,7 +787,7 @@ eet_read(Eet_File *ef, char *name, int *size_ret) else { void *tmp_data; - + /* get size of data in file */ tmp_size = ef->header->directory->hash[hash].node[i].size; tmp_data = malloc(tmp_size); @@ -798,11 +799,11 @@ eet_read(Eet_File *ef, char *name, int *size_ret) if (data) { uLongf dlen; - + /* if we already have the data in ram... copy that */ if (ef->header->directory->hash[hash].node[i].data) - memcpy(tmp_data, - ef->header->directory->hash[hash].node[i].data, + memcpy(tmp_data, + ef->header->directory->hash[hash].node[i].data, tmp_size); /* or get data from disk */ else @@ -826,7 +827,7 @@ eet_read(Eet_File *ef, char *name, int *size_ret) } /* decompress it */ dlen = size; - if (uncompress((Bytef *)data, &dlen, + if (uncompress((Bytef *)data, &dlen, tmp_data, (uLongf)tmp_size)) { free(tmp_data); @@ -855,13 +856,13 @@ eet_write(Eet_File *ef, char *name, void *data, int size, int compress) char *name2; void *data2; int exists_already = 0; - - /* check to see its' an eet file pointer */ + + /* check to see its' an eet file pointer */ if ((!ef) || (ef->magic != EET_MAGIC_FILE) - || (!name) || (!data) || (size <= 0) || + || (!name) || (!data) || (size <= 0) || ((ef->mode != EET_FILE_MODE_WRITE) && (ef->mode != EET_FILE_MODE_READ_WRITE))) - + return 0; if (!ef->header) @@ -901,10 +902,10 @@ eet_write(Eet_File *ef, char *name, void *data, int size, int compress) { uLongf buflen; int ok; - + /* compress the data with max compression */ buflen = (uLongf)data_size; - if ((ok = compress2((Bytef *)data2, &buflen, (Bytef *)data, + if ((ok = compress2((Bytef *)data2, &buflen, (Bytef *)data, (uLong)size, 9)) != Z_OK) { free(name2); @@ -913,7 +914,7 @@ eet_write(Eet_File *ef, char *name, void *data, int size, int compress) } /* record compressed chunk size */ data_size = (int)buflen; - if (data_size >= size) + if (data_size >= size) { compress = 0; data_size = size; @@ -921,7 +922,7 @@ eet_write(Eet_File *ef, char *name, void *data, int size, int compress) else { void *data3; - + data3 = realloc(data2, data_size); if (data3) data2 = data3; } @@ -952,9 +953,9 @@ eet_write(Eet_File *ef, char *name, void *data, int size, int compress) if (!exists_already) { /* increase hash bucket size */ - node = realloc(ef->header->directory->hash[hash].node, + node = realloc(ef->header->directory->hash[hash].node, (node_size + 1) * sizeof(Eet_File_Node)); - if (!node) + if (!node) { free(name2); free(data2); @@ -983,8 +984,8 @@ eet_delete(Eet_File *ef, char *name) { int hash, node_size, i; int exists_already = 0; - - /* check to see its' an eet file pointer */ + + /* check to see its' an eet file pointer */ if ((!ef) || (ef->magic != EET_MAGIC_FILE) || (!name)) return 0; @@ -992,11 +993,11 @@ eet_delete(Eet_File *ef, char *name) if (ef->mode != EET_FILE_MODE_READ_WRITE) return 0; if (!ef->header) return 0; - + /* figure hash bucket */ hash = eet_hash_gen(name, ef->header->directory->size); node_size = ef->header->directory->hash[hash].size; - + /* Does this node already exist? */ for (i = 0; i < node_size; i++) { @@ -1026,7 +1027,7 @@ eet_list(Eet_File *ef, char *glob, int *count_ret) int list_count_alloc = 0; int i, j, num; - /* check to see its' an eet file pointer */ + /* check to see its' an eet file pointer */ if ((!ef) || (ef->magic != EET_MAGIC_FILE) || (!glob) || (!ef->header) || (!ef->header->directory) || ((ef->mode != EET_FILE_MODE_READ) && @@ -1045,7 +1046,7 @@ eet_list(Eet_File *ef, char *glob, int *count_ret) if (!fnmatch(glob, ef->header->directory->hash[i].node[j].name, 0)) { char **new_list; - + /* add it to our list */ list_count++; /* only realloc in 32 entry chunks */ @@ -1057,7 +1058,7 @@ eet_list(Eet_File *ef, char *glob, int *count_ret) { free(list_ret); if (count_ret) *count_ret = 0; - return NULL; + return NULL; } list_ret = new_list; } @@ -1067,7 +1068,7 @@ eet_list(Eet_File *ef, char *glob, int *count_ret) } } /* return count and list */ - if (count_ret) *count_ret = list_count; + if (count_ret) *count_ret = list_count; return list_ret; } diff --git a/legacy/eet/src/lib/eet_memfile.c b/legacy/eet/src/lib/eet_memfile.c index 99ca515c59..dcf8d43634 100644 --- a/legacy/eet/src/lib/eet_memfile.c +++ b/legacy/eet/src/lib/eet_memfile.c @@ -8,7 +8,7 @@ _eet_memfile_read_open(void *data, size_t size) return (FILE *)fmemopen(data, size, "rb"); #else FILE *f; - + f = tmpfile(); if (!f) { @@ -29,7 +29,7 @@ _eet_memfile_read_close(FILE *f) fclose(f); #else fclose(f); -#endif +#endif } @@ -67,17 +67,17 @@ _eet_memfile_write_open(void **data, size_t *size) { #ifdef HAVE_OPEN_MEMSTREAM return open_memstream((char **)data, size); -#else +#else FILE *f; - + _eet_memfile_info_num++; if (_eet_memfile_info_num > _eet_memfile_info_alloc_num) { Eet_Memfile_Write_Info *tmp; - + _eet_memfile_info_alloc_num += 16; - tmp = realloc(_eet_memfile_info, - _eet_memfile_info_alloc_num * + tmp = realloc(_eet_memfile_info, + _eet_memfile_info_alloc_num * sizeof(Eet_Memfile_Write_Info)); if (!tmp) { @@ -88,7 +88,7 @@ _eet_memfile_write_open(void **data, size_t *size) _eet_memfile_info = tmp; } f = tmpfile(); - if (!f) + if (!f) { _eet_memfile_info_num--; return NULL; @@ -104,10 +104,10 @@ void _eet_memfile_write_close(FILE *f) { #ifdef HAVE_OPEN_MEMSTREAM - fclose(f); + fclose(f); #else int i; - + for (i = 0; i < _eet_memfile_info_num; i++) { if (_eet_memfile_info[i].f == f)