FreeCalypso > hg > sms-coding-utils
comparison libcoding/gsm7_encode.c @ 0:2d0082216916
libcoding: beginning with a subset of uptools version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 05 Aug 2023 00:46:23 +0000 |
| parents | |
| children | e56bb9f09ff1 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:2d0082216916 |
|---|---|
| 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 outcnt += n; | |
| 33 } | |
| 34 *outlenp = outcnt; | |
| 35 return(0); | |
| 36 } |
