Make the internal pager actually work. In the process, remove getch()
authorEric S. Raymond <esr@thyrsus.com>
Thu, 4 Nov 2004 20:52:38 +0000 (20:52 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 4 Nov 2004 20:52:38 +0000 (20:52 +0000)
and the ANSI-terminal assumption.

TODO
linux.c
makefile
os2.c
setup.c
sst.c
sst.h
sst.xml

diff --git a/TODO b/TODO
index aacd81414df269c2142fdd5a32b1edac1d8da631..202039288aa7a6a462f4d175137f2ab8b7f221be 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,8 +1,5 @@
                Super Star Trek TO-DO list
 
                Super Star Trek TO-DO list
 
-* Yes-no confirmations and "press-to-continue" situations should print
-  a recognizable standard prompt.
-
 * The time machine switch.  Specify a year, get only the features that
   then existed.  (This would be partly so people can try the original
   non-"super" version Matuszek and Reynolds wrote.)
 * The time machine switch.  Specify a year, get only the features that
   then existed.  (This would be partly so people can try the original
   non-"super" version Matuszek and Reynolds wrote.)
@@ -13,8 +10,5 @@
 
 * Write a curses-based interface.  Shouldn't be hard, all output goes through
   prout/proutn/prouts so we can split the screen into two panes with the upper
 
 * Write a curses-based interface.  Shouldn't be hard, all output goes through
   prout/proutn/prouts so we can split the screen into two panes with the upper
-  one for the charts.  (Note, there's one fputs() used in the help reader to
-  avoid % expansion.)
-
-
+  one for the charts.
 
 
diff --git a/linux.c b/linux.c
index 9bd3b13e45464f8b891b39e671bf08e429c526ad..708f933eb51df9f39ddee8e58e2235def8e6e7bd 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -1,6 +1,5 @@
 #include <stdlib.h>
 #include <time.h>
 #include <stdlib.h>
 #include <time.h>
-#include <sys/ioctl.h>
 
 void randomize(void) {
        srand((int)time(NULL));
 
 void randomize(void) {
        srand((int)time(NULL));
@@ -17,15 +16,3 @@ int min(int a, int b) {
        return b;
 }
 
        return b;
 }
 
-int getch(void) {
-       char chbuf[1];
-       struct termio oldstate, newstate;
-    ioctl(0,TCGETA,&oldstate);
-       newstate = oldstate;
-       newstate.c_iflag = 0;
-       newstate.c_lflag = 0;
-       ioctl(0,TCSETA,&newstate);
-       read(0, &chbuf, 1);
-    ioctl(0,TCSETA,&oldstate);
-}
-
index a163b72d726ac3784ae675fe5c991a66089e3eb5..0a0f9ffc185bb3c9959c2ec1c9649fef82f2ce32 100644 (file)
--- a/makefile
+++ b/makefile
@@ -31,9 +31,9 @@ sst.doc: sst-doc.txt
        makehelp.py >sst.doc
 
 sst-doc.html: sst-doc.xml
        makehelp.py >sst.doc
 
 sst-doc.html: sst-doc.xml
-       xmlto --skip-validation xhhtml-nochunks sst-doc.xml
+       xmlto --skip-validation xhtml-nochunks sst-doc.xml
 
 
-install: sst.6 uninstall
+install: uninstall sst.6 sst.doc sst-doc.html 
        install -m 755 -o 0 -g 0 -d $(ROOT)/usr/bin/
        install -m 755 -o 0 -g 0 sst $(ROOT)/usr/bin/sst
        install -m 755 -o 0 -g 0 -d $(ROOT)/usr/share/man/man6/
        install -m 755 -o 0 -g 0 -d $(ROOT)/usr/bin/
        install -m 755 -o 0 -g 0 sst $(ROOT)/usr/bin/sst
        install -m 755 -o 0 -g 0 -d $(ROOT)/usr/share/man/man6/
diff --git a/os2.c b/os2.c
index ca0eb54264c33687bceb26f3d16abbac308a2888..e419e297c733dbf608cc98e145709247a6ba346d 100644 (file)
--- a/os2.c
+++ b/os2.c
@@ -1,7 +1,5 @@
 #include <stdlib.h>\r
 #include <time.h>\r
 #include <stdlib.h>\r
 #include <time.h>\r
-#include <sys/ioctl.h>\r
-#include <sys/termio.h>\r
 \r
 void randomize(void) {\r
        srand((int)time(NULL));\r
 \r
 void randomize(void) {\r
        srand((int)time(NULL));\r
@@ -17,15 +15,3 @@ int min(int a, int b) {
        if (a < b) return a;\r
        return b;\r
 }\r
        if (a < b) return a;\r
        return b;\r
 }\r
-\r
-int getch(void) {\r
-       char chbuf[1];\r
-       struct termio oldstate, newstate;\r
-    ioctl(0,TCGETA,&oldstate);\r
-       newstate = oldstate;\r
-       newgame.state.c_iflag = 0;\r
-       newgame.state.c_lflag = 0;\r
-       ioctl(0,TCSETA,&newstate);\r
-       read(0, &chbuf, 1);\r
-    ioctl(0,TCSETA,&oldstate);\r
-}
\ No newline at end of file
diff --git a/setup.c b/setup.c
index 002188291aff1dafc53b7b9cf80c1ddf0dfcbca9..5b8c20d2b65c1798caa07f31aa60e515be3b8dda 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -179,7 +179,7 @@ void abandn(void) {
        return;\r
 }\r
        \r
        return;\r
 }\r
        \r
-void setup(void) {\r
+void setup(int needprompt) {\r
        int i,j, krem, klumper;\r
        int ix, iy;\r
        alldone = gamewon = 0;\r
        int i,j, krem, klumper;\r
        int ix, iy;\r
        alldone = gamewon = 0;\r
@@ -187,7 +187,7 @@ void setup(void) {
        idebug = 0;\r
 #endif\r
        //  Decide how many of everything\r
        idebug = 0;\r
 #endif\r
        //  Decide how many of everything\r
-       if (choose()) return; // frozen game\r
+       if (choose(needprompt)) return; // frozen game\r
        // Prepare the Enterprise\r
        ship = IHE;\r
        energy = inenrg = 5000.0;\r
        // Prepare the Enterprise\r
        ship = IHE;\r
        energy = inenrg = 5000.0;\r
@@ -372,23 +372,20 @@ void setup(void) {
         proutn(cramlc(sector, sectx, secty));\r
        skip(2);\r
        prout("Good Luck!");\r
         proutn(cramlc(sector, sectx, secty));\r
        skip(2);\r
        prout("Good Luck!");\r
-       if (game.state.nscrem) proutn("  YOU'LL NEED IT.");\r
-       skip(1);\r
+       if (game.state.nscrem) prout("  YOU'LL NEED IT.");\r
        newqad(0);\r
        if (nenhere) shldup=1.0;\r
        if (neutz) attack(0);   // bad luck to start in a Romulan Neutral Zone\r
 }\r
 \r
        newqad(0);\r
        if (nenhere) shldup=1.0;\r
        if (neutz) attack(0);   // bad luck to start in a Romulan Neutral Zone\r
 }\r
 \r
-int choose(void) {\r
+int choose(int needprompt) {\r
        tourn = 0;\r
        thawed = 0;\r
        skill = 0;\r
        length = 0;\r
        while (TRUE) {\r
        tourn = 0;\r
        thawed = 0;\r
        skill = 0;\r
        length = 0;\r
        while (TRUE) {\r
-               if (fromcommandline) /* Can start with command line options */\r
-                       fromcommandline = 0;\r
-               else\r
-                       proutn("Would you like a regular, tournament, or frozen game?");\r
+               if (needprompt) /* Can start with command line options */\r
+                   proutn("Would you like a regular, tournament, or frozen game?");\r
                scan();\r
                if (strlen(citem)==0) continue; // Try again\r
                if (isit("tournament")) {\r
                scan();\r
                if (strlen(citem)==0) continue; // Try again\r
                if (isit("tournament")) {\r
diff --git a/sst.c b/sst.c
index ae209e2cb373ed7cf7ad8a156e1fbf01b55bc092..5fc099739e6b9aaaba8fa67de1ce427f04d0606c 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -11,8 +11,6 @@
 #define SSTDOC "sst.doc"\r
 #endif\r
        \r
 #define SSTDOC "sst.doc"\r
 #endif\r
        \r
-int getch(void);\r
-\r
 static char line[128], *linep = line;\r
 static int linecount;  /* for paging */\r
 static int screenheight = 24;\r
 static char line[128], *linep = line;\r
 static int linecount;  /* for paging */\r
 static int screenheight = 24;\r
@@ -44,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
@@ -168,8 +166,7 @@ static void helpme(void) {
        while (fgets(linebuf, sizeof(linebuf),fp)) {\r
                if (strstr(linebuf, "******"))\r
                        break;\r
        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
        }\r
        fclose(fp);\r
 }\r
@@ -365,19 +362,16 @@ int main(int argc, char **argv) {
        if (LINES)\r
            screenheight = atoi(LINES);\r
 \r
        if (LINES)\r
            screenheight = atoi(LINES);\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
@@ -553,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
@@ -609,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
diff --git a/sst.h b/sst.h
index 8705b8480ce06277cbb4e6c410e2e658f35a99c7..40ba849118746bff69c88b28956aaf0418e974c4 100644 (file)
--- a/sst.h
+++ b/sst.h
@@ -251,7 +251,6 @@ EXTERN struct {
 #define nprobes game.nprobes           // number of probes available\r
 \r
 /* the following global state doesn't need to be saved */\r
 #define nprobes game.nprobes           // number of probes available\r
 \r
 /* the following global state doesn't need to be saved */\r
-EXTERN int fromcommandline; // Game start from command line options\r
 EXTERN char    *device[NDEVICES+1];\r
 EXTERN int iscore, iskill; // Common PLAQ\r
 EXTERN double perdate;\r
 EXTERN char    *device[NDEVICES+1];\r
 EXTERN int iscore, iskill; // Common PLAQ\r
 EXTERN double perdate;\r
@@ -340,8 +339,8 @@ char *device[NDEVICES+1] = {
 /* Function prototypes */\r
 void prelim(void);\r
 void attack(int);\r
 /* Function prototypes */\r
 void prelim(void);\r
 void attack(int);\r
-int choose(void);\r
-void setup(void);\r
+int choose(int);\r
+void setup(int);\r
 void score(void);\r
 void atover(int);\r
 void srscan(int);\r
 void score(void);\r
 void atover(int);\r
 void srscan(int);\r
@@ -404,6 +403,7 @@ void snova(int, int);
 void scom(int *);\r
 void hittem(double *);\r
 void prouts(char *, ...);\r
 void scom(int *);\r
 void hittem(double *);\r
 void prouts(char *, ...);\r
+void proutc(char *);\r
 int isit(char *);\r
 void preport(void);\r
 void orbit(void);\r
 int isit(char *);\r
 void preport(void);\r
 void orbit(void);\r
diff --git a/sst.xml b/sst.xml
index abef525266568317b3e6b3ccb96588674be30cbe..3cc6e33d6b764a1a168d1405a389eff8acf50d33 100644 (file)
--- a/sst.xml
+++ b/sst.xml
@@ -35,6 +35,17 @@ each one individually as well.  Full documentation is <ulink
 url='http://sst.berlios.de/sst-doc.html'>browseable</ulink>.  On
 systems where <filename>/usr/share/doc/sst/</filename> is a legal
 filename, it will probably be installed there as well.</para>
 url='http://sst.berlios.de/sst-doc.html'>browseable</ulink>.  On
 systems where <filename>/usr/share/doc/sst/</filename> is a legal
 filename, it will probably be installed there as well.</para>
+
+<para>Input tokens for the setup prompts will be read from the command
+line before standard input.  Thus, for example, you can invoke the
+program as</para>
+
+<programlisting>
+sst regular medium good foobar
+</programlisting>
+
+<para>to start a regular medium game as a good player 
+with password "foobar".</para>
 </refsect1>
 
 <refsect1 id='authors'><title>AUTHORS</title> <para>Super Star Trek
 </refsect1>
 
 <refsect1 id='authors'><title>AUTHORS</title> <para>Super Star Trek