annotate target-utils/libcommon/hexarg.c @ 559:fba5efca2293

gsm-fw/L1/dsp/leadapi.h: #include fix
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 04 Aug 2014 17:59:41 +0000
parents f4fc449a64ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Many commands take hex arguments. This module contains the parse_hexarg()
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * function, which is a wrapper around strtoul that performs some additional
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * checks.
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/types.h>
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <ctype.h>
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 parse_hexarg(arg, maxdigits, valp)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 char *arg;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 int maxdigits;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 u_long *valp;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 {
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *cp = arg, *bp;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 int len;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 if (cp[0] == '0' && (cp[1] == 'x' || cp[1] == 'X'))
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 cp += 2;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 for (bp = cp; *cp; cp++)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 if (!isxdigit(*cp))
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 return(-1);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 len = cp - bp;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 if (len < 1 || len > maxdigits)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 return(-1);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 *valp = strtoul(arg, 0, 16);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 return(0);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 }