Better project documentation.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index 2ef4261a62f2183f1c05532379de791cd272fc8a..b06a82fade956d28bd2b9b4f6b32a250d39db369 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -103,7 +103,7 @@ static void listCommands(int x) {
 \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
@@ -130,9 +130,9 @@ static void helpme(void) {
                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
        fp = fopen("sst.doc", "r");\r
        if (fp == NULL) {\r
@@ -141,26 +141,31 @@ static void helpme(void) {
                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
-       } 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
-       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
+               linebuf[strlen(linebuf)-1] = '\0'; // No \n at end\r
+               prout(linebuf);\r
+       }\r
        fclose(fp);\r
 }\r
 \r