diff options
author | marha <marha@users.sourceforge.net> | 2015-02-22 14:31:16 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2015-02-22 14:31:16 +0100 |
commit | f1c2db43dcf35d2cf4715390bd2391c28e42a8c2 (patch) | |
tree | 46b537271afe0f6534231b1bd4cc4f91ae1fb446 /libfontenc/src/encparse.c | |
parent | 5e5a48ff8cd08f123601cd0625ca62a86675aac9 (diff) | |
download | vcxsrv-f1c2db43dcf35d2cf4715390bd2391c28e42a8c2.tar.gz vcxsrv-f1c2db43dcf35d2cf4715390bd2391c28e42a8c2.tar.bz2 vcxsrv-f1c2db43dcf35d2cf4715390bd2391c28e42a8c2.zip |
xwininfo fontconfig libX11 libXdmcp libfontenc libxcb libxcb/xcb-proto mesalib xserver xkeyboard-config mkfontscale git update 22 Feb 2015
xserver commit 3a06faf3fcdb7451125a46181f9152e8e59e9770
libxcb commit e3ec1f74637237ce500dfd0ca59f2e422da4e019
libxcb/xcb-proto commit 4c550465934164aab2449a125f75f4ca07816233
xkeyboard-config commit 26f344c93f8c6141e9233eb68088ba4fd56bc9ef
libX11 commit c8e19b393defd53f046ddc2da3a16881221b3c34
libXdmcp commit 9f4cac7656b221ce2a8f97e7bd31e5e23126d001
libfontenc commit de1843aaf76015c9d99416f3122d169fe331b849
mkfontscale commit 87d628f8eec170ec13bb9feefb1ce05aed07d1d6
xwininfo commit 0c49f8f2bd56b1e77721e81030ea948386dcdf4e
fontconfig commit d6d5adeb7940c0d0beb86489c2a1c2ce59e5c044
mesa commit 4359954d842caa2a9f8d4b50d70ecc789884b68b
Diffstat (limited to 'libfontenc/src/encparse.c')
-rw-r--r-- | libfontenc/src/encparse.c | 613 |
1 files changed, 338 insertions, 275 deletions
diff --git a/libfontenc/src/encparse.c b/libfontenc/src/encparse.c index d10634d48..f47454a3e 100644 --- a/libfontenc/src/encparse.c +++ b/libfontenc/src/encparse.c @@ -35,6 +35,7 @@ THE SOFTWARE. #include "zlib.h" typedef gzFile FontFilePtr; + #define FontFileGetc(f) gzgetc(f) #define FontFileOpen(filename) gzopen(filename, "rb") #define FontFileClose(f) gzclose(f) @@ -70,7 +71,7 @@ typedef gzFile FontFilePtr; #define MAXKEYWORDLEN 100 static long number_value; -static char keyword_value[MAXKEYWORDLEN+1]; +static char keyword_value[MAXKEYWORDLEN + 1]; static long value1, value2, value3; @@ -80,11 +81,11 @@ static long value1, value2, value3; static void skipEndOfLine(FontFilePtr f, int c) { - if(c == 0) + if (c == 0) c = FontFileGetc(f); - for(;;) - if(c <= 0 || c == '\n') + for (;;) + if (c <= 0 || c == '\n') return; else c = FontFileGetc(f); @@ -98,47 +99,54 @@ getnum(FontFilePtr f, int c, int *cp) int base = 10; /* look for `0' or `0x' prefix */ - if(c == '0') { + if (c == '0') { c = FontFileGetc(f); base = 8; - if(c == 'x' || c == 'X') { + if (c == 'x' || c == 'X') { base = 16; c = FontFileGetc(f); } } /* accumulate digits */ - for(;;) { + for (;;) { if ('0' <= c && c <= '9') { - n *= base; n += c - '0'; - } else if('a' <= c && c <= 'f') { - n *= base; n += c - 'a' + 10; - } else if('A' <=c && c <= 'F') { - n *= base; n += c - 'A' + 10; - } else + n *= base; + n += c - '0'; + } + else if ('a' <= c && c <= 'f') { + n *= base; + n += c - 'a' + 10; + } + else if ('A' <= c && c <= 'F') { + n *= base; + n += c - 'A' + 10; + } + else break; c = FontFileGetc(f); } - *cp = c; return n; + *cp = c; + return n; } /* Skip to beginning of new line; return 1 if only whitespace was found. */ static int endOfLine(FontFilePtr f, int c) { - if(c == 0) + if (c == 0) c = FontFileGetc(f); - for(;;) { - if(c <= 0 || c == '\n') + for (;;) { + if (c <= 0 || c == '\n') return 1; - else if(c == '#') { - skipEndOfLine(f,c); + else if (c == '#') { + skipEndOfLine(f, c); return 1; } - else if(c == ' ' || c == '\t') { - skipEndOfLine(f,c); + else if (c == ' ' || c == '\t') { + skipEndOfLine(f, c); return 0; } c = FontFileGetc(f); @@ -151,39 +159,43 @@ gettoken(FontFilePtr f, int c, int *cp) { char *p; - if(c <= 0) - c = FontFileGetc(f); + if (c <= 0) + c = FontFileGetc(f); - if(c <= 0) { + if (c <= 0) { return EOF_TOKEN; } - while(c == ' ' || c == '\t') + while (c == ' ' || c == '\t') c = FontFileGetc(f); - if(c=='\n') { + if (c == '\n') { return EOL_TOKEN; - } else if(c == '#') { - skipEndOfLine(f,c); + } + else if (c == '#') { + skipEndOfLine(f, c); return EOL_TOKEN; - } else if(c >= '0' && c <= '9') { - number_value = getnum(f,c,cp); + } + else if (c >= '0' && c <= '9') { + number_value = getnum(f, c, cp); return NUMBER_TOKEN; - } else if((c >= 'A' && c <= 'Z') || - (c >= 'a' && c <= 'z') || - c == '/' || c == '_' || c == '-' || c == '.') { + } + else if ((c >= 'A' && c <= 'Z') || + (c >= 'a' && c <= 'z') || + c == '/' || c == '_' || c == '-' || c == '.') { p = keyword_value; *p++ = c; - while(p-keyword_value < MAXKEYWORDLEN) { + while (p - keyword_value < MAXKEYWORDLEN) { c = FontFileGetc(f); - if(c <= ' ' || c > '~' || c == '#') + if (c <= ' ' || c > '~' || c == '#') break; *p++ = c; } *cp = c; *p = '\0'; return KEYWORD_TOKEN; - } else { + } + else { *cp = c; return ERROR_TOKEN; } @@ -195,14 +207,15 @@ static int getnextline(FontFilePtr f) { int c, token; + c = FontFileGetc(f); - if(c <= 0) + if (c <= 0) return EOF_LINE; - again: - token=gettoken(f,c,&c); + again: + token = gettoken(f, c, &c); - switch(token) { + switch (token) { case EOF_TOKEN: return EOF_LINE; case EOL_TOKEN: @@ -211,79 +224,85 @@ getnextline(FontFilePtr f) goto again; case NUMBER_TOKEN: value1 = number_value; - token = gettoken(f,c,&c); - switch(token) { + token = gettoken(f, c, &c); + switch (token) { case NUMBER_TOKEN: value2 = number_value; - token = gettoken(f,c,&c); - switch(token) { + token = gettoken(f, c, &c); + switch (token) { case NUMBER_TOKEN: value3 = number_value; return CODE_RANGE_LINE; case EOL_TOKEN: return CODE_LINE; default: - skipEndOfLine(f,c); + skipEndOfLine(f, c); return ERROR_LINE; } case KEYWORD_TOKEN: - if(!endOfLine(f,c)) + if (!endOfLine(f, c)) return ERROR_LINE; else return NAME_LINE; default: - skipEndOfLine(f,c); + skipEndOfLine(f, c); return ERROR_LINE; } case KEYWORD_TOKEN: - if(!strcasecmp(keyword_value, "STARTENCODING")) { - token = gettoken(f,c,&c); - if(token == KEYWORD_TOKEN) { - if(endOfLine(f,c)) + if (!strcasecmp(keyword_value, "STARTENCODING")) { + token = gettoken(f, c, &c); + if (token == KEYWORD_TOKEN) { + if (endOfLine(f, c)) return STARTENCODING_LINE; else return ERROR_LINE; - } else { - skipEndOfLine(f,c); + } + else { + skipEndOfLine(f, c); return ERROR_LINE; } - } else if(!strcasecmp(keyword_value, "ALIAS")) { - token = gettoken(f,c,&c); - if(token == KEYWORD_TOKEN) { - if(endOfLine(f,c)) + } + else if (!strcasecmp(keyword_value, "ALIAS")) { + token = gettoken(f, c, &c); + if (token == KEYWORD_TOKEN) { + if (endOfLine(f, c)) return ALIAS_LINE; else return ERROR_LINE; - } else { - skipEndOfLine(f,c); + } + else { + skipEndOfLine(f, c); return ERROR_LINE; } - } else if(!strcasecmp(keyword_value, "SIZE")) { - token = gettoken(f,c,&c); - if(token == NUMBER_TOKEN) { + } + else if (!strcasecmp(keyword_value, "SIZE")) { + token = gettoken(f, c, &c); + if (token == NUMBER_TOKEN) { value1 = number_value; - token = gettoken(f,c,&c); - switch(token) { + token = gettoken(f, c, &c); + switch (token) { case NUMBER_TOKEN: value2 = number_value; return SIZE_LINE; case EOL_TOKEN: - value2=0; + value2 = 0; return SIZE_LINE; default: - skipEndOfLine(f,c); + skipEndOfLine(f, c); return ERROR_LINE; } - } else { - skipEndOfLine(f,c); + } + else { + skipEndOfLine(f, c); return ERROR_LINE; } - } else if(!strcasecmp(keyword_value, "FIRSTINDEX")) { - token = gettoken(f,c,&c); - if(token == NUMBER_TOKEN) { + } + else if (!strcasecmp(keyword_value, "FIRSTINDEX")) { + token = gettoken(f, c, &c); + if (token == NUMBER_TOKEN) { value1 = number_value; - token = gettoken(f,c,&c); - switch(token) { + token = gettoken(f, c, &c); + switch (token) { case NUMBER_TOKEN: value2 = number_value; return FIRSTINDEX_LINE; @@ -291,85 +310,99 @@ getnextline(FontFilePtr f) value2 = 0; return FIRSTINDEX_LINE; default: - skipEndOfLine(f,c); + skipEndOfLine(f, c); return ERROR_LINE; } - } else { - skipEndOfLine(f,c); + } + else { + skipEndOfLine(f, c); return ERROR_LINE; } - } else if(!strcasecmp(keyword_value, "STARTMAPPING")) { + } + else if (!strcasecmp(keyword_value, "STARTMAPPING")) { keyword_value[0] = 0; - value1 = 0; value2 = 0; + value1 = 0; + value2 = 0; /* first a keyword */ - token = gettoken(f,c,&c); - if(token != KEYWORD_TOKEN) { + token = gettoken(f, c, &c); + if (token != KEYWORD_TOKEN) { skipEndOfLine(f, c); return ERROR_LINE; } /* optional first integer */ - token = gettoken(f,c,&c); - if(token == NUMBER_TOKEN) { + token = gettoken(f, c, &c); + if (token == NUMBER_TOKEN) { value1 = number_value; - } else if(token == EOL_TOKEN) { + } + else if (token == EOL_TOKEN) { return STARTMAPPING_LINE; - } else { + } + else { skipEndOfLine(f, c); return ERROR_LINE; } /* optional second integer */ - token = gettoken(f,c,&c); - if(token == NUMBER_TOKEN) { + token = gettoken(f, c, &c); + if (token == NUMBER_TOKEN) { value2 = number_value; - } else if(token == EOL_TOKEN) { + } + else if (token == EOL_TOKEN) { return STARTMAPPING_LINE; - } else { + } + else { skipEndOfLine(f, c); return ERROR_LINE; } - if(!endOfLine(f,c)) + if (!endOfLine(f, c)) return ERROR_LINE; else { return STARTMAPPING_LINE; } - } else if(!strcasecmp(keyword_value, "UNDEFINE")) { + } + else if (!strcasecmp(keyword_value, "UNDEFINE")) { /* first integer */ - token = gettoken(f,c,&c); - if(token != NUMBER_TOKEN) { - skipEndOfLine(f,c); + token = gettoken(f, c, &c); + if (token != NUMBER_TOKEN) { + skipEndOfLine(f, c); return ERROR_LINE; } value1 = number_value; /* optional second integer */ - token = gettoken(f,c,&c); - if(token == EOL_TOKEN) { + token = gettoken(f, c, &c); + if (token == EOL_TOKEN) { value2 = value1; return CODE_UNDEFINE_LINE; - } else if(token == NUMBER_TOKEN) { + } + else if (token == NUMBER_TOKEN) { value2 = number_value; - if(endOfLine(f,c)) { + if (endOfLine(f, c)) { return CODE_UNDEFINE_LINE; - } else + } + else return ERROR_LINE; - } else { - skipEndOfLine(f,c); + } + else { + skipEndOfLine(f, c); return ERROR_LINE; } - } else if(!strcasecmp(keyword_value, "ENDENCODING")) { - if(endOfLine(f,c)) + } + else if (!strcasecmp(keyword_value, "ENDENCODING")) { + if (endOfLine(f, c)) return EOF_LINE; else return ERROR_LINE; - } else if(!strcasecmp(keyword_value, "ENDMAPPING")) { - if(endOfLine(f,c)) + } + else if (!strcasecmp(keyword_value, "ENDMAPPING")) { + if (endOfLine(f, c)) return ENDMAPPING_LINE; else return ERROR_LINE; - } else { - skipEndOfLine(f,c); + } + else { + skipEndOfLine(f, c); return ERROR_LINE; } default: @@ -382,11 +415,11 @@ install_mapping(FontEncPtr encoding, FontMapPtr mapping) { FontMapPtr m; - if(encoding->mappings == NULL) + if (encoding->mappings == NULL) encoding->mappings = mapping; else { m = encoding->mappings; - while(m->next != NULL) + while (m->next != NULL) m = m->next; m->next = mapping; } @@ -400,46 +433,49 @@ setCode(unsigned from, unsigned to, unsigned row_size, unsigned *encsize, unsigned short **enc) { unsigned index, i; + unsigned short *newenc; - if(from>0xFFFF) + if (from > 0xFFFF) return 0; /* success */ - if(row_size==0) - index=from; + if (row_size == 0) + index = from; else { - if((value1 & 0xFF) >= row_size) + if ((value1 & 0xFF) >= row_size) return 0; /* ignore out of range mappings */ - index = (from>>8) * row_size + (from&0xFF); + index = (from >> 8) * row_size + (from & 0xFF); } /* Optimize away useless identity mappings. This is only expected to be useful with linear encodings. */ - if(index == to && (index < *first || index > *last)) + if (index == to && (index < *first || index > *last)) return 0; - if(*encsize == 0) { + if (*encsize == 0) { *encsize = (index < 256) ? 256 : 0x10000; *enc = malloc((*encsize) * sizeof(unsigned short)); - if(*enc == NULL) { + if (*enc == NULL) { *encsize = 0; return 1; } - } else if(*encsize <= index) { + } + else if (*encsize <= index) { *encsize = 0x10000; - if((newenc = realloc(*enc, (*encsize) * sizeof(unsigned short)))==NULL) + if ((newenc = + realloc(*enc, (*encsize) * sizeof(unsigned short))) == NULL) return 1; *enc = newenc; } - if(*first > *last) { + if (*first > *last) { *first = *last = index; } - if(index < *first) { - for(i = index; i < *first; i++) + if (index < *first) { + for (i = index; i < *first; i++) (*enc)[i] = i; *first = index; } - if(index > *last) { - for(i = *last + 1; i <= index; i++) + if (index > *last) { + for (i = *last + 1; i <= index; i++) (*enc)[i] = i; *last = index; } @@ -462,50 +498,51 @@ parseEncodingFile(FontFilePtr f, int headerOnly) { int line; - unsigned short *enc=NULL; + unsigned short *enc = NULL; char **nam = NULL, **newnam; - unsigned i, first = 0xFFFF, last=0, encsize=0, namsize=0; + unsigned i, first = 0xFFFF, last = 0, encsize = 0, namsize = 0; FontEncPtr encoding = NULL; FontMapPtr mapping = NULL; FontEncSimpleMapPtr sm; FontEncSimpleNamePtr sn; - char *aliases[MAXALIASES]; - int numaliases=0; + char *aliases[MAXALIASES] = { NULL }; + int numaliases = 0; #if 0 /* GCC complains about unused labels. Please fix GCC rather than obfuscating my code. */ - no_encoding: + no_encoding: #endif line = getnextline(f); - switch(line) { + switch (line) { case EOF_LINE: goto error; case STARTENCODING_LINE: encoding = malloc(sizeof(FontEncRec)); - if(encoding == NULL) + if (encoding == NULL) goto error; encoding->name = strdup(keyword_value); - if(encoding->name == NULL) + if (encoding->name == NULL) goto error; encoding->size = 256; encoding->row_size = 0; encoding->mappings = NULL; encoding->next = NULL; - encoding->first = encoding->first_col=0; + encoding->first = encoding->first_col = 0; goto no_mapping; default: goto error; } - no_mapping: + no_mapping: line = getnextline(f); - switch(line) { - case EOF_LINE: goto done; + switch (line) { + case EOF_LINE: + goto done; case ALIAS_LINE: - if(numaliases < MAXALIASES) { + if (numaliases < MAXALIASES) { aliases[numaliases] = strdup(keyword_value); - if(aliases[numaliases] == NULL) + if (aliases[numaliases] == NULL) goto error; numaliases++; } @@ -519,11 +556,11 @@ parseEncodingFile(FontFilePtr f, int headerOnly) encoding->first_col = value2; goto no_mapping; case STARTMAPPING_LINE: - if(headerOnly) + if (headerOnly) goto done; - if(!strcasecmp(keyword_value, "unicode")) { + if (!strcasecmp(keyword_value, "unicode")) { mapping = malloc(sizeof(FontMapRec)); - if(mapping == NULL) + if (mapping == NULL) goto error; mapping->type = FONT_ENCODING_UNICODE; mapping->pid = 0; @@ -533,9 +570,10 @@ parseEncodingFile(FontFilePtr f, int headerOnly) mapping->client_data = NULL; mapping->next = NULL; goto mapping; - } else if(!strcasecmp(keyword_value, "cmap")) { + } + else if (!strcasecmp(keyword_value, "cmap")) { mapping = malloc(sizeof(FontMapRec)); - if(mapping == NULL) + if (mapping == NULL) goto error; mapping->type = FONT_ENCODING_TRUETYPE; mapping->pid = value1; @@ -545,9 +583,10 @@ parseEncodingFile(FontFilePtr f, int headerOnly) mapping->client_data = NULL; mapping->next = NULL; goto mapping; - } else if(!strcasecmp(keyword_value, "postscript")) { + } + else if (!strcasecmp(keyword_value, "postscript")) { mapping = malloc(sizeof(FontMapRec)); - if(mapping == NULL) + if (mapping == NULL) goto error; mapping->type = FONT_ENCODING_POSTSCRIPT; mapping->pid = 0; @@ -557,17 +596,19 @@ parseEncodingFile(FontFilePtr f, int headerOnly) mapping->client_data = NULL; mapping->next = NULL; goto string_mapping; - } else { /* unknown mapping type -- ignore */ + } + else { /* unknown mapping type -- ignore */ goto skipmapping; } /* NOTREACHED */ goto error; - default: goto no_mapping; /* ignore unknown lines */ + default: + goto no_mapping; /* ignore unknown lines */ } - skipmapping: + skipmapping: line = getnextline(f); - switch(line) { + switch (line) { case ENDMAPPING_LINE: goto no_mapping; case EOF_LINE: @@ -576,207 +617,230 @@ parseEncodingFile(FontFilePtr f, int headerOnly) goto skipmapping; } - mapping: + mapping: line = getnextline(f); - switch(line) { - case EOF_LINE: goto error; + switch (line) { + case EOF_LINE: + goto error; case ENDMAPPING_LINE: mapping->recode = FontEncSimpleRecode; mapping->name = FontEncUndefinedName; mapping->client_data = sm = malloc(sizeof(FontEncSimpleMapRec)); - if(sm == NULL) + if (sm == NULL) goto error; sm->row_size = encoding->row_size; - if(first <= last) { + if (first <= last) { unsigned short *newmap; sm->first = first; - sm->len=last-first+1; + sm->len = last - first + 1; newmap = malloc(sm->len * sizeof(unsigned short)); - if(newmap == NULL) { + if (newmap == NULL) { free(sm); mapping->client_data = sm = NULL; goto error; } - for(i=0; i < sm->len; i++) - newmap[i] = enc[first+i]; - sm->map = newmap; - } else { + for (i = 0; i < sm->len; i++) + newmap[i] = enc[first + i]; + sm->map = newmap; + } + else { sm->first = 0; sm->len = 0; sm->map = NULL; } install_mapping(encoding, mapping); mapping = NULL; - first = 0xFFFF; last=0; + first = 0xFFFF; + last = 0; goto no_mapping; case CODE_LINE: - if(setCode(value1, value2, encoding->row_size, - &first, &last, &encsize, &enc)) + if (setCode(value1, value2, encoding->row_size, + &first, &last, &encsize, &enc)) goto error; goto mapping; case CODE_RANGE_LINE: - if(value1 > 0x10000) + if (value1 > 0x10000) value1 = 0x10000; - if(value2 > 0x10000) + if (value2 > 0x10000) value2 = 0x10000; - if(value2 < value1) + if (value2 < value1) goto mapping; /* Do the last value first to avoid having to realloc() */ - if(setCode(value2, value3+(value2-value1), encoding->row_size, - &first, &last, &encsize, &enc)) + if (setCode(value2, value3 + (value2 - value1), encoding->row_size, + &first, &last, &encsize, &enc)) goto error; - for(i=value1; i<value2; i++) { - if(setCode(i, value3+(i-value1), encoding->row_size, - &first, &last, &encsize, &enc)) + for (i = value1; i < value2; i++) { + if (setCode(i, value3 + (i - value1), encoding->row_size, + &first, &last, &encsize, &enc)) goto error; } goto mapping; case CODE_UNDEFINE_LINE: - if(value1 > 0x10000) + if (value1 > 0x10000) value1 = 0x10000; - if(value2 > 0x10000) + if (value2 > 0x10000) value2 = 0x10000; - if(value2 < value1) + if (value2 < value1) goto mapping; /* Do the last value first to avoid having to realloc() */ - if(setCode(value2, 0, encoding->row_size, - &first, &last, &encsize, &enc)) + if (setCode(value2, 0, encoding->row_size, + &first, &last, &encsize, &enc)) goto error; - for(i = value1; i < value2; i++) { - if(setCode(i, 0, encoding->row_size, - &first, &last, &encsize, &enc)) + for (i = value1; i < value2; i++) { + if (setCode(i, 0, encoding->row_size, + &first, &last, &encsize, &enc)) goto error; } goto mapping; - default: goto mapping; /* ignore unknown lines */ + default: + goto mapping; /* ignore unknown lines */ } - string_mapping: + string_mapping: line = getnextline(f); - switch(line) { - case EOF_LINE: goto error; + switch (line) { + case EOF_LINE: + goto error; case ENDMAPPING_LINE: mapping->recode = FontEncUndefinedRecode; mapping->name = FontEncSimpleName; mapping->client_data = sn = malloc(sizeof(FontEncSimpleNameRec)); - if(sn == NULL) + if (sn == NULL) goto error; - if(first > last) { + if (first > last) { free(sn); mapping->client_data = sn = NULL; goto error; } sn->first = first; sn->len = last - first + 1; - sn->map = malloc(sn->len*sizeof(char*)); - if(sn->map == NULL) { + sn->map = malloc(sn->len * sizeof(char *)); + if (sn->map == NULL) { free(sn); mapping->client_data = sn = NULL; goto error; } - for(i = 0; i < sn->len; i++) - sn->map[i] = nam[first+i]; - install_mapping(encoding,mapping); + for (i = 0; i < sn->len; i++) + sn->map[i] = nam[first + i]; + install_mapping(encoding, mapping); mapping = NULL; - first = 0xFFFF; last=0; + first = 0xFFFF; + last = 0; goto no_mapping; case NAME_LINE: - if(value1 >= 0x10000) goto string_mapping; - if(namsize == 0) { + if (value1 >= 0x10000) + goto string_mapping; + if (namsize == 0) { namsize = (value1) < 256 ? 256 : 0x10000; - nam = malloc(namsize * sizeof(char*)); - if(nam == NULL) { - namsize=0; + nam = malloc(namsize * sizeof(char *)); + if (nam == NULL) { + namsize = 0; goto error; } - } else if(namsize <= value1) { + } + else if (namsize <= value1) { namsize = 0x10000; - if((newnam = (char**)realloc(nam, namsize)) == NULL) + if ((newnam = (char **) realloc(nam, namsize)) == NULL) goto error; nam = newnam; } - if(first > last) { + if (first > last) { first = last = value1; } - if(value1 < first) { - for(i = value1; i < first; i++) + if (value1 < first) { + for (i = value1; i < first; i++) nam[i] = NULL; first = value1; } - if(value1 > last) { - for(i=last+1; i <= value1; i++) - nam[i]=NULL; + if (value1 > last) { + for (i = last + 1; i <= value1; i++) + nam[i] = NULL; last = value1; } nam[value1] = strdup(keyword_value); - if(nam[value1] == NULL) { + if (nam[value1] == NULL) { goto error; } goto string_mapping; - default: goto string_mapping; /* ignore unknown lines */ + default: + goto string_mapping; /* ignore unknown lines */ } - done: - if(encsize) free(enc); encsize=0; enc = NULL; - if(namsize) free(nam); namsize=0; nam = NULL; /* don't free entries! */ + done: + if (encsize) { + free(enc); + encsize = 0; + enc = NULL; + } + if (namsize) { + free(nam); /* don't free entries! */ + namsize = 0; + nam = NULL; + } - encoding->aliases=NULL; - if(numaliases) { - encoding->aliases = malloc((numaliases+1)*sizeof(char*)); - if(encoding->aliases == NULL) + encoding->aliases = NULL; + if (numaliases) { + encoding->aliases = malloc((numaliases + 1) * sizeof(char *)); + if (encoding->aliases == NULL) goto error; - for(i=0; i<numaliases; i++) + for (i = 0; i < numaliases; i++) encoding->aliases[i] = aliases[i]; - encoding->aliases[numaliases]=NULL; + encoding->aliases[numaliases] = NULL; } return encoding; -error: - if(encsize) free(enc); encsize=0; - if(namsize) { - for(i = first; i <= last; i++) + error: + if (encsize) { + free(enc); + encsize = 0; + } + if (namsize) { + for (i = first; i <= last; i++) free(nam[i]); free(nam); } - if(mapping) { + if (mapping) { free(mapping->client_data); free(mapping); } - if(encoding) { - FontMapPtr nextmap; - free(encoding->name); - for (mapping = encoding->mappings; mapping; mapping = nextmap) { - free(mapping->client_data); - nextmap = mapping->next; - free(mapping); - } - free(encoding); - } - for(i = 0; i < numaliases; i++) + if (encoding) { + FontMapPtr nextmap; + + free(encoding->name); + for (mapping = encoding->mappings; mapping; mapping = nextmap) { + free(mapping->client_data); + nextmap = mapping->next; + free(mapping); + } + free(encoding); + } + for (i = 0; i < numaliases; i++) free(aliases[i]); - /* We don't need to free sn and sm as they handled locally in the body.*/ + /* We don't need to free sn and sm as they handled locally in the body. */ return NULL; } -char* +char * FontEncDirectory(void) { - static char* dir = NULL; + static char *dir = NULL; - if(dir == NULL) { + if (dir == NULL) { char *c = getenv("FONT_ENCODINGS_DIRECTORY"); - if(c) { + + if (c) { dir = strdup(c); - if(!dir) + if (!dir) return NULL; - } else { + } + else { dir = FONT_ENCODINGS_DIRECTORY; } } @@ -789,20 +853,19 @@ parseFontFileName(const char *fontFileName, char *buf, char *dir) const char *p; char *q, *lastslash; - for(p = fontFileName, q = dir, lastslash = NULL; *p; p++, q++) { + for (p = fontFileName, q = dir, lastslash = NULL; *p; p++, q++) { *q = *p; - if(*p == '/') - lastslash = q+1; + if (*p == '/') + lastslash = q + 1; } - if(!lastslash) + if (!lastslash) lastslash = dir; *lastslash = '\0'; - if(buf && strlen(dir) + 14 < MAXFONTFILENAMELEN) { - strcpy(buf, dir); - strcat(buf, "encodings.dir"); + if (buf && strlen(dir) + 14 < MAXFONTFILENAMELEN) { + snprintf(buf, MAXFONTFILENAMELEN, "%s%s", dir, "encodings.dir"); } } @@ -821,44 +884,44 @@ FontEncReallyReallyLoad(const char *charset, /* As we don't really expect to open encodings that often, we don't take the trouble of caching encodings directories. */ - if((file = fopen(dirname, "r")) == NULL) { + if ((file = fopen(dirname, "r")) == NULL) { return NULL; } count = fscanf(file, "%d\n", &n); - if(count == EOF || count != 1) { + if (count == EOF || count != 1) { fclose(file); return NULL; } encoding = NULL; if (!format[0]) { - sprintf(format, "%%%ds %%%d[^\n]\n", (int)sizeof(encoding_name) - 1, - (int)sizeof(file_name) - 1); + snprintf(format, sizeof(format), "%%%ds %%%d[^\n]\n", + (int) sizeof(encoding_name) - 1, (int) sizeof(file_name) - 1); } - for(;;) { + for (;;) { count = fscanf(file, format, encoding_name, file_name); - if(count == EOF) + if (count == EOF) break; - if(count != 2) + if (count != 2) break; - if(!strcasecmp(encoding_name, charset)) { + if (!strcasecmp(encoding_name, charset)) { /* Found it */ - if(file_name[0] != '/') { - if(strlen(dir) + strlen(file_name) >= MAXFONTFILENAMELEN) { - fclose(file); + if (file_name[0] != '/') { + if (strlen(dir) + strlen(file_name) >= MAXFONTFILENAMELEN) { + fclose(file); return NULL; - } - strcpy(buf, dir); - strcat(buf, file_name); - } else { - strcpy(buf , file_name); + } + snprintf(buf, MAXFONTFILENAMELEN, "%s%s", dir, file_name); + } + else { + snprintf(buf, MAXFONTFILENAMELEN, "%s", file_name); } f = FontFileOpen(buf); - if(f == NULL) { - fclose(file); + if (f == NULL) { + fclose(file); return NULL; } encoding = parseEncodingFile(f, 0); @@ -880,15 +943,15 @@ FontEncReallyLoad(const char *charset, const char *fontFileName) char dir[MAXFONTFILENAMELEN], dirname[MAXFONTFILENAMELEN]; char *d; - if(fontFileName) { + if (fontFileName) { parseFontFileName(fontFileName, dirname, dir); encoding = FontEncReallyReallyLoad(charset, dirname, dir); - if(encoding) - return(encoding); + if (encoding) + return (encoding); } d = FontEncDirectory(); - if(d) { + if (d) { parseFontFileName(d, NULL, dir); encoding = FontEncReallyReallyLoad(charset, d, dir); return encoding; @@ -909,22 +972,22 @@ FontEncIdentify(const char *fileName) char **names, **name, **alias; int numaliases; - if((f = FontFileOpen(fileName))==NULL) { + if ((f = FontFileOpen(fileName)) == NULL) { return NULL; } encoding = parseEncodingFile(f, 1); FontFileClose(f); - if(!encoding) + if (!encoding) return NULL; numaliases = 0; - if(encoding->aliases) - for(alias = encoding->aliases; *alias; alias++) + if (encoding->aliases) + for (alias = encoding->aliases; *alias; alias++) numaliases++; - names = malloc((numaliases+2)*sizeof(char*)); - if(names == NULL) { + names = malloc((numaliases + 2) * sizeof(char *)); + if (names == NULL) { free(encoding->aliases); free(encoding); return NULL; @@ -932,9 +995,9 @@ FontEncIdentify(const char *fileName) name = names; *(name++) = encoding->name; - if(numaliases > 0) - for(alias = encoding->aliases; *alias; alias++, name++) - *name = *alias; + if (numaliases > 0) + for (alias = encoding->aliases; *alias; alias++, name++) + *name = *alias; *name = NULL; free(encoding->aliases); |