diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-11-04 11:28:44 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-11-06 14:19:08 -0800 |
commit | 19137ec2f129f91ce3adb46218c86e1bf547e661 (patch) | |
tree | 237a5a879a738a18009863ecd12464eaff3af544 /mkfontscale.c | |
parent | ffd69eb38f153229f5033ef5cc789c0ab3704edd (diff) |
Variable scope reductions as recommended by cppcheck
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'mkfontscale.c')
-rw-r--r-- | mkfontscale.c | 104 |
1 files changed, 47 insertions, 57 deletions
diff --git a/mkfontscale.c b/mkfontscale.c index 09599d0..79d41bc 100644 --- a/mkfontscale.c +++ b/mkfontscale.c @@ -142,7 +142,7 @@ main(int argc, char **argv) { int argn; FT_Error ftrc; - int rc, ll = 0; + int ll = 0; ListPtr encodingsToDo; char prefix[NPREFIX]; @@ -210,6 +210,8 @@ main(int argc, char **argv) argn += 2; } else if (strcmp(argv[argn], "-e") == 0) { + int rc; + if (argn >= argc - 1) { missing_arg("-e"); } @@ -299,13 +301,13 @@ getNameHelper(FT_Face face, int nid, int pid, int eid, FT_SfntName *name_return) { FT_SfntName name; - int n, i; + int n; n = FT_Get_Sfnt_Name_Count(face); if (n <= 0) return 0; - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { if (FT_Get_Sfnt_Name(face, i, &name)) continue; if (name.name_id == nid && @@ -337,13 +339,12 @@ static char * getName(FT_Face face, int nid) { FT_SfntName name; - char *string; - unsigned int i; if (getNameHelper(face, nid, TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, &name) || getNameHelper(face, nid, TT_PLATFORM_APPLE_UNICODE, -1, &name)) { - string = malloc(name.string_len / 2 + 1); + unsigned int i; + char *string = malloc(name.string_len / 2 + 1); if (string == NULL) { fprintf(stderr, "Couldn't allocate name\n"); exit(1); @@ -360,7 +361,7 @@ getName(FT_Face face, int nid) /* Pretend that Apple Roman is ISO 8859-1. */ if (getNameHelper(face, nid, TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, &name)) { - string = malloc(name.string_len + 1); + char *string = malloc(name.string_len + 1); if (string == NULL) { fprintf(stderr, "Couldn't allocate name\n"); exit(1); @@ -706,13 +707,11 @@ makeXLFD(char *filename, FT_Face face, int isBitmap) weight, slant, sWidth, adstyle, spacing); } else { - int i, w, h, xres, yres; - - for (i = 0; i < face->num_fixed_sizes; i++) { - w = face->available_sizes[i].width; - h = face->available_sizes[i].height; - xres = 75; - yres = (double) h / w * xres; + for (int i = 0; i < face->num_fixed_sizes; i++) { + int w = face->available_sizes[i].width; + int h = face->available_sizes[i].height; + int xres = 75; + int yres = (double) h / w * xres; xlfd = listConsF(xlfd, "-%s-%s-%s-%s-%s-%s-%d-%d-%d-%d-%s-%d", foundry, family, @@ -734,7 +733,7 @@ readFontScale(HashTablePtr entries, char *dirname) size_t n = strlen(dirname); char *filename; FILE *in; - int rc, count, i; + int rc, count; char file[MAXFONTFILENAMELEN + 1], font[MAXFONTNAMELEN + 1]; if (dirname[n - 1] == '/') @@ -759,7 +758,7 @@ readFontScale(HashTablePtr entries, char *dirname) return -1; } - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { rc = fscanf(in, "%" STRINGIFY(MAXFONTFILENAMELEN) "s " "%" STRINGIFY(MAXFONTNAMELEN) "[^\n]\n", @@ -1093,8 +1092,6 @@ checkEncoding(FT_Face face, const char *encoding_name) { FontEncPtr encoding; FontMapPtr mapping; - int i, j, c, koi8; - char *n; encoding = FontEncFind(encoding_name, NULL); if (!encoding) @@ -1116,10 +1113,10 @@ checkEncoding(FT_Face face, const char *encoding_name) for (mapping = encoding->mappings; mapping; mapping = mapping->next) { if (mapping->type == FONT_ENCODING_POSTSCRIPT) { if (encoding->row_size > 0) { - for (i = encoding->first; i < encoding->size; i++) { - for (j = encoding->first_col; + for (int i = encoding->first; i < encoding->size; i++) { + for (int j = encoding->first_col; j < encoding->row_size; j++) { - n = FontEncName((i << 8) | j, mapping); + char *n = FontEncName((i << 8) | j, mapping); if (n && FT_Get_Name_Index(face, n) == 0) { return 0; } @@ -1128,8 +1125,8 @@ checkEncoding(FT_Face face, const char *encoding_name) return 1; } else { - for (i = encoding->first; i < encoding->size; i++) { - n = FontEncName(i, mapping); + for (int i = encoding->first; i < encoding->size; i++) { + char *n = FontEncName(i, mapping); if (n && FT_Get_Name_Index(face, n) == 0) { return 0; } @@ -1148,9 +1145,10 @@ checkEncoding(FT_Face face, const char *encoding_name) int estimate = (encoding->size - encoding->first) * (encoding->row_size - encoding->first_col); - for (i = encoding->first; i < encoding->size; i++) { - for (j = encoding->first_col; j < encoding->row_size; j++) { - c = FontEncRecode((i << 8) | j, mapping); + for (int i = encoding->first; i < encoding->size; i++) { + for (int j = encoding->first_col; j < encoding->row_size; + j++) { + int c = FontEncRecode((i << 8) | j, mapping); if (CODE_IGNORED(c)) { continue; } @@ -1174,6 +1172,7 @@ checkEncoding(FT_Face face, const char *encoding_name) } else { int estimate = encoding->size - encoding->first; + int koi8; /* For the KOI8 encodings, we ignore the lack of linedrawing and pseudo-math characters */ @@ -1181,8 +1180,8 @@ checkEncoding(FT_Face face, const char *encoding_name) koi8 = 1; else koi8 = 0; - for (i = encoding->first; i < encoding->size; i++) { - c = FontEncRecode(i, mapping); + for (int i = encoding->first; i < encoding->size; i++) { + int c = FontEncRecode(i, mapping); if (CODE_IGNORED(c) || (koi8 && ((c >= 0x2200 && c < 0x2600) || c == 0x00b2))) { @@ -1212,17 +1211,14 @@ checkEncoding(FT_Face face, const char *encoding_name) static int find_cmap(int type, int pid, int eid, FT_Face face) { - int i, n, rc; - FT_CharMap cmap = NULL; - - n = face->num_charmaps; + int n = face->num_charmaps; switch (type) { case FONT_ENCODING_TRUETYPE: /* specific cmap */ - for (i = 0; i < n; i++) { - cmap = face->charmaps[i]; + for (int i = 0; i < n; i++) { + FT_CharMap cmap = face->charmaps[i]; if (cmap->platform_id == pid && cmap->encoding_id == eid) { - rc = FT_Set_Charmap(face, cmap); + int rc = FT_Set_Charmap(face, cmap); if (rc == 0) return 1; } @@ -1230,29 +1226,29 @@ find_cmap(int type, int pid, int eid, FT_Face face) break; case FONT_ENCODING_UNICODE: /* any Unicode cmap */ /* prefer Microsoft Unicode */ - for (i = 0; i < n; i++) { - cmap = face->charmaps[i]; + for (int i = 0; i < n; i++) { + FT_CharMap cmap = face->charmaps[i]; if (cmap->platform_id == TT_PLATFORM_MICROSOFT && cmap->encoding_id == TT_MS_ID_UNICODE_CS) { - rc = FT_Set_Charmap(face, cmap); + int rc = FT_Set_Charmap(face, cmap); if (rc == 0) return 1; } } /* Try Apple Unicode */ - for (i = 0; i < n; i++) { - cmap = face->charmaps[i]; + for (int i = 0; i < n; i++) { + FT_CharMap cmap = face->charmaps[i]; if (cmap->platform_id == TT_PLATFORM_APPLE_UNICODE) { - rc = FT_Set_Charmap(face, cmap); + int rc = FT_Set_Charmap(face, cmap); if (rc == 0) return 1; } } /* ISO Unicode? */ - for (i = 0; i < n; i++) { - cmap = face->charmaps[i]; + for (int i = 0; i < n; i++) { + FT_CharMap cmap = face->charmaps[i]; if (cmap->platform_id == TT_PLATFORM_ISO) { - rc = FT_Set_Charmap(face, cmap); + int rc = FT_Set_Charmap(face, cmap); if (rc == 0) return 1; } @@ -1267,8 +1263,6 @@ find_cmap(int type, int pid, int eid, FT_Face face) static int checkExtraEncoding(FT_Face face, const char *encoding_name, int found) { - int c; - if (strcasecmp(encoding_name, "iso10646-1") == 0) { if (doISO10646_1_encoding && find_cmap(FONT_ENCODING_UNICODE, -1, -1, face)) { @@ -1276,7 +1270,7 @@ checkExtraEncoding(FT_Face face, const char *encoding_name, int found) /* Export as Unicode if there are at least 15 BMP characters that are not a space or ignored. */ - for (c = 0x21; c < 0x10000; c++) { + for (int c = 0x21; c < 0x10000; c++) { if (CODE_IGNORED(c)) continue; if (FT_Get_Char_Index(face, c) > 0) @@ -1315,9 +1309,7 @@ checkExtraEncoding(FT_Face face, const char *encoding_name, int found) static const char * notice_foundry(const char *notice) { - unsigned int i; - - for (i = 0; i < countof(notice_foundries); i++) + for (unsigned int i = 0; i < countof(notice_foundries); i++) if (notice && strstr(notice, notice_foundries[i][0])) return notice_foundries[i][1]; return NULL; @@ -1341,9 +1333,7 @@ vendor_match(const signed char *vendor, const char *vendor_string) static const char * vendor_foundry(const signed char *vendor) { - unsigned int i; - - for (i = 0; i < countof(vendor_foundries); i++) + for (unsigned int i = 0; i < countof(vendor_foundries); i++) if (vendor_match(vendor, vendor_foundries[i][0])) return vendor_foundries[i][1]; return NULL; @@ -1352,10 +1342,8 @@ vendor_foundry(const signed char *vendor) static int readEncodings(ListPtr *encodingsToDo, char *dirname) { - char *fullname; DIR *dirp; struct dirent *file; - char **names, **name; if (strlen(dirname) > 1 && dirname[strlen(dirname) - 1] == '/') dirname[strlen(dirname) - 1] = '\0'; @@ -1367,7 +1355,9 @@ readEncodings(ListPtr *encodingsToDo, char *dirname) } while ((file = readdir(dirp)) != NULL) { - fullname = dsprintf("%s/%s", dirname, file->d_name); + char *fullname = dsprintf("%s/%s", dirname, file->d_name); + char **names; + if (fullname == NULL) { fprintf(stderr, "Couldn't allocate fullname\n"); closedir(dirp); @@ -1378,7 +1368,7 @@ readEncodings(ListPtr *encodingsToDo, char *dirname) if (!names) continue; - for (name = names; *name; name++) { + for (char **name = names; *name; name++) { if (fullname[0] != '/' && !relative) { char *n; |