FreeCalypso > hg > freecalypso-tools
annotate uptools/libcoding/gsm7_encode.c @ 1014:961efadd530a default tip
fc-shell TCH DL handler: add support for CSD modes
TCH DL capture mechanism in FC Tourmaline firmware has been extended
to support CSD modes in addition to speech - add the necessary support
on the host tools side.
It needs to be noted that this mechanism in its present state does NOT
provide the debug utility value that was sought: as we learned only
after the code was implemented, TI's DSP has a misfeature in that the
buffer we are reading (a_dd_0[]) is zeroed out when the IDS block
is enabled, i.e., we are reading all zeros and not the real DL bits
we were after. But since the code has already been written, we are
keeping it - perhaps we can do some tests with IDS disabled.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 26 Nov 2024 06:27:43 +0000 |
parents | ec7e23d5151f |
children |
rev | line source |
---|---|
356
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This library module implements the function for encoding from ISO 8859-1 |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * into the GSM 7-bit default alphabet (03.38 or 23.038). |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
7 #include <ctype.h> |
356
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 extern u_char gsm7_encode_table[256]; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
11 static unsigned |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
12 handle_escape(ipp) |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
13 u_char **ipp; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
14 { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
15 unsigned c; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
16 |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
17 c = *(*ipp)++; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
18 if (c >= '0' && c <= '7' && isxdigit(**ipp)) { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
19 c = ((c - '0') << 4) | decode_hex_digit(*(*ipp)++); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
20 return c; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
21 } |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
22 switch (c) { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
23 case 'n': |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
24 return '\n'; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
25 case 'r': |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
26 return '\r'; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
27 case 'e': |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
28 return 0x1B; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
29 case 'E': /* Euro currency symbol */ |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
30 return 0xE5; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
31 case '"': |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
32 case '\\': |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
33 c = gsm7_encode_table[c]; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
34 return c; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
35 default: |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
36 return 0xFF; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
37 } |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
38 } |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
39 |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
40 latin1_to_gsm7(inbuf, outbuf, outmax, outlenp, allow_escape) |
356
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 u_char *inbuf, *outbuf; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 unsigned outmax, *outlenp; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 { |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 u_char *ip = inbuf, *op = outbuf; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 unsigned outcnt = 0, c, n; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 while (c = *ip++) { |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
48 if (c == '\\' && allow_escape) { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
49 c = handle_escape(&ip); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
50 if (c == 0xFF) |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
51 return(-3); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
52 } else { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
53 c = gsm7_encode_table[c]; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
54 if (c == 0xFF) |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
55 return(-1); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
359
diff
changeset
|
56 } |
356
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (c & 0x80) |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 n = 2; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 else |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 n = 1; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (outcnt + n > outmax) |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(-2); |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (c & 0x80) { |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 *op++ = 0x1B; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 *op++ = c & 0x7F; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } else |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 *op++ = c; |
359
061f8d75083d
uptools/libcoding/gsm7_encode.c: bug found on review
Mychaela Falconia <falcon@freecalypso.org>
parents:
356
diff
changeset
|
68 outcnt += n; |
356
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 *outlenp = outcnt; |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(0); |
dbeb4a5628f5
uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |