Date: Fri, 8 Jun 2018 01:55:47 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334822 - head/usr.bin/top Message-ID: <201806080155.w581tlpY012437@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eadler Date: Fri Jun 8 01:55:47 2018 New Revision: 334822 URL: https://svnweb.freebsd.org/changeset/base/334822 Log: top(1): fix several style & const related issues - use parens for return - put function names on newline - sprinkle const where possible Modified: head/usr.bin/top/display.c head/usr.bin/top/machine.c head/usr.bin/top/top.c head/usr.bin/top/username.c head/usr.bin/top/utils.c Modified: head/usr.bin/top/display.c ============================================================================== --- head/usr.bin/top/display.c Fri Jun 8 01:25:07 2018 (r334821) +++ head/usr.bin/top/display.c Fri Jun 8 01:55:47 2018 (r334822) @@ -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); } /* Modified: head/usr.bin/top/machine.c ============================================================================== --- head/usr.bin/top/machine.c Fri Jun 8 01:25:07 2018 (r334821) +++ head/usr.bin/top/machine.c Fri Jun 8 01:55:47 2018 (r334822) @@ -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 Modified: head/usr.bin/top/top.c ============================================================================== --- head/usr.bin/top/top.c Fri Jun 8 01:25:07 2018 (r334821) +++ head/usr.bin/top/top.c Fri Jun 8 01:55:47 2018 (r334822) @@ -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); Modified: head/usr.bin/top/username.c ============================================================================== --- head/usr.bin/top/username.c Fri Jun 8 01:25:07 2018 (r334821) +++ head/usr.bin/top/username.c Fri Jun 8 01:55:47 2018 (r334822) @@ -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 */ } Modified: head/usr.bin/top/utils.c ============================================================================== --- head/usr.bin/top/utils.c Fri Jun 8 01:25:07 2018 (r334821) +++ head/usr.bin/top/utils.c Fri Jun 8 01:55:47 2018 (r334822) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806080155.w581tlpY012437>