FreeCalypso > hg > freecalypso-tools
annotate uptools/atcmd/smsend_pduin.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 | 3eb92855f7b9 |
children | dc2fd8e6f42c |
rev | line source |
---|---|
384
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This is the main module for the fcup-smsendpdu utility. |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <unistd.h> |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../../rvinterf/include/exitcodes.h" |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 int sms_write_mode; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char input_line[176*2+2]; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 int lineno; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int initdone, cmms_done; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 process_cmdline(argc, argv) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char **argv; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int c; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern int optind; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 while ((c = getopt(argc, argv, "B:np:RwWX:")) != EOF) { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (atinterf_cmdline_opt(c)) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 continue; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 switch (c) { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case 'w': |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 sms_write_mode = 1; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case 'W': |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 sms_write_mode = 2; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 continue; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 default: |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* error msg already printed */ |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 exit(ERROR_USAGE); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (argc != optind) { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, "usage: %s [options]\n", argv[0]); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(ERROR_USAGE); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 more_input() |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 int c; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 c = getc(stdin); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (c == EOF) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return(0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 ungetc(c, stdin); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(1); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 init_send_process() |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (initdone) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 return(0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 atinterf_init(); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 /* enable verbose error messages */ |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 /* set PDU mode */ |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 prep_for_pdu_mode(); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (sms_write_mode == 0 && more_input()) { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 cmms_done = 1; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 initdone = 1; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return(1); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 process_line() |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 char *cp; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 u_char pdubin[176]; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 int cc, scalen; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 cp = index(input_line, '\n'); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (!cp) { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 fprintf(stderr, "input line %d: too long or unterminated\n", |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 lineno); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(ERROR_USAGE); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 *cp = '\0'; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 cc = decode_hex_line(input_line, pdubin, sizeof pdubin); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (cc < 1) { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 inv: fprintf(stderr, "input line %d: not a valid PDU\n", lineno); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 exit(ERROR_USAGE); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (pdubin[0] == 1 || pdubin[0] > 11) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 goto inv; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 scalen = pdubin[0] + 1; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (cc < scalen + 1) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 goto inv; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 /* good to go */ |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 init_send_process(); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 send_pdu_out(input_line, cc - scalen); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 main(argc, argv) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 char **argv; |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 { |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 process_cmdline(argc, argv); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 process_line(); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 if (!initdone) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 exit(0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 if (cmms_done) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (sms_write_mode == 1) |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 sendafterwr_process(); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 exit(0); |
3eb92855f7b9
fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |