diff options
Diffstat (limited to 'engines/sci/tools/bdfgname.cpp')
-rw-r--r-- | engines/sci/tools/bdfgname.cpp | 556 |
1 files changed, 282 insertions, 274 deletions
diff --git a/engines/sci/tools/bdfgname.cpp b/engines/sci/tools/bdfgname.cpp index 200202562e..b7e9b50d81 100644 --- a/engines/sci/tools/bdfgname.cpp +++ b/engines/sci/tools/bdfgname.cpp @@ -21,7 +21,7 @@ */ #ifndef lint #ifdef __GNUC__ -static char rcsid[] __attribute__ ((unused)) = "$Id: bdfgname.c 1284 2004-04-02 07:42:44Z jameson $"; +static char rcsid[] __attribute__((unused)) = "$Id: bdfgname.c 1284 2004-04-02 07:42:44Z jameson $"; #else static char rcsid[] = "$Id: bdfgname.c 1284 2004-04-02 07:42:44Z jameson $"; #endif @@ -30,10 +30,10 @@ static char rcsid[] = "$Id: bdfgname.c 1284 2004-04-02 07:42:44Z jameson $"; #include "bdfP.h" typedef struct { - long code; - long start; - long end; - long pad; + long code; + long start; + long end; + long pad; } _bdf_adobe_name_t; static _bdf_adobe_name_t *adobe_names; @@ -55,33 +55,33 @@ char *buf; int limit; #endif { - int c, i; - - c = EOF; - - for (i = 0; i < limit - 1; i++) { - if ((c = getc(in)) == EOF || (c == '\n' || c == '\r')) - break; - buf[i] = c; - } - buf[i] = 0; - - /* - * Discard the rest of the line which did not fit into the buffer. - */ - while (c != EOF && c != '\n' && c != '\r') - c = getc(in); - - if (c == '\r') { - /* - * Check for a trailing newline. - */ - c = getc(in); - if (c != '\n') - ungetc(c, in); - } - - return i; + int c, i; + + c = EOF; + + for (i = 0; i < limit - 1; i++) { + if ((c = getc(in)) == EOF || (c == '\n' || c == '\r')) + break; + buf[i] = c; + } + buf[i] = 0; + + /* + * Discard the rest of the line which did not fit into the buffer. + */ + while (c != EOF && c != '\n' && c != '\r') + c = getc(in); + + if (c == '\r') { + /* + * Check for a trailing newline. + */ + c = getc(in); + if (c != '\n') + ungetc(c, in); + } + + return i; } static long @@ -94,42 +94,42 @@ char *name; FILE *in; #endif { - long c, i, pos; - char *sp, buf[256]; - - while (!feof(in)) { - pos = ftell(in); - (void) getline(in, buf, 256); - while (!feof(in) && (buf[0] == 0 || buf[0] == '#')) { - buf[0] = 0; - pos = ftell(in); - (void) getline(in, buf, 256); - } - - if (buf[0] == 0) - return -1; - - c = _bdf_atol(buf, 0, 16); - - if (c > code) { - /* - * Restore the last position read in case the code is not in the - * file and the current code is greater than the expected code. - */ - fseek(in, pos, 0L); - return -1; - } - - if (c == code) { - for (sp = buf; *sp != ';'; sp++) ; - sp++; - for (i = 0; *sp != ';' && i < MAX_GLYPH_NAME_LEN; sp++, i++) - name[i] = *sp; - name[i] = 0; - return i; - } - } - return -1; + long c, i, pos; + char *sp, buf[256]; + + while (!feof(in)) { + pos = ftell(in); + (void) getline(in, buf, 256); + while (!feof(in) && (buf[0] == 0 || buf[0] == '#')) { + buf[0] = 0; + pos = ftell(in); + (void) getline(in, buf, 256); + } + + if (buf[0] == 0) + return -1; + + c = _bdf_atol(buf, 0, 16); + + if (c > code) { + /* + * Restore the last position read in case the code is not in the + * file and the current code is greater than the expected code. + */ + fseek(in, pos, 0L); + return -1; + } + + if (c == code) { + for (sp = buf; *sp != ';'; sp++) ; + sp++; + for (i = 0; *sp != ';' && i < MAX_GLYPH_NAME_LEN; sp++, i++) + name[i] = *sp; + name[i] = 0; + return i; + } + } + return -1; } static int @@ -140,15 +140,15 @@ by_encoding(a, b) char *a, *b; #endif { - _bdf_adobe_name_t *c1, *c2; - - c1 = (_bdf_adobe_name_t *) a; - c2 = (_bdf_adobe_name_t *) b; - if (c1->code < c2->code) - return -1; - else if (c1->code > c2->code) - return 1; - return 0; + _bdf_adobe_name_t *c1, *c2; + + c1 = (_bdf_adobe_name_t *) a; + c2 = (_bdf_adobe_name_t *) b; + if (c1->code < c2->code) + return -1; + else if (c1->code > c2->code) + return 1; + return 0; } static void @@ -159,60 +159,60 @@ _bdf_load_adobe_names(in) FILE *in; #endif { - long c, pos; - char *sp, buf[256]; - - /* - * Go back to the beginning of the file to look for the code because the - * codes are not in order in the current Adobe Glyph Name list file. - */ - fseek(in, 0, 0); - - while (!feof(in)) { - pos = ftell(in); - (void) getline(in, buf, 256); - while (!feof(in) && (buf[0] == 0 || buf[0] == '#')) { - buf[0] = 0; - pos = ftell(in); - (void) getline(in, buf, 256); - } - - c = _bdf_atol(buf, 0, 16); - - /* - * Ignore the Adobe-specific names in the Private Use Area. - */ - if (c >= 0xe000 && c <= 0xf8ff) - continue; - - if (adobe_names_used == adobe_names_size) { - if (adobe_names_size == 0) - adobe_names = (_bdf_adobe_name_t *) - malloc(sizeof(_bdf_adobe_name_t) << 9); - else - adobe_names = (_bdf_adobe_name_t *) - realloc((char *) adobe_names, - sizeof(_bdf_adobe_name_t) * - (adobe_names_size + 512)); - (void) memset((char *) (adobe_names + adobe_names_size), 0, - sizeof(_bdf_adobe_name_t) << 9); - adobe_names_size += 512; - } - - adobe_names[adobe_names_used].code = c; - for (sp = buf; *sp != ';'; sp++) ; - sp++; - adobe_names[adobe_names_used].start = pos + (sp - buf); - for (; *sp != ';'; sp++) ; - adobe_names[adobe_names_used].end = pos + (sp - buf); - adobe_names_used++; - } - - /* - * Sort the results by code. - */ - qsort((char *) adobe_names, adobe_names_used, sizeof(_bdf_adobe_name_t), - by_encoding); + long c, pos; + char *sp, buf[256]; + + /* + * Go back to the beginning of the file to look for the code because the + * codes are not in order in the current Adobe Glyph Name list file. + */ + fseek(in, 0, 0); + + while (!feof(in)) { + pos = ftell(in); + (void) getline(in, buf, 256); + while (!feof(in) && (buf[0] == 0 || buf[0] == '#')) { + buf[0] = 0; + pos = ftell(in); + (void) getline(in, buf, 256); + } + + c = _bdf_atol(buf, 0, 16); + + /* + * Ignore the Adobe-specific names in the Private Use Area. + */ + if (c >= 0xe000 && c <= 0xf8ff) + continue; + + if (adobe_names_used == adobe_names_size) { + if (adobe_names_size == 0) + adobe_names = (_bdf_adobe_name_t *) + malloc(sizeof(_bdf_adobe_name_t) << 9); + else + adobe_names = (_bdf_adobe_name_t *) + realloc((char *) adobe_names, + sizeof(_bdf_adobe_name_t) * + (adobe_names_size + 512)); + (void) memset((char *)(adobe_names + adobe_names_size), 0, + sizeof(_bdf_adobe_name_t) << 9); + adobe_names_size += 512; + } + + adobe_names[adobe_names_used].code = c; + for (sp = buf; *sp != ';'; sp++) ; + sp++; + adobe_names[adobe_names_used].start = pos + (sp - buf); + for (; *sp != ';'; sp++) ; + adobe_names[adobe_names_used].end = pos + (sp - buf); + adobe_names_used++; + } + + /* + * Sort the results by code. + */ + qsort((char *) adobe_names, adobe_names_used, sizeof(_bdf_adobe_name_t), + by_encoding); } static long @@ -225,44 +225,44 @@ char *name; FILE *in; #endif { - long len; - int l, r, m; - - if (code < 0x20 || (code >= 0x7f && code <= 0x9f) || - code == 0xfffe || code == 0xffff) { - sprintf(name, "char%lu", code); - return (long) strlen(name); - } - - if (code >= 0xe000 && code <= 0xf8ff) { - sprintf(name, "uni%04lX", code & 0xffff); - return (long) strlen(name); - } - - if (adobe_names_size == 0) - _bdf_load_adobe_names(in); - - l = 0; - r = adobe_names_used - 1; - while (l <= r) { - m = (l + r) >> 1; - if (adobe_names[m].code < code) - l = m + 1; - else if (adobe_names[m].code > code) - r = m - 1; - else { - fseek(in, adobe_names[m].start, 0); - len = adobe_names[m].end - adobe_names[m].start; - if (len > MAX_GLYPH_NAME_LEN) - len = MAX_GLYPH_NAME_LEN; - len = (long) fread(name, sizeof(char), len, in); - name[len] = 0; - return len; - } - } - - sprintf(name, "uni%04lX", code & 0xffff); - return (long) strlen(name); + long len; + int l, r, m; + + if (code < 0x20 || (code >= 0x7f && code <= 0x9f) || + code == 0xfffe || code == 0xffff) { + sprintf(name, "char%lu", code); + return (long) strlen(name); + } + + if (code >= 0xe000 && code <= 0xf8ff) { + sprintf(name, "uni%04lX", code & 0xffff); + return (long) strlen(name); + } + + if (adobe_names_size == 0) + _bdf_load_adobe_names(in); + + l = 0; + r = adobe_names_used - 1; + while (l <= r) { + m = (l + r) >> 1; + if (adobe_names[m].code < code) + l = m + 1; + else if (adobe_names[m].code > code) + r = m - 1; + else { + fseek(in, adobe_names[m].start, 0); + len = adobe_names[m].end - adobe_names[m].start; + if (len > MAX_GLYPH_NAME_LEN) + len = MAX_GLYPH_NAME_LEN; + len = (long) fread(name, sizeof(char), len, in); + name[len] = 0; + return len; + } + } + + sprintf(name, "uni%04lX", code & 0xffff); + return (long) strlen(name); } static int @@ -277,55 +277,55 @@ bdf_callback_t callback; int adobe; #endif { - int changed; - long i, size, len; - bdf_glyph_t *gp; - bdf_callback_struct_t cb; - char name[MAX_GLYPH_NAME_LEN + 1]; - - if (callback != 0) { - cb.reason = BDF_GLYPH_NAME_START; - cb.current = 0; - cb.total = font->glyphs_used; - (*callback)(&cb, 0); - } - for (changed = 0, i = 0, gp = font->glyphs; i < font->glyphs_used; - i++, gp++) { - size = (adobe) ? - _bdf_find_adobe_name(gp->encoding, name, in) : - _bdf_find_name(gp->encoding, name, in); - if (size < 0) - continue; - - len = (gp->name) ? strlen(gp->name) : 0; - if (len == 0) { - gp->name = (char *) _bdf_strdup((unsigned char *) name, size + 1); - changed = 1; - } else if (size != len || strcmp(gp->name, name) != 0) { - /* - * Simply resize existing storage so lots of memory allocations - * are not needed. - */ - if (size > len) - gp->name = (char *) realloc(gp->name, size + 1); - (void) strcpy(gp->name, name); - changed = 1; - } - - if (callback != 0) { - cb.reason = BDF_GLYPH_NAME; - cb.current = i; - (*callback)(&cb, 0); - } - } - - if (callback != 0) { - cb.reason = BDF_GLYPH_NAME; - cb.current = cb.total; - (*callback)(&cb, 0); - } - - return changed; + int changed; + long i, size, len; + bdf_glyph_t *gp; + bdf_callback_struct_t cb; + char name[MAX_GLYPH_NAME_LEN + 1]; + + if (callback != 0) { + cb.reason = BDF_GLYPH_NAME_START; + cb.current = 0; + cb.total = font->glyphs_used; + (*callback)(&cb, 0); + } + for (changed = 0, i = 0, gp = font->glyphs; i < font->glyphs_used; + i++, gp++) { + size = (adobe) ? + _bdf_find_adobe_name(gp->encoding, name, in) : + _bdf_find_name(gp->encoding, name, in); + if (size < 0) + continue; + + len = (gp->name) ? strlen(gp->name) : 0; + if (len == 0) { + gp->name = (char *) _bdf_strdup((unsigned char *) name, size + 1); + changed = 1; + } else if (size != len || strcmp(gp->name, name) != 0) { + /* + * Simply resize existing storage so lots of memory allocations + * are not needed. + */ + if (size > len) + gp->name = (char *) realloc(gp->name, size + 1); + (void) strcpy(gp->name, name); + changed = 1; + } + + if (callback != 0) { + cb.reason = BDF_GLYPH_NAME; + cb.current = i; + (*callback)(&cb, 0); + } + } + + if (callback != 0) { + cb.reason = BDF_GLYPH_NAME; + cb.current = cb.total; + (*callback)(&cb, 0); + } + + return changed; } int @@ -339,7 +339,7 @@ bdf_font_t *font; bdf_callback_t callback; #endif { - return _bdf_set_glyph_names(in, font, callback, 0); + return _bdf_set_glyph_names(in, font, callback, 0); } int @@ -352,7 +352,7 @@ bdf_font_t *font; bdf_callback_t callback; #endif { - return _bdf_set_glyph_names(in, font, callback, 1); + return _bdf_set_glyph_names(in, font, callback, 1); } int @@ -365,57 +365,65 @@ bdf_font_t *font; bdf_callback_t callback; #endif { - int changed; - long i, size, len; - bdf_glyph_t *gp; - bdf_callback_struct_t cb; - char name[128]; - - if (callback != 0) { - cb.reason = BDF_GLYPH_NAME_START; - cb.current = 0; - cb.total = font->glyphs_used; - (*callback)(&cb, 0); - } - for (changed = 0, i = 0, gp = font->glyphs; i < font->glyphs_used; - i++, gp++) { - switch (prefix) { - case 'u': sprintf(name, "uni%04lX", gp->encoding & 0xffff); break; - case 'x': sprintf(name, "0x%04lX", gp->encoding & 0xffff); break; - case '+': sprintf(name, "U+%04lX", gp->encoding & 0xffff); break; - case '\\': sprintf(name, "\\u%04lX", gp->encoding & 0xffff); break; - } - size = 6; - - len = (gp->name) ? strlen(gp->name) : 0; - if (len == 0) { - gp->name = (char *) _bdf_strdup((unsigned char *) name, size + 1); - changed = 1; - } else if (size != len || strcmp(gp->name, name) != 0) { - /* - * Simply resize existing storage so lots of memory allocations - * are not needed. - */ - if (size > len) - gp->name = (char *) realloc(gp->name, size + 1); - (void) strcpy(gp->name, name); - changed = 1; - } - - if (callback != 0) { - cb.reason = BDF_GLYPH_NAME; - cb.current = i; - (*callback)(&cb, 0); - } - } - - if (callback != 0) { - cb.reason = BDF_GLYPH_NAME; - cb.current = cb.total; - (*callback)(&cb, 0); - } - - return changed; + int changed; + long i, size, len; + bdf_glyph_t *gp; + bdf_callback_struct_t cb; + char name[128]; + + if (callback != 0) { + cb.reason = BDF_GLYPH_NAME_START; + cb.current = 0; + cb.total = font->glyphs_used; + (*callback)(&cb, 0); + } + for (changed = 0, i = 0, gp = font->glyphs; i < font->glyphs_used; + i++, gp++) { + switch (prefix) { + case 'u': + sprintf(name, "uni%04lX", gp->encoding & 0xffff); + break; + case 'x': + sprintf(name, "0x%04lX", gp->encoding & 0xffff); + break; + case '+': + sprintf(name, "U+%04lX", gp->encoding & 0xffff); + break; + case '\\': + sprintf(name, "\\u%04lX", gp->encoding & 0xffff); + break; + } + size = 6; + + len = (gp->name) ? strlen(gp->name) : 0; + if (len == 0) { + gp->name = (char *) _bdf_strdup((unsigned char *) name, size + 1); + changed = 1; + } else if (size != len || strcmp(gp->name, name) != 0) { + /* + * Simply resize existing storage so lots of memory allocations + * are not needed. + */ + if (size > len) + gp->name = (char *) realloc(gp->name, size + 1); + (void) strcpy(gp->name, name); + changed = 1; + } + + if (callback != 0) { + cb.reason = BDF_GLYPH_NAME; + cb.current = i; + (*callback)(&cb, 0); + } + } + + if (callback != 0) { + cb.reason = BDF_GLYPH_NAME; + cb.current = cb.total; + (*callback)(&cb, 0); + } + + return changed; } void @@ -425,7 +433,7 @@ _bdf_glyph_name_cleanup(void) _bdf_glyph_name_cleanup() #endif { - if (adobe_names_size > 0) - free((char *) adobe_names); - adobe_names_size = adobe_names_used = 0; + if (adobe_names_size > 0) + free((char *) adobe_names); + adobe_names_size = adobe_names_used = 0; } |