top(1): bring some structure to commands
Right now this is only used for help text but it'll eventually be used to build up long options array, dispatch commands, etc.
This commit is contained in:
parent
4eef480b46
commit
b26cf3d06c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334919
@ -51,61 +51,56 @@ static int str_addarg(char *str, int len, char *arg, bool first);
|
||||
* either 'h' or '?'.
|
||||
*/
|
||||
|
||||
static const struct command all_commands[] =
|
||||
{
|
||||
{'C', "toggle the displaying of weighted CPU percentage", false },
|
||||
{'d', "change number of displays to show", false},
|
||||
{'e', "list errors generated by last \"kill\" or \"renice\" command", false},
|
||||
{'H', "toggle the displaying of threads", false},
|
||||
{'h', "show this help text", false},
|
||||
{'i', "toggle the displaying of idle processes", false},
|
||||
{'j', "toggle the displaying of jail ID", false},
|
||||
{'J', "display processes for only one jail (+ selects all jails)", false},
|
||||
{'k', "kill processes; send a signal to a list of processes", false},
|
||||
{'q', "quit" , false},
|
||||
{'m', "toggle the display between 'cpu' and 'io' modes", false},
|
||||
{'n', "change number of processes to display", false},
|
||||
{'o', "specify the sort order", false},
|
||||
{'p', "display one process (+ selects all processes)", false},
|
||||
{'P', "toggle the displaying of per-CPU statistics", false},
|
||||
{'r', "renice a process", false},
|
||||
{'s', "change number of seconds to delay between updates", false},
|
||||
{'S', "toggle the displaying of system processes", false},
|
||||
{'a', "toggle the displaying of process titles", false},
|
||||
{'T', "toggle the displaying of thread IDs", false},
|
||||
{'t', "toggle the display of this process", false},
|
||||
{'u', "display processes for only one user (+ selects all users)", false},
|
||||
{'w', "toggle the display of swap use for each process", false},
|
||||
{'z', "toggle the displaying of the system idle process", false },
|
||||
{0, NULL, true}
|
||||
};
|
||||
/* XXX: eventually remove command_chars, but assert they are the same for now */
|
||||
|
||||
void
|
||||
show_help(void)
|
||||
{
|
||||
printf("Top version FreeBSD, %s\n", copyright);
|
||||
fputs("\n\n\
|
||||
A top users display for Unix\n\
|
||||
\n\
|
||||
These single-character commands are available:\n\
|
||||
\n\
|
||||
^L - redraw screen\n\
|
||||
q - quit\n\
|
||||
h or ? - help; show this text\n", stdout);
|
||||
const struct command *curcmd;
|
||||
|
||||
/* not all commands are available with overstrike terminals */
|
||||
printf("Top version FreeBSD, %s\n", copyright);
|
||||
curcmd = all_commands;
|
||||
while (curcmd->c != 0) {
|
||||
if (overstrike && !curcmd->available_to_dumb) {
|
||||
++curcmd;
|
||||
continue;
|
||||
}
|
||||
printf("%c\t- %s\n", curcmd->c, curcmd->desc);
|
||||
++curcmd;
|
||||
}
|
||||
if (overstrike)
|
||||
{
|
||||
fputs("\n\
|
||||
Other commands are also available, but this terminal is not\n\
|
||||
sophisticated enough to handle those commands gracefully.\n\n", stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs("\
|
||||
C - toggle the displaying of weighted CPU percentage\n\
|
||||
d - change number of displays to show\n\
|
||||
e - list errors generated by last \"kill\" or \"renice\" command\n\
|
||||
H - toggle the displaying of threads\n\
|
||||
i or I - toggle the displaying of idle processes\n\
|
||||
j - toggle the displaying of jail ID\n\
|
||||
J - display processes for only one jail (+ selects all jails)\n\
|
||||
k - kill processes; send a signal to a list of processes\n\
|
||||
m - toggle the display between 'cpu' and 'io' modes\n\
|
||||
n or # - change number of processes to display\n", stdout);
|
||||
if (displaymode == DISP_CPU)
|
||||
fputs("\
|
||||
o - specify sort order (pri, size, res, cpu, time, threads, jid, pid)\n",
|
||||
stdout);
|
||||
else
|
||||
fputs("\
|
||||
o - specify sort order (vcsw, ivcsw, read, write, fault, total, jid, pid)\n",
|
||||
stdout);
|
||||
fputs("\
|
||||
p - display one process (+ selects all processes)\n\
|
||||
P - toggle the displaying of per-CPU statistics\n\
|
||||
r - renice a process\n\
|
||||
s - change number of seconds to delay between updates\n\
|
||||
S - toggle the displaying of system processes\n\
|
||||
a - toggle the displaying of process titles\n\
|
||||
T - toggle the displaying of thread IDs\n\
|
||||
t - toggle the display of this process\n\
|
||||
u - display processes for only one user (+ selects all users)\n\
|
||||
w - toggle the display of swap use for each process\n\
|
||||
z - toggle the displaying of the system idle process\n\
|
||||
\n\
|
||||
\n", stdout);
|
||||
Other commands are also available, but this terminal is not\n\
|
||||
sophisticated enough to handle those commands gracefully.\n", stdout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,17 +347,17 @@ show_errors(void)
|
||||
}
|
||||
}
|
||||
|
||||
static char no_proc_specified[] = " no processes specified";
|
||||
static char invalid_signal_number[] = " invalid_signal_number";
|
||||
static char bad_signal_name[] = " bad signal name";
|
||||
static char bad_pri_value[] = " bad priority value";
|
||||
static const char no_proc_specified[] = " no processes specified";
|
||||
static const char invalid_signal_number[] = " invalid_signal_number";
|
||||
static const char bad_signal_name[] = " bad signal name";
|
||||
static const char bad_pri_value[] = " bad priority value";
|
||||
|
||||
/*
|
||||
* kill_procs(str) - send signals to processes, much like the "kill"
|
||||
* command does; invoked in response to 'k'.
|
||||
*/
|
||||
|
||||
char *
|
||||
const char *
|
||||
kill_procs(char *str)
|
||||
{
|
||||
char *nptr;
|
||||
@ -450,7 +445,7 @@ kill_procs(char *str)
|
||||
* "renice" command does; invoked in response to 'r'.
|
||||
*/
|
||||
|
||||
char *
|
||||
const char *
|
||||
renice_procs(char *str)
|
||||
{
|
||||
char negate;
|
||||
|
@ -18,4 +18,10 @@ void show_errors(void);
|
||||
int error_count(void);
|
||||
void show_help(void);
|
||||
|
||||
struct command {
|
||||
char c;
|
||||
const char * const desc;
|
||||
bool available_to_dumb;
|
||||
};
|
||||
|
||||
#endif /* COMMANDS_H */
|
||||
|
@ -43,8 +43,8 @@ extern const char * myname;
|
||||
|
||||
extern int (*compares[])(const void*, const void*);
|
||||
|
||||
char* kill_procs(char *);
|
||||
char* renice_procs(char *);
|
||||
const char* kill_procs(char *);
|
||||
const char* renice_procs(char *);
|
||||
|
||||
extern char copyright[];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user