annotate libutil/number_decode.c @ 49:831a224e182b

doc/Back-end-selection article written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Mar 2021 06:24:52 +0000
parents 34bbb0585cab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements functions for decoding phone numbers.
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 static char gsm_address_digits[16] =
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 {'0','1','2','3','4','5','6','7','8','9','*','#','a','b','c','?'};
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 decode_phone_number(data, nbytes, out)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u_char *data;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned nbytes;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char *out;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 u_char *dp, *endp;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int c;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 dp = data;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 endp = data + nbytes;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 while (dp < endp) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 c = *dp & 0xF;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (c == 0xF)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(-1);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 *out++ = gsm_address_digits[c];
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 c = *dp >> 4;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (c == 0xF) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (dp + 1 == endp)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 break;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 else
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 *out++ = gsm_address_digits[c];
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 dp++;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *out = '\0';
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(0);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 decode_address_digits(inbuf, outbuf, ndigits)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 u_char *inbuf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 char *outbuf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 unsigned ndigits;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 u_char *inp = inbuf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char *outp = outbuf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 unsigned n = 0, b;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 while (n < ndigits) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 b = *inp++;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *outp++ = gsm_address_digits[b & 0xF];
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 n++;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (n >= ndigits)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 *outp++ = gsm_address_digits[b >> 4];
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 n++;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *outp = '\0';
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }