top: provide -1 command line switch as 'Cpu(s)' toggle

If built without ./configure --disable-modern-top, the
program displays each cpu individually providing there
is sufficient vertical screen real estate. For massive
SMP environments this will necessitate use of a config
file where the cpu summary toggle ('1') could be saved
via the 'W' command. But, an rcfile may not be viable.

So this commit introduces a '1' command line switch to
emulate exactly the effects of the interactive toggle.

And since it is our first numeric switch some existing
parsing logic had to be changed slightly. Such changes
are, in truth, an improvement. For example, instead of
seeing "inappropriate '2'" with ./top -2 we'll now see
the vastly more appropriate error "unknown option '2'.

References(s):
https://gitlab.com/procps-ng/procps/issues/55

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2017-03-10 00:00:00 -06:00
committed by Craig Small
parent fb48b5d9fb
commit 89db82d143
4 changed files with 22 additions and 6 deletions

View File

@@ -3650,6 +3650,7 @@ static void parse_args (char **args) {
. bunched args are actually handled properly and none are ignored
. we tolerate NO whitespace and NO switches -- maybe too tolerant? */
static const char numbs_str[] = "+,-.0123456789";
static const char wrong_str[] = "+,-.";
float tmp_delay = FLT_MAX;
int i;
@@ -3666,10 +3667,16 @@ static void parse_args (char **args) {
case '-':
if (cp[1]) ++cp;
else if (*args) cp = *args++;
if (strspn(cp, numbs_str))
if (strspn(cp, wrong_str))
error_exit(fmtmk(N_fmt(WRONG_switch_fmt)
, cp, Myname, N_txt(USAGE_abbrev_txt)));
continue;
case '1': // ensure behavior identical to run-time toggle
if (CHKw(Curwin, View_CPUNOD)) OFFw(Curwin, View_CPUSUM);
else TOGw(Curwin, View_CPUSUM);
OFFw(Curwin, View_CPUNOD);
SETw(Curwin, View_STATES);
break;
case 'b':
Batch = 1;
break;
@@ -3769,8 +3776,7 @@ static void parse_args (char **args) {
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if ((errmsg = user_certify(Curwin, cp, ch))) error_exit(errmsg);
cp += strlen(cp);
break;
}
} break;
case 'w':
{ const char *pn = NULL;
int ai = 0, ci = 0;