Fix some C that gcc tags as unclean or unsafe. Rename 'a' structure to 'game'.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 31 Oct 2004 15:53:36 +0000 (15:53 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 31 Oct 2004 15:53:36 +0000 (15:53 +0000)
Someday we'll bundle every saveable thing into this. Add a clean
production to the makefile and fix the target.

makefile
setup.c
sst.c
sst.h

index 3e351422990f7e31d8fe731a2292f55fae855e9c..59efa674f7b46fc22e82dee0689d894ce571d04a 100644 (file)
--- a/makefile
+++ b/makefile
@@ -7,9 +7,11 @@ OFILES=     sst.o finish.o reports.o setup.o linux.o moving.o battle.o events.o
 
 HFILES=     sst.h
 
-sstos2.exe:  $(OFILES)
+sst:  $(OFILES)
        gcc  -o sst $(OFILES) -lm
 
-        
 $(OFILES):  $(HFILES)
 
+clean:
+       rm -f *.o sst
+
diff --git a/setup.c b/setup.c
index 29bcd291ee9fb3e46bd5e4684c7d18cacfcc5015..8cd1536bc95af5709bbe35e1d035ed1a0b0e5831 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -47,7 +47,7 @@ void freeze(int boss) {
        fwrite(kavgd, sizeof(kavgd), 1, fp);\r
        fwrite(damage, sizeof(damage), 1, fp);\r
        fwrite(future, sizeof(future), 1, fp);\r
-       fwrite(&a, sizeof(a), 1, fp);\r
+       fwrite(&game, sizeof(game), 1, fp);\r
        fwrite(passwd, sizeof(passwd), 1, fp);\r
 \r
        fclose(fp);\r
@@ -91,7 +91,7 @@ void thaw(void) {
        fread(kavgd, sizeof(kavgd), 1, fp);\r
        fread(damage, sizeof(damage), 1, fp);\r
        fread(future, sizeof(future), 1, fp);\r
-       fread(&a, sizeof(a), 1, fp);\r
+       fread(&game, sizeof(game), 1, fp);\r
        fread(passwd, sizeof(passwd), 1, fp);\r
 \r
        fclose(fp);\r
diff --git a/sst.c b/sst.c
index fa24d75dbaafb779fb486f9d02e57cef79a8b3e7..e4fe2afe0fcf55a0eab1f3f5d3a4001e47c6bd79 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -13,8 +13,6 @@ static int linecount; /* for paging */
 \r
 static void clearscreen(void);\r
 \r
-#define NUMCOMMANDS 34\r
-\r
 /* Compared to original version, I've changed the "help" command to\r
    "call" and the "terminate" command to "quit" to better match\r
    user expectations. The DECUS version apparently made those changes\r
@@ -52,7 +50,7 @@ static void clearscreen(void);
    */\r
 \r
 \r
-static char *commands[NUMCOMMANDS] = {\r
+static char *commands[] = {\r
        "srscan",\r
        "lrscan",\r
        "phasers",\r
@@ -88,6 +86,7 @@ static char *commands[NUMCOMMANDS] = {
        "quit",\r
        "help"\r
 };\r
+#define NUMCOMMANDS    sizeof(commands)/sizeof(commands[0])\r
 \r
 static void listCommands(int x) {\r
        prout("   SRSCAN    MOVE      PHASERS   CALL\n"\r
@@ -345,7 +344,7 @@ static void makemoves(void) {
 }\r
 \r
 \r
-void main(int argc, char **argv) {\r
+int main(int argc, char **argv) {\r
        int i;\r
        int hitme;\r
        char ch;\r
@@ -486,7 +485,8 @@ int scan(void) {
                        chew();\r
                        return IHEOL;\r
                }\r
-               gets(line);\r
+               fgets(line, sizeof(line), stdin);\r
+               line[strlen(line)-1] = '\0';\r
                linep = line;\r
        }\r
        // Skip leading white space\r
diff --git a/sst.h b/sst.h
index 7c8272dd36f3b220e183631833f34d829d67075d..b34312068646182ccd7a1eb77a100f3715adfa14 100644 (file)
--- a/sst.h
+++ b/sst.h
@@ -145,95 +145,95 @@ EXTERN struct foo2 {
        probey,\r
        probeinx,\r
        probeiny;\r
-} a;\r
+} game;\r
 \r
-#define inkling a.inkling              // Initial number of klingons\r
-#define inbase a.inbase                        // Initial number of bases\r
-#define incom a.incom                  // Initian number of commanders\r
-#define instar a.instar                        // Initial stars\r
-#define intorps a.intorps              // Initial/Max torpedoes\r
-#define condit a.condit                        // Condition (red, yellow, green docked)\r
-#define torps a.torps                  // number of torpedoes\r
-#define ship a.ship                            // Ship type -- 'E' is Enterprise\r
-#define quadx a.quadx                  // where we are\r
-#define quady a.quady                  //\r
-#define sectx a.sectx                  // where we are\r
-#define secty a.secty                  //\r
-#define length a.length                        // length of game\r
-#define skill a.skill                  // skill level\r
-#define basex a.basex                  // position of base in current quad\r
-#define basey a.basey                  //\r
-#define klhere a.klhere                        // klingons here\r
-#define comhere a.comhere              // commanders here\r
-#define casual a.casual                        // causalties\r
-#define nhelp a.nhelp                  // calls for help\r
-#define nkinks a.nkinks                        //\r
-#define ididit a.ididit                        // Action taken -- allows enemy to attack\r
-#define gamewon a.gamewon              // Finished!\r
-#define alive a.alive                  // We are alive (not killed)\r
-#define justin a.justin                        // just entered quadrant\r
-#define alldone a.alldone              // game is now finished\r
-#define shldchg a.shldchg              // shield is changing (affects efficiency)\r
-#define thingx a.thingx                        // location of strange object in galaxy\r
-#define thingy a.thingy                        //\r
-#define plnetx a.plnetx                        // location of planet in quadrant\r
-#define plnety a.plnety                        //\r
-#define inorbit a.inorbit              // orbiting\r
-#define landed a.landed                        // party on planet (1), on ship (-1)\r
-#define iplnet a.iplnet                        // planet # in quadrant\r
-#define imine a.imine                  // mining\r
-#define inplan a.inplan                        // initial planets\r
-#define nenhere a.nenhere              // Number of enemies in quadrant\r
-#define ishere a.ishere                        // Super-commander in quandrant\r
-#define neutz a.neutz                  // Romulan Neutral Zone\r
-#define irhere a.irhere                        // Romulans in quadrant\r
-#define icraft a.icraft                        // Kirk in Galileo\r
-#define ientesc a.ientesc              // Attempted escape from supercommander\r
-#define iscraft a.iscraft              // =1 if craft on ship, -1 if removed from game\r
-#define isatb a.isatb                  // =1 if SuperCommander is attacking base\r
-#define iscate a.iscate                        // Super Commander is here\r
+#define inkling game.inkling           // Initial number of klingons\r
+#define inbase game.inbase                     // Initial number of bases\r
+#define incom game.incom                       // Initian number of commanders\r
+#define instar game.instar                     // Initial stars\r
+#define intorps game.intorps           // Initial/Max torpedoes\r
+#define condit game.condit                     // Condition (red, yellow, green docked)\r
+#define torps game.torps                       // number of torpedoes\r
+#define ship game.ship                         // Ship type -- 'E' is Enterprise\r
+#define quadx game.quadx                       // where we are\r
+#define quady game.quady                       //\r
+#define sectx game.sectx                       // where we are\r
+#define secty game.secty                       //\r
+#define length game.length                     // length of game\r
+#define skill game.skill                       // skill level\r
+#define basex game.basex                       // position of base in current quad\r
+#define basey game.basey                       //\r
+#define klhere game.klhere                     // klingons here\r
+#define comhere game.comhere           // commanders here\r
+#define casual game.casual                     // causalties\r
+#define nhelp game.nhelp                       // calls for help\r
+#define nkinks game.nkinks                     //\r
+#define ididit game.ididit                     // Action taken -- allows enemy to attack\r
+#define gamewon game.gamewon           // Finished!\r
+#define alive game.alive                       // We are alive (not killed)\r
+#define justin game.justin                     // just entered quadrant\r
+#define alldone game.alldone           // game is now finished\r
+#define shldchg game.shldchg           // shield is changing (affects efficiency)\r
+#define thingx game.thingx                     // location of strange object in galaxy\r
+#define thingy game.thingy                     //\r
+#define plnetx game.plnetx                     // location of planet in quadrant\r
+#define plnety game.plnety                     //\r
+#define inorbit game.inorbit           // orbiting\r
+#define landed game.landed                     // party on planet (1), on ship (-1)\r
+#define iplnet game.iplnet                     // planet # in quadrant\r
+#define imine game.imine                       // mining\r
+#define inplan game.inplan                     // initial planets\r
+#define nenhere game.nenhere           // Number of enemies in quadrant\r
+#define ishere game.ishere                     // Super-commander in quandrant\r
+#define neutz game.neutz                       // Romulan Neutral Zone\r
+#define irhere game.irhere                     // Romulans in quadrant\r
+#define icraft game.icraft                     // Kirk in Galileo\r
+#define ientesc game.ientesc           // Attempted escape from supercommander\r
+#define iscraft game.iscraft           // =1 if craft on ship, -1 if removed from game\r
+#define isatb game.isatb                       // =1 if SuperCommander is attacking base\r
+#define iscate game.iscate                     // Super Commander is here\r
 #ifdef DEBUG\r
-#define idebug a.idebug                        // Debug mode\r
+#define idebug game.idebug                     // Debug mode\r
 #endif\r
-#define iattak a.iattak                        // attack recursion elimination (was cracks[4])\r
-#define icrystl a.icrystl              // dilithium crystals aboard\r
-#define tourn a.tourn                  // Tournament number\r
-#define thawed a.thawed                        // Thawed game\r
-#define batx a.batx                            // Base coordinates being attacked\r
-#define baty a.baty                            //\r
-#define ithere a.ithere                        // Tholean is here \r
-#define ithx a.ithx                            // coordinates of tholean\r
-#define ithy a.ithy\r
-#define iseenit a.iseenit              // Seen base attack report\r
-#define inresor a.inresor              // initial resources\r
-#define intime a.intime                        // initial time\r
-#define inenrg a.inenrg                        // Initial/Max Energy\r
-#define inshld a.inshld                        // Initial/Max Shield\r
-#define inlsr a.inlsr                  // initial life support resources\r
-#define indate a.indate                        // Initial date\r
-#define energy a.energy                        // Energy level\r
-#define shield a.shield                        // Shield level\r
-#define shldup a.shldup                        // Shields are up\r
-#define warpfac a.warpfac              // Warp speed\r
-#define wfacsq a.wfacsq                        // squared warp factor\r
-#define lsupres a.lsupres              // life support reserves\r
-#define dist a.dist                            // movement distance\r
-#define direc a.direc                  // movement direction\r
-#define Time a.Time                            // time taken by current operation\r
-#define docfac a.docfac                        // repair factor when docking (constant?)\r
-#define resting a.resting              // rest time\r
-#define damfac a.damfac                        // damage factor\r
-#define stdamtim a.stdamtim            // time that star chart was damaged\r
-#define cryprob a.cryprob              // probability that crystal will work\r
-#define probex a.probex                        // location of probe\r
-#define probey a.probey\r
-#define probecx a.probecx              // current probe quadrant\r
-#define probecy a.probecy      \r
-#define probeinx a.probeinx            // Probe x,y increment\r
-#define probeiny a.probeiny            \r
-#define proben a.proben                        // number of moves for probe\r
-#define isarmed a.isarmed              // Probe is armed\r
-#define nprobes a.nprobes              // number of probes available\r
+#define iattak game.iattak                     // attack recursion elimination (was cracks[4])\r
+#define icrystl game.icrystl           // dilithium crystals aboard\r
+#define tourn game.tourn                       // Tournament number\r
+#define thawed game.thawed                     // Thawed game\r
+#define batx game.batx                         // Base coordinates being attacked\r
+#define baty game.baty                         //\r
+#define ithere game.ithere                     // Tholean is here \r
+#define ithx game.ithx                         // coordinates of tholean\r
+#define ithy game.ithy\r
+#define iseenit game.iseenit           // Seen base attack report\r
+#define inresor game.inresor           // initial resources\r
+#define intime game.intime                     // initial time\r
+#define inenrg game.inenrg                     // Initial/Max Energy\r
+#define inshld game.inshld                     // Initial/Max Shield\r
+#define inlsr game.inlsr                       // initial life support resources\r
+#define indate game.indate                     // Initial date\r
+#define energy game.energy                     // Energy level\r
+#define shield game.shield                     // Shield level\r
+#define shldup game.shldup                     // Shields are up\r
+#define warpfac game.warpfac           // Warp speed\r
+#define wfacsq game.wfacsq                     // squared warp factor\r
+#define lsupres game.lsupres           // life support reserves\r
+#define dist game.dist                         // movement distance\r
+#define direc game.direc                       // movement direction\r
+#define Time game.Time                         // time taken by current operation\r
+#define docfac game.docfac                     // repair factor when docking (constant?)\r
+#define resting game.resting           // rest time\r
+#define damfac game.damfac                     // damage factor\r
+#define stdamtim game.stdamtim         // time that star chart was damaged\r
+#define cryprob game.cryprob           // probability that crystal will work\r
+#define probex game.probex                     // location of probe\r
+#define probey game.probey\r
+#define probecx game.probecx           // current probe quadrant\r
+#define probecy game.probecy   \r
+#define probeinx game.probeinx         // Probe x,y increment\r
+#define probeiny game.probeiny         \r
+#define proben game.proben                     // number of moves for probe\r
+#define isarmed game.isarmed           // Probe is armed\r
+#define nprobes game.nprobes           // number of probes available\r
 \r
 EXTERN int\r
                kx[21],                 // enemy sector locations\r