FreeCalypso > hg > fc-sim-tools
annotate libutil/gsm7_decode.c @ 85:c179deb9bb39
uicc/writecmd.c: forgot to update #include header set
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 11 Apr 2021 02:48:22 +0000 |
parents | c5e7c9e1d857 |
children |
rev | line source |
---|---|
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
2 * This module implements a function for decoding GSM7 strings |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
3 * to ASCII with output to a stdio file; it is an implementation |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
4 * of lossless conversion per our SIM-data-formats spec |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
5 * in freecalypso-docs. |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/types.h> |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
11 static char basic_table[128] = { |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
12 '@', 0, '$', 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
13 0, 0, 'n'|0x80, 0, 0, 'r'|0x80, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
14 0, '_', 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
15 0, 0, 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
16 ' ', '!', '"'|0x80, '#', 0, '%', '&', 0x27, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
17 '(', ')', '*', '+', ',', '-', '.', '/', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
18 '0', '1', '2', '3', '4', '5', '6', '7', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
19 '8', '9', ':', ';', '<', '=', '>', '?', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
20 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
21 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
22 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
23 'X', 'Y', 'Z', 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
24 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
25 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
26 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
27 'x', 'y', 'z', 0, 0, 0, 0, 0 |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 }; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
30 static char escape_table[128] = { |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
32 0, 0, 0, 0, '^', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
33 0, 0, 0, 0, 0, 0, 0, 0, '{', '}', 0, 0, 0, 0, 0, '\\'|0x80, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[', '~', ']', 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
35 '|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
37 0, 0, 0, 0, 0,'E'|0x80,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 }; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 void |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 print_gsm7_string_to_file(data, nbytes, outf) |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 u_char *data; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 unsigned nbytes; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 FILE *outf; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 u_char *dp, *endp; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 int b, c; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 dp = data; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 endp = data + nbytes; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 putc('"', outf); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 while (dp < endp) { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 b = *dp++; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (b == 0x1B) { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (dp >= endp || *dp == 0x1B || *dp == '\n' || |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 *dp == '\r') { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 putc('\\', outf); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 putc('e', outf); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 continue; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 b = *dp++; |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
63 c = escape_table[b]; |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (!c) { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fprintf(outf, "\\e\\%02X", b); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 continue; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } else { |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
69 c = basic_table[b]; |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (!c) { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 fprintf(outf, "\\%02X", b); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 continue; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
75 if (c & 0x80) { |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 putc('\\', outf); |
68
c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
77 c &= 0x7F; |
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 putc(c, outf); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 putc('"', outf); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |