changeset 2574:3feca4682680

Move functions around to get rid of the unknown-size dmFormatList array forward declaration (without the need to give it a size), so that we compile cleanly with -pedantic.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Mar 2022 14:48:56 +0200
parents 21d296803fac
children 64a58285d3bb
files tools/data2inc.c
diffstat 1 files changed, 139 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/tools/data2inc.c	Thu Mar 10 22:37:05 2022 +0200
+++ b/tools/data2inc.c	Fri Mar 11 14:48:56 2022 +0200
@@ -72,139 +72,6 @@
 };
 
 static const int optListN = sizeof(optList) / sizeof(optList[0]);
-static const DMOutputFormat dmFormatList[];
-static const int ndmFormatList;
-
-
-void argShowHelp()
-{
-    dmPrintBanner(stdout, dmProgName,
-    "[options] [sourcefile] [destfile]");
-
-    dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2);
-
-    fprintf(stdout,
-    "\n"
-    "Available output formats (-f <frmt>):\n"
-    " frmt | Description (filename extensions)\n"
-    "------+------------------------------------------\n");
-
-    for (int i = 0; i < ndmFormatList; i++)
-    {
-        const DMOutputFormat *fmt = &dmFormatList[i];
-        fprintf(stdout, "%-5s | %s (",
-            fmt->name, fmt->desc);
-
-        for (int n = 0; n < SET_MAX_FEXTS && fmt->fexts[n] != NULL; n++)
-        {
-            fprintf(stdout, ".%s%s",
-                fmt->fexts[n],
-                (n + 1 < SET_MAX_FEXTS &&
-                fmt->fexts[n + 1] != NULL) ? " " : "");
-        }
-        fprintf(stdout, ")\n");
-    }
-
-    fprintf(stdout,
-    "\n"
-    "To convert a data file to a C structure using 'Uint8' as type:\n"
-    "$ data2inc -n variable_name -t Uint8 input.bin output.h\n"
-    "\n"
-    );
-}
-
-
-BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
-{
-    switch (optN)
-    {
-        case 0:
-            argShowHelp();
-            exit(0);
-            break;
-
-        case 1:
-            dmPrintLicense(stdout);
-            exit(0);
-            break;
-
-        case 10:
-            optObjName = optArg;
-            break;
-
-        case 12:
-            optDataType = optArg;
-            break;
-
-        case 14:
-            for (int i = 0; i < ndmFormatList; i++)
-            {
-                const DMOutputFormat *fmt = &dmFormatList[i];
-                if (strcasecmp(fmt->name, optArg) == 0)
-                {
-                    setFormat = fmt;
-                    return TRUE;
-                }
-            }
-            dmErrorMsg("Invalid format name '%s'.\n",
-                optArg);
-            return FALSE;
-
-        case 16:
-            optAddLine = optArg;
-            break;
-
-        case 18:
-            optLineLen = atoi(optArg);
-            if (optLineLen < 1)
-            {
-                dmErrorMsg("Invalid line length / number of items per line '%s'.\n",
-                    optArg);
-                return FALSE;
-            }
-            break;
-
-        case 20:
-            optHexMode = TRUE;
-            break;
-
-        case 22:
-            optQuiet = TRUE;
-            break;
-
-        case 24:
-            optFormatting = FALSE;
-            break;
-
-        case 26:
-            optIndentation = atoi(optArg);
-            break;
-
-        case 28:
-            optExtraData = TRUE;
-            break;
-
-        default:
-            dmErrorMsg("Unimplemented option argument '%s'.\n", currArg);
-            return FALSE;
-    }
-
-    return TRUE;
-}
-
-
-BOOL argHandleFile(char * currArg)
-{
-    if (optInFilename == NULL)
-        optInFilename = currArg;
-    else
-    if (optOutFilename == NULL)
-        optOutFilename = currArg;
-    else
-        dmErrorMsg("Source and destination filenames already specified, extraneous argument '%s'.\n", currArg);
-
-    return TRUE;
-}
 
 
 static void dmPrintIndentation(FILE *fh)
@@ -234,6 +101,16 @@
 }
 
 
+off_t dmGetFileSize(FILE *fh)
+{
+    off_t len, pos = ftello(fh);
+    fseeko(fh, 0, SEEK_END);
+    len = ftello(fh);
+    fseeko(fh, pos, SEEK_SET);
+    return len;
+}
+
+
 /* Assembler include data output functions
  */
 int writeHeader_ASM(FILE *fh, void *ctx, const char *name)
@@ -442,13 +319,136 @@
 static const int ndmFormatList = sizeof(dmFormatList) / sizeof(dmFormatList[0]);
 
 
-off_t dmGetFileSize(FILE *fh)
+
+
+void argShowHelp()
+{
+    dmPrintBanner(stdout, dmProgName,
+    "[options] [sourcefile] [destfile]");
+
+    dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2);
+
+    fprintf(stdout,
+    "\n"
+    "Available output formats (-f <frmt>):\n"
+    " frmt | Description (filename extensions)\n"
+    "------+------------------------------------------\n");
+
+    for (int i = 0; i < ndmFormatList; i++)
+    {
+        const DMOutputFormat *fmt = &dmFormatList[i];
+        fprintf(stdout, "%-5s | %s (",
+            fmt->name, fmt->desc);
+
+        for (int n = 0; n < SET_MAX_FEXTS && fmt->fexts[n] != NULL; n++)
+        {
+            fprintf(stdout, ".%s%s",
+                fmt->fexts[n],
+                (n + 1 < SET_MAX_FEXTS &&
+                fmt->fexts[n + 1] != NULL) ? " " : "");
+        }
+        fprintf(stdout, ")\n");
+    }
+
+    fprintf(stdout,
+    "\n"
+    "To convert a data file to a C structure using 'Uint8' as type:\n"
+    "$ data2inc -n variable_name -t Uint8 input.bin output.h\n"
+    "\n"
+    );
+}
+
+
+BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
 {
-    off_t len, pos = ftello(fh);
-    fseeko(fh, 0, SEEK_END);
-    len = ftello(fh);
-    fseeko(fh, pos, SEEK_SET);
-    return len;
+    switch (optN)
+    {
+        case 0:
+            argShowHelp();
+            exit(0);
+            break;
+
+        case 1:
+            dmPrintLicense(stdout);
+            exit(0);
+            break;
+
+        case 10:
+            optObjName = optArg;
+            break;
+
+        case 12:
+            optDataType = optArg;
+            break;
+
+        case 14:
+            for (int i = 0; i < ndmFormatList; i++)
+            {
+                const DMOutputFormat *fmt = &dmFormatList[i];
+                if (strcasecmp(fmt->name, optArg) == 0)
+                {
+                    setFormat = fmt;
+                    return TRUE;
+                }
+            }
+            dmErrorMsg("Invalid format name '%s'.\n",
+                optArg);
+            return FALSE;
+
+        case 16:
+            optAddLine = optArg;
+            break;
+
+        case 18:
+            optLineLen = atoi(optArg);
+            if (optLineLen < 1)
+            {
+                dmErrorMsg("Invalid line length / number of items per line '%s'.\n",
+                    optArg);
+                return FALSE;
+            }
+            break;
+
+        case 20:
+            optHexMode = TRUE;
+            break;
+
+        case 22:
+            optQuiet = TRUE;
+            break;
+
+        case 24:
+            optFormatting = FALSE;
+            break;
+
+        case 26:
+            optIndentation = atoi(optArg);
+            break;
+
+        case 28:
+            optExtraData = TRUE;
+            break;
+
+        default:
+            dmErrorMsg("Unimplemented option argument '%s'.\n", currArg);
+            return FALSE;
+    }
+
+    return TRUE;
+}
+
+
+BOOL argHandleFile(char * currArg)
+{
+    if (optInFilename == NULL)
+        optInFilename = currArg;
+    else
+    if (optOutFilename == NULL)
+        optOutFilename = currArg;
+    else
+        dmErrorMsg("Source and destination filenames already specified, extraneous argument '%s'.\n", currArg);
+
+    return TRUE;
 }