pmap: add range arguments parsing function

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2012-03-03 17:11:45 +01:00
parent 031afacb48
commit ed57504c38

49
pmap.c
View File

@ -382,6 +382,28 @@ static int one_proc(proc_t * p)
return 0;
}
static void range_arguments(char *optarg)
{
char *arg1;
char *arg2;
arg1 = xstrdup(optarg);
arg2 = strchr(arg1, ',');
if (arg2)
*arg2 = '\0';
if (arg2)
++arg2;
else
arg2 = arg1;
if (arg1 && *arg1)
range_low = STRTOUKL(arg1, &arg1, 16);
if (*arg2)
range_high = STRTOUKL(arg2, &arg2, 16);
if (arg1 && (*arg1 || *arg2))
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"),
optarg);
}
int main(int argc, char **argv)
{
unsigned *pidlist;
@ -422,32 +444,7 @@ int main(int argc, char **argv)
q_option = 1;
break;
case 'A':
{
/* FIXME: this should be a function. */
char *walk = optarg;
char *arg1;
char *arg2;
if (walk[1]) {
arg1 = walk + 1;
walk += strlen(walk) - 1;
} else {
arg1 = *++argv;
if (!arg1)
usage(stderr);
}
arg2 = strchr(arg1, ',');
if (arg2)
*arg2 = '\0';
if(arg2) ++arg2;
else arg2 = arg1;
if (arg1 && *arg1)
range_low = STRTOUKL(arg1, &arg1, 16);
if (*arg2)
range_high = STRTOUKL(arg2, &arg2, 16);
if (arg1 && (*arg1 || *arg2))
usage(stderr);
}
range_arguments(optarg);
break;
case 'h':
usage(stdout);