comparison uptools/libcoding/gsm7_encode.c @ 356:dbeb4a5628f5

uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Feb 2018 20:18:43 +0000
parents
children 061f8d75083d
comparison
equal deleted inserted replaced
355:8fee530f7850 356:dbeb4a5628f5
1 /*
2 * This library module implements the function for encoding from ISO 8859-1
3 * into the GSM 7-bit default alphabet (03.38 or 23.038).
4 */
5
6 #include <sys/types.h>
7
8 extern u_char gsm7_encode_table[256];
9
10 latin1_to_gsm7(inbuf, outbuf, outmax, outlenp)
11 u_char *inbuf, *outbuf;
12 unsigned outmax, *outlenp;
13 {
14 u_char *ip = inbuf, *op = outbuf;
15 unsigned outcnt = 0, c, n;
16
17 while (c = *ip++) {
18 c = gsm7_encode_table[c];
19 if (c == 0xFF)
20 return(-1);
21 if (c & 0x80)
22 n = 2;
23 else
24 n = 1;
25 if (outcnt + n > outmax)
26 return(-2);
27 if (c & 0x80) {
28 *op++ = 0x1B;
29 *op++ = c & 0x7F;
30 } else
31 *op++ = c;
32 }
33 *outlenp = outcnt;
34 return(0);
35 }