Get rid of linux.c and os2.c, code is pure ANSI now.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index 2ef4261a62f2183f1c05532379de791cd272fc8a..ee5bd3eeb3c64ca443c67fc1696a015ec752df79 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -6,11 +6,14 @@
 #include <dos.h>\r
 #endif\r
 #include <time.h>\r
 #include <dos.h>\r
 #endif\r
 #include <time.h>\r
-       \r
-int getch(void);\r
 \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 char line[128], *linep = line;\r
 static int linecount;  /* for paging */\r
+static int screenheight = 24;\r
 \r
 static void clearscreen(void);\r
 \r
 \r
 static void clearscreen(void);\r
 \r
@@ -39,7 +42,7 @@ static void clearscreen(void);
    2. deathray improvement (but keeping original failure alternatives)\r
 \r
    3. Tholian Web\r
    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
    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
@@ -103,7 +106,7 @@ static void listCommands(int x) {
 \r
 static void helpme(void) {\r
        int i, j;\r
 \r
 static void helpme(void) {\r
        int i, j;\r
-       char cmdbuf[32];\r
+       char cmdbuf[32], *cp;\r
        char linebuf[132];\r
        FILE *fp;\r
        /* Give help on commands */\r
        char linebuf[132];\r
        FILE *fp;\r
        /* Give help on commands */\r
@@ -130,37 +133,41 @@ static void helpme(void) {
                strcpy(cmdbuf, " ABBREV");\r
        }\r
        else {\r
                strcpy(cmdbuf, " ABBREV");\r
        }\r
        else {\r
-               strcpy(cmdbuf, "  Mnemonic:  ");\r
-               j = 0;\r
-               while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++;\r
+           for (j = 0; commands[i][j]; j++)\r
+               cmdbuf[j] = toupper(commands[i][j]);\r
+           cmdbuf[j] = '\0';\r
        }\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
                prout("   current directory.\"");\r
                return;\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
                prout("   current directory.\"");\r
                return;\r
        }\r
-       i = strlen(cmdbuf);\r
-       do {\r
-               if (fgets(linebuf, 132, fp) == NULL) {\r
+       for (;;) {\r
+           if (fgets(linebuf, sizeof(linebuf), fp) == NULL) {\r
                        prout("Spock- \"Captain, there is no information on that command.\"");\r
                        fclose(fp);\r
                        return;\r
                }\r
                        prout("Spock- \"Captain, there is no information on that command.\"");\r
                        fclose(fp);\r
                        return;\r
                }\r
-       } while (strncmp(linebuf, cmdbuf, i) != 0);\r
+           if (linebuf[0] == '%' && linebuf[1] == '%'&& linebuf[2] == ' ') {\r
+               for (cp = linebuf+3; isspace(*cp); cp++)\r
+                       continue;\r
+               linebuf[strlen(linebuf)-1] = '\0';\r
+               if (strcmp(cp, cmdbuf) == 0)\r
+                   break;\r
+           }\r
+       }\r
 \r
        skip(1);\r
        prout("Spock- \"Captain, I've found the following information:\"");\r
        skip(1);\r
 \r
 \r
        skip(1);\r
        prout("Spock- \"Captain, I've found the following information:\"");\r
        skip(1);\r
 \r
-       do {\r
-               if (linebuf[0]!=12) { // ignore page break lines \r
-                       linebuf[strlen(linebuf)-1] = '\0'; // No \n at end\r
-                       prout(linebuf);\r
-               }\r
-               fgets(linebuf,132,fp);\r
-       } while (strstr(linebuf, "******")==NULL);\r
+       while (fgets(linebuf, sizeof(linebuf),fp)) {\r
+               if (strstr(linebuf, "******"))\r
+                       break;\r
+               proutc(linebuf);\r
+       }\r
        fclose(fp);\r
 }\r
 \r
        fclose(fp);\r
 }\r
 \r
@@ -350,20 +357,21 @@ int main(int argc, char **argv) {
        int hitme;\r
        char ch;\r
        prelim();\r
        int hitme;\r
        char ch;\r
        prelim();\r
+       char *LINES = getenv("LINES");\r
\r
+       if (LINES)\r
+           screenheight = atoi(LINES);\r
 \r
 \r
+       line[0] = '\0';\r
        if (argc > 1) {\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
                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
 \r
        while (TRUE) { /* Play a game */\r
-               setup();\r
+               setup(line[0] == '\0');\r
                if (alldone) {\r
                        score();\r
                        alldone = 0;\r
                if (alldone) {\r
                        score();\r
                        alldone = 0;\r
@@ -420,7 +428,7 @@ char *cramlc(enum loctype key, int x, int y) {
 void crmena(int i, int enemy, int key, int x, int y) {\r
        if (i == 1) proutn("***");\r
        cramen(enemy);\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
+       proutn(" at ");\r
        proutn(cramlc(key, x, y));\r
 }\r
 \r
        proutn(cramlc(key, x, y));\r
 }\r
 \r
@@ -539,29 +547,33 @@ static void clearscreen(void) {
        extern void clrscr(void);\r
        clrscr();\r
 #else\r
        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
 #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
        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
        }\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
        }\r
+       fgets(buf, sizeof(buf), stdin);\r
        if (i != 0) {\r
                clearscreen();\r
        }\r
        if (i != 0) {\r
                clearscreen();\r
        }\r
@@ -572,7 +584,7 @@ void pause(int i) {
 void skip(int i) {\r
        while (i-- > 0) {\r
                linecount++;\r
 void skip(int i) {\r
        while (i-- > 0) {\r
                linecount++;\r
-               if (linecount >= 23)\r
+               if (linecount >= screenheight)\r
                        pause(0);\r
                else\r
                        putchar('\n');\r
                        pause(0);\r
                else\r
                        putchar('\n');\r
@@ -595,6 +607,12 @@ void prout(char *fmt, ...) {
     skip(1);\r
 }\r
 \r
     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
 void prouts(char *fmt, ...) {\r
        clock_t endTime;\r
        char *s, buf[BUFSIZ];\r