From: Ben Harris Date: Sat, 8 Jul 2017 20:04:18 +0000 (+0100) Subject: Move knowledge of different widths out of main(). X-Git-Tag: bedstead-001.003~13 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=065de736439cc604d7d777534114897ea4b6afcb;p=bedstead.git Move knowledge of different widths out of main(). It's now contained in on place in bedstead.c (and in the Makefile). --- diff --git a/bedstead.c b/bedstead.c index e168d4b..13afb26 100644 --- a/bedstead.c +++ b/bedstead.c @@ -126,37 +126,41 @@ */ struct param { + char const * option; char const * fontname; char const * fullname; int xpix; int ttfwidth; }; -struct param default_param = { - "Bedstead", "Bedstead", - 100, /* xpix */ - 5, /* ttfwidth */ +struct param const params[] = { + { + "--normal", + "Bedstead", "Bedstead", + 100, /* xpix */ + 5, /* ttfwidth */ + }, + { + "--extended", + "Bedstead-Extended", "Bedstead Extended", + 124, /* xpix */ + 7, /* ttfwidth */ + }, + { + "--condensed", + "Bedstead-Condensed", "Bedstead Condensed", + 50, /* xpix */ + 1, /* ttfwidth */ + }, + { + "--semicondensed", + "Bedstead-Semicondensed", "Bedstead Semicondensed", + 62, /* xpix */ + 2, /* ttfwidth */ + }, }; -struct param extended_param = { - "Bedstead-Extended", "Bedstead Extended", - 124, /* xpix */ - 7, /* ttfwidth */ -}; - -struct param condensed_param = { - "Bedstead-Condensed", "Bedstead Condensed", - 50, /* xpix */ - 1, /* ttfwidth */ -}; - -struct param semicondensed_param = { - "Bedstead-Semicondensed", "Bedstead Semicondensed", - 62, /* xpix */ - 2, /* ttfwidth */ -}; - -struct param *param = &default_param; +struct param const *param = ¶ms[0]; /* Size of pixels in font design units (usually 1000/em) */ #define XPIX (param->xpix) @@ -1228,20 +1232,18 @@ main(int argc, char **argv) { int i; int const nglyphs = sizeof(glyphs) / sizeof(glyphs[0]); + int const nparams = sizeof(params) / sizeof(params[0]); int extraglyphs = 0; char *endptr; while (argc > 1) { - if (strcmp(argv[1], "--extended") == 0) { - param = &extended_param; - argv++; argc--; - } else if (strcmp(argv[1], "--condensed") == 0) { - param = &condensed_param; - argv++; argc--; - } else if (strcmp(argv[1], "--semicondensed") == 0) { - param = &semicondensed_param; - argv++; argc--; - } else if (strcmp(argv[1], "--") == 0) { + for (i = 0; i < nparams; i++) + if (strcmp(argv[1], params[i].option) == 0) { + param = ¶ms[i]; + argv++; argc--; + goto next; + } + if (strcmp(argv[1], "--") == 0) { argv++; argc--; break; } else if (argv[1][0] == '-') { @@ -1249,6 +1251,7 @@ main(int argc, char **argv) return 1; } else break; argv++; argc--; + next:; } if (argc > 1) {