summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--constlist.c8
-rw-r--r--hash.c31
-rw-r--r--ident.c8
-rw-r--r--mkfontscale.c104
4 files changed, 64 insertions, 87 deletions
diff --git a/constlist.c b/constlist.c
index bdff352..076a33a 100644
--- a/constlist.c
+++ b/constlist.c
@@ -45,7 +45,7 @@ appendConstList(ConstListPtr first, ConstListPtr second)
ConstListPtr
makeConstList(const char **a, int n, ConstListPtr old, int begin)
{
- ConstListPtr first, current, next;
+ ConstListPtr first, current;
int i;
if (n == 0)
@@ -60,7 +60,7 @@ makeConstList(const char **a, int n, ConstListPtr old, int begin)
current = first;
for (i = 1; i < n; i++) {
- next = malloc(sizeof(ConstListRec));
+ ConstListPtr next = malloc(sizeof(ConstListRec));
if (!next) {
destroyConstList(first);
return NULL;
@@ -83,12 +83,10 @@ makeConstList(const char **a, int n, ConstListPtr old, int begin)
void
destroyConstList(ConstListPtr old)
{
- ConstListPtr next;
-
if (!old)
return;
while (old) {
- next = old->next;
+ ConstListPtr next = old->next;
free(old);
old = next;
}
diff --git a/hash.c b/hash.c
index 3a3e67e..5877dc6 100644
--- a/hash.c
+++ b/hash.c
@@ -37,10 +37,9 @@
static unsigned
hash(const char *string)
{
- int i;
unsigned u = 0;
- for (i = 0; string[i] != '\0'; i++)
+ for (int i = 0; string[i] != '\0'; i++)
u = (u << 5) + (u >> (LOG2_NUMBUCKETS - 5)) + (unsigned char) string[i];
return (u & (NUMBUCKETS - 1));
}
@@ -63,12 +62,9 @@ makeHashTable(void)
void
destroyHashTable(HashTablePtr table)
{
- int i;
- HashBucketPtr bp;
-
- for (i = 0; i < NUMBUCKETS; i++) {
+ for (int i = 0; i < NUMBUCKETS; i++) {
while (table[i]) {
- bp = table[i];
+ HashBucketPtr bp = table[i];
table[i] = table[i]->next;
free(bp->key);
free(bp->value);
@@ -82,9 +78,8 @@ char *
getHash(HashTablePtr table, const char *key)
{
unsigned int i = hash(key);
- HashBucketPtr bp;
- for (bp = table[i]; bp; bp = bp->next) {
+ for (HashBucketPtr bp = table[i]; bp; bp = bp->next) {
if (strcasecmp(bp->key, key) == 0)
return bp->value;
}
@@ -144,12 +139,10 @@ putHash(HashTablePtr table, char *key, char *value, int prio)
int
hashElements(HashTablePtr table)
{
- int i, n;
- HashBucketPtr bp;
+ int n = 0;
- n = 0;
- for (i = 0; i < NUMBUCKETS; i++) {
- for (bp = table[i]; bp; bp = bp->next) {
+ for (int i = 0; i < NUMBUCKETS; i++) {
+ for (HashBucketPtr bp = table[i]; bp; bp = bp->next) {
n++;
}
}
@@ -181,16 +174,14 @@ value_first_cmp(const void *v1, const void *v2)
HashBucketPtr *
hashArray(HashTablePtr table, int value_first)
{
- int i, j, n;
- HashBucketPtr *dst;
-
- n = hashElements(table);
- dst = malloc((n + 1) * sizeof(HashBucketPtr));
+ int j;
+ int n = hashElements(table);
+ HashBucketPtr *dst = malloc((n + 1) * sizeof(HashBucketPtr));
if (dst == NULL)
return NULL;
j = 0;
- for (i = 0; i < NUMBUCKETS; i++) {
+ for (int i = 0; i < NUMBUCKETS; i++) {
while (table[i]) {
dst[j++] = table[i];
table[i] = table[i]->next;
diff --git a/ident.c b/ident.c
index 6d3cff3..4a1d1eb 100644
--- a/ident.c
+++ b/ident.c
@@ -355,11 +355,10 @@ static char *
getKeyword(fontFile *f, int *eol)
{
static char keyword[NKEY + 1];
- int c, i;
+ int i = 0;
- i = 0;
while (i < NKEY) {
- c = fontFileGetc(f);
+ int c = fontFileGetc(f);
if (c == ' ' || c == '\n') {
if (i <= 0)
return NULL;
@@ -437,7 +436,6 @@ static int
bdfIdentify(fontFile *f, char **name)
{
char *k;
- int rc;
int eol;
/* bitmapIdentify already read "STAR", so we need to check for
@@ -449,7 +447,7 @@ bdfIdentify(fontFile *f, char **name)
goto fail;
while (1) {
if (!eol) {
- rc = bdfskip(f);
+ int rc = bdfskip(f);
if (rc < 0)
goto fail;
}
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;