FreeCalypso > hg > sms-coding-utils
annotate libcoding/gsm7_encode.c @ 1:13518c86b73c
libcoding: add hexout.c, implementing emit_hex_out()
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 02:06:14 +0000 |
parents | 2d0082216916 |
children | e56bb9f09ff1 |
rev | line source |
---|---|
0
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This library module implements the function for encoding from ISO 8859-1 |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * into the GSM 7-bit default alphabet (03.38 or 23.038). |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 extern u_char gsm7_encode_table[256]; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 latin1_to_gsm7(inbuf, outbuf, outmax, outlenp) |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char *inbuf, *outbuf; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 unsigned outmax, *outlenp; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char *ip = inbuf, *op = outbuf; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 unsigned outcnt = 0, c, n; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 while (c = *ip++) { |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 c = gsm7_encode_table[c]; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (c == 0xFF) |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 return(-1); |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (c & 0x80) |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 n = 2; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 else |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 n = 1; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (outcnt + n > outmax) |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(-2); |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (c & 0x80) { |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 *op++ = 0x1B; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 *op++ = c & 0x7F; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } else |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *op++ = c; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 outcnt += n; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 *outlenp = outcnt; |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(0); |
2d0082216916
libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |