summaryrefslogtreecommitdiff
path: root/games/dipmap/patches/patch-ac
blob: 646c74cdf9d6c3cb63b7dc1a8252e583d8517c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
$NetBSD: patch-ac,v 1.3 2012/12/23 18:43:47 dholland Exp $

- use standard headers
- declare functions before calling them
- use c89 function declarations
- give functions return types, including sometimes "void"
- silence clang and gcc warnings about assignments inside conditionals
- silence clang warnings about braces
- silence gcc warnings about unused/uninitialized variables
- fix insecure-temporary-files
- use snprintf() instead of sprintf()
- call free() correctly
- call qsort() correctly
- pass gcc -Wall -Werror (with gcc 4.5)


--- mapit.c.orig	1998-03-13 19:38:03.000000000 +0000
+++ mapit.c
@@ -149,11 +149,18 @@
   fix parse_status to handle retreat with mutilple alternate destinations
 */
 #ifdef MACINTOSH
-#include <stdlib.h>
 #include <console.h>
 #include <Files.h>
+#else
+#include <unistd.h>
 #endif
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+
 #ifdef STRDUP_MISSING
 #ifdef ANSI
 char *strdup(char *s1);
@@ -162,7 +169,7 @@ char *strdup();
 #endif
 #endif
 
-#ifdef STRRSTR_MISSING
+#ifdef STRSTR_MISSING
 #ifdef ANSI
 char *strrstr(char *s1,char *s2);
 #else
@@ -170,11 +177,13 @@ char *strrstr();
 #endif
 #endif
 
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-extern char *strstr();
+#ifdef STRRSTR_MISSING
+#ifdef ANSI
+char *strrstr(char *s1,char *s2);
+#else
+char *strrstr();
+#endif
+#endif
 
 
 #define MIN(x,y) (x<y?x:y)
@@ -211,10 +220,27 @@ int ownernum;
 
 char *info_file,*ps_file;
 
+static void parse_movement(void);
+static void parse_adjustment(void);
+static void parse_retreat(void);
+static void parse_fall_report(void);
+static void parse_start(int report);
+static int moveto(char *s);
+static void drawmap(char *title, char *message);
+static void drawnew(void);
+static void copyline(char *s1, const char *s2);
+static int string_check(const char *s, int fatal);
+static int init(void);
+static int mapi(char *name);
+static void StartPage(void);
+static void EndPage(void);
+static void EndDocument(void);
+static int same_owner(char *c1, char *c2);
+static int countrynum(char *country);
+static int ownerlookup(char *country);
 
-main(argc,argv)
-     int argc;
-     char **argv;
+int
+main(int argc, char **argv)
 {
   /* input line, current season, year, and game name */
   char line[BUFSIZ],copy[BUFSIZ],season[BUFSIZ], name[BUFSIZ];
@@ -225,10 +251,10 @@ main(argc,argv)
   char defmsg[BUFSIZ];          /* default message from command line */
   int usemsg,usetitle;          /* true if we should use the command line value */
   int onlystatus;		/* true is we want only the status map */
-  int i,j,k;                    /* misc counters */
-  char *p0,*p1;                 /* and character pointers */
+  int i,j;                      /* misc counters */
   int started;                  /* is a map already started? */
   int report;                   /* type of report */
+  int fd=-1;			/* file descriptor for output file */
 
   extern char *optarg;          /* used by getopt() */
   extern int optind;
@@ -318,8 +344,8 @@ main(argc,argv)
     }
 
   if (new_borders) {            /* We'll need a temporary file */
-    tmpnam(tempfilename);
-    if(!(nstdout = fopen(tempfilename, "w")))
+    fd=mkstemp(tempfilename);
+    if(fd == -1 || !(nstdout = fdopen(fd, "w")))
       fprintf(stderr, "Unable to open file..\n");
   }   
    
@@ -389,7 +415,7 @@ main(argc,argv)
     j = sscanf(&line[i]," for %s of %d. (%[^.])",
                season, &year, name);
     if (j == 3)                 /* yup, create title from it */
-      sprintf(title,"%s, %s %d", name, season, year);
+      snprintf(title, sizeof(title), "%s, %s %d", name, season, year);
     else {
       season[0] = '\0';
       strcpy(title,deftitle);
@@ -483,7 +509,7 @@ main(argc,argv)
       ++year;
     }
     if (season[0])
-      sprintf(title,"%s, %s %d", name, season, year);
+      snprintf(title, sizeof(title), "%s, %s %d", name, season, year);
     else
       strcpy(title,deftitle);
     StartPage();
@@ -504,14 +530,16 @@ main(argc,argv)
 	  ownerlist[countrynum(map[i].nick)] = ownerlist[countrynum(map[i].owner)]; 
     
     /* Handle multiple coasts */
-    for(i = 0; i < mapcount; ++i)  
-      if(countrynum(map[i].nick) == countrynum(map[i+1].nick))
+    for (i = 0; i < mapcount; ++i) {
+      if(countrynum(map[i].nick) == countrynum(map[i+1].nick)) {
 	if(ownerlist[i+1] > ownerlist[i])
 	  ownerlist[i] = ownerlist[i+1];
 	else
 	  ownerlist[i+1] = ownerlist[i];
+      }
+    }
     
-    if(!(nstdout = fopen(tempfilename, "r")))
+    if(!(nstdout = fdopen(fd, "r")))
       fprintf(stderr,"Unable to reopen file.\n");
     else {
       while(fgets(line, BUFSIZ, nstdout))
@@ -532,6 +560,7 @@ main(argc,argv)
       remove(tempfilename);
     }
   }
+  return 0;
 }
 
 
@@ -555,12 +584,13 @@ main(argc,argv)
   
   location      nick | full_name
 */
