annotate rvinterf/etmsync/help.c @ 620:dd162a4cb9fa

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