FreeCalypso > hg > themwi-interim
comparison libutil/imsi_entry.c @ 1:b161dbfffdaa
include, libutil: port from old ThemWi
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 08 Jun 2024 23:06:53 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:214716b13c61 | 1:b161dbfffdaa |
---|---|
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 #include <strings.h> | |
10 | |
11 grok_imsi_user_arg(arg, dest) | |
12 char *arg, *dest; | |
13 { | |
14 char *cp, *dp; | |
15 int n, tail_len, remain; | |
16 | |
17 if (!isdigit(*arg)) | |
18 return(-1); | |
19 cp = arg; | |
20 dp = dest; | |
21 n = 0; | |
22 while (isdigit(*cp)) { | |
23 if (n >= 15) | |
24 return(-1); | |
25 *dp++ = *cp++; | |
26 n++; | |
27 } | |
28 if (!*cp) { | |
29 if (n < 6) | |
30 return(-1); | |
31 *dp = '\0'; | |
32 return(0); | |
33 } | |
34 if (*cp != '-') | |
35 return(-1); | |
36 cp++; | |
37 tail_len = strlen(cp); | |
38 if (!tail_len) | |
39 return(-1); | |
40 remain = 15 - n; | |
41 if (remain < tail_len + 1) | |
42 return(-1); | |
43 while (remain > tail_len) { | |
44 *dp++ = '0'; | |
45 remain--; | |
46 } | |
47 while (*cp) { | |
48 if (!isdigit(*cp)) | |
49 return(-1); | |
50 *dp++ = *cp++; | |
51 } | |
52 *dp = '\0'; | |
53 return(0); | |
54 } |