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