top: provide command line sort field override switches

This commit adds two new command line switches dealing
with the potential need to automate/script the setting
of top's current sort field independent of the rcfile.

The -o (lower case) switch requires a lone valid field
name as an argument, from among the 42 currently used.
Then, it overrides the config file's Curwin->sortindx.

And since field names are now translatable, they could
diverge from those reflected in the documentation. So,
a 2nd switch of -O (upper case) is also provided which
outputs all names as translated and understood by top.

(now that we know a '.' + 2 spaces is squeezed to one)
(everything's perfectly justified, but it's just luck)

Reference(s):
Bug-Redhat: https://bugzilla.redhat.com/871844
http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857,9
http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857,15
http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857,16

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2012-12-13 00:00:00 -06:00
committed by Craig Small
parent d747659ad8
commit 407d1fc8f2
4 changed files with 45 additions and 14 deletions

View File

@@ -3177,6 +3177,7 @@ static void parse_args (char **args) {
static const char numbs_str[] = "+,-.0123456789";
float tmp_delay = MAXFLOAT;
char *p;
int i;
while (*args) {
const char *cp = *(args++);
@@ -3212,8 +3213,8 @@ static void parse_args (char **args) {
break;
case 'h':
case 'v':
fprintf(stdout, N_fmt(HELP_cmdline_fmt)
, procps_version, Myname, N_txt(USAGE_abbrev_txt));
puts(fmtmk(N_fmt(HELP_cmdline_fmt)
, procps_version, Myname, N_txt(USAGE_abbrev_txt)));
bye_bye(NULL);
case 'i':
TOGw(Curwin, Show_IDLEPS);
@@ -3226,9 +3227,25 @@ static void parse_args (char **args) {
if (1 != sscanf(cp, "%d", &Loops) || 1 > Loops)
error_exit(fmtmk(N_fmt(BAD_niterate_fmt), cp));
break;
case 'o':
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
for (i = 0; i < P_MAXPFLGS; i++)
if (!STRCMP(cp, N_col(i))) break;
if (i == P_MAXPFLGS)
error_exit(fmtmk(N_fmt(XTRA_sortopt_fmt), cp));
OFFw(Curwin, Show_FOREST);
Curwin->rc.sortindx = i;
cp += strlen(cp);
break;
case 'O':
for (i = 0; i < P_MAXPFLGS; i++)
puts(N_col(i));
bye_bye(NULL);
case 'p':
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
do { int i, pid;
do { int pid;
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));