top: make command line switch parsing even more robust
This program has always tried to maintain an extermely
robust command line parsing procedure, far more robust
that what's available with the getopt stuff. But, with
the introduction of our first numeric switch it should
have been made even more robust than, in fact, it was.
This commit will now accomplish such a desirable goal.
Reference(s):
. added '1' command line switch
commit 89db82d143
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
90ac0dabf5
commit
909b37d755
28
top/top.c
28
top/top.c
@ -3676,13 +3676,13 @@ static void parse_args (char **args) {
|
|||||||
else TOGw(Curwin, View_CPUSUM);
|
else TOGw(Curwin, View_CPUSUM);
|
||||||
OFFw(Curwin, View_CPUNOD);
|
OFFw(Curwin, View_CPUNOD);
|
||||||
SETw(Curwin, View_STATES);
|
SETw(Curwin, View_STATES);
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'b':
|
case 'b':
|
||||||
Batch = 1;
|
Batch = 1;
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'c':
|
case 'c':
|
||||||
TOGw(Curwin, Show_CMDLIN);
|
TOGw(Curwin, Show_CMDLIN);
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (cp[1]) ++cp;
|
if (cp[1]) ++cp;
|
||||||
else if (*args) cp = *args++;
|
else if (*args) cp = *args++;
|
||||||
@ -3700,10 +3700,10 @@ static void parse_args (char **args) {
|
|||||||
if (!(got = strchr(get, tolower(*cp))))
|
if (!(got = strchr(get, tolower(*cp))))
|
||||||
error_exit(fmtmk(N_fmt(BAD_memscale_fmt), *cp));
|
error_exit(fmtmk(N_fmt(BAD_memscale_fmt), *cp));
|
||||||
Rc.summ_mscale = (int)(got - get);
|
Rc.summ_mscale = (int)(got - get);
|
||||||
} break;
|
} goto bump_cp;
|
||||||
case 'H':
|
case 'H':
|
||||||
Thread_mode = 1;
|
Thread_mode = 1;
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'v':
|
case 'v':
|
||||||
puts(fmtmk(N_fmt(HELP_cmdline_fmt)
|
puts(fmtmk(N_fmt(HELP_cmdline_fmt)
|
||||||
@ -3712,7 +3712,7 @@ static void parse_args (char **args) {
|
|||||||
case 'i':
|
case 'i':
|
||||||
TOGw(Curwin, Show_IDLEPS);
|
TOGw(Curwin, Show_IDLEPS);
|
||||||
Curwin->rc.maxtasks = 0;
|
Curwin->rc.maxtasks = 0;
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (cp[1]) cp++;
|
if (cp[1]) cp++;
|
||||||
else if (*args) cp = *args++;
|
else if (*args) cp = *args++;
|
||||||
@ -3739,8 +3739,8 @@ static void parse_args (char **args) {
|
|||||||
for (i = 0; i < EU_MAXPFLGS; i++)
|
for (i = 0; i < EU_MAXPFLGS; i++)
|
||||||
puts(N_col(i));
|
puts(N_col(i));
|
||||||
bye_bye(NULL);
|
bye_bye(NULL);
|
||||||
case 'p': {
|
case 'p':
|
||||||
int pid; char *p;
|
{ int pid; char *p;
|
||||||
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
|
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
|
||||||
do {
|
do {
|
||||||
if (cp[1]) cp++;
|
if (cp[1]) cp++;
|
||||||
@ -3749,8 +3749,7 @@ static void parse_args (char **args) {
|
|||||||
if (Monpidsidx >= MONPIDMAX)
|
if (Monpidsidx >= MONPIDMAX)
|
||||||
error_exit(fmtmk(N_fmt(LIMIT_exceed_fmt), MONPIDMAX));
|
error_exit(fmtmk(N_fmt(LIMIT_exceed_fmt), MONPIDMAX));
|
||||||
if (1 != sscanf(cp, "%d", &pid)
|
if (1 != sscanf(cp, "%d", &pid)
|
||||||
|| strpbrk(cp, "+-.")
|
|| strpbrk(cp, wrong_str))
|
||||||
|| 0 > pid)
|
|
||||||
error_exit(fmtmk(N_fmt(BAD_mon_pids_fmt), cp));
|
error_exit(fmtmk(N_fmt(BAD_mon_pids_fmt), cp));
|
||||||
if (!pid) pid = getpid();
|
if (!pid) pid = getpid();
|
||||||
for (i = 0; i < Monpidsidx; i++)
|
for (i = 0; i < Monpidsidx; i++)
|
||||||
@ -3763,10 +3762,10 @@ static void parse_args (char **args) {
|
|||||||
} break;
|
} break;
|
||||||
case 's':
|
case 's':
|
||||||
Secure_mode = 1;
|
Secure_mode = 1;
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'S':
|
case 'S':
|
||||||
TOGw(Curwin, Show_CTIMES);
|
TOGw(Curwin, Show_CTIMES);
|
||||||
break;
|
goto bump_cp;
|
||||||
case 'u':
|
case 'u':
|
||||||
case 'U':
|
case 'U':
|
||||||
{ const char *errmsg;
|
{ const char *errmsg;
|
||||||
@ -3797,8 +3796,9 @@ static void parse_args (char **args) {
|
|||||||
} // end: switch (*cp)
|
} // end: switch (*cp)
|
||||||
|
|
||||||
// advance cp and jump over any numerical args used above
|
// advance cp and jump over any numerical args used above
|
||||||
if (*cp) cp += strspn(&cp[1], numbs_str) + 1;
|
if (*cp) cp += strspn(&cp[1], numbs_str);
|
||||||
|
bump_cp:
|
||||||
|
++cp;
|
||||||
} // end: while (*cp)
|
} // end: while (*cp)
|
||||||
} // end: while (*args)
|
} // end: while (*args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user