comparison smsc-sendmt/imsi_entry.c @ 12:7543aa173634

proto-smsc-sendmt program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Aug 2023 16:36:28 -0800
parents
children
comparison
equal deleted inserted replaced
11:44148d13283c 12:7543aa173634
1 /*
2 * The library function implemented in this module supports IMSI entry
3 * at UI level, either in the standard form (long string of digits)
4 * or in the shorthand notation introduced in fc-sim-tools.
5 */
6
7 #include <ctype.h>
8 #include <string.h>
9
10 int grok_imsi_user_arg(const char *arg, char *dest)
11 {
12 const char *cp;
13 char *dp;
14 int n, tail_len, remain;
15
16 if (!isdigit(*arg))
17 return(-1);
18 cp = arg;
19 dp = dest;
20 n = 0;
21 while (isdigit(*cp)) {
22 if (n >= 15)
23 return(-1);
24 *dp++ = *cp++;
25 n++;
26 }
27 if (!*cp) {
28 if (n < 6)
29 return(-1);
30 *dp = '\0';
31 return(0);
32 }
33 if (*cp != '-')
34 return(-1);
35 cp++;
36 tail_len = strlen(cp);
37 if (!tail_len)
38 return(-1);
39 remain = 15 - n;
40 if (remain < tail_len + 1)
41 return(-1);
42 while (remain > tail_len) {
43 *dp++ = '0';
44 remain--;
45 }
46 while (*cp) {
47 if (!isdigit(*cp))
48 return(-1);
49 *dp++ = *cp++;
50 }
51 *dp = '\0';
52 return(0);
53 }