FreeCalypso > hg > sms-coding-utils
comparison decode/sms-pdu-decode.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 | |
children |
comparison
equal
deleted
inserted
replaced
28:6e925aa54727 | 29:aae078d9eaa6 |
---|---|
1 #include <sys/types.h> | |
2 #include <ctype.h> | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 #include <strings.h> | |
7 #include <unistd.h> | |
8 | |
9 extern int ascii_ext_mode, global_hexdump_mode; | |
10 extern u_char pdu[176]; | |
11 extern unsigned pdu_length; | |
12 | |
13 static char *infname; | |
14 static FILE *inf; | |
15 static int keep_raw_pdu, pdu_has_sca = 1; | |
16 | |
17 static char input_line[1024]; | |
18 | |
19 static | |
20 process_cmdline(argc, argv) | |
21 char **argv; | |
22 { | |
23 int c; | |
24 extern int optind; | |
25 | |
26 while ((c = getopt(argc, argv, "ehnpu")) != EOF) | |
27 switch (c) { | |
28 case 'e': | |
29 ascii_ext_mode = 1; | |
30 continue; | |
31 case 'h': | |
32 global_hexdump_mode = 1; | |
33 continue; | |
34 case 'n': | |
35 pdu_has_sca = 0; | |
36 continue; | |
37 case 'p': | |
38 keep_raw_pdu = 1; | |
39 continue; | |
40 case 'u': | |
41 ascii_ext_mode = 2; | |
42 continue; | |
43 default: | |
44 fprintf(stderr, "%s: invalid option\n", argv[0]); | |
45 exit(1); | |
46 } | |
47 if (argc > optind) | |
48 infname = argv[optind]; | |
49 } | |
50 | |
51 static | |
52 swallow_empty_line() | |
53 { | |
54 int c; | |
55 | |
56 c = getc(inf); | |
57 if (c != '\n') | |
58 ungetc(c, inf); | |
59 } | |
60 | |
61 main(argc, argv) | |
62 char **argv; | |
63 { | |
64 char *nl; | |
65 int lineno, cc; | |
66 | |
67 process_cmdline(argc, argv); | |
68 if (infname) { | |
69 inf = fopen(infname, "r"); | |
70 if (!inf) { | |
71 perror(infname); | |
72 exit(1); | |
73 } | |
74 } else { | |
75 inf = stdin; | |
76 infname = "stdin"; | |
77 } | |
78 for (lineno = 1; fgets(input_line, sizeof input_line, inf); lineno++) { | |
79 nl = index(input_line, '\n'); | |
80 if (!nl) { | |
81 fprintf(stderr, "%s line %d: no newline\n", | |
82 infname, lineno); | |
83 exit(1); | |
84 } | |
85 *nl = '\0'; | |
86 cc = decode_hex_line(input_line, pdu, sizeof pdu); | |
87 if (cc <= 0) { | |
88 puts(input_line); | |
89 continue; | |
90 } | |
91 pdu_length = cc; | |
92 if (keep_raw_pdu) | |
93 printf("%s\n\n", input_line); | |
94 process_pdu(1, pdu_has_sca); | |
95 putchar('\n'); | |
96 swallow_empty_line(); | |
97 } | |
98 exit(0); | |
99 } |