comparison uptools/sms-pdu-decode/pcm-sms-decode.c @ 600:31e219088cd6

uptools/sms-pdu-decode: pcm-sms-decode utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Feb 2020 02:47:43 +0000
parents
children 3a80bfa87496
comparison
equal deleted inserted replaced
599:18bfc10ba20e 600:31e219088cd6
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
16 static char *msgtype[4] = {"received", "received unread", "sent",
17 "stored unsent"};
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, "ehu")) != 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 'u':
35 ascii_ext_mode = 2;
36 continue;
37 default:
38 fprintf(stderr, "%s: invalid option\n", argv[0]);
39 exit(1);
40 }
41 if (argc != optind + 1) {
42 fprintf(stderr, "usage: %s [options] pcm-sms-binfile\n",
43 argv[0]);
44 exit(1);
45 }
46 infname = argv[optind];
47 }
48
49 main(argc, argv)
50 char **argv;
51 {
52 u_char record[176];
53 unsigned recno;
54
55 process_cmdline(argc, argv);
56 inf = fopen(infname, "r");
57 if (!inf) {
58 perror(infname);
59 exit(1);
60 }
61 pdu_length = 176;
62 for (recno = 0; fread(record, sizeof record, 1, inf); recno++) {
63 if (record[0] & 1) {
64 printf("Record #%u is %s message:\n", recno,
65 msgtype[(record[0] >> 1) & 3]);
66 bcopy(record + 1, pdu, 175);
67 process_pdu(0);
68 putchar('\n');
69 } else
70 printf("Record #%u is empty\n\n", recno);
71 }
72 exit(0);
73 }