annotate uptools/libcoding/gsm7_encode.c @ 710:c1f72d807250

CHANGES: tiffs-mkfs addition
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 23 May 2020 03:39:48 +0000
parents 061f8d75083d
children ec7e23d5151f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 extern u_char gsm7_encode_table[256];
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 latin1_to_gsm7(inbuf, outbuf, outmax, outlenp)
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u_char *inbuf, *outbuf;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned outmax, *outlenp;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char *ip = inbuf, *op = outbuf;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 unsigned outcnt = 0, c, n;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 while (c = *ip++) {
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 c = gsm7_encode_table[c];
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (c == 0xFF)
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(-1);
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (c & 0x80)
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 n = 2;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 else
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 n = 1;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (outcnt + n > outmax)
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(-2);
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (c & 0x80) {
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *op++ = 0x1B;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 *op++ = c & 0x7F;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 } else
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 *op++ = c;
359
061f8d75083d uptools/libcoding/gsm7_encode.c: bug found on review
Mychaela Falconia <falcon@freecalypso.org>
parents: 356
diff changeset
32 outcnt += n;
356
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *outlenp = outcnt;
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(0);
dbeb4a5628f5 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }