FreeCalypso > hg > sms-coding-utils
comparison libcoding/gsm7_encode2.c @ 15:5854e48d0ef7
sms-gen-tpdu: add support for alphanumeric user-addr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Aug 2023 06:43:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
14:b014abaf0898 | 15:5854e48d0ef7 |
---|---|
1 /* | |
2 * This module implements functions for parsing quoted string | |
3 * arguments intended for GSM7 string encoding, and actually | |
4 * encoding them into GSM7 binary strings. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <ctype.h> | |
9 #include <stdio.h> | |
10 | |
11 extern u_char gsm7_encode_table[256]; | |
12 | |
13 qstring_arg_to_gsm7(arg, record, maxlen) | |
14 char *arg; | |
15 u_char *record; | |
16 unsigned maxlen; | |
17 { | |
18 unsigned acclen, nadd; | |
19 char *cp; | |
20 int c; | |
21 | |
22 cp = arg; | |
23 for (acclen = 0; *cp; ) { | |
24 c = *cp++; | |
25 if (c == '\\') { | |
26 if (*cp == '\0') | |
27 return(-1); | |
28 c = *cp++; | |
29 if (c >= '0' && c <= '7' && isxdigit(*cp)) { | |
30 c = ((c - '0') << 4) | decode_hex_digit(*cp++); | |
31 goto bypass_encoding; | |
32 } | |
33 switch (c) { | |
34 case 'n': | |
35 c = '\n'; | |
36 goto bypass_encoding; | |
37 case 'r': | |
38 c = '\r'; | |
39 goto bypass_encoding; | |
40 case 'e': | |
41 c = 0x1B; | |
42 goto bypass_encoding; | |
43 case 'E': /* Euro currency symbol */ | |
44 c = 0xE5; | |
45 goto bypass_encoding; | |
46 case '"': | |
47 case '\\': | |
48 break; | |
49 default: | |
50 return(-1); | |
51 } | |
52 } | |
53 c = gsm7_encode_table[c]; | |
54 if (c == 0xFF) | |
55 return(-1); | |
56 bypass_encoding: | |
57 if (c & 0x80) | |
58 nadd = 2; | |
59 else | |
60 nadd = 1; | |
61 if (acclen + nadd > maxlen) | |
62 return(-1); | |
63 if (c & 0x80) | |
64 record[acclen++] = 0x1B; | |
65 record[acclen++] = c & 0x7F; | |
66 } | |
67 return(acclen); | |
68 } |