comparison loadtools/lthelp.c @ 105:02cb0206aa47

fc-loadtool help implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 03 Sep 2013 07:31:26 +0000
parents
children
comparison
equal deleted inserted replaced
104:f65df1d640aa 105:02cb0206aa47
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 }