FreeCalypso > hg > freecalypso-tools
annotate rvinterf/etmsync/help.c @ 465:003e48f8ebe1
rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel
I generally don't use NULL and use plain 0 instead, based on a "NULL
considered harmful" discussion on the classiccmp mailing list many aeons
ago (I couldn't find it, and I reason that it must have been 2005 or
earlier), but a recent complaint by a packager sent me searching, and I
found this:
https://ewontfix.com/11/
While I don't give a @#$% about "modern" systems and code-nazi tools,
I realized that passing a plain 0 as a pointer sentinel in execl is wrong
because it will break on systems where pointers are longer than the plain
int type. Again, I don't give a @#$% about the abomination of x86_64 and
the like, but if anyone ever manages to port my code to something like a
PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0
as a function argument where a pointer is expected most definitely won't
work: if the most natural stack slot and SP alignment unit is 16 bits,
fitting an int, with longs and pointers taking up two such slots, then
the call stack will be totally wrong with a plain 0 passed for a pointer.
Casting the 0 to (char *) ought to be the most kosher solution for the
most retro systems possible.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Feb 2019 00:00:19 +0000 |
parents | 24cb10d508d7 |
children |
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 } |