FreeCalypso > hg > freecalypso-sw
annotate loadtools/lthelp.c @ 525:98c6be4d3d8d
CONFIG_GSM vs CONFIG_INCLUDE_L1: a few changes in preparation
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 14 Jul 2014 18:42:38 +0000 |
parents | 02cb0206aa47 |
children |
rev | line source |
---|---|
105
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the loadtool help facility. |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <stdio.h> |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <ctype.h> |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <string.h> |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <strings.h> |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdlib.h> |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 extern char loadtool_help_file[]; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 loadtool_help(topic) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 char *topic; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 FILE *f; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 char linebuf[256]; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 char *cp, *np; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 int flag; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 f = fopen(loadtool_help_file, "r"); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 if (!f) { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 perror(loadtool_help_file); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 return(-1); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 for (;;) { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 if (!fgets(linebuf, sizeof linebuf, f)) { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 fprintf(stderr, "Help topic \"%s\" not found\n", topic); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 fclose(f); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 return(-1); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (linebuf[0] != '=' || linebuf[1] != '=' || linebuf[2] != '=') |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 continue; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 for (cp = linebuf + 3; isspace(*cp); cp++) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 ; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 for (np = cp; *cp && !isspace(*cp); cp++) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 ; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 if (*cp) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 *cp++ = '\0'; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 if (!strcmp(np, topic)) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 break; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 for (flag = 0; fgets(linebuf, sizeof linebuf, f); ) { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (linebuf[0] == '=' && linebuf[1] == '=' && |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 linebuf[2] == '=') { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 if (flag) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 break; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 else |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 continue; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 fputs(linebuf, stdout); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 flag = 1; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 fclose(f); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 return(0); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 cmd_help(argc, argv) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 char **argv; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 char flashtopic[32]; |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 switch (argc) { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 case 1: |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 return loadtool_help("main"); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 case 2: |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 return loadtool_help(argv[1]); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 case 3: |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 if ((!strcmp(argv[1], "flash") || !strcmp(argv[1], "flash2")) |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 && strlen(argv[2]) <= 20) { |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 sprintf(flashtopic, "flash:%s", argv[2]); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 return loadtool_help(flashtopic); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 fprintf(stderr, "No such help topic\n"); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 return(-1); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 default: |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 fprintf(stderr, "internal error in cmd_help(): bad argc\n"); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 abort(); |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 } |
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 } |