\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
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
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