printfs have been banished. All outputnow goes through prout/proutn/prouts.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 1 Nov 2004 03:48:44 +0000 (03:48 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 1 Nov 2004 03:48:44 +0000 (03:48 +0000)
These are now prinf-like variadic functions.  The point of this
maneuver was to make the output capturable by a different front end,
for example a curses-based front end.

ai.c
battle.c
finish.c
moving.c
planets.c
reports.c
setup.c
sst.c
sst.h

diff --git a/ai.c b/ai.c
index d2223cab385e9ab9892bffb269b8da889aeceb53..37f266c8150d360012fb2232297c0d0f90b29b96 100644 (file)
--- a/ai.c
+++ b/ai.c
@@ -173,9 +173,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
        if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */\r
 #ifdef DEBUG\r
        if (idebug) {\r
-               proutn("NSTEPS = ");\r
-               crami(nsteps, 1);\r
-               skip(1);\r
+               prout("NSTEPS = %d", nsteps);\r
        }\r
 #endif\r
        /* Compute preferred values of delta X and Y */\r
@@ -192,8 +190,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
        for (ll = 1; ll <= nsteps; ll++) {\r
 #ifdef DEBUG\r
                if (idebug) {\r
-                       crami(ll,2);\r
-                       skip(1);\r
+                       prout("%d", ll);\r
                }\r
 #endif\r
                /* Check if preferred position available */\r
index 590d08cdb4c8498ac4f67d7c314cd203fa7817cb..d47671174b0b67fa631c1fbf091d34005c4327d0 100644 (file)
--- a/battle.c
+++ b/battle.c
@@ -152,9 +152,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) {
        crmshp();\r
        prout(" heavily damaged.");\r
        icas = 10.0+20.0*Rand();\r
-       proutn("***Sickbay reports ");\r
-       crami(icas, 1);\r
-       prout(" casualties.");\r
+       prout("***Sickbay reports %d casualties", icas);\r
        casual += icas;\r
        for (l=1; l <= NDEVICES; l++) {\r
                if (l == DDRAY) continue; // Don't damage deathray \r
@@ -532,7 +530,7 @@ void attack(int k) {
                if (hit > hitmax) hitmax = hit;\r
                hittot += hit;\r
                fry(hit);\r
-               printf("Hit %g energy %g\n", hit, energy);\r
+               prout("Hit %g energy %g", hit, energy);\r
                energy -= hit;\r
        }\r
        if (energy <= 0) {\r
@@ -551,25 +549,18 @@ void attack(int k) {
        else {\r
                /* Print message if starship suffered hit(s) */\r
                skip(1);\r
-               proutn("Energy left ");\r
-               cramf(energy, 0, 2);\r
-               proutn("    shields ");\r
-               if (shldup) proutn("up, ");\r
-               else if (game.damage[DSHIELD] == 0) proutn("down, ");\r
+               proutn("Energy left %2d    shields ", (int)energy);\r
+               if (shldup) proutn("up ");\r
+               else if (game.damage[DSHIELD] == 0) proutn("down ");\r
                else proutn("damaged, ");\r
        }\r
-       crami(percent, 1);\r
-       proutn("%   torpedoes left ");\r
-       crami(torps, 1);\r
-       skip(1);\r
+       prout("%d%%,   torpedoes left %d", percent, torps);\r
        /* Check if anyone was hurt */\r
        if (hitmax >= 200 || hittot >= 500) {\r
                int icas= hittot*Rand()*0.015;\r
                if (icas >= 2) {\r
                        skip(1);\r
-                       proutn("Mc Coy-  \"Sickbay to bridge.  We suffered ");\r
-                       crami(icas, 1);\r
-                       prout(" casualties");\r
+                       prout("Mc Coy-  \"Sickbay to bridge.  We suffered %d casualties", icas);\r
                        prout("   in that last attack.\"");\r
                        casual += icas;\r
                }\r
@@ -705,8 +696,7 @@ void photon(void) {
                        return;\r
                }\r
                else if (key == IHEOL) {\r
-                       crami(torps,1);\r
-                       prout(" torpedoes left.");\r
+                       prout("%d torpedoes left.", torps);\r
                        proutn("Number of torpedoes to fire- ");\r
                        key = scan();\r
                }\r
@@ -758,9 +748,7 @@ void photon(void) {
        if (i == 1 && key == IHEOL) {\r
                /* prompt for each one */\r
                for (i = 1; i <= n; i++) {\r
-                       proutn("Target sector for torpedo number");\r
-                       crami(i, 2);\r
-                       proutn("- ");\r
+                   proutn("Target sector for torpedo number %d- ", i);\r
                        key = scan();\r
                        if (key != IHREAL) {\r
                                huh();\r
@@ -787,9 +775,7 @@ void photon(void) {
                        /* misfire! */\r
                        r = (Rand()+1.2) * r;\r
                        if (n>1) {\r
-                               prouts("***TORPEDO NUMBER");\r
-                               crami(i, 2);\r
-                               prouts(" MISFIRES.");\r
+                           prouts("***TORPEDO NUMBER %d MISFIRES", i);\r
                        }\r
                        else prouts("***TORPEDO MISFIRES.");\r
                        skip(1);\r
@@ -805,9 +791,7 @@ void photon(void) {
                if (shldup != 0 || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;\r
                if (n != 1) {\r
                        skip(1);\r
-                       proutn("Track for torpedo number");\r
-                       crami(i, 2);\r
-                       proutn("-   ");\r
+                       proutn("Track for torpedo number %d-  ", i);\r
                }\r
                else {\r
                        skip(1);\r
@@ -862,9 +846,7 @@ static int checkshctrl(double rpow) {
        if (icas) {\r
                skip(1);\r
                prout("McCoy to bridge- \"Severe radiation burns, Jim.");\r
-               proutn("  ");\r
-               crami(icas, 1);\r
-               prout(" casualties so far.\"");\r
+               prout("  %d casualties so far.\"", icas);\r
                casual -= icas;\r
        }\r
        skip(1);\r
@@ -1083,9 +1065,7 @@ void phasers(void) {
                                                int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*\r
                                                                 (1.01+0.05*Rand()) + 1.0;\r
                                                kz = k;\r
-                                               proutn("(");\r
-                                               crami(irec, 1);\r
-                                               proutn(")  ");\r
+                                               proutn("(%d)", irec);\r
                                        }\r
                                        proutn("units to fire at ");\r
                                        crmena(0, ienm, 2, ii, jj);\r
index e0fb221822b892e0c4257bb6a237700c996f6584..657bc51c15dbd376a26136cd2cba93d9de1637a1 100644 (file)
--- a/finish.c
+++ b/finish.c
@@ -68,11 +68,12 @@ void finish(FINTYPE ifin) {
        int igotit = 0;\r
        alldone = 1;\r
        skip(3);\r
-       printf("It is stardate %.1f .\n\n", game.state.date);\r
+       prout("It is stardate %.1f.", game.state.date);\r
+       prout("");\r
        switch (ifin) {\r
                case FWON: // Game has been won\r
                        if (game.state.nromrem != 0)\r
-                               printf("The remaining %d Romulans surrender to Starfleet Command.\n",\r
+                               prout("The remaining %d Romulans surrender to Starfleet Command.",\r
                                           game.state.nromrem);\r
                        \r
                        prout("You have smashed the Klingon invasion fleet and saved");\r
@@ -325,40 +326,40 @@ void score(void) {
        skip(2);\r
        prout("Your score --");\r
        if (game.state.nromkl)\r
-               printf("%6d Romulans destroyed                 %5d\n",\r
+               prout("%6d Romulans destroyed                 %5d",\r
                           game.state.nromkl,20*game.state.nromkl);\r
        if (game.state.nromrem)\r
-               printf("%6d Romulans captured                  %5d\n",\r
+               prout("%6d Romulans captured                  %5d",\r
                           game.state.nromrem, game.state.nromrem);\r
        if (game.state.killk)\r
-               printf("%6d ordinary Klingons destroyed        %5d\n",\r
+               prout("%6d ordinary Klingons destroyed        %5d",\r
                           game.state.killk, 10*game.state.killk);\r
        if (game.state.killc)\r
-               printf("%6d Klingon commanders destroyed       %5d\n",\r
+               prout("%6d Klingon commanders destroyed       %5d",\r
                           game.state.killc, 50*game.state.killc);\r
        if (game.state.nsckill)\r
-               printf("%6d Super-Commander destroyed          %5d\n",\r
+               prout("%6d Super-Commander destroyed          %5d",\r
                           game.state.nsckill, 200*game.state.nsckill);\r
        if (ithperd)\r
-               printf("%6.2f Klingons per stardate              %5d\n",\r
+               prout("%6.2f Klingons per stardate              %5d",\r
                           perdate, ithperd);\r
        if (game.state.starkl)\r
-               printf("%6d stars destroyed by your action     %5d\n",\r
+               prout("%6d stars destroyed by your action     %5d",\r
                           game.state.starkl, -5*game.state.starkl);\r
        if (game.state.nplankl)\r
-               printf("%6d planets destroyed by your action   %5d\n",\r
+               prout("%6d planets destroyed by your action   %5d",\r
                           game.state.nplankl, -10*game.state.nplankl);\r
        if (game.state.basekl)\r
-               printf("%6d bases destroyed by your action     %5d\n",\r
+               prout("%6d bases destroyed by your action     %5d",\r
                           game.state.basekl, -100*game.state.basekl);\r
        if (nhelp)\r
-               printf("%6d calls for help from starbase       %5d\n",\r
+               prout("%6d calls for help from starbase       %5d",\r
                           nhelp, -45*nhelp);\r
        if (casual)\r
-               printf("%6d casualties incurred                %5d\n",\r
+               prout("%6d casualties incurred                %5d",\r
                           casual, -casual);\r
        if (klship)\r
-               printf("%6d ship(s) lost or destroyed          %5d\n",\r
+               prout("%6d ship(s) lost or destroyed          %5d",\r
                           klship, -100*klship);\r
        if (alive==0)\r
                prout("Penalty for getting yourself killed        -200");\r
@@ -372,10 +373,10 @@ void score(void) {
                        case 4: proutn("Expert game  "); break;\r
                        case 5: proutn("Emeritus game"); break;\r
                }\r
-               printf("           %5d\n", iwon);\r
+               prout("           %5d", iwon);\r
        }\r
        skip(2);\r
-       printf("TOTAL SCORE                               %5d\n", iscore);\r
+       prout("TOTAL SCORE                               %5d", iscore);\r
 }\r
 \r
 void plaque(void) {\r
@@ -388,16 +389,16 @@ void plaque(void) {
        skip(2);\r
        \r
        while (fp == NULL) {\r
-               printf("File or device name for your plaque:");\r
+               proutn("File or device name for your plaque:");\r
                fgets(winner, 128, stdin);\r
                winner[strlen(winner)-1] = '\0';\r
                fp = fopen(winner, "w");\r
                if (fp==NULL) {\r
-                       printf("Invalid name.\n");\r
+                       prout("Invalid name.");\r
                }\r
        }\r
 \r
-       printf("Enter name to go on plaque (up to 30 characters):");\r
+       proutn("Enter name to go on plaque (up to 30 characters):");\r
        fgets(winner, 128, stdin);\r
        winner[strlen(winner)-1] = '\0';\r
        winner[30] = '\0';\r
index 0b9ecbed686f32c5b5997607e835ec29fc4fe9dc..d1f5bafaea108c1396b6d5fd2ae2b539ab3f34f2 100644 (file)
--- a/moving.c
+++ b/moving.c
@@ -500,10 +500,11 @@ void warp(int i) {
                                        prout("We can't do it, Captain. We haven't the energy.");\r
                                }\r
                                else {\r
-                                       proutn("We haven't the energy, but we could do it at warp ");\r
-                                       crami(iwarp, 1);\r
-                                       if (shldup)\r
-                                               prout(",\nif you'll lower the shields.");\r
+                                       proutn("We haven't the energy, but we could do it at warp %d", iwarp);\r
+                                       if (shldup) {\r
+                                               prout(",");\r
+                                               prout("if you'll lower the shields.");\r
+                                       }\r
                                        else\r
                                                prout(".");\r
                                }\r
@@ -837,8 +838,7 @@ void probe(void) {
 \r
        if (key == IHEOL) {\r
                /* slow mode, so let Kirk know how many probes there are left */\r
-               crami(nprobes,1);\r
-               prout(nprobes==1 ? " probe left." : " probes left.");\r
+               prout(nprobes==1 ? "%d probe left." : "%d probes left.", nprobes);\r
                proutn("Are you sure you want to fire a probe? ");\r
                if (ja()==0) return;\r
        }\r
index 3f9bfc3e4381ef0b447d5e0b9c21ce9881102518..51a174738308c5bf3f14efd469b3190cac7abe3b 100644 (file)
--- a/planets.c
+++ b/planets.c
@@ -446,7 +446,7 @@ void deathray(void) {
                        prout("   is still operational.\"");\r
                }\r
                else {\r
-                       prout("   has been rendered disfunctional.\"");\r
+                       prout("   has been rendered nonfunctional.\"");\r
                        game.damage[DDRAY] = 39.95;\r
                }\r
                return;\r
index 436900e5e6044716eaaa66faf14e9ef0b6de55c9..ccb13cd80a0ac465a6bc205e1f2abe1a19bb0c01 100644 (file)
--- a/reports.c
+++ b/reports.c
@@ -42,44 +42,41 @@ void report(int f) {
                case 5: s3="emeritus"; break;\r
                default: s3="skilled"; break;\r
        }\r
-       printf("\nYou %s playing a %s%s %s game.\n",\r
+       prout("");\r
+       prout("You %s playing a %s%s %s game.",\r
                   alldone? "were": "are now", s1, s2, s3);\r
        if (skill>3 && thawed && !alldone) prout("No plaque is allowed.");\r
-       if (tourn) printf("This is tournament game %d.\n", tourn);\r
-       if (f) printf("Your secret password is \"%s\"\n",game.passwd);\r
-       printf("%d of %d Klingons have been killed",\r
+       if (tourn) prout("This is tournament game %d.", tourn);\r
+       if (f) prout("Your secret password is \"%s\"",game.passwd);\r
+       proutn("%d of %d Klingons have been killed",\r
                   game.state.killk+game.state.killc+game.state.nsckill, inkling);\r
-       if (game.state.killc) printf(", including %d Commander%s.\n", game.state.killc, game.state.killc==1?"":"s");\r
+       if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s");\r
        else if (game.state.killk+game.state.nsckill > 0) prout(", but no Commanders.");\r
        else prout(".");\r
-       if (skill > 2) printf("The Super Commander has %sbeen destroyed.\n",\r
+       if (skill > 2) prout("The Super Commander has %sbeen destroyed.",\r
                                                  game.state.nscrem?"not ":"");\r
        if (game.state.rembase != inbase) {\r
                proutn("There ");\r
                if (inbase-game.state.rembase==1) proutn("has been 1 base");\r
                else {\r
-                       proutn("have been ");\r
-                       crami(inbase-game.state.rembase, 1);\r
-                       proutn(" bases");\r
+                   proutn("have been %d bases", inbase-game.state.rembase);\r
                }\r
-               proutn(" destroyed, ");\r
-               crami(game.state.rembase, 1);\r
-               prout(" remaining.");\r
+               prout(" destroyed, %d remaining.", game.state.rembase);\r
        }\r
-       else printf("There are %d bases.\n", inbase);\r
+       else prout("There are %d bases.", inbase);\r
        if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) {\r
                /* Don't report this if not seen and\r
                        either the radio is dead or not at base! */\r
                attakreport();\r
                iseenit = 1;\r
        }\r
-       if (casual) printf("%d casualt%s suffered so far.\n",\r
+       if (casual) prout("%d casualt%s suffered so far.",\r
                                           casual, casual==1? "y" : "ies");\r
-       if (nhelp) printf("There were %d call%s for help.\n",\r
+       if (nhelp) prout("There were %d call%s for help.",\r
                                          nhelp, nhelp==1 ? "" : "s");\r
        if (ship == IHE) {\r
                proutn("You have ");\r
-               if (nprobes) crami(nprobes,1);\r
+               if (nprobes) proutn("%d", nprobes);\r
                else proutn("no");\r
                proutn(" deep space probe");\r
                if (nprobes!=1) proutn("s");\r
@@ -104,7 +101,7 @@ void report(int f) {
                                ai *= 2.0;\r
                                i++;\r
                        }\r
-                       printf("Dilithium crystals have been used %d time%s.\n",\r
+                       prout("Dilithium crystals have been used %d time%s.",\r
                                   i, i==1? "" : "s");\r
                }\r
        }\r
@@ -132,9 +129,9 @@ void lrscan(void) {
        for (x = quadx-1; x <= quadx+1; x++) {\r
                for (y = quady-1; y <= quady+1; y++) {\r
                        if (x == 0 || x > 8 || y == 0 || y > 8)\r
-                               printf("   -1");\r
+                               proutn("   -1");\r
                        else {\r
-                               printf("%5d", game.state.galaxy[x][y]);\r
+                               proutn("%5d", game.state.galaxy[x][y]);\r
                                game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+1000 :1;\r
                        }\r
                }\r
@@ -155,7 +152,7 @@ void dreprt(void) {
                                prout("                IN FLIGHT   DOCKED");\r
                                jdam = TRUE;\r
                        }\r
-                       printf("  %16s ", device[i]);\r
+                       proutn("  %16s ", device[i]);\r
                        cramf(game.damage[i]+0.05, 8, 2);\r
                        proutn("  ");\r
                        cramf(docfac*game.damage[i]+0.005, 8, 2);\r
@@ -194,18 +191,18 @@ void chart(int nn) {
 \r
        prout("      1    2    3    4    5    6    7    8");\r
        prout("    ----------------------------------------");\r
-       if (nn==0) prout("  -");\r
+       /* if (nn==0) prout("  -"); */\r
        for (i = 1; i <= 8; i++) {\r
-               printf("%d -", i);\r
+               proutn("%d -", i);\r
                for (j = 1; j <= 8; j++) {\r
                        if (game.starch[i][j] < 0)\r
-                               printf("  .1.");\r
+                               proutn("  .1.");\r
                        else if (game.starch[i][j] == 0)\r
-                               printf("  ...");\r
+                               proutn("  ...");\r
                        else if (game.starch[i][j] > 999)\r
-                               printf("%5d", game.starch[i][j]-1000);\r
+                               proutn("%5d", game.starch[i][j]-1000);\r
                        else\r
-                               printf("%5d", game.state.galaxy[i][j]);\r
+                               proutn("%5d", game.state.galaxy[i][j]);\r
                }\r
                prout("  -");\r
        }\r
@@ -247,7 +244,7 @@ void srscan(int l) {
                        break;\r
                case 2: // REQUEST\r
                        while (scan() == IHEOL)\r
-                               printf("Information desired? ");\r
+                               proutn("Information desired? ");\r
                        chew();\r
                        for (k = 1; k <= 10; k++)\r
                                if (strncmp(citem,requests[k],min(2,strlen(citem)))==0)\r
@@ -267,18 +264,18 @@ void srscan(int l) {
        for (i = 1; i <= 10; i++) {\r
                int jj = (k!=0 ? k : i);\r
                if (leftside) {\r
-                       printf("%2d  ", i);\r
+                       proutn("%2d  ", i);\r
                        for (j = 1; j <= 10; j++) {\r
                                if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1))\r
-                                       printf("%c ",game.quad[i][j]);\r
+                                       proutn("%c ",game.quad[i][j]);\r
                                else\r
-                                       printf("- ");\r
+                                       proutn("- ");\r
                        }\r
                }\r
                if (rightside) {\r
                        switch (jj) {\r
                                case 1:\r
-                                       printf(" Stardate      %.1f", game.state.date);\r
+                                       proutn(" Stardate      %.1f", game.state.date);\r
                                        break;\r
                                case 2:\r
                                        if (condit != IHDOCKED) newcnd();\r
@@ -288,50 +285,50 @@ void srscan(int l) {
                                                case IHYELLOW: cp = "YELLOW"; break;\r
                                                case IHDOCKED: cp = "DOCKED"; break;\r
                                        }\r
-                                       printf(" Condition     %s", cp);\r
+                                       proutn(" Condition     %s", cp);\r
                                        break;\r
                                case 3:\r
-                                       printf(" Position     ");\r
+                                       proutn(" Position     ");\r
                                        cramlc(0, quadx, quady);\r
-                                       putchar(',');\r
+                                       proutn(",");\r
                                        cramlc(0, sectx, secty);\r
                                        break;\r
                                case 4:\r
-                                       printf(" Life Support  ");\r
+                                       proutn(" Life Support  ");\r
                                        if (game.damage[DLIFSUP] != 0.0) {\r
                                                if (condit == IHDOCKED)\r
-                                                       printf("DAMAGED, supported by starbase");\r
+                                                       proutn("DAMAGED, supported by starbase");\r
                                                else\r
-                                                       printf("DAMAGED, reserves=%4.2f", lsupres);\r
+                                                       proutn("DAMAGED, reserves=%4.2f", lsupres);\r
                                        }\r
                                        else\r
-                                               printf("ACTIVE");\r
+                                               proutn("ACTIVE");\r
                                        break;\r
                                case 5:\r
-                                       printf(" Warp Factor   %.1f", warpfac);\r
+                                       proutn(" Warp Factor   %.1f", warpfac);\r
                                        break;\r
                                case 6:\r
-                                       printf(" Energy        %.2f", energy);\r
+                                       proutn(" Energy        %.2f", energy);\r
                                        break;\r
                                case 7:\r
-                                       printf(" Torpedoes     %d", torps);\r
+                                       proutn(" Torpedoes     %d", torps);\r
                                        break;\r
                                case 8:\r
-                                       printf(" Shields       ");\r
+                                       proutn(" Shields       ");\r
                                        if (game.damage[DSHIELD] != 0)\r
-                                               printf("DAMAGED,");\r
+                                               proutn("DAMAGED,");\r
                                        else if (shldup)\r
-                                               printf("UP,");\r
+                                               proutn("UP,");\r
                                        else\r
-                                               printf("DOWN,");\r
-                                       printf(" %d%% %.1f units",\r
+                                               proutn("DOWN,");\r
+                                       proutn(" %d%% %.1f units",\r
                                                   (int)((100.0*shield)/inshld + 0.5), shield);\r
                                        break;\r
                                case 9:\r
-                                       printf(" Klingons Left %d", game.state.remkl);\r
+                                       proutn(" Klingons Left %d", game.state.remkl);\r
                                        break;\r
                                case 10:\r
-                                       printf(" Time Left     %.2f", game.state.remtime);\r
+                                       proutn(" Time Left     %.2f", game.state.remtime);\r
                                        break;\r
                        }\r
                                        \r
diff --git a/setup.c b/setup.c
index 24c5f6f6d25e58a82da1c78e1650ed046cd1f875..747618c4bde4f7fae9a656798c1b9e28e3901837 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -36,6 +36,7 @@ void freeze(int boss) {
                skip(1);\r
                return;\r
        }\r
+       strcpy(game.magic, SSTMAGIC);\r
        fwrite(&game, sizeof(game), 1, fp);\r
 \r
        fclose(fp);\r
@@ -69,6 +70,11 @@ void thaw(void) {
                return;\r
        }\r
        fread(&game, sizeof(game), 1, fp);\r
+       if (strcmp(game.magic, SSTMAGIC)) {\r
+               prout("Game file format is bad, should begin with " SSTMAGIC);\r
+               skip(1);\r
+               return;\r
+       }\r
 \r
        fclose(fp);\r
 \r
@@ -239,13 +245,13 @@ void setup(void) {
                                if (distq < 6.0*(6-inbase) && Rand() < 0.75) {\r
                                        contflag = TRUE;\r
 #ifdef DEBUG\r
-                                       printf("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);\r
+                                       proutn("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);\r
 #endif\r
                                        break;\r
                                }\r
 #ifdef DEBUG\r
                                else if (distq < 6.0 * (6-inbase)) {\r
-                                       printf("DEBUG: saving base #%d, close to #%d\n", i, j);\r
+                                       proutn("DEBUG: saving base #%d, close to #%d\n", i, j);\r
                                }\r
 #endif\r
                        }\r
@@ -334,24 +340,26 @@ void setup(void) {
        game.state.snap = 0;\r
                \r
        if (skill == 1) {\r
-               printf("It is stardate %d. The Federation is being attacked by\n",\r
+               prout("It is stardate %d. The Federation is being attacked by",\r
                           (int)game.state.date);\r
-               printf("a deadly Klingon invasion force. As captain of the United\n"\r
-                          "Starship U.S.S. Enterprise, it is your mission to seek out\n"\r
-                          "and destroy this invasion force of %d battle cruisers.\n",\r
+               prout("a deadly Klingon invasion force. As captain of the United");\r
+               prout("Starship U.S.S. Enterprise, it is your mission to seek out");\r
+               prout("and destroy this invasion force of %d battle cruisers.",\r
                           inkling);\r
-               printf("You have an initial allotment of %d stardates to complete\n"\r
-                          "your mission.  As you proceed you may be given more time.\n\n"\r
-                          "You will have %d supporting starbases.\n"\r
-                          "Starbase locations-  ",\r
-                          (int)intime, inbase);\r
+               prout("You have an initial allotment of %d stardates to complete", (int)intime);\r
+               prout("your mission.  As you proceed you may be given more time.");\r
+               prout("");\r
+               prout("You will have %d supporting starbases.", inbase);\r
+               proutn("Starbase locations-  ");\r
        }\r
        else {\r
-               printf("Stardate %d.\n\n"\r
-                          "%d Klingons.\nAn unknown number of Romulans\n",\r
-                          (int)game.state.date, inkling);\r
-               if (game.state.nscrem) printf("and one (GULP) Super-Commander.\n");\r
-               printf("%d stardates\n%d starbases in  ",(int)intime, inbase);\r
+               prout("Stardate %d.", (int)game.state.date);\r
+               prout("");\r
+               prout("%d Klingons.", inkling);\r
+               prout("An unknown number of Romulans.");\r
+               if (game.state.nscrem) prout("and one (GULP) Super-Commander.");\r
+                       prout("%d stardates.",(int)intime);\r
+                       proutn("%d starbases in  ", inbase);\r
        }\r
        for (i = 1; i <= inbase; i++) {\r
                cramlc(0, game.state.baseqx[i], game.state.baseqy[i]);\r
diff --git a/sst.c b/sst.c
index f6db8870c9ae1856cf8eb55d345ac0981475a7c6..af932a0dbcb000c7e1e3ba7f260ece91f3cda2bc 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -1,6 +1,7 @@
 #define INCLUDED       // Define externs here\r
 #include "sst.h"\r
 #include <ctype.h>\r
+#include <stdarg.h>\r
 #ifdef MSDOS\r
 #include <dos.h>\r
 #endif\r
@@ -373,13 +374,13 @@ int main(int argc, char **argv) {
                skip(1);\r
 \r
                if (tourn && alldone) {\r
-                       printf("Do you want your score recorded?");\r
+                       proutn("Do you want your score recorded?");\r
                        if (ja()) {\r
                                chew2();\r
                                freeze(FALSE);\r
                        }\r
                }\r
-               printf("Do you want to play again?");\r
+               proutn("Do you want to play again?");\r
                if (!ja()) break;\r
        }\r
        skip(1);\r
@@ -410,10 +411,7 @@ void cramen(int i) {
 void cramlc(int key, int x, int y) {\r
        if (key == 1) proutn(" Quadrant");\r
        else if (key == 2) proutn(" Sector");\r
-       proutn(" ");\r
-       crami(x, 1);\r
-       proutn(" - ");\r
-       crami(y, 1);\r
+       proutn(" %d - %d", x, y);\r
 }\r
 \r
 void crmena(int i, int enemy, int key, int x, int y) {\r
@@ -536,12 +534,6 @@ void cramf(double x, int w, int d) {
        proutn(buf);\r
 }\r
 \r
-void crami(int i, int w) {\r
-       char buf[16];\r
-       sprintf(buf, "%*d", w, i);\r
-       proutn(buf);\r
-}\r
-\r
 double square(double i) { return i*i; }\r
                                                                        \r
 static void clearscreen(void) {\r
@@ -591,22 +583,34 @@ void skip(int i) {
 }\r
 \r
 \r
-void proutn(char *s) {\r
-       fputs(s, stdout);\r
+void proutn(char *fmt, ...) {\r
+    va_list ap;\r
+    va_start(ap, fmt);\r
+    vprintf(fmt, ap);\r
+    va_end(ap);\r
 }\r
 \r
-void prout(char *s) {\r
-       proutn(s);\r
-       skip(1);\r
+void prout(char *fmt, ...) {\r
+    va_list ap;\r
+    va_start(ap, fmt);\r
+    vprintf(fmt, ap);\r
+    va_end(ap);\r
+    skip(1);\r
 }\r
 \r
-void prouts(char *s) {\r
+void prouts(char *fmt, ...) {\r
        clock_t endTime;\r
+       char *s, buf[BUFSIZ];\r
        /* print slowly! */\r
-       while (*s) {\r
+       va_list ap;\r
+       va_start(ap, fmt);\r
+       vsprintf(buf, fmt, ap);\r
+       va_end(ap);\r
+       skip(1);\r
+       for (s = buf; *s; s++) {\r
                endTime = clock() + CLOCKS_PER_SEC*0.05;\r
                while (clock() < endTime) ;\r
-               putchar(*s++);\r
+               putchar(*s);\r
                fflush(stdout);\r
        }\r
 }\r
diff --git a/sst.h b/sst.h
index a2c4c92cbcac44e638945b80bc0c76cdc04c6314..255e5cc41f0050407fed56b709086470a974e665 100644 (file)
--- a/sst.h
+++ b/sst.h
@@ -373,8 +373,8 @@ int scan(void);
 void chew(void);\r
 void chew2(void);\r
 void skip(int);\r
-void prout(char *s);\r
-void proutn(char *s);\r
+void prout(char *, ...);\r
+void proutn(char *, ...);\r
 void stars(void);\r
 void newqad(int);\r
 int ja(void);\r
@@ -397,14 +397,13 @@ void timwrp(void);
 void movcom(void);\r
 void torpedo(double, double, int, int, double *);\r
 void cramf(double, int, int);\r
-void crami(int, int);\r
 void huh(void);\r
 void pause(int);\r
 void nova(int, int);\r
 void snova(int, int);\r
 void scom(int *);\r
 void hittem(double *);\r
-void prouts(char *);\r
+void prouts(char *, ...);\r
 int isit(char *);\r
 void preport(void);\r
 void orbit(void);\r