FreeCalypso > hg > themwi-interim
annotate libutil/imsi_entry.c @ 5:e7b192a5dee5
mtctest: initial import from old ThemWi
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 09 Jun 2024 00:58:38 +0000 |
parents | b161dbfffdaa |
children |
rev | line source |
---|---|
1
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The library function implemented in this module supports IMSI entry |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * at UI level, either in the standard form (long string of digits) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * or in the shorthand notation introduced in fc-sim-tools. |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 grok_imsi_user_arg(arg, dest) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *arg, *dest; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char *cp, *dp; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int n, tail_len, remain; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 if (!isdigit(*arg)) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 cp = arg; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 dp = dest; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 n = 0; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 while (isdigit(*cp)) { |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (n >= 15) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 *dp++ = *cp++; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 n++; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (!*cp) { |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (n < 6) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *dp = '\0'; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(0); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (*cp != '-') |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 cp++; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 tail_len = strlen(cp); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (!tail_len) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 remain = 15 - n; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (remain < tail_len + 1) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 while (remain > tail_len) { |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 *dp++ = '0'; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 remain--; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 while (*cp) { |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (!isdigit(*cp)) |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(-1); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 *dp++ = *cp++; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 *dp = '\0'; |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return(0); |
b161dbfffdaa
include, libutil: port from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |