changeset 1775:db7fdbc8f81b

Modernification cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 28 Oct 2017 04:07:28 +0300
parents c7ee1c1e5bdf
children eada713379fe
files mapstats.c mkcitymap.c mkloc.c
diffstat 3 files changed, 45 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/mapstats.c	Fri Oct 27 17:19:14 2017 +0300
+++ b/mapstats.c	Sat Oct 28 04:07:28 2017 +0300
@@ -208,7 +208,6 @@
 {
     FILE *outFile;
     MapBlock *map;
-    int i, x, y;
     unsigned char *d;
     ulint_t statTotal, statUnknown;
     MapPieceStat statPieces[nmapPieces];
@@ -230,7 +229,7 @@
 
     // Read input file
     statTotal = statUnknown = 0;
-    for (i = 0; i < nmapPieces; i++)
+    for (int i = 0; i < nmapPieces; i++)
     {
         statPieces[i].n = 0;
         statPieces[i].piece = i;
@@ -250,10 +249,10 @@
         THMSG(1, "Analyzing %dx%d area ...\n",
             map->width, map->height);
 
-        for (y = 0; y < map->height; y++)
+        for (int y = 0; y < map->height; y++)
         {
             d = map->data + (map->scansize * y);
-            for (x = 0; x < map->width; x++)
+            for (int x = 0; x < map->width; x++)
             {
                 int c;
                 if ((c = muGetMapPieceIndex(*d, optUseOldFormat, optCityFormat)) >= 0)
@@ -298,9 +297,9 @@
         exit(1);
     }
 
-    for (i = 0; i < nmapPieces; i++)
+    for (int i = 0; i < nmapPieces; i++)
     {
-        int p = statPieces[i].piece;
+        const int p = statPieces[i].piece;
         int symbol = optUseOldFormat ? mapPieces[p].oldSymbol : mapPieces[p].symbol;
         if (symbol >= 0)
         {
--- a/mkcitymap.c	Fri Oct 27 17:19:14 2017 +0300
+++ b/mkcitymap.c	Sat Oct 28 04:07:28 2017 +0300
@@ -330,13 +330,13 @@
 
 void outputMapHTML(FILE *outFile, MapBlock *map, MapLocations *l)
 {
-    int x, y, n, p = -1, c;
+    int n, p = -1, c;
     BOOL span = FALSE;
 
-    for (y = 0; y < map->height; y++)
+    for (int y = 0; y < map->height; y++)
     {
         unsigned char *d = map->data + (map->scansize * y);
-        for (x = 0; x < map->width; x++)
+        for (int x = 0; x < map->width; x++)
         {
             if ((n = locFindByCoords(l, x, y, TRUE)) >= 0)
             {
--- a/mkloc.c	Fri Oct 27 17:19:14 2017 +0300
+++ b/mkloc.c	Sat Oct 28 04:07:28 2017 +0300
@@ -274,9 +274,7 @@
  */
 void adjustLocInfoCoords(MapBlock *map, MapLocations *l)
 {
-    int i;
-
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         int y, x0, x1, len;
         LocMarker *tmp = l->locations[i];
@@ -353,18 +351,17 @@
  */
 void updateLocations(MapBlock *worldMap, MapLocations *worldLoc)
 {
-    int x, y, n, numNewLoc = 0, numInvLoc = 0, numNoMarker = 0;
-    unsigned char *dp;
+    int n, numNewLoc = 0, numInvLoc = 0, numNoMarker = 0;
     LocMarker *tmpl;
 
     THMSG(2, "Updating location information ..\n");
 
     // Find new, unknown locations
-    for (y = 0; y < worldMap->height; y++)
+    for (int y = 0; y < worldMap->height; y++)
     {
-        dp = worldMap->data + (worldMap->scansize * y);
+        unsigned char *dp = worldMap->data + (worldMap->scansize * y);
 
-        for (x = 0; x < worldMap->width; x++)
+        for (int x = 0; x < worldMap->width; x++)
         {
             if (strchr(optLocMarkers, dp[x]))
             {
@@ -458,27 +455,25 @@
  */
 void maplocSort(MapLocations *l)
 {
-    int i;
-
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         LocMarker *loc = l->locations[i];
         loc->val = 2;
 
         switch (loc->flags & LOCF_M_MASK)
         {
-        case LOCF_M_CITY:   loc->val = 1; break;
-        case LOCF_M_PCITY:  loc->val = 10; break;
-        default:
-            switch (loc->flags & LOCF_T_MASK)
-            {
-            case LOCF_T_GUILD:   loc->val = 3; break;
-            case LOCF_T_TRAINER: loc->val = 4; break;
-            case LOCF_T_SHRINE:  loc->val = 5; break;
-            case LOCF_T_SS:      loc->val = 6; break;
-            case LOCF_T_MONSTER: loc->val = 7; break;
-            case LOCF_T_FORT:    loc->val = 100; break;
-            }
+            case LOCF_M_CITY:   loc->val = 1; break;
+            case LOCF_M_PCITY:  loc->val = 10; break;
+            default:
+                switch (loc->flags & LOCF_T_MASK)
+                {
+                case LOCF_T_GUILD:   loc->val = 3; break;
+                case LOCF_T_TRAINER: loc->val = 4; break;
+                case LOCF_T_SHRINE:  loc->val = 5; break;
+                case LOCF_T_SS:      loc->val = 6; break;
+                case LOCF_T_MONSTER: loc->val = 7; break;
+                case LOCF_T_FORT:    loc->val = 100; break;
+                }
         }
     }
 
@@ -491,15 +486,13 @@
  */
 void outputMapCTRL(FILE *outFile, MapBlock *map, MapLocations *l)
 {
-    unsigned char *dp;
-    int x, y, n;
-
-    for (y = 0; y < map->height; y++)
+    for (int y = 0; y < map->height; y++)
     {
-        dp = map->data + (map->scansize * y);
+        unsigned char *dp = map->data + (map->scansize * y);
 
-        for (x = 0; x < map->width; x++)
+        for (int x = 0; x < map->width; x++)
         {
+            int n;
             if ((n = locFindByCoords(l, x, y, TRUE)) >= 0)
             {
                 LocMarker *tmp = l->locations[n];
@@ -575,7 +568,8 @@
                 }
                 else
                     fputc(dp[x], outFile);
-            } else
+            }
+            else
                 fputc(dp[x], outFile);
         }
 
@@ -588,12 +582,11 @@
  */
 void outputMapLocHTML(FILE *outFile, MapLocations *l)
 {
-    int i;
     assert(l != NULL);
 
     fprintf(outFile, "<option value=\"\">-</option>\n");
 
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         LocMarker *tmp = l->locations[i];
 
@@ -626,8 +619,6 @@
 
 void outputLocationFile(FILE *outFile, MapLocations *l)
 {
-    int i, n;
-
     // Output header
     fprintf(outFile,
     "# " LOC_MAGIC " (version %d.%d)\n",
@@ -640,7 +631,7 @@
     );
 
     // Output each location entry
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         LocMarker *tmp = l->locations[i];
 
@@ -693,7 +684,7 @@
 
         fprintf(outFile, "\t;");
         printLocNameEsc(outFile, &tmp->names[0]);
-        for (n = 1; n < tmp->nnames; n++)
+        for (int n = 1; n < tmp->nnames; n++)
         {
             fprintf(outFile, "|");
             printLocNameEsc(outFile, &tmp->names[n]);
@@ -703,7 +694,7 @@
         if (tmp->ncoders > 0)
         {
             printLocNameEsc(outFile, &tmp->coders[0]);
-            for (n = 1; n < tmp->ncoders; n++)
+            for (int n = 1; n < tmp->ncoders; n++)
             {
                 fprintf(outFile, ",");
                 printLocNameEsc(outFile, &tmp->coders[n]);
@@ -738,7 +729,7 @@
  */
 void outputMagickScript(FILE *outFile, MapLocations *l)
 {
-    int i, numCity, numLoc, numTotal;
+    int numCity, numLoc, numTotal;
 
     // Output script start
     fprintf(outFile,
@@ -748,7 +739,7 @@
     numCity = numLoc = numTotal = 0;
 
     // Output instructions for each visible location
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         LocMarker *tmp = l->locations[i];
         int x, y, leftMove;
@@ -855,8 +846,8 @@
 static char *getQuestLink(const char *name, const char *desc)
 {
     char *str, *tmp = th_strdup(name);
-    size_t i;
-    for (i = 0; i < strlen(tmp); i++)
+
+    for (size_t i = 0; i < strlen(tmp); i++)
         tmp[i] = th_isspace(tmp[i]) ? '+' : th_tolower(tmp[i]);
 
     str = th_strdup_printf("<a target=\"_blank\" href=\"http://www.bat.org/help/quests?str=%s\">%s</a>", tmp, desc);
@@ -885,8 +876,6 @@
 void outputGMapsHTML(FILE *outFile, LocMarker *tmp,
     int (*fpr)(FILE *, const char *fmt, ...), int (*fps)(const char *, FILE *))
 {
-    int n;
-
     if (tmp->uri != NULL)
     {
         fpr(outFile, "<b><a target=\"_blank\" href=\"%s\">", tmp->uri);
@@ -904,7 +893,7 @@
     if (tmp->nnames > 1)
     {
         fpr(outFile, "Also known as <i>");
-        for (n = 1; n < tmp->nnames; n++)
+        for (int n = 1; n < tmp->nnames; n++)
         {
             fps(tmp->names[n].name, outFile);
             if (tmp->names[n].flags & NAME_ORIG)
@@ -928,7 +917,7 @@
         if (tmp->flags & LOCF_M_PCITY)
         {
             fprintf(outFile, "Societies: ");
-            for (n = 0; n < tmp->ncoders; n++)
+            for (int n = 0; n < tmp->ncoders; n++)
             {
                 fps(tmp->coders[n].name, outFile);
                 if (n < tmp->ncoders - 1)
@@ -938,7 +927,7 @@
         else
         {
             fprintf(outFile, "Coders: ");
-            for (n = 0; n < tmp->ncoders; n++)
+            for (int n = 0; n < tmp->ncoders; n++)
             {
                 char *info = "", *sinfo = "";
                 switch (tmp->coders[n].flags)
@@ -995,14 +984,12 @@
 
 void outputGMapsXML(FILE *outFile, MapLocations *l)
 {
-    int i;
-
     fprintf(outFile,
     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
     "<markers>\n");
 
     // Output each location entry
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         LocMarker *tmp = l->locations[i];
 
@@ -1042,12 +1029,10 @@
 
 void outputGMapsJSON(FILE *outFile, MapLocations *l)
 {
-    int i;
-
     fprintf(outFile, "[\n");
 
     // Output each location entry
-    for (i = 0; i < l->n; i++)
+    for (int i = 0; i < l->n; i++)
     {
         LocMarker *tmp = l->locations[i];