Changeset View
Changeset View
Standalone View
Standalone View
commands.c
Show All 13 Lines | |||||
/* | /* | ||||
* This file contains the routines that implement some of the interactive | * This file contains the routines that implement some of the interactive | ||||
* mode commands. Note that some of the commands are implemented in-line | * mode commands. Note that some of the commands are implemented in-line | ||||
* in "main". This is necessary because they change the global state of | * in "main". This is necessary because they change the global state of | ||||
* "top" (i.e.: changing the number of processes to display). | * "top" (i.e.: changing the number of processes to display). | ||||
*/ | */ | ||||
#include "os.h" | #include "os.h" | ||||
#include <ctype.h> | |||||
#include <signal.h> | |||||
#include <errno.h> | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <sys/resource.h> | #include <sys/resource.h> | ||||
#include <ctype.h> | |||||
#include <errno.h> | |||||
#include <signal.h> | |||||
#include <unistd.h> | |||||
#include "commands.h" | |||||
#include "sigdesc.h" /* generated automatically */ | #include "sigdesc.h" /* generated automatically */ | ||||
#include "top.h" | #include "top.h" | ||||
#include "boolean.h" | #include "boolean.h" | ||||
#include "utils.h" | #include "utils.h" | ||||
#include "machine.h" | |||||
extern int errno; | extern int errno; | ||||
extern char *copyright; | extern char *copyright; | ||||
/* imported from screen.c */ | /* imported from screen.c */ | ||||
extern int overstrike; | extern int overstrike; | ||||
int err_compar(); | int err_compar(); | ||||
char *err_string(); | char *err_string(); | ||||
static int str_adderr(char *str, int len, int err); | |||||
static int str_addarg(char *str, int len, char *arg, int first); | |||||
/* | /* | ||||
* show_help() - display the help screen; invoked in response to | * show_help() - display the help screen; invoked in response to | ||||
* either 'h' or '?'. | * either 'h' or '?'. | ||||
*/ | */ | ||||
void | |||||
show_help() | show_help() | ||||
{ | { | ||||
printf("Top version %s, %s\n", version_string(), copyright); | printf("Top version %s, %s\n", version_string(), copyright); | ||||
fputs("\n\n\ | fputs("\n\n\ | ||||
A top users display for Unix\n\ | A top users display for Unix\n\ | ||||
\n\ | \n\ | ||||
These single-character commands are available:\n\ | These single-character commands are available:\n\ | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | return(NULL); | ||||
*str = '\0'; | *str = '\0'; | ||||
while (*++str == ' ') /* loop */; | while (*++str == ' ') /* loop */; | ||||
/* 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); | ||||
} | } | ||||
int | |||||
scanint(str, intp) | scanint(str, intp) | ||||
char *str; | char *str; | ||||
int *intp; | int *intp; | ||||
{ | { | ||||
register int val = 0; | register int val = 0; | ||||
register char ch; | register char ch; | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | first = No; | ||||
return(stringlen == 0 ? err_listem : string); | return(stringlen == 0 ? err_listem : string); | ||||
} | } | ||||
/* | /* | ||||
* str_adderr(str, len, err) - add an explanation of error "err" to | * str_adderr(str, len, err) - add an explanation of error "err" to | ||||
* the string "str". | * the string "str". | ||||
*/ | */ | ||||
static int | |||||
str_adderr(str, len, err) | str_adderr(str, len, err) | ||||
char *str; | char *str; | ||||
int len; | int len; | ||||
int err; | int err; | ||||
{ | { | ||||
register char *msg; | register char *msg; | ||||
Show All 11 Lines | |||||
} | } | ||||
/* | /* | ||||
* str_addarg(str, len, arg, first) - add the string argument "arg" to | * str_addarg(str, len, arg, first) - add the string argument "arg" to | ||||
* the string "str". This is the first in the group when "first" | * the string "str". This is the first in the group when "first" | ||||
* 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 int | |||||
str_addarg(str, len, arg, first) | str_addarg(str, len, arg, first) | ||||
char *str; | char *str; | ||||
int len; | int len; | ||||
char *arg; | char *arg; | ||||
int first; | int first; | ||||
{ | { | ||||
Show All 16 Lines | (void) strcat(str, ", "); | ||||
return(len - arglen); | return(len - arglen); | ||||
} | } | ||||
/* | /* | ||||
* err_compar(p1, p2) - comparison routine used by "qsort" | * err_compar(p1, p2) - comparison routine used by "qsort" | ||||
* for sorting errors. | * for sorting errors. | ||||
*/ | */ | ||||
int | |||||
err_compar(p1, p2) | err_compar(p1, p2) | ||||
register struct errs *p1, *p2; | register struct errs *p1, *p2; | ||||
{ | { | ||||
register int result; | register int result; | ||||
if ((result = p1->errnum - p2->errnum) == 0) | if ((result = p1->errnum - p2->errnum) == 0) | ||||
{ | { | ||||
return(strcmp(p1->arg, p2->arg)); | return(strcmp(p1->arg, p2->arg)); | ||||
} | } | ||||
return(result); | return(result); | ||||
} | } | ||||
/* | /* | ||||
* error_count() - return the number of errors currently logged. | * error_count() - return the number of errors currently logged. | ||||
*/ | */ | ||||
int | |||||
error_count() | error_count() | ||||
{ | { | ||||
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() | show_errors() | ||||
{ | { | ||||
register int cnt = 0; | register int cnt = 0; | ||||
register struct errs *errp = errs; | register struct errs *errp = errs; | ||||
printf("%d error%s:\n\n", errcnt, errcnt == 1 ? "" : "s"); | printf("%d error%s:\n\n", errcnt, errcnt == 1 ? "" : "s"); | ||||
while (cnt++ < errcnt) | while (cnt++ < errcnt) | ||||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |