version 1.7, 2003/04/06 20:39:20 |
version 1.8, 2003/06/12 22:30:23 |
|
|
*/ |
*/ |
|
|
void |
void |
show_help() |
show_help(void) |
|
|
{ |
{ |
printf("Top version %s, %s\n", version_string(), copyright); |
printf("Top version %s, %s\n", version_string(), copyright); |
fputs("\n\n\ |
fputs("\n\n\ |
|
|
* Utility routines that help with some of the commands. |
* Utility routines that help with some of the commands. |
*/ |
*/ |
|
|
static char *next_field(str) |
static char * |
|
next_field(char *str) |
char *str; |
|
|
|
{ |
{ |
if ((str = strchr(str, ' ')) == NULL) |
if ((str = strchr(str, ' ')) == NULL) |
{ |
{ |
|
|
|
|
/* if there is nothing left of the string, return NULL */ |
/* if there is nothing left of the string, return NULL */ |
/* This fix is dedicated to Greg Earle */ |
/* This fix is dedicated to Greg Earle */ |
return(*str == '\0' ? NULL : str); |
return (*str == '\0' ? NULL : str); |
} |
} |
|
|
static int scanint(str, intp) |
static int scanint(char *str, int *intp) |
|
|
char *str; |
|
int *intp; |
|
|
|
{ |
{ |
int val = 0; |
int val = 0; |
char ch; |
char ch; |
|
|
|
|
#define STRMAX 80 |
#define STRMAX 80 |
|
|
static char *err_string() |
static char * |
|
err_string(void) |
{ |
{ |
struct errs *errp; |
struct errs *errp; |
int cnt = 0; |
int cnt = 0; |
|
|
* the string "str". |
* the string "str". |
*/ |
*/ |
|
|
static size_t str_adderr(str, len, err) |
static size_t |
|
str_adderr(char *str, size_t len, int err) |
char *str; |
|
size_t len; |
|
int err; |
|
|
|
{ |
{ |
char *msg; |
char *msg; |
size_t msglen; |
size_t msglen; |
|
|
msg = err == 0 ? "Not a number" : strerror(err); |
msg = err == 0 ? "Not a number" : strerror(err); |
|
|
if ((msglen = strlcat(str, ": ", len)) >= len) |
if ((msglen = strlcat(str, ": ", len)) >= len) |
return(msglen); |
return(msglen); |
|
|
return(strlcat(str, msg, len)); |
return(strlcat(str, msg, len)); |
} |
} |
|
|
|
|
* is set (indicating that a comma should NOT be added to the front). |
* is set (indicating that a comma should NOT be added to the front). |
*/ |
*/ |
|
|
static size_t str_addarg(str, len, arg, first) |
static size_t |
|
str_addarg(char *str, size_t len, char *arg, int first) |
char *str; |
|
size_t len; |
|
char *arg; |
|
int first; |
|
|
|
{ |
{ |
size_t msglen; |
size_t msglen; |
|
|
|
|
if ((msglen = strlcat(str, ", ", len)) >= len) |
if ((msglen = strlcat(str, ", ", len)) >= len) |
return(msglen); |
return(msglen); |
} |
} |
return(strlcat(str, arg, len)); |
|
|
return (strlcat(str, arg, len)); |
} |
} |
|
|
/* |
/* |
|
|
* for sorting errors. |
* for sorting errors. |
*/ |
*/ |
|
|
static int err_compar(e1, e2) |
static int |
|
err_compar(const void *e1, const void *e2) |
const void *e1, *e2; |
|
|
|
{ |
{ |
const struct errs *p1 = (struct errs *)e1; |
const struct errs *p1 = (struct errs *)e1; |
const struct errs *p2 = (struct errs *)e2; |
const struct errs *p2 = (struct errs *)e2; |
|
|
* error_count() - return the number of errors currently logged. |
* error_count() - return the number of errors currently logged. |
*/ |
*/ |
|
|
int error_count() |
int |
|
error_count(void) |
{ |
{ |
return(errcnt); |
return(errcnt); |
} |
} |
|
|
* show_errors() - display on stdout the current log of errors. |
* show_errors() - display on stdout the current log of errors. |
*/ |
*/ |
|
|
void show_errors() |
void |
|
show_errors(void) |
{ |
{ |
int cnt = 0; |
int cnt = 0; |
struct errs *errp = errs; |
struct errs *errp = errs; |
|
|
* command does; invoked in response to 'k'. |
* command does; invoked in response to 'k'. |
*/ |
*/ |
|
|
char *kill_procs(str) |
char * |
|
kill_procs(char *str) |
char *str; |
|
|
|
{ |
{ |
char *nptr; |
char *nptr; |
int signum = SIGTERM; /* default */ |
int signum = SIGTERM; /* default */ |
|
|
* "renice" command does; invoked in response to 'r'. |
* "renice" command does; invoked in response to 'r'. |
*/ |
*/ |
|
|
char *renice_procs(str) |
char * |
|
renice_procs(char *str) |
char *str; |
|
|
|
{ |
{ |
char negate; |
char negate; |
int prio; |
int prio; |
|
|
/* return appropriate error string */ |
/* return appropriate error string */ |
return(err_string()); |
return(err_string()); |
} |
} |
|
|