-parse_movement()
+static void
+parse_movement(void)
 {
   char line[BUFSIZ];            /* the current order being processed */
   char copy[BUFSIZ];            /* a temp copy */
   char *p0,*p1,*p2, *p3;        /* some char pointers */
-  int i,j,k;                    /* misc counters */
+  int i;                        /* misc counters */
 
   char country[BUFSIZ];
   char country2[BUFSIZ];
@@ -587,13 +617,11 @@ parse_movement()
 
   char *msg;                    /* current bouce/cut message */
   int fail;                     /* flag to indicate success of order */
-  int x,y;                      /* map coordinate of support/convoy arrow */
 
   int error;                    /* true if a syntax (or malloc) error */
 
   for (i=0; i<unitcount; ++i) {
-    if (free(units[i].country) == 0)
-    ;
+    free(units[i].country);
   }
   unitcount = 0;
 
@@ -682,29 +710,29 @@ parse_movement()
 
     order = UNKNOWN;
     /* test for support first since we can support hold/convoy/move */
-    if ((p1=strstr(p0," SUPPORT")) || /* or SUPPORTS */
-        (p1=strstr(p0," S ")))
+    if ((p1=strstr(p0," SUPPORT")) != NULL || /* or SUPPORTS */
+        (p1=strstr(p0," S ")) != NULL)
       order = SUPPORT;
     /* test convoy next since convoy implies a move order */
-    else if ((p1=strstr(p0," CONVOY")) || /* or CONVOYS */
+    else if ((p1=strstr(p0," CONVOY"))!=NULL || /* or CONVOYS */
 	     /* KDI - I included a copy of strrstr.c, and killed the NEXT
 	        special case */
-             ((p1=strrstr(p0," C ")) && (strncmp(p0,"OFF BOARD", 9) > 0)))
+             ((p1=strrstr(p0," C "))!=NULL && (strncmp(p0,"OFF BOARD", 9) > 0)))
       order = CONVOY;
-	else if (p1=strstr(p0," PROXY GIVEN TO "))
+    else if ((p1=strstr(p0," PROXY GIVEN TO ")) != NULL)
 		order = PROXY;
-    else if ((p1=strstr(p0," -> ")) ||
-             (p1=strstr(p0," - ")) ||
-             (p1=strstr(p0," M ")) ||
-             (p1=strstr(p0," TO ")) ||
-             (p1=strstr(p0," MOVE"))) /* or MOVES */
+    else if ((p1=strstr(p0," -> "))!=NULL ||
+             (p1=strstr(p0," - "))!=NULL ||
+             (p1=strstr(p0," M "))!=NULL ||
+             (p1=strstr(p0," TO "))!=NULL ||
+             (p1=strstr(p0," MOVE"))!=NULL) /* or MOVES */
       order = MOVE;
-    else if ((p1=strstr(p0," HOLD")) || /* or HOLDS */
-             (p1=strstr(p0," H.")))
+    else if ((p1=strstr(p0," HOLD"))!=NULL || /* or HOLDS */
+             (p1=strstr(p0," H."))!=NULL)
       order = HOLD;
-    else if ((p1=strstr(p0,", NO ORDER PROCESSED")) ||
-             (p1=strstr(p0,", NO MOVE RECEIVED")) ||
-             (p1=strstr(p0," NMR")))
+    else if ((p1=strstr(p0,", NO ORDER PROCESSED"))!=NULL ||
+             (p1=strstr(p0,", NO MOVE RECEIVED"))!=NULL ||
+             (p1=strstr(p0," NMR"))!=NULL)
       order = NMR;
 
     if (order == UNKNOWN) {
@@ -774,33 +802,35 @@ parse_movement()
         fprintf(stderr,"movement: unable to parse destination location in convoy command: %s\n",p1);
         break;
       }
-      sprintf(new," %c %.3s C %.3s - %-6.6s %.9s",
+      snprintf(new, sizeof(new), " %c %.3s C %.3s - %-6.6s %.9s",
               unit,map[si].nick,map[di].nick,map[di2].nick,msg);
       if (fail)
-        sprintf(newg,"FailedOrder %d %d %d %d %d %d ArrowConvoy OkOrder",
+        snprintf(newg, sizeof(newg),
+		"FailedOrder %d %d %d %d %d %d ArrowConvoy OkOrder",
                 map[si].x,map[si].y,
                 map[di].x,map[di].y,
                 map[di2].x,map[di2].y);
       else
-        sprintf(newg,"%d %d %d %d %d %d ArrowConvoy",
+        snprintf(newg, sizeof(newg),
+		"%d %d %d %d %d %d ArrowConvoy",
                 map[si].x,map[si].y,
                 map[di].x,map[di].y,
                 map[di2].x,map[di2].y);
       break;
       
     case HOLD:
-      sprintf(new," %c %.3s H              %.9s",
+      snprintf(new, sizeof(new), " %c %.3s H              %.9s",
               unit,map[si].nick,msg);
       break;
       
-	case PROXY:
-		strcpy(country2, strstr(p1, "TO ") + 3);
-		sprintf(new," %c %.3s PROXY TO %s    %.9s",
-				unit,map[si].nick,country2,msg);
+    case PROXY:
+      strcpy(country2, strstr(p1, "TO ") + 3);
+      snprintf(new, sizeof(new), " %c %.3s PROXY TO %s    %.9s",
+	      unit,map[si].nick,country2,msg);
 
-		break;
+      break;
     case NMR:
-      sprintf(new," %c %.3s NMR            %.9s",
+      snprintf(new, sizeof(new), " %c %.3s NMR            %.9s",
               unit,map[si].nick,msg);
       break;
       
@@ -824,8 +854,7 @@ parse_movement()
           p0 = NULL;            /* couldn't find unit type */
           p1 = p2;              /* assume no nationality either */
         } else {
-          if (free(p2) == 0)
-          ;
+          free(p2);
         }
       }
 
@@ -856,14 +885,15 @@ parse_movement()
           fprintf(stderr,"movement: unable to parse target of support command: %s\n",p0);
           break;
         }
-        sprintf(new," %c %.3s S %.3s H        %.9s",
+        snprintf(new, sizeof(new), " %c %.3s S %.3s H        %.9s",
                 unit,map[si].nick,map[di].nick,msg);
         if (fail)
-          sprintf(newg,"FailedOrder %d %d %d %d ArrowHold OkOrder",
+          snprintf(newg, sizeof(newg),
+		  "FailedOrder %d %d %d %d ArrowHold OkOrder",
                   map[si].x,map[si].y,
                   map[di].x,map[di].y);
         else
-          sprintf(newg,"%d %d %d %d ArrowHold",
+          snprintf(newg, sizeof(newg), "%d %d %d %d ArrowHold",
                   map[si].x,map[si].y,
                   map[di].x,map[di].y);
       } else {  /* support a unit moving */
@@ -878,15 +908,16 @@ parse_movement()
           fprintf(stderr,"movement: unable to parse second target of support command: %s\n",p1);
           break;
         }
-        sprintf(new," %c %.3s S %.3s - %-6.6s %.9s",
+        snprintf(new, sizeof(new), " %c %.3s S %.3s - %-6.6s %.9s",
                 unit,map[si].nick,map[di].nick,map[di2].nick,msg);
         if (fail)
-          sprintf(newg,"FailedOrder %d %d %d %d %d %d ArrowSupport OkOrder",
+          snprintf(newg, sizeof(newg),
+		  "FailedOrder %d %d %d %d %d %d ArrowSupport OkOrder",
                   map[si].x,map[si].y,
                   map[di].x,map[di].y,
                   map[di2].x,map[di2].y);
         else
-          sprintf(newg,"%d %d %d %d %d %d ArrowSupport",
+          snprintf(newg, sizeof(newg), "%d %d %d %d %d %d ArrowSupport",
                   map[si].x,map[si].y,
                   map[di].x,map[di].y,
                   map[di2].x,map[di2].y);
@@ -899,16 +930,17 @@ parse_movement()
         fprintf(stderr,"movement: unable to parse destination of move command: %s\n",p1);
         break;
       }
-      sprintf(new," %c %.3s - %-6.6s       %.9s",
+      snprintf(new, sizeof(new), " %c %.3s - %-6.6s       %.9s",
               unit,map[si].nick,map[di].nick,msg);
       
       if (fail)
-        sprintf(newg,"FailedOrder %d %d %d %d ArrowMove OkOrder",
+        snprintf(newg, sizeof(newg),
+		"FailedOrder %d %d %d %d ArrowMove OkOrder",
                 map[si].x,map[si].y,
                 map[di].x,map[di].y);
       else {
         units[unitcount].loc = di;
-        sprintf(newg,"%d %d %d %d ArrowMove",
+        snprintf(newg, sizeof(newg), "%d %d %d %d ArrowMove",
                 map[si].x,map[si].y,
                 map[di].x,map[di].y);
       }
@@ -948,16 +980,14 @@ parse_movement()
     fprintf(nstdout,"OrderReport\n");
     for (i = 0; i<ordernum; i++) {
       fprintf(nstdout,"(%s) WriteOrder\n",orders[i]);
-      if (free(orders[i]) == 0)
-      ;
+      free(orders[i]);
     }
   }
 
   if (graphicnum>0) {
     for (i = 0; i<graphicnum; i++) {
       fprintf(nstdout,"%s\n",graphics[i]);
-      if (free(graphics[i]) == 0)
-      ;
+      free(graphics[i]);
     }
   }
 }
@@ -982,7 +1012,8 @@ parse_movement()
   waived        BUILD WAIVED
   defaults      DEFAULTS, REMOVING [THE unit IN [THE] | unit] location
 */
-parse_adjustment()
+static void
+parse_adjustment(void)
 {
   char line[BUFSIZ],copy[BUFSIZ];
   char report[BUFSIZ];          /* line being built to output */
@@ -993,7 +1024,7 @@ parse_adjustment()
   int count;                    /* count of units for this country */
   int ci;                       /* index of center */
   int pending;                  /* true if line is a special message */
-  int i,j,k;                    /* misc counters */
+  int i,j;                      /* misc counters */
   int building;                 /* true if building units */
   int error;                    /* true if an error occurs during parse */
 
@@ -1037,7 +1068,7 @@ parse_adjustment()
         strcpy(country,p0);
         if (report[0]!='\0')
           fprintf(nstdout,"(%s) WriteAdjust\n",report);
-        sprintf(report,"%-10s",country);
+        snprintf(report, sizeof(report), "%-10s", country);
         count = 0;
       }
       if (p1==NULL || *p1=='\0')
@@ -1132,7 +1163,8 @@ parse_adjustment()
   disband       unit location DISBAND
   nop           unit location, NO ORDER PROCESSED (DISBAND)
 */
-parse_retreat()
+static void
+parse_retreat(void)
 {
   char line[BUFSIZ],copy[BUFSIZ];
   char *p0,*p1, *p2, *msg;
@@ -1140,7 +1172,6 @@ parse_retreat()
   char country[BUFSIZ];         /* nation */
   int si,di;                    /* source and destination */
   char unit;                    /* unit type */
-  int i,j,k;
   int error;
 
   country[0] = '\0';
@@ -1190,12 +1221,12 @@ parse_retreat()
       break;
     }
 
-    if (p1 = strstr(p0,"DISBAND")) {
+    if ((p1 = strstr(p0,"DISBAND")) != NULL) {
       /* zap end of unit location */
       *(p1-1) = '\0';
 
       /* DCK */
-      if (p1 = strstr(p0,", NO ORDER")) {
+      if ((p1 = strstr(p0,", NO ORDER")) != NULL) {
 	/* zap again */
 	*(p1) = '\0';
       }
@@ -1323,7 +1354,8 @@ parse_retreat()
   written "FOO/xx". If a (destination) location contains a dash then a
   single dash can not be used to indicate a move, use -> instead.
 */
-parse_fall_report()
+static void
+parse_fall_report(void)
 {
   char line[BUFSIZ],copy[BUFSIZ],temp[BUFSIZ];
   char report[BUFSIZ];
@@ -1331,7 +1363,7 @@ parse_fall_report()
   char country[BUFSIZ],save[BUFSIZ];
   int centers,units;
   int ci;                       /* index of center in map database */
-  int i,j,k;
+  int i;
 
 
   /* first we have ownership report */
@@ -1346,7 +1378,7 @@ parse_fall_report()
         fprintf(stderr,"ownership: expecting continuation line\n\t%s\n",line);
         break;
       }
-      sprintf(temp,"%s %s",save,line);
+      snprintf(temp, sizeof(temp), "%s %s",save,line);
       copyline(copy,temp);
     } else
       copyline(copy,line);
@@ -1363,7 +1395,7 @@ parse_fall_report()
         strcpy(country,p0);
         if (report[0]!='\0')
           fprintf(nstdout,"(%s) WriteOwner\n",report);
-        sprintf(report,"%-10s ",country);
+        snprintf(report, sizeof(report), "%-10s ", country);
       }
       if (p1==NULL || *p1=='\0')
         continue;               /* just a country token, get next line */
@@ -1439,17 +1471,16 @@ If it is a Status Report, it might inclu
   [country:] unit location [can retreat to location [or location]]
 
 */
-parse_start(report)
-     int report;
+static void
+parse_start(int report)
 {
   char line[BUFSIZ];            /* the current order being processed */
   char copy[BUFSIZ];            /* a temp copy */
   char *p0,*p1,*p2;             /* some char pointers */
-  int i,j,k;                    /* misc counters */
+  int i;                        /* misc counters */
 
   char country[BUFSIZ];
   char unit;                    /* unit type, "A" or "F" */
-  int order;                    /* one of the following: */
   int si;                       /* index of source location) */
 
 #define MAXORDERS MAXUNITS
@@ -1457,12 +1488,10 @@ parse_start(report)
   char new[BUFSIZ];             /* current order being formed */
   int ordernum;                 /* count of orders */
 
-  int x,y;                      /* map coordinate of support/convoy arrow */
   int error;                    /* true if a syntax (or malloc) error */
 
   for (i=0; i<unitcount; ++i) {
-    if (free(units[i].country) == 0)
-    ;
+    free(units[i].country);
   }
   unitcount = 0;
 
@@ -1529,7 +1558,7 @@ parse_start(report)
       break;
     }
 
-    if (report = SR) {
+    if (report == SR) {
       /* retreat report might list possible retreat options on the line */
 #define CANRETREAT " CAN RETREAT TO "
       p1 = strstr(p0,CANRETREAT);
@@ -1566,11 +1595,12 @@ parse_start(report)
     /* XXX todo: parse mulitiple retreat sites and print nicknames */
     if (p2!=NULL)               /* p2 points to retreat comment */
       if (strchr(p2,',') != NULL)	/* more than one choice */
-	sprintf(new," %c %s (-> ???)",unit,map[si].nick);
+	snprintf(new, sizeof(new),
+		" %c %s (-> %s)", unit, map[si].nick, "??" "?");
       else
-	sprintf(new," %c %s (-> %s)",unit,map[si].nick,p2);
+	snprintf(new, sizeof(new), " %c %s (-> %s)", unit, map[si].nick, p2);
     else {
-      sprintf(new," %c %s",unit,map[si].nick);
+      snprintf(new, sizeof(new), " %c %s",unit,map[si].nick);
 
       /* remember that we have a unit at this location */
       units[unitcount].country = (char *) strdup(country);
@@ -1600,15 +1630,14 @@ parse_start(report)
     fprintf(nstdout,"OrderReport\n");
     for (i = 0; i<ordernum; i++) {
       fprintf(nstdout,"(%s) WriteOrder\n",orders[i]);
-      if (free(orders[i]) == 0)
-      ;
+      free(orders[i]);
     }
   }
 }
 
 /* given a string with a move order, find the (final) destination */
-moveto(s)
-     char *s;
+static int
+moveto(char *s)
 {
   char copy[BUFSIZ];
   char *p0,*p1;
@@ -1644,14 +1673,17 @@ moveto(s)
   return(mapi(p1));
 }
 
-country_compare(u1,u2)
-     struct unitstruct *u1,*u2;
+static int
+country_compare(const void *v1, const void *v2)
 {
+  const struct unitstruct *u1 = v1;
+  const struct unitstruct *u2 = v2;
+
   return strcmp(u1->country,u2->country);
 }
 
-drawmap(title,message)
-     char *title,*message;
+static void
+drawmap(char *title, char *message)
 { 
   int i;
 
@@ -1666,9 +1698,10 @@ drawmap(title,message)
 }
 
 /* given the new unit positions, draw a new map */
-drawnew()
+static void
+drawnew(void)
 {
-  int i,j,k;
+  int i;
   char country[BUFSIZ];
 
   if (unitcount==0)
@@ -1703,15 +1736,14 @@ drawnew()
     if (units[i].loc>0)
       fprintf(nstdout,"( %c %s) WriteOrder\n",
              units[i].type,map[units[i].loc].nick);
-    if (free(units[i].country) == 0)
-    ;
+    free(units[i].country);
   }
   unitcount= 0;
 }
 
 /* copy s2 to s1, uppercase, squeeze whitespace */
-copyline(s1,s2)
-     char *s1,*s2;
+static void
+copyline(char *s1, const char *s2)
 {
   int white;                    /* white space seen */
 
@@ -1724,8 +1756,8 @@ copyline(s1,s2)
       }
     } else {
       white = 0;
-      if (islower(*s2))
-	  *(s1++) = toupper(*s2);
+      if (islower((unsigned char)*s2))
+	  *(s1++) = toupper((unsigned char)*s2);
       else
 	  *(s1++) = *s2;	  
     }
@@ -1736,8 +1768,8 @@ copyline(s1,s2)
     
 }
 
-string_check(s,fatal)
-     char *s; int fatal;
+static int
+string_check(const char *s, int fatal)
 {
   if (s==NULL) {
     fprintf(stderr,"?: unexpected error, null string pointer\n");
@@ -1753,13 +1785,14 @@ string_check(s,fatal)
 }
 
 /* init reads the 2 files described above... */
-init()
+static int
+init(void)
 {
   char *fn;
   FILE *f;
   char line[BUFSIZ],copy[BUFSIZ],nick[BUFSIZ],owner[BUFSIZ], name[BUFSIZ],nicks[BUFSIZ];
   int x,y;
-  int i,j,k;
+  int i,j;
 
   unitcount = 0;
   nationcount = 0;
@@ -1771,7 +1804,7 @@ init()
     fn = (char *)getenv("MAPPS");
   if (fn == NULL)
     fn = DEFAULT_PS;
-  if (f = fopen(fn,"r")) {
+  if ((f = fopen(fn,"r")) != NULL) {
     while (fgets(line,BUFSIZ,f))
       fprintf(nstdout,"%s",line);
     fclose(f);
@@ -1795,7 +1828,7 @@ init()
     fn = (char *)getenv("MAPINFO");
   if (fn == NULL)
     fn = DEFAULT_INFO;
-  if (f = fopen(fn,"r")) {
+  if ((f = fopen(fn,"r")) != NULL) {
     j = 0;
     while (fgets(line,BUFSIZ,f)) { /* first section is just a list of nations */
       if (line[0]=='#' || line[0]==' ')
@@ -1848,13 +1881,13 @@ init()
   return 0;
 }
 
-mapi(name)                      /* return index of map table entry */
-     char *name;
+static int
+mapi(char *name)                      /* return index of map table entry */
 {
-  int i,j,k;
+  int i;
   char t[BUFSIZ];
 
-  sprintf(t,"|%s|",name);
+  snprintf(t, sizeof(t), "|%s|", name);
   for ( i=1; i<MAXNAMES; ++i ) {
     if (map[i].name == NULL)
       break;
@@ -1870,7 +1903,8 @@ int PagesSoFar=0;
 /* StartPage
    Outputs the appropriate postscript comments to start a page to start
  */
-StartPage()
+static void
+StartPage(void)
 {
   PagesSoFar++;
   fprintf(nstdout, "%%%%Page: %d %d\n", PagesSoFar, PagesSoFar );
@@ -1880,7 +1914,8 @@ StartPage()
 /* EndPage
    Outputs the appropriate postscript comments to end a page to start
  */
-EndPage()
+static void
+EndPage(void)
 {
   fprintf(nstdout, "%%%%PageTrailer\n" );
 }
@@ -1888,7 +1923,8 @@ EndPage()
 /* EndDocument
    Outputs the appropriate postscript comments to end the whole thing
  */
-EndDocument()
+static void
+EndDocument(void)
 {
   fprintf(nstdout, "%%%%Trailer\n" );
   fprintf(nstdout, "%%%%Pages: %d 1\n", PagesSoFar );
@@ -1898,14 +1934,14 @@ EndDocument()
 
 /* Some procedures for the -b option */
 
-int same_owner(c1,c2)
-char *c1,*c2;
+static int
+same_owner(char *c1, char *c2)
 {
   return (ownerlist[countrynum(c1)] == ownerlist[countrynum(c2)]);
 }
 
-int countrynum(country)
-char *country;
+static int
+countrynum(char *country)
 {
   int i;
 
@@ -1916,8 +1952,8 @@ char *country;
   return 0;
 }
 
-int ownerlookup(country)
-char *country;
+static int
+ownerlookup(char *country)
 {
   int i;