annotate gen-pdu/input.c @ 10:17dd30989c0b

sms-gen-tpdu: fix bug in GSM7 data source
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 07:47:22 +0000
parents 003660a57f99
children d9d722033ff1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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();
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern void cmd_msg_plain();
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern void cmd_msg_udh();
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static struct cmdtab {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *cmd;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int minargs;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int maxargs;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 void (*func)();
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 } cmdtab[] = {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {"sc-addr", 1, 1, set_sc_addr},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {"user-addr", 1, 1, set_user_addr},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {"mr", 1, 1, set_mr_byte},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {"pid", 1, 1, set_pid_byte},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {"dcs", 2, 2, set_dcs},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"sc-ts", 1, 1, set_scts},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"msg", 1, 1, cmd_msg_plain},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"msg-udh", 1, 1, cmd_msg_udh},
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /* table search terminator */
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {0, 0, 0, 0}
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 };
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 process_input_line()
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char *argv[10];
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 char *cp, **ap;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 struct cmdtab *tp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 cp = index(input_line, '\n');
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (!cp) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 fprintf(stderr, ERR_PREFIX "missing newline\n", input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (cp = input_line; isspace(*cp); cp++)
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 if (*cp == '\0' || *cp == '#')
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 argv[0] = cp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 while (*cp && !isspace(*cp))
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 cp++;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (*cp)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *cp++ = '\0';
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 for (tp = cmdtab; tp->cmd; tp++)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!strcmp(tp->cmd, argv[0]))
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 break;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!tp->func) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(stderr, ERR_PREFIX "invalid command \"%s\"\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 input_lineno, argv[0]);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 for (ap = argv + 1; ; ) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 while (isspace(*cp))
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 cp++;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (!*cp || *cp == '#')
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 break;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (ap - argv - 1 >= tp->maxargs) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr, ERR_PREFIX "too many arguments\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (*cp == '"') {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 *ap++ = ++cp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 for (;;) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (!*cp) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 unterm_qstring: fprintf(stderr, ERR_PREFIX
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 "unterminated quoted string\n",
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(1);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (*cp == '"')
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 break;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (*cp++ == '\\') {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!*cp)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 goto unterm_qstring;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 cp++;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 *cp++ = '\0';
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 } else {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 *ap++ = cp;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 while (*cp && !isspace(*cp))
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 cp++;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (*cp)
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 *cp++ = '\0';
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (ap - argv - 1 < tp->minargs) {
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 fprintf(stderr, ERR_PREFIX "too few arguments\n", input_lineno);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 exit(1);
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 *ap = 0;
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 tp->func(ap - argv, argv);
003660a57f99 new program sms-gen-tpdu
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }