From 03ea69145938e4b01e7efc6be80a543bad1739c7 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 4 Nov 2004 20:52:38 +0000 Subject: [PATCH] Make the internal pager actually work. In the process, remove getch() and the ANSI-terminal assumption. --- TODO | 8 +------- linux.c | 13 ------------- makefile | 4 ++-- os2.c | 14 -------------- setup.c | 15 ++++++--------- sst.c | 42 +++++++++++++++++++++++------------------- sst.h | 6 +++--- sst.xml | 11 +++++++++++ 8 files changed, 46 insertions(+), 67 deletions(-) diff --git a/TODO b/TODO index aacd814..2020392 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,5 @@ 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.) @@ -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 - 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 9bd3b13..708f933 100644 --- a/linux.c +++ b/linux.c @@ -1,6 +1,5 @@ #include #include -#include void randomize(void) { srand((int)time(NULL)); @@ -17,15 +16,3 @@ int min(int a, int 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); -} - diff --git a/makefile b/makefile index a163b72..0a0f9ff 100644 --- a/makefile +++ b/makefile @@ -31,9 +31,9 @@ sst.doc: sst-doc.txt 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/ diff --git a/os2.c b/os2.c index ca0eb54..e419e29 100644 --- a/os2.c +++ b/os2.c @@ -1,7 +1,5 @@ #include #include -#include -#include void randomize(void) { srand((int)time(NULL)); @@ -17,15 +15,3 @@ int min(int a, int b) { if (a < b) return a; return b; } - -int getch(void) { - char chbuf[1]; - struct termio oldstate, newstate; - ioctl(0,TCGETA,&oldstate); - newstate = oldstate; - newgame.state.c_iflag = 0; - newgame.state.c_lflag = 0; - ioctl(0,TCSETA,&newstate); - read(0, &chbuf, 1); - ioctl(0,TCSETA,&oldstate); -} \ No newline at end of file diff --git a/setup.c b/setup.c index 0021882..5b8c20d 100644 --- a/setup.c +++ b/setup.c @@ -179,7 +179,7 @@ void abandn(void) { return; } -void setup(void) { +void setup(int needprompt) { int i,j, krem, klumper; int ix, iy; alldone = gamewon = 0; @@ -187,7 +187,7 @@ void setup(void) { idebug = 0; #endif // Decide how many of everything - if (choose()) return; // frozen game + if (choose(needprompt)) return; // frozen game // Prepare the Enterprise ship = IHE; energy = inenrg = 5000.0; @@ -372,23 +372,20 @@ void setup(void) { proutn(cramlc(sector, sectx, secty)); skip(2); prout("Good Luck!"); - if (game.state.nscrem) proutn(" YOU'LL NEED IT."); - skip(1); + if (game.state.nscrem) prout(" YOU'LL NEED IT."); newqad(0); if (nenhere) shldup=1.0; if (neutz) attack(0); // bad luck to start in a Romulan Neutral Zone } -int choose(void) { +int choose(int needprompt) { tourn = 0; thawed = 0; skill = 0; length = 0; while (TRUE) { - if (fromcommandline) /* Can start with command line options */ - fromcommandline = 0; - else - proutn("Would you like a regular, tournament, or frozen game?"); + if (needprompt) /* Can start with command line options */ + proutn("Would you like a regular, tournament, or frozen game?"); scan(); if (strlen(citem)==0) continue; // Try again if (isit("tournament")) { diff --git a/sst.c b/sst.c index ae209e2..5fc0997 100644 --- a/sst.c +++ b/sst.c @@ -11,8 +11,6 @@ #define SSTDOC "sst.doc" #endif -int getch(void); - static char line[128], *linep = line; static int linecount; /* for paging */ static int screenheight = 24; @@ -44,7 +42,7 @@ static void clearscreen(void); 2. deathray improvement (but keeping original failure alternatives) 3. Tholian Web - +s 4. Enemies can ram the Enterprise. Regular Klingons and Romulans can move in Expert and Emeritus games. This code could use improvement. @@ -168,8 +166,7 @@ static void helpme(void) { while (fgets(linebuf, sizeof(linebuf),fp)) { if (strstr(linebuf, "******")) break; - /* use fputs here to avoid % expansion */ - fputs(linebuf, stdout); + proutc(linebuf); } fclose(fp); } @@ -365,19 +362,16 @@ int main(int argc, char **argv) { if (LINES) screenheight = atoi(LINES); + line[0] = '\0'; if (argc > 1) { - fromcommandline = 1; - line[0] = '\0'; while (--argc > 0) { strcat(line, *(++argv)); strcat(line, " "); } } - else fromcommandline = 0; - while (TRUE) { /* Play a game */ - setup(); + setup(line[0] == '\0'); if (alldone) { score(); alldone = 0; @@ -553,29 +547,33 @@ static void clearscreen(void) { extern void clrscr(void); clrscr(); #else - proutn("\033[2J"); /* Hope for an ANSI display */ + // proutn("\033[2J"); /* Hope for an ANSI display */ + /* much more in that old-time TTY spirit to just throw linefeeds */ + int i; + for (i = 0; i < screenheight; i++) + putchar('\n'); #endif } /* We will pull these out in case we want to do something special later */ void pause(int i) { + char buf[BUFSIZ]; putchar('\n'); if (i==1) { if (skill > 2) prout("[ANOUNCEMENT ARRIVING...]"); else - prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- HIT SPACE BAR TO CONTINUE]"); - getch(); + prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]"); } else { - if (skill > 2) - proutn("[CONTINUE?]"); - else - proutn("[HIT SPACE BAR TO CONTINUE]"); - getch(); - proutn("\r \r"); + if (skill > 2) + proutn("[CONTINUE?]"); + else + proutn("[PRESS ENTER TO CONTINUE]"); + } + fgets(buf, sizeof(buf), stdin); if (i != 0) { clearscreen(); } @@ -609,6 +607,12 @@ void prout(char *fmt, ...) { skip(1); } +void proutc(char *line) { + line[strlen(line)-1] = '\0'; + fputs(line, stdout); + skip(1); +} + void prouts(char *fmt, ...) { clock_t endTime; char *s, buf[BUFSIZ]; diff --git a/sst.h b/sst.h index 8705b84..40ba849 100644 --- a/sst.h +++ b/sst.h @@ -251,7 +251,6 @@ EXTERN struct { #define nprobes game.nprobes // number of probes available /* the following global state doesn't need to be saved */ -EXTERN int fromcommandline; // Game start from command line options EXTERN char *device[NDEVICES+1]; EXTERN int iscore, iskill; // Common PLAQ EXTERN double perdate; @@ -340,8 +339,8 @@ char *device[NDEVICES+1] = { /* Function prototypes */ void prelim(void); void attack(int); -int choose(void); -void setup(void); +int choose(int); +void setup(int); void score(void); void atover(int); void srscan(int); @@ -404,6 +403,7 @@ void snova(int, int); void scom(int *); void hittem(double *); void prouts(char *, ...); +void proutc(char *); int isit(char *); void preport(void); void orbit(void); diff --git a/sst.xml b/sst.xml index abef525..3cc6e33 100644 --- a/sst.xml +++ b/sst.xml @@ -35,6 +35,17 @@ each one individually as well. Full documentation is browseable. On systems where /usr/share/doc/sst/ is a legal filename, it will probably be installed there as well. + +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 + + +sst regular medium good foobar + + +to start a regular medium game as a good player +with password "foobar". AUTHORS Super Star Trek -- 2.31.1