comparison decode/pcm-sms-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 unsigned start_recno;
16
17 static char *msgtype[4] = {"received", "received unread", "sent",
18 "stored unsent"};
19
20 static
21 process_cmdline(argc, argv)
22 char **argv;
23 {
24 int c;
25 extern int optind;
26
27 while ((c = getopt(argc, argv, "ehsu")) != EOF)
28 switch (c) {
29 case 'e':
30 ascii_ext_mode = 1;
31 continue;
32 case 'h':
33 global_hexdump_mode = 1;
34 continue;
35 case 's':
36 start_recno = 1;
37 continue;
38 case 'u':
39 ascii_ext_mode = 2;
40 continue;
41 default:
42 fprintf(stderr, "%s: invalid option\n", argv[0]);
43 exit(1);
44 }
45 if (argc != optind + 1) {
46 fprintf(stderr, "usage: %s [options] pcm-sms-binfile\n",
47 argv[0]);
48 exit(1);
49 }
50 infname = argv[optind];
51 }
52
53 main(argc, argv)
54 char **argv;
55 {
56 u_char record[176];
57 unsigned recno;
58
59 process_cmdline(argc, argv);
60 inf = fopen(infname, "r");
61 if (!inf) {
62 perror(infname);
63 exit(1);
64 }
65 pdu_length = 176;
66 for (recno = start_recno; fread(record, sizeof record, 1, inf);
67 recno++) {
68 if (record[0] & 1) {
69 printf("Record #%u is %s message:\n", recno,
70 msgtype[(record[0] >> 1) & 3]);
71 bcopy(record + 1, pdu, 175);
72 process_pdu(0, 1);
73 putchar('\n');
74 } else
75 printf("Record #%u is empty\n\n", recno);
76 }
77 exit(0);
78 }