annotate libcoding/utf8_decode.c @ 13:b8d8f8a3cdb7

scripts: wrappers for network-side SMS-DELIVER PDU generation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Aug 2023 05:11:21 +0000
parents 2d0082216916
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 a function that converts text input
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * from UTF-8 to ISO 8859-1, rejecting any input Unicode characters
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * that aren't in the 8859-1 range. The conversion in done in place.
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
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 utf8_to_latin1(buf)
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 u_char *buf;
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 u_char *ip = buf, *op = buf;
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int c, c2;
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 while (c = *ip++) {
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (c < 0x80) {
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 *op++ = c;
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 continue;
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 }
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (c != 0xC2 && c != 0xC3)
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(-1);
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 c2 = *ip++;
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (c2 < 0x80 || c2 > 0xBF)
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return(-1);
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *op++ = ((c & 3) << 6) | (c2 & 0x3F);
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 *op = '\0';
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(0);
2d0082216916 libcoding: beginning with a subset of uptools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }