changeset 1749:5958640cdd13

Code cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 18 Oct 2017 16:50:41 +0300
parents 1b00969757d9
children 4db581ac116d
files colormap.c
diffstat 1 files changed, 29 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/colormap.c	Wed Oct 18 15:42:04 2017 +0300
+++ b/colormap.c	Wed Oct 18 16:50:41 2017 +0300
@@ -7,8 +7,9 @@
 #include "th_args.h"
 #include "th_string.h"
 
-#define MAXCOL    (256)
-#define MAXSTR    (1024)
+#define SET_MAX_COLORS    (256)
+#define SET_MAX_STRLEN    (1024)
+
 
 typedef struct
 {
@@ -27,8 +28,8 @@
 } CMapOutFormat;
 
 
-char    *srcFilename = NULL,
-        *destFilename = NULL;
+char    *inFilename = NULL,
+        *outFilename = NULL;
 
 char    *optXHTMLTagName = "i",
         *optMapTitle = NULL,
@@ -414,14 +415,14 @@
         else
         if (k == 0xfb)
         {
-            char tmpStr[MAXSTR];
+            char tmpStr[SET_MAX_STRLEN];
             int mch;
 
             // Location marker mode
             checkEndTag(outFile, fmt, prevColor);
 
             // Get location marker tag
-            if (!getTagStr(inFile, tmpStr, MAXSTR, 0xfc))
+            if (!getTagStr(inFile, tmpStr, SET_MAX_STRLEN, 0xfc))
                 return FALSE;
 
             // Get marker character
@@ -445,14 +446,14 @@
         else
         if (k == 0xff)
         {
-            char tmpStr[MAXSTR], tmpStr2[MAXSTR];
+            char tmpStr[SET_MAX_STRLEN], tmpStr2[SET_MAX_STRLEN];
             int mcol;
 
             // Location title mode
             checkEndTag(outFile, fmt, prevColor);
 
             // Get location marker tag
-            if (!getTagStr(inFile, tmpStr, MAXSTR, 0xfc))
+            if (!getTagStr(inFile, tmpStr, SET_MAX_STRLEN, 0xfc))
                 return FALSE;
 
             // Get color
@@ -464,7 +465,7 @@
             }
 
             // Get location name
-            if (!getTagStr(inFile, tmpStr2, MAXSTR, 0xfe))
+            if (!getTagStr(inFile, tmpStr2, SET_MAX_STRLEN, 0xfe))
             {
                 THERR("Expected location tag '%s' end, but did not find one.\n", tmpStr);
                 return FALSE;
@@ -614,8 +615,8 @@
         break;
 
     case 7:
-        destFilename = optArg;
-        THMSG(2, "Output file set to '%s'.\n", destFilename);
+        outFilename = optArg;
+        THMSG(2, "Output file set to '%s'.\n", outFilename);
         break;
 
     case 8:
@@ -675,8 +676,8 @@
 
 BOOL argHandleFile(char *currArg)
 {
-    if (!srcFilename)
-        srcFilename = currArg;
+    if (!inFilename)
+        inFilename = currArg;
     else
     {
         THERR("Too many input map files specified!\n");
@@ -703,7 +704,7 @@
         argHandleOpt, argHandleFile, OPTH_BAILOUT))
         exit(1);
 
-    if (srcFilename == NULL)
+    if (inFilename == NULL)
     {
         THERR("Nothing to do. (try --help)\n");
         exit(0);
@@ -713,18 +714,18 @@
     if (optPerformAnalysis)
     {
         int k, c, p, i, tMax, fMax, tn, fn;
-        int colChangesTo[MAXCOL];
-        int colChangesFrom[MAXCOL];
+        int colChangesTo[SET_MAX_COLORS];
+        int colChangesFrom[SET_MAX_COLORS];
 
         THMSG(1, "Performing statistical frequency analysis ...\n");
 
         THMSG(2, "Reading '%s' for analysis data ...\n",
-            srcFilename);
+            inFilename);
 
-        if ((inFile = fopen(srcFilename, "rb")) == NULL)
+        if ((inFile = fopen(inFilename, "rb")) == NULL)
         {
             THERR("Error opening input file '%s'!\n",
-                srcFilename);
+                inFilename);
             exit(1);
         }
 
@@ -736,14 +737,14 @@
         c = p = -1;
         while ((k = fgetc(inFile)) != EOF)
         {
-            if (k != '\n' && k != ' ' && k < 0xfe)
+            if (k != '\n' && k != ' ' && k < 0xfb)
             {
                 c = muGetMapPieceColor(k, optUseOldFormat, optCityFormat);
-                if (c != p && c >= 0 && c < MAXCOL)
+                if (c != p && c >= 0 && c < SET_MAX_COLORS)
                 {
                     colChangesTo[c]++;
 
-                    if (p >= 0 && p < MAXCOL)
+                    if (p >= 0 && p < SET_MAX_COLORS)
                         colChangesFrom[p]++;
                 }
             }
@@ -756,7 +757,7 @@
         THMSG(2, "Computing results.\n");
 
         tMax = fMax = tn = fn = -1;
-        for (i = 0; i < MAXCOL; i++)
+        for (i = 0; i < SET_MAX_COLORS; i++)
         {
             if (colChangesTo[i] > tMax)
             {
@@ -783,21 +784,21 @@
     }
 
     // Open input file
-    if ((inFile = fopen(srcFilename, "rb")) == NULL)
+    if ((inFile = fopen(inFilename, "rb")) == NULL)
     {
         THERR("Error opening input file '%s'!\n",
-            srcFilename);
+            inFilename);
         goto out;
     }
 
     // Open output file
-    if (destFilename == NULL)
+    if (outFilename == NULL)
         outFile = stdout;
     else
-    if ((outFile = fopen(destFilename, "wb")) == NULL)
+    if ((outFile = fopen(outFilename, "wb")) == NULL)
     {
         THERR("Error opening output file '%s'!\n",
-            destFilename);
+            outFilename);
         goto out;
     }