bdf2sfd

BDF to SFD converter, allowing to vectorize bitmap fonts
Log | Files | Refs | README | LICENSE

commit 168e892a4b8a8df44518e08eecb5b29bc2411059
parent c521ef43856695c3321402edf4d8419fc2765f5e
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu,  6 Feb 2020 16:19:06 +0100

Parse the key in the parse() function, this allows removing some code.

Diffstat:
Msrc/bdftosfd.c | 48++++++++++--------------------------------------
Msrc/parse.c | 51+++++++++++++++++++++++++++++----------------------
2 files changed, 39 insertions(+), 60 deletions(-)

diff --git a/src/bdftosfd.c b/src/bdftosfd.c @@ -137,23 +137,16 @@ main(int argc, char *argv[]) switch(key) { case FAMILY_NAME: if (!font.name) { - token = strtok(lineBuffer, " \t"); - - if (token) - name = strtok(NULL, "\n"); + name = strtok(NULL, "\n"); if (name) font.name = strdup(name); - } continue; case COPYRIGHT: - token = strtok(lineBuffer, " \t"); - - if (token) - copyright = strtok(NULL, "\n"); + copyright = strtok(NULL, "\n"); if (copyright) font.copyright = strdup(copyright); @@ -161,10 +154,7 @@ main(int argc, char *argv[]) continue; case FONTBOUNDINGBOX: - token = strtok(lineBuffer, " \t"); - - if (token) - value = strtok(NULL, " \t"); + value = strtok(NULL, " \t"); if (value) width = strtonum(value, 0, 32, &errstr); @@ -191,10 +181,7 @@ main(int argc, char *argv[]) continue; case FONT_ASCENT: - token = strtok(lineBuffer, " \t"); - - if (token) - value = strtok(NULL, "\n"); + value = strtok(NULL, "\n"); if (value) ascent = strtonum(value, 0, 64, &errstr); @@ -207,10 +194,7 @@ main(int argc, char *argv[]) continue; case FONT_DESCENT: - token = strtok(lineBuffer, " \t"); - - if (token) - value = strtok(NULL, "\n"); + value = strtok(NULL, "\n"); if (value) descent = strtonum(value, 0, 64, &errstr); @@ -223,10 +207,7 @@ main(int argc, char *argv[]) continue; case FONT_VERSION: - token = strtok(lineBuffer, " \t"); - - if (token) - version = strtok(NULL, "\n"); + version = strtok(NULL, "\n"); if (version) font.version = strdup(version); @@ -234,10 +215,7 @@ main(int argc, char *argv[]) continue; case CHARS: - token = strtok(lineBuffer, " \t"); - - if (token) - font.chars = strtok(NULL, " \n"); + font.chars = strtok(NULL, " \n"); if (font.chars) header(stdout, &font); @@ -248,24 +226,18 @@ main(int argc, char *argv[]) case STARTCHAR: fprintf(stdout, "StartChar:"); - token = strtok(lineBuffer, " \t"); - if (token) { - charname = strtok(NULL, " \n"); + charname = strtok(NULL, "\n"); while (charname) { - fprintf(stdout, " %s", charname); + fprintf(stdout, " %s\n", charname); charname = strtok(NULL, " \n"); } - } continue; case ENCODING: - token = strtok(lineBuffer, " \t"); - - if (token) - encoding = strtok(NULL, " \n"); + encoding = strtok(NULL, " \n"); if (encoding) fprintf(stdout, "\nEncoding: %s %s %s\n", encoding, encoding, encoding); diff --git a/src/parse.c b/src/parse.c @@ -11,43 +11,50 @@ */ #include <string.h> +#include <string.h> #include "parse.h" int parseLine(char *lineBuffer) { + char *key = NULL; + if (*lineBuffer) { - if (!strncmp(lineBuffer, "FAMILY_NAME ", 12)) - return FAMILY_NAME; + key = strtok(lineBuffer, " \t\n"); + + if (key) { + if (!strcmp(key, "FAMILY_NAME")) + return FAMILY_NAME; - if (!strncmp(lineBuffer, "COPYRIGHT ", 10)) - return COPYRIGHT; + if (!strcmp(key, "COPYRIGHT")) + return COPYRIGHT; - if (!strncmp(lineBuffer, "FONTBOUNDINGBOX ", 16)) - return FONTBOUNDINGBOX; + if (!strcmp(key, "FONTBOUNDINGBOX")) + return FONTBOUNDINGBOX; - if (!strncmp(lineBuffer, "FONT_ASCENT ", 12)) - return FONT_ASCENT; + if (!strcmp(key, "FONT_ASCENT")) + return FONT_ASCENT; - if (!strncmp(lineBuffer, "FONT_DESCENT ", 12)) - return FONT_DESCENT; + if (!strcmp(key, "FONT_DESCENT")) + return FONT_DESCENT; - if (!strncmp(lineBuffer, "FONT_VERSION ", 13)) - return FONT_VERSION; + if (!strcmp(key, "FONT_VERSION")) + return FONT_VERSION; - if (!strncmp(lineBuffer, "CHARS ", 6)) - return CHARS; + if (!strcmp(key, "CHARS")) + return CHARS; - if (!strncmp(lineBuffer, "STARTCHAR", 9)) - return STARTCHAR; + if (!strcmp(key, "STARTCHAR")) + return STARTCHAR; - if (!strncmp(lineBuffer, "ENCODING", 8)) - return ENCODING; + if (!strcmp(key, "ENCODING")) + return ENCODING; - if (!strncmp(lineBuffer, "BITMAP", 6)) - return BITMAP; + if (!strcmp(key, "BITMAP")) + return BITMAP; - if (!strncmp(lineBuffer, "ENDCHAR", 7)) - return ENDCHAR; + if (!strcmp(key, "ENDCHAR")) + return ENDCHAR; + } } return 0;