comparison libutil/number_decode.c @ 8:34bbb0585cab

libutil: import from previous fc-pcsc-tools version
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 05:42:37 +0000
parents
children
comparison
equal deleted inserted replaced
7:b25d4dfe5798 8:34bbb0585cab
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 }