More de-FORTRANizing of the output code.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index 31202254ae78c2a785f392a4c7d46970522c777b..653e06be826b8a71d4950682fa2ad04fb78f1267 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
@@ -407,20 +408,20 @@ void cramen(int i) {
        proutn(s);\r
 }\r
 \r
-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
+char *cramlc(enum loctype key, int x, int y) {\r
+       static char buf[32];\r
+       buf[0] = '\0';\r
+       if (key == quadrant) strcpy(buf, "Quadrant ");\r
+       else if (key == sector) strcpy(buf, "Sector ");\r
+       sprintf(buf+strlen(buf), "%d-%d", x, y);\r
+       return buf;\r
 }\r
 \r
 void crmena(int i, int enemy, int key, int x, int y) {\r
        if (i == 1) proutn("***");\r
        cramen(enemy);\r
        proutn(" at");\r
-       cramlc(key, x, y);\r
+       proutn(cramlc(key, x, y));\r
 }\r
 \r
 void crmshp(void) {\r
@@ -530,18 +531,6 @@ int ja(void) {
        }\r
 }\r
 \r
-void cramf(double x, int w, int d) {\r
-       char buf[64];\r
-       sprintf(buf, "%*.*f", w, d, x);\r
-       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 +580,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
@@ -637,7 +638,7 @@ void debugme(void) {
        proutn("Reset damage? ");\r
        if (ja() != 0) {\r
                int i;\r
-               for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0;\r
+               for (i=0; i <= NDEVICES; i++) if (damage[i] > 0.0) damage[i] = 0.0;\r
                stdamtim = 1e30;\r
        }\r
        proutn("Toggle idebug? ");\r
@@ -649,7 +650,7 @@ void debugme(void) {
        proutn("Cause selective damage? ");\r
        if (ja() != 0) {\r
                int i, key;\r
-               for (i=1; i <= ndevice; i++) {\r
+               for (i=1; i <= NDEVICES; i++) {\r
                        proutn("Kill ");\r
                        proutn(device[i]);\r
                        proutn("? ");\r
@@ -676,7 +677,7 @@ void debugme(void) {
                                case FSCMOVE: proutn("SC Move         "); break;\r
                                case FSCDBAS: proutn("SC Base Destroy "); break;\r
                        }\r
-                       cramf(future[i]-game.state.date, 8, 2);\r
+                       proutn("%82.2f", future[i]-game.state.date);\r
                        chew();\r
                        proutn("  ?");\r
                        key = scan();\r