annotate rvinterf/asyncshell/help.c @ 75:bbc41034f14c

fc-shell: added support for AT commands in one-shot mode
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 27 Oct 2016 02:13:38 +0000
parents 27d7d7e2d9bd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the fc-shell help facility.
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
53
27d7d7e2d9bd rvinterf/asyncshell/help.c: new help file location
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
11 char help_file_pathname[] = "/opt/freecalypso/helpfiles/fc-shell.help";
31
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 show_help_topic(topic)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *topic;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *f;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char linebuf[256];
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *cp, *np;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int flag;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 f = fopen(help_file_pathname, "r");
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (!f) {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 perror(help_file_pathname);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return(-1);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 for (;;) {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!fgets(linebuf, sizeof linebuf, f)) {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 printf("error: help topic \"%s\" not found\n", topic);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fclose(f);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (linebuf[0] != '=' || linebuf[1] != '=' || linebuf[2] != '=')
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 continue;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (cp = linebuf + 3; isspace(*cp); cp++)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 ;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 for (np = cp; *cp && !isspace(*cp); cp++)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 ;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (*cp)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 *cp++ = '\0';
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!strcmp(np, topic))
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 break;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (flag = 0; fgets(linebuf, sizeof linebuf, f); ) {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (linebuf[0] == '=' && linebuf[1] == '=' &&
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 linebuf[2] == '=') {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (flag)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 else
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 continue;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 fputs(linebuf, stdout);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 flag = 1;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fclose(f);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(0);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 void
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 cmd_help(argstr)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 char *argstr;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 char *argv[3], dbltopic[34];
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 int argc, rc;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 rc = parse_interactive_command_into_argv(argstr, argv, 0, 2, &argc);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (rc < 0)
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 switch (argc) {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 case 0:
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 show_help_topic("main");
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 break;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 case 1:
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 show_help_topic(argv[0]);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 break;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 case 2:
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (strlen(argv[0]) <= 16 && strlen(argv[1]) <= 16) {
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 sprintf(dbltopic, "%s:%s", argv[0], argv[1]);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 show_help_topic(dbltopic);
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 } else
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 printf("error: no such help topic\n");
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 break;
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 default:
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(stderr, "internal error in cmd_help(): bad argc\n");
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 abort();
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
5b4e345095c4 fc-shell help command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }