# HG changeset patch # User Mychaela Falconia # Date 1656311922 28800 # Node ID 40e5097437fa74ea96043f0a291b04e912ad6433 # Parent 87c077b23996f9cc1ff596ce4f46e7e23c85b956 libutil: add grok_imsi_user_arg() diff -r 87c077b23996 -r 40e5097437fa libutil/Makefile --- a/libutil/Makefile Sun Jun 26 18:28:08 2022 -0800 +++ b/libutil/Makefile Sun Jun 26 22:38:42 2022 -0800 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= mncc_utils.o nanp_valid.o numstring.o sockinit.o +OBJS= imsi_entry.o mncc_utils.o nanp_valid.o numstring.o sockinit.o LIB= libutil.a all: ${LIB} diff -r 87c077b23996 -r 40e5097437fa libutil/imsi_entry.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/imsi_entry.c Sun Jun 26 22:38:42 2022 -0800 @@ -0,0 +1,54 @@ +/* + * The library function implemented in this module supports IMSI entry + * at UI level, either in the standard form (long string of digits) + * or in the shorthand notation introduced in fc-sim-tools. + */ + +#include +#include +#include + +grok_imsi_user_arg(arg, dest) + char *arg, *dest; +{ + char *cp, *dp; + int n, tail_len, remain; + + if (!isdigit(*arg)) + return(-1); + cp = arg; + dp = dest; + n = 0; + while (isdigit(*cp)) { + if (n >= 15) + return(-1); + *dp++ = *cp++; + n++; + } + if (!*cp) { + if (n < 6) + return(-1); + *dp = '\0'; + return(0); + } + if (*cp != '-') + return(-1); + cp++; + tail_len = strlen(cp); + if (!tail_len) + return(-1); + remain = 15 - n; + if (remain < tail_len + 1) + return(-1); + while (remain > tail_len) { + *dp++ = '0'; + remain--; + } + while (*cp) { + if (!isdigit(*cp)) + return(-1); + *dp++ = *cp++; + } + *dp = '\0'; + return(0); +}