chiark / gitweb /
Move knowledge of different widths out of main().
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 8 Jul 2017 20:04:18 +0000 (21:04 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 8 Jul 2017 20:04:18 +0000 (21:04 +0100)
It's now contained in on place in bedstead.c (and in the Makefile).

bedstead.c

index e168d4b1f075429f7db99d93d8101818b0a4b68a..13afb269b0cf9bc8090c3aca20e13497424e66d8 100644 (file)
  */
 
 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 = &params[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 = &params[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) {