FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/help.c @ 27:24cb10d508d7
fc-fsio help command implemented
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 23 Oct 2016 01:33:21 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 26:b301b75de0e0 | 27:24cb10d508d7 |
|---|---|
| 1 /* | |
| 2 * This module implements the fc-fsio help facility. | |
| 3 */ | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 #include <ctype.h> | |
| 7 #include <string.h> | |
| 8 #include <strings.h> | |
| 9 #include <stdlib.h> | |
| 10 #include "exitcodes.h" | |
| 11 | |
| 12 extern char help_file_pathname[]; | |
| 13 | |
| 14 show_help_topic(topic) | |
| 15 char *topic; | |
| 16 { | |
| 17 FILE *f; | |
| 18 char linebuf[256]; | |
| 19 char *cp, *np; | |
| 20 int flag; | |
| 21 | |
| 22 f = fopen(help_file_pathname, "r"); | |
| 23 if (!f) { | |
| 24 perror(help_file_pathname); | |
| 25 return(ERROR_UNIX); | |
| 26 } | |
| 27 for (;;) { | |
| 28 if (!fgets(linebuf, sizeof linebuf, f)) { | |
| 29 fprintf(stderr, "Help topic \"%s\" not found\n", topic); | |
| 30 fclose(f); | |
| 31 return(ERROR_USAGE); | |
| 32 } | |
| 33 if (linebuf[0] != '=' || linebuf[1] != '=' || linebuf[2] != '=') | |
| 34 continue; | |
| 35 for (cp = linebuf + 3; isspace(*cp); cp++) | |
| 36 ; | |
| 37 for (np = cp; *cp && !isspace(*cp); cp++) | |
| 38 ; | |
| 39 if (*cp) | |
| 40 *cp++ = '\0'; | |
| 41 if (!strcmp(np, topic)) | |
| 42 break; | |
| 43 } | |
| 44 for (flag = 0; fgets(linebuf, sizeof linebuf, f); ) { | |
| 45 if (linebuf[0] == '=' && linebuf[1] == '=' && | |
| 46 linebuf[2] == '=') { | |
| 47 if (flag) | |
| 48 break; | |
| 49 else | |
| 50 continue; | |
| 51 } | |
| 52 fputs(linebuf, stdout); | |
| 53 flag = 1; | |
| 54 } | |
| 55 fclose(f); | |
| 56 return(0); | |
| 57 } | |
| 58 | |
| 59 cmd_help(argc, argv) | |
| 60 char **argv; | |
| 61 { | |
| 62 switch (argc) { | |
| 63 case 1: | |
| 64 return show_help_topic("main"); | |
| 65 case 2: | |
| 66 return show_help_topic(argv[1]); | |
| 67 default: | |
| 68 fprintf(stderr, "internal error in cmd_help(): bad argc\n"); | |
| 69 abort(); | |
| 70 } | |
| 71 } |
