comparison loadtools/lthelp.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 464a531122ab
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module implements the loadtool 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
11 extern char loadtool_help_file[];
12
13 loadtool_help(topic)
14 char *topic;
15 {
16 FILE *f;
17 char linebuf[256];
18 char *cp, *np;
19 int flag;
20
21 f = fopen(loadtool_help_file, "r");
22 if (!f) {
23 perror(loadtool_help_file);
24 return(-1);
25 }
26 for (;;) {
27 if (!fgets(linebuf, sizeof linebuf, f)) {
28 fprintf(stderr, "Help topic \"%s\" not found\n", topic);
29 fclose(f);
30 return(-1);
31 }
32 if (linebuf[0] != '=' || linebuf[1] != '=' || linebuf[2] != '=')
33 continue;
34 for (cp = linebuf + 3; isspace(*cp); cp++)
35 ;
36 for (np = cp; *cp && !isspace(*cp); cp++)
37 ;
38 if (*cp)
39 *cp++ = '\0';
40 if (!strcmp(np, topic))
41 break;
42 }
43 for (flag = 0; fgets(linebuf, sizeof linebuf, f); ) {
44 if (linebuf[0] == '=' && linebuf[1] == '=' &&
45 linebuf[2] == '=') {
46 if (flag)
47 break;
48 else
49 continue;
50 }
51 fputs(linebuf, stdout);
52 flag = 1;
53 }
54 fclose(f);
55 return(0);
56 }
57
58 cmd_help(argc, argv)
59 char **argv;
60 {
61 char flashtopic[32];
62
63 switch (argc) {
64 case 1:
65 return loadtool_help("main");
66 case 2:
67 return loadtool_help(argv[1]);
68 case 3:
69 if ((!strcmp(argv[1], "flash") || !strcmp(argv[1], "flash2"))
70 && strlen(argv[2]) <= 20) {
71 sprintf(flashtopic, "flash:%s", argv[2]);
72 return loadtool_help(flashtopic);
73 }
74 fprintf(stderr, "No such help topic\n");
75 return(-1);
76 default:
77 fprintf(stderr, "internal error in cmd_help(): bad argc\n");
78 abort();
79 }
80 }