FreeCalypso > hg > fc-pcsc-tools
comparison libutil/number_decode.c @ 157:f064dbcc5f41
libutil split from libcommon
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 26 Feb 2021 20:19:58 +0000 |
parents | libcommon/number_decode.c@f5a26c1d0b93 |
children |
comparison
equal
deleted
inserted
replaced
156:5f1f3f6fd865 | 157:f064dbcc5f41 |
---|---|
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 } | |
38 | |
39 decode_address_digits(inbuf, outbuf, ndigits) | |
40 u_char *inbuf; | |
41 char *outbuf; | |
42 unsigned ndigits; | |
43 { | |
44 u_char *inp = inbuf; | |
45 char *outp = outbuf; | |
46 unsigned n = 0, b; | |
47 | |
48 while (n < ndigits) { | |
49 b = *inp++; | |
50 *outp++ = gsm_address_digits[b & 0xF]; | |
51 n++; | |
52 if (n >= ndigits) | |
53 break; | |
54 *outp++ = gsm_address_digits[b >> 4]; | |
55 n++; | |
56 } | |
57 *outp = '\0'; | |
58 } |