Make the internal pager actually work. In the process, remove getch()
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index b3a0202663bd5d6760366c82f8a1bf73d4f24545..5fc099739e6b9aaaba8fa67de1ce427f04d0606c 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -6,9 +6,11 @@
 #include <dos.h>\r
 #endif\r
 #include <time.h>\r
-       \r
-int getch(void);\r
 \r
+#ifndef SSTDOC\r
+#define SSTDOC "sst.doc"\r
+#endif\r
+       \r
 static char line[128], *linep = line;\r
 static int linecount;  /* for paging */\r
 static int screenheight = 24;\r
@@ -40,7 +42,7 @@ static void clearscreen(void);
    2. deathray improvement (but keeping original failure alternatives)\r
 \r
    3. Tholian Web\r
-\r
+s\r
    4. Enemies can ram the Enterprise. Regular Klingons and Romulans can\r
       move in Expert and Emeritus games. This code could use improvement.\r
 \r
@@ -135,7 +137,7 @@ static void helpme(void) {
                cmdbuf[j] = toupper(commands[i][j]);\r
            cmdbuf[j] = '\0';\r
        }\r
-       fp = fopen("sst.doc", "r");\r
+       fp = fopen(SSTDOC, "r");\r
        if (fp == NULL) {\r
                prout("Spock-  \"Captain, that information is missing from the");\r
                prout("   computer. You need to find SST.DOC and put it in the");\r
@@ -164,8 +166,7 @@ static void helpme(void) {
        while (fgets(linebuf, sizeof(linebuf),fp)) {\r
                if (strstr(linebuf, "******"))\r
                        break;\r
-               /* use fputs here to avoid % expansion */\r
-               fputs(linebuf, stdout);\r
+               proutc(linebuf);\r
        }\r
        fclose(fp);\r
 }\r
@@ -361,19 +362,16 @@ int main(int argc, char **argv) {
        if (LINES)\r
            screenheight = atoi(LINES);\r
 \r
+       line[0] = '\0';\r
        if (argc > 1) {\r
-               fromcommandline = 1;\r
-               line[0] = '\0';\r
                while (--argc > 0) {\r
                        strcat(line, *(++argv));\r
                        strcat(line, " ");\r
                }\r
        }\r
-       else fromcommandline = 0;\r
-\r
 \r
        while (TRUE) { /* Play a game */\r
-               setup();\r
+               setup(line[0] == '\0');\r
                if (alldone) {\r
                        score();\r
                        alldone = 0;\r
@@ -549,29 +547,33 @@ static void clearscreen(void) {
        extern void clrscr(void);\r
        clrscr();\r
 #else\r
-       proutn("\033[2J");      /* Hope for an ANSI display */\r
+       // proutn("\033[2J");   /* Hope for an ANSI display */\r
+       /* much more in that old-time TTY spirit to just throw linefeeds */\r
+       int i;\r
+       for (i = 0; i < screenheight; i++)\r
+           putchar('\n');\r
 #endif\r
 }\r
 \r
 /* We will pull these out in case we want to do something special later */\r
 \r
 void pause(int i) {\r
+       char buf[BUFSIZ];\r
        putchar('\n');\r
        if (i==1) {\r
                if (skill > 2)\r
                        prout("[ANOUNCEMENT ARRIVING...]");\r
                else\r
-                       prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- HIT SPACE BAR TO CONTINUE]");\r
-               getch();\r
+                       prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]");\r
        }\r
        else {\r
-               if (skill > 2)\r
-                       proutn("[CONTINUE?]");\r
-               else\r
-                       proutn("[HIT SPACE BAR TO CONTINUE]");\r
-               getch();\r
-               proutn("\r                           \r");\r
+               if (skill > 2)\r
+                       proutn("[CONTINUE?]");\r
+               else\r
+                       proutn("[PRESS ENTER TO CONTINUE]");\r
+\r
        }\r
+       fgets(buf, sizeof(buf), stdin);\r
        if (i != 0) {\r
                clearscreen();\r
        }\r
@@ -605,6 +607,12 @@ void prout(char *fmt, ...) {
     skip(1);\r
 }\r
 \r
+void proutc(char *line) {\r
+    line[strlen(line)-1] = '\0';\r
+    fputs(line, stdout);\r
+    skip(1);\r
+}\r
+\r
 void prouts(char *fmt, ...) {\r
        clock_t endTime;\r
        char *s, buf[BUFSIZ];\r