From: Eric S. Raymond Date: Thu, 4 Nov 2004 21:33:11 +0000 (+0000) Subject: Move I/O to a separate module -- first step towards curses interface. X-Git-Tag: 2.0~431 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=25f221b092e0e9d85aa5d3e6863043f2ab4d7c43;p=super-star-trek.git Move I/O to a separate module -- first step towards curses interface. --- diff --git a/MAKEFILE.DOS b/MAKEFILE.DOS index e7e4821..c263c0c 100644 --- a/MAKEFILE.DOS +++ b/MAKEFILE.DOS @@ -4,11 +4,11 @@ CFLAGS=-f87 -2 -m$(MODEL) .c.obj:; bcc $(CFLAGS) -c $*.c OBJS= sst.obj setup.obj reports.obj finish.obj moving.obj\ - battle.obj events.obj ai.obj planets.obj + battle.obj events.obj ai.obj planets.obj io.o sst.exe: $(OBJS) sst.lnk bcc @sst.lnk sst.lnk: makefile - >sst.lnk $(CFLAGS) -M $(OBJS) noeh$(MODEL).lib \ No newline at end of file + >sst.lnk $(CFLAGS) -M $(OBJS) noeh$(MODEL).lib diff --git a/MAKEFILE.OS2 b/MAKEFILE.OS2 index 98678f0..a35865e 100644 --- a/MAKEFILE.OS2 +++ b/MAKEFILE.OS2 @@ -5,7 +5,7 @@ CFLAGS= -O .c.o: $(CC) $(CFLAGS) -c $< -OFILES= sst.o finish.o reports.o setup.o moving.o battle.o events.o ai.o planets.o +OFILES= sst.o finish.o reports.o setup.o moving.o battle.o events.o ai.o planets.o io.o HFILES= sst.h diff --git a/makefile b/makefile index 592f4ef..f98e173 100644 --- a/makefile +++ b/makefile @@ -7,7 +7,7 @@ CFLAGS= -O -g -DSSTDOC='"/usr/share/doc/sst/sst.doc"' .c.o: $(CC) $(CFLAGS) -c $< -CFILES= sst.c finish.c reports.c setup.c moving.c battle.c events.c ai.c planets.c +CFILES= sst.c finish.c reports.c setup.c moving.c battle.c events.c ai.c planets.c io.c OFILES= $(CFILES:.c=.o) HFILES=sst.h DOCS = README sst-doc.xml sst.xml TODO diff --git a/sst.c b/sst.c index ee5bd3e..d35b255 100644 --- a/sst.c +++ b/sst.c @@ -1,21 +1,12 @@ #define INCLUDED // Define externs here #include "sst.h" #include -#include -#ifdef MSDOS -#include -#endif -#include #ifndef SSTDOC #define SSTDOC "sst.doc" #endif static char line[128], *linep = line; -static int linecount; /* for paging */ -static int screenheight = 24; - -static void clearscreen(void); /* Compared to original version, I've changed the "help" command to "call" and the "terminate" command to "quit" to better match @@ -356,12 +347,9 @@ int main(int argc, char **argv) { int i; int hitme; char ch; - prelim(); - char *LINES = getenv("LINES"); - - if (LINES) - screenheight = atoi(LINES); + prelim(); + iostart(); line[0] = '\0'; if (argc > 1) { while (--argc > 0) { @@ -466,14 +454,12 @@ void iran10(int *i, int *j) { } void chew(void) { - linecount = 0; linep = line; *linep = 0; } void chew2(void) { /* return IHEOL next time */ - linecount = 0; linep = line+1; *linep = 0; } @@ -482,8 +468,6 @@ int scan(void) { int i; char *cp; - linecount = 0; - // Init result aaitem = 0.0; *citem = 0; @@ -541,95 +525,6 @@ int ja(void) { double square(double i) { return i*i; } -static void clearscreen(void) { - /* Somehow we need to clear the screen */ -#ifdef __BORLANDC__ - extern void clrscr(void); - clrscr(); -#else - // 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 -- PRESS ENTER TO CONTINUE]"); - } - else { - if (skill > 2) - proutn("[CONTINUE?]"); - else - proutn("[PRESS ENTER TO CONTINUE]"); - - } - fgets(buf, sizeof(buf), stdin); - if (i != 0) { - clearscreen(); - } - linecount = 0; -} - - -void skip(int i) { - while (i-- > 0) { - linecount++; - if (linecount >= screenheight) - pause(0); - else - putchar('\n'); - } -} - - -void proutn(char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -void prout(char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); - 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]; - /* print slowly! */ - va_list ap; - va_start(ap, fmt); - vsprintf(buf, fmt, ap); - va_end(ap); - skip(1); - for (s = buf; *s; s++) { - endTime = clock() + CLOCKS_PER_SEC*0.05; - while (clock() < endTime) ; - putchar(*s); - fflush(stdout); - } -} - void huh(void) { chew(); skip(1); diff --git a/sst.h b/sst.h index 0966319..fc7ecc5 100644 --- a/sst.h +++ b/sst.h @@ -420,3 +420,6 @@ void debugme(void); void attakreport(void); void movetho(void); void probe(void); +void clearscreen(void); +void iostart(void); +