FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smsend_main.c @ 966:ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 01 Sep 2023 15:44:52 +0000 |
parents | 2969032bdfac |
children | 6bf473f77fc4 |
comparison
equal
deleted
inserted
replaced
965:2969032bdfac | 966:ec7e23d5151f |
---|---|
11 #include "../../rvinterf/include/exitcodes.h" | 11 #include "../../rvinterf/include/exitcodes.h" |
12 | 12 |
13 #define MAX_MSG_CHARS (153*255) | 13 #define MAX_MSG_CHARS (153*255) |
14 #define MAX_MSG_UNI (67*255) | 14 #define MAX_MSG_UNI (67*255) |
15 | 15 |
16 int sms_write_mode, text_mode, utf8_input, ucs2_mode; | 16 int sms_write_mode, text_mode, utf8_input, ucs2_mode, allow_escape; |
17 int concat_enable, concat_refno_set, concat_quiet; | 17 int concat_enable, concat_refno_set, concat_quiet; |
18 u_char dest_addr[12]; | 18 u_char dest_addr[12]; |
19 char msgtext[MAX_MSG_CHARS*2+2]; | 19 char msgtext[MAX_MSG_CHARS*3+2]; |
20 u_char concat_refno; | 20 u_char concat_refno; |
21 | 21 |
22 process_cmdline(argc, argv) | 22 process_cmdline(argc, argv) |
23 char **argv; | 23 char **argv; |
24 { | 24 { |
25 int c; | 25 int c; |
26 extern int optind; | 26 extern int optind; |
27 extern char *optarg; | 27 extern char *optarg; |
28 | 28 |
29 while ((c = getopt(argc, argv, "B:cC:np:qRtuUwWX:")) != EOF) { | 29 while ((c = getopt(argc, argv, "B:cC:enp:qRtuUwWX:")) != EOF) { |
30 if (atinterf_cmdline_opt(c)) | 30 if (atinterf_cmdline_opt(c)) |
31 continue; | 31 continue; |
32 switch (c) { | 32 switch (c) { |
33 case 'c': | 33 case 'c': |
34 concat_enable = 1; | 34 concat_enable = 1; |
36 case 'C': | 36 case 'C': |
37 concat_enable = 1; | 37 concat_enable = 1; |
38 concat_refno = strtoul(optarg, 0, 0); | 38 concat_refno = strtoul(optarg, 0, 0); |
39 concat_refno_set = 1; | 39 concat_refno_set = 1; |
40 continue; | 40 continue; |
41 case 'e': | |
42 allow_escape = 1; | |
43 continue; | |
41 case 'q': | 44 case 'q': |
42 concat_quiet = 1; | 45 concat_quiet = 1; |
43 continue; | 46 continue; |
44 case 't': | 47 case 't': |
45 text_mode = 1; | 48 text_mode = 1; |
68 argv[0]); | 71 argv[0]); |
69 exit(ERROR_USAGE); | 72 exit(ERROR_USAGE); |
70 } | 73 } |
71 if (ucs2_mode && text_mode) { | 74 if (ucs2_mode && text_mode) { |
72 fprintf(stderr, "%s error: UCS-2 not supported in text mode\n", | 75 fprintf(stderr, "%s error: UCS-2 not supported in text mode\n", |
76 argv[0]); | |
77 exit(ERROR_USAGE); | |
78 } | |
79 if (allow_escape && text_mode) { | |
80 fprintf(stderr, | |
81 "%s error: escapes not supported in text mode\n", | |
82 argv[0]); | |
83 exit(ERROR_USAGE); | |
84 } | |
85 if (ucs2_mode && allow_escape) { | |
86 fprintf(stderr, "%s error: UCS-2 escapes not supported yet\n", | |
73 argv[0]); | 87 argv[0]); |
74 exit(ERROR_USAGE); | 88 exit(ERROR_USAGE); |
75 } | 89 } |
76 if (argc > optind + 2) { | 90 if (argc > optind + 2) { |
77 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", | 91 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", |
92 "error: destination address argument is invalid\n"); | 106 "error: destination address argument is invalid\n"); |
93 exit(ERROR_USAGE); | 107 exit(ERROR_USAGE); |
94 } | 108 } |
95 if (argc < optind + 2) | 109 if (argc < optind + 2) |
96 return(0); | 110 return(0); |
97 if (strlen(argv[optind+1]) > MAX_MSG_CHARS*2) { | 111 if (strlen(argv[optind+1]) > MAX_MSG_CHARS*3) { |
98 fprintf(stderr, "error: message argument is too long\n"); | 112 fprintf(stderr, "error: message argument is too long\n"); |
99 exit(ERROR_USAGE); | 113 exit(ERROR_USAGE); |
100 } | 114 } |
101 strcpy(msgtext, argv[optind+1]); | 115 strcpy(msgtext, argv[optind+1]); |
102 return(1); | 116 return(1); |
174 if (sms_write_mode == 1) | 188 if (sms_write_mode == 1) |
175 sendafterwr_process(); | 189 sendafterwr_process(); |
176 exit(0); | 190 exit(0); |
177 } | 191 } |
178 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, | 192 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, |
179 &msgtext_gsmlen); | 193 &msgtext_gsmlen, allow_escape); |
180 if (rc == -1) { | 194 if (rc == -1) { |
181 fprintf(stderr, "error: message not valid for GSM7 charset\n"); | 195 fprintf(stderr, "error: message not valid for GSM7 charset\n"); |
182 exit(ERROR_USAGE); | 196 exit(ERROR_USAGE); |
183 } | 197 } |
184 if (rc == -2) { | 198 if (rc == -2) { |
185 fprintf(stderr, "error: message too long for max concat SMS\n"); | 199 fprintf(stderr, "error: message too long for max concat SMS\n"); |
200 exit(ERROR_USAGE); | |
201 } | |
202 if (rc == -3) { | |
203 fprintf(stderr, | |
204 "error: message contains invalid backslash escape\n"); | |
186 exit(ERROR_USAGE); | 205 exit(ERROR_USAGE); |
187 } | 206 } |
188 if (msgtext_gsmlen <= 160) { | 207 if (msgtext_gsmlen <= 160) { |
189 common_init(); | 208 common_init(); |
190 prep_for_pdu_mode(); | 209 prep_for_pdu_mode(); |