comparison libcommon/number_decode.c @ 8:4a9bf783491d

phone number decoding factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 00:07:24 +0000
parents
children f5a26c1d0b93
comparison
equal deleted inserted replaced
7:4360a7906f34 8:4a9bf783491d
1 /*
2 * This module implements functions for decoding phone numbers.
3 */
4
5 #include <sys/types.h>
6
7 static char gsm_address_digits[16] =
8 {'0','1','2','3','4','5','6','7','8','9','*','#','a','b','c','?'};
9
10 decode_phone_number(data, nbytes, out)
11 u_char *data;
12 unsigned nbytes;
13 char *out;
14 {
15 u_char *dp, *endp;
16 int c;
17
18 dp = data;
19 endp = data + nbytes;
20 while (dp < endp) {
21 c = *dp & 0xF;
22 if (c == 0xF)
23 return(-1);
24 *out++ = gsm_address_digits[c];
25 c = *dp >> 4;
26 if (c == 0xF) {
27 if (dp + 1 == endp)
28 break;
29 else
30 return(-1);
31 }
32 *out++ = gsm_address_digits[c];
33 dp++;
34 }
35 *out = '\0';
36 return(0);
37 }