X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=sst.c;h=ae209e2cb373ed7cf7ad8a156e1fbf01b55bc092;hb=e9397676148f7e501e7a181d354020f86602a566;hp=2ef4261a62f2183f1c05532379de791cd272fc8a;hpb=2a0411c349010501abd2f907b8965a8ca9b4e80c;p=super-star-trek.git diff --git a/sst.c b/sst.c index 2ef4261..ae209e2 100644 --- a/sst.c +++ b/sst.c @@ -6,11 +6,16 @@ #include #endif #include + +#ifndef SSTDOC +#define SSTDOC "sst.doc" +#endif int getch(void); static char line[128], *linep = line; static int linecount; /* for paging */ +static int screenheight = 24; static void clearscreen(void); @@ -103,7 +108,7 @@ static void listCommands(int x) { static void helpme(void) { int i, j; - char cmdbuf[32]; + char cmdbuf[32], *cp; char linebuf[132]; FILE *fp; /* Give help on commands */ @@ -130,37 +135,42 @@ static void helpme(void) { strcpy(cmdbuf, " ABBREV"); } else { - strcpy(cmdbuf, " Mnemonic: "); - j = 0; - while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++; + for (j = 0; commands[i][j]; j++) + cmdbuf[j] = toupper(commands[i][j]); + cmdbuf[j] = '\0'; } - fp = fopen("sst.doc", "r"); + fp = fopen(SSTDOC, "r"); if (fp == NULL) { prout("Spock- \"Captain, that information is missing from the"); prout(" computer. You need to find SST.DOC and put it in the"); prout(" current directory.\""); return; } - i = strlen(cmdbuf); - do { - if (fgets(linebuf, 132, fp) == NULL) { + for (;;) { + if (fgets(linebuf, sizeof(linebuf), fp) == NULL) { prout("Spock- \"Captain, there is no information on that command.\""); fclose(fp); return; } - } while (strncmp(linebuf, cmdbuf, i) != 0); + if (linebuf[0] == '%' && linebuf[1] == '%'&& linebuf[2] == ' ') { + for (cp = linebuf+3; isspace(*cp); cp++) + continue; + linebuf[strlen(linebuf)-1] = '\0'; + if (strcmp(cp, cmdbuf) == 0) + break; + } + } skip(1); prout("Spock- \"Captain, I've found the following information:\""); skip(1); - do { - if (linebuf[0]!=12) { // ignore page break lines - linebuf[strlen(linebuf)-1] = '\0'; // No \n at end - prout(linebuf); - } - fgets(linebuf,132,fp); - } while (strstr(linebuf, "******")==NULL); + while (fgets(linebuf, sizeof(linebuf),fp)) { + if (strstr(linebuf, "******")) + break; + /* use fputs here to avoid % expansion */ + fputs(linebuf, stdout); + } fclose(fp); } @@ -350,6 +360,10 @@ int main(int argc, char **argv) { int hitme; char ch; prelim(); + char *LINES = getenv("LINES"); + + if (LINES) + screenheight = atoi(LINES); if (argc > 1) { fromcommandline = 1; @@ -572,7 +586,7 @@ void pause(int i) { void skip(int i) { while (i-- > 0) { linecount++; - if (linecount >= 23) + if (linecount >= screenheight) pause(0); else putchar('\n');