top(1): fix several style & const related issues
- use parens for return - put function names on newline - sprinkle const where possible
This commit is contained in:
parent
bd60b9b499
commit
d408c8f742
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334822
@ -464,8 +464,8 @@ void
|
||||
u_cpustates(int *states)
|
||||
{
|
||||
int value;
|
||||
char **names;
|
||||
char *thisname;
|
||||
const char * const *names;
|
||||
const char *thisname;
|
||||
int *lp;
|
||||
int *colp;
|
||||
int cpu;
|
||||
@ -514,40 +514,34 @@ void
|
||||
z_cpustates(void)
|
||||
{
|
||||
int i = 0;
|
||||
char **names;
|
||||
const char **names;
|
||||
char *thisname;
|
||||
int *lp;
|
||||
int cpu, value;
|
||||
|
||||
for (cpu = 0; cpu < num_cpus; cpu++) {
|
||||
names = cpustate_names;
|
||||
for (cpu = 0; cpu < num_cpus; cpu++) {
|
||||
names = cpustate_names;
|
||||
|
||||
/* show tag and bump lastline */
|
||||
if (num_cpus == 1)
|
||||
printf("\nCPU: ");
|
||||
else {
|
||||
value = printf("\nCPU %d: ", cpu);
|
||||
while (value++ <= cpustates_column)
|
||||
printf(" ");
|
||||
}
|
||||
lastline++;
|
||||
/* show tag and bump lastline */
|
||||
if (num_cpus == 1)
|
||||
printf("\nCPU: ");
|
||||
else {
|
||||
value = printf("\nCPU %d: ", cpu);
|
||||
while (value++ <= cpustates_column)
|
||||
printf(" ");
|
||||
}
|
||||
lastline++;
|
||||
|
||||
while ((thisname = *names++) != NULL)
|
||||
{
|
||||
if (*thisname != '\0')
|
||||
{
|
||||
printf("%s %% %s", (i++ % num_cpustates) == 0 ? "" : ", ", thisname);
|
||||
}
|
||||
while ((thisname = *names++) != NULL)
|
||||
{
|
||||
if (*thisname != '\0')
|
||||
{
|
||||
printf("%s %% %s", (i++ % num_cpustates) == 0 ? "" : ", ", thisname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fill the "last" array with all -1s, to insure correct updating */
|
||||
lp = lcpustates;
|
||||
i = num_cpustates * num_cpus;
|
||||
while (--i >= 0)
|
||||
{
|
||||
*lp++ = -1;
|
||||
}
|
||||
memset(lcpustates, -1, num_cpustates * num_cpus);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -260,7 +260,7 @@ find_uid(uid_t needle, int *haystack)
|
||||
for (; i < TOP_MAX_UIDS; ++i)
|
||||
if ((uid_t)haystack[i] == needle)
|
||||
return 1;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
@ -615,7 +615,7 @@ get_system_info(struct system_info *si)
|
||||
static const struct kinfo_proc *
|
||||
get_old_proc(struct kinfo_proc *pp)
|
||||
{
|
||||
struct kinfo_proc **oldpp, *oldp;
|
||||
const struct kinfo_proc * const *oldpp, *oldp;
|
||||
|
||||
/*
|
||||
* If this is the first fetch of the kinfo_procs then we don't have
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*-
|
||||
* Top users/processes display for Unix
|
||||
*
|
||||
* This program may be freely redistributed,
|
||||
@ -144,7 +144,7 @@ handle_user(char *buf, size_t buflen)
|
||||
if (readline(buf, buflen, false) <= 0)
|
||||
{
|
||||
clear_message();
|
||||
return rc;
|
||||
return (rc);
|
||||
}
|
||||
|
||||
if (buf[0] == '+' || buf[0] == '-')
|
||||
@ -186,7 +186,7 @@ handle_user(char *buf, size_t buflen)
|
||||
|
||||
end:
|
||||
putchar('\r');
|
||||
return rc;
|
||||
return (rc);
|
||||
}
|
||||
|
||||
int
|
||||
@ -214,7 +214,7 @@ main(int argc, char *argv[])
|
||||
char *env_top;
|
||||
const char **preset_argv;
|
||||
int preset_argc = 0;
|
||||
char **av;
|
||||
const char **av;
|
||||
int ac;
|
||||
bool dostates = false;
|
||||
bool do_unames = true;
|
||||
@ -523,7 +523,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
if ((order_index = string_index(order_name, statics.order_names)) == -1)
|
||||
{
|
||||
char **pp;
|
||||
const char * const *pp;
|
||||
|
||||
fprintf(stderr, "%s: '%s' is not a recognized sorting order.\n",
|
||||
myname, order_name);
|
||||
|
@ -102,7 +102,7 @@ int enter_user(int uid, char name[], bool wecare)
|
||||
if (!is_empty_hash(hashindex))
|
||||
{
|
||||
if (!wecare)
|
||||
return 0; /* Don't clobber a slot for trash */
|
||||
return (0); /* Don't clobber a slot for trash */
|
||||
if (hash_table[hashindex].uid == uid)
|
||||
return(hashindex); /* Fortuitous find */
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ atoiwi(const char *str)
|
||||
*/
|
||||
_Static_assert(sizeof(int) <= 4, "buffer too small for this sized int");
|
||||
|
||||
char *itoa(unsigned int val)
|
||||
char *
|
||||
itoa(unsigned int val)
|
||||
{
|
||||
char *ptr;
|
||||
static char buffer[16]; /* result is built here */
|
||||
@ -94,7 +95,8 @@ char *itoa(unsigned int val)
|
||||
* a front end to a more general routine for efficiency.
|
||||
*/
|
||||
|
||||
char *itoa7(int val)
|
||||
char *
|
||||
itoa7(int val)
|
||||
{
|
||||
char *ptr;
|
||||
static char buffer[16]; /* result is built here */
|
||||
@ -125,7 +127,8 @@ char *itoa7(int val)
|
||||
* positive numbers. If val <= 0 then digits(val) == 0.
|
||||
*/
|
||||
|
||||
int digits(int val)
|
||||
int
|
||||
digits(int val)
|
||||
{
|
||||
int cnt = 0;
|
||||
|
||||
@ -182,7 +185,7 @@ argparse(char *line, int *cntp)
|
||||
ap++;
|
||||
}
|
||||
}
|
||||
return argv;
|
||||
return (argv);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -313,7 +316,8 @@ format_time(long seconds)
|
||||
|
||||
#define NUM_STRINGS 8
|
||||
|
||||
char *format_k(int amt)
|
||||
char *
|
||||
format_k(int amt)
|
||||
{
|
||||
static char retarray[NUM_STRINGS][16];
|
||||
static int index = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user