FreeCalypso > hg > sms-coding-utils
annotate gen-pdu/input.c @ 29:aae078d9eaa6
immigrate sms-pdu-decode and pcm-sms-decode here
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 13 Jun 2024 02:39:21 +0000 |
parents | 590b0b5bcbbb |
children |
rev | line source |
---|---|
9
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements input handling for sms-gen-tpdu. |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <ctype.h> |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "error.h" |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern char input_line[]; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int input_lineno; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern void set_sc_addr(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern void set_user_addr(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern void set_mr_byte(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern void set_pid_byte(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern void set_dcs(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 extern void set_scts(); |
18
590b0b5bcbbb
sms-gen-tpdu: support setting VP for MO
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
21 extern void set_vp_abs(); |
590b0b5bcbbb
sms-gen-tpdu: support setting VP for MO
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
22 extern void set_vp_rel(); |
16
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
23 extern void set_flag_rp(); |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
24 extern void set_flag_sr(); |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
25 extern void set_flag_lp(); |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
26 extern void set_flag_mms(); |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
27 extern void set_flag_rd(); |
9
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 extern void cmd_msg_plain(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 extern void cmd_msg_udh(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static struct cmdtab { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 char *cmd; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 int minargs; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 int maxargs; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 void (*func)(); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } cmdtab[] = { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 {"sc-addr", 1, 1, set_sc_addr}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 {"user-addr", 1, 1, set_user_addr}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 {"mr", 1, 1, set_mr_byte}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 {"pid", 1, 1, set_pid_byte}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 {"dcs", 2, 2, set_dcs}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 {"sc-ts", 1, 1, set_scts}, |
18
590b0b5bcbbb
sms-gen-tpdu: support setting VP for MO
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
43 {"vp-abs", 1, 1, set_vp_abs}, |
590b0b5bcbbb
sms-gen-tpdu: support setting VP for MO
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
44 {"vp-rel", 1, 1, set_vp_rel}, |
16
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
45 {"rp", 0, 0, set_flag_rp}, |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
46 {"sr", 0, 0, set_flag_sr}, |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
47 {"lp", 0, 0, set_flag_lp}, |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
48 {"mms", 0, 0, set_flag_mms}, |
d9d722033ff1
sms-gen-tpdu: add support for first octet flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
49 {"rd", 0, 0, set_flag_rd}, |
9
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 {"msg", 1, 1, cmd_msg_plain}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 {"msg-udh", 1, 1, cmd_msg_udh}, |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 /* table search terminator */ |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 {0, 0, 0, 0} |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 }; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 void |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 process_input_line() |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 char *argv[10]; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 char *cp, **ap; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 struct cmdtab *tp; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 cp = index(input_line, '\n'); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (!cp) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fprintf(stderr, ERR_PREFIX "missing newline\n", input_lineno); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 exit(1); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 for (cp = input_line; isspace(*cp); cp++) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 ; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (*cp == '\0' || *cp == '#') |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 argv[0] = cp; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 while (*cp && !isspace(*cp)) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 cp++; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (*cp) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 *cp++ = '\0'; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 for (tp = cmdtab; tp->cmd; tp++) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (!strcmp(tp->cmd, argv[0])) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 break; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (!tp->func) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 fprintf(stderr, ERR_PREFIX "invalid command \"%s\"\n", |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 input_lineno, argv[0]); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 exit(1); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 for (ap = argv + 1; ; ) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 while (isspace(*cp)) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 cp++; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (!*cp || *cp == '#') |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 break; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (ap - argv - 1 >= tp->maxargs) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, ERR_PREFIX "too many arguments\n", |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 input_lineno); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 exit(1); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (*cp == '"') { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 *ap++ = ++cp; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 for (;;) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (!*cp) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 unterm_qstring: fprintf(stderr, ERR_PREFIX |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 "unterminated quoted string\n", |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 input_lineno); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 exit(1); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (*cp == '"') |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 break; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (*cp++ == '\\') { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 if (!*cp) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 goto unterm_qstring; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 cp++; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 *cp++ = '\0'; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } else { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 *ap++ = cp; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 while (*cp && !isspace(*cp)) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 cp++; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (*cp) |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 *cp++ = '\0'; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 if (ap - argv - 1 < tp->minargs) { |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 fprintf(stderr, ERR_PREFIX "too few arguments\n", input_lineno); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 exit(1); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 *ap = 0; |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 tp->func(ap - argv, argv); |
003660a57f99
new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |