From owner-svn-src-head@freebsd.org Sat Jun 2 00:02:17 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A0F00EFE417; Sat, 2 Jun 2018 00:02:17 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 50CED7DA98; Sat, 2 Jun 2018 00:02:17 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 31C922FD1E; Sat, 2 Jun 2018 00:02:17 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5202Gnw045003; Sat, 2 Jun 2018 00:02:16 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5202FWX044996; Sat, 2 Jun 2018 00:02:15 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806020002.w5202FWX044996@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Sat, 2 Jun 2018 00:02:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334509 - head/usr.bin/top X-SVN-Group: head X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: head/usr.bin/top X-SVN-Commit-Revision: 334509 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jun 2018 00:02:18 -0000 Author: eadler Date: Sat Jun 2 00:02:15 2018 New Revision: 334509 URL: https://svnweb.freebsd.org/changeset/base/334509 Log: top(1): ansify, style(9). and nits - Prefer using ansi prototypes rather than C prototypes - Keep type on separate line from name of function - Try to keep things const where possible. This will help get to WARNS=6 - switch to "bool" where it makes sense Modified: head/usr.bin/top/commands.c head/usr.bin/top/display.c head/usr.bin/top/machine.h head/usr.bin/top/screen.c head/usr.bin/top/top.c head/usr.bin/top/username.c head/usr.bin/top/username.h head/usr.bin/top/utils.c Modified: head/usr.bin/top/commands.c ============================================================================== --- head/usr.bin/top/commands.c Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/commands.c Sat Jun 2 00:02:15 2018 (r334509) @@ -53,8 +53,7 @@ static int str_addarg(char *str, int len, char *arg, i */ void -show_help() - +show_help(void) { printf("Top version FreeBSD, %s\n", copyright); fputs("\n\n\ @@ -198,7 +197,7 @@ static char err_listem[] = #define STRMAX 80 -char *err_string() +char *err_string(void) { struct errs *errp; int cnt = 0; @@ -281,13 +280,7 @@ str_adderr(char *str, int len, int err) */ static int -str_addarg(str, len, arg, first) - -char *str; -int len; -char *arg; -int first; - +str_addarg(char str[], int len, char arg[], int first) { int arglen; @@ -334,8 +327,7 @@ err_compar(const void *p1, const void *p2) */ int -error_count() - +error_count(void) { return(errcnt); } @@ -345,8 +337,7 @@ error_count() */ void -show_errors() - +show_errors(void) { int cnt = 0; struct errs *errp = errs; Modified: head/usr.bin/top/display.c ============================================================================== --- head/usr.bin/top/display.c Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/display.c Sat Jun 2 00:02:15 2018 (r334509) @@ -52,9 +52,6 @@ FILE *debug; #endif -/* imported from screen.c */ -extern int overstrike; - static int lmpid = 0; static int last_hi = 0; /* used in u_process and u_endscreen */ static int lastline = 0; @@ -123,8 +120,8 @@ int y_procs = 7; int y_cpustates = 2; int Header_lines = 7; -int display_resize() - +int +display_resize(void) { int lines; @@ -162,10 +159,7 @@ int display_resize() return(smart_terminal ? lines : Largest); } -int display_updatecpus(statics) - -struct statics *statics; - +int display_updatecpus(struct statics *statics) { int *lp; int lines; @@ -194,10 +188,7 @@ struct statics *statics; return(lines); } -int display_init(statics) - -struct statics *statics; - +int display_init(struct statics * statics) { int lines; char **pp; @@ -249,11 +240,7 @@ struct statics *statics; } void -i_loadave(mpid, avenrun) - -int mpid; -double *avenrun; - +i_loadave(int mpid, double avenrun[]) { int i; @@ -278,11 +265,7 @@ double *avenrun; } void -u_loadave(mpid, avenrun) - -int mpid; -double *avenrun; - +u_loadave(int mpid, double *avenrun) { int i; @@ -318,10 +301,7 @@ double *avenrun; } void -i_timeofday(tod) - -time_t *tod; - +i_timeofday(time_t *tod) { /* * Display the current time. @@ -364,11 +344,7 @@ static char procstates_buffer[MAX_COLS]; */ void -i_procstates(total, brkdn) - -int total; -int *brkdn; - +i_procstates(int total, int *brkdn) { int i; @@ -392,11 +368,7 @@ int *brkdn; } void -u_procstates(total, brkdn) - -int total; -int *brkdn; - +u_procstates(int total, int *brkdn) { static char new[MAX_COLS]; int i; @@ -441,10 +413,7 @@ int *brkdn; } void -i_cpustates(states) - -int *states; - +i_cpustates(int *states) { int i = 0; int value; @@ -487,10 +456,7 @@ for (cpu = 0; cpu < num_cpus; cpu++) { } void -u_cpustates(states) - -int *states; - +u_cpustates(int *states) { int value; char **names; @@ -540,8 +506,7 @@ for (cpu = 0; cpu < num_cpus; cpu++) { } void -z_cpustates() - +z_cpustates(void) { int i = 0; char **names; @@ -633,10 +598,7 @@ i_arc(int *stats) } void -u_arc(stats) - -int *stats; - +u_arc(int *stats) { static char new[MAX_COLS]; @@ -672,10 +634,7 @@ i_carc(int *stats) } void -u_carc(stats) - -int *stats; - +u_carc(int *stats) { static char new[MAX_COLS]; @@ -737,7 +696,7 @@ static int msglen = 0; on the screen (even when next_msg doesn't contain that message). */ void -i_message() +i_message(void) { while (lastline < y_message) @@ -759,8 +718,7 @@ i_message() } void -u_message() - +u_message(void) { i_message(); } @@ -773,10 +731,7 @@ static int header_length; */ char * -trim_header(text) - -char *text; - +trim_header(char *text) { char *s; int width; @@ -801,10 +756,7 @@ char *text; */ void -i_header(text) - -char *text; - +i_header(char *text) { char *s; @@ -825,12 +777,8 @@ char *text; free(s); } -/*ARGSUSED*/ void -u_header(text) - -char *text __unused; /* ignored */ - +u_header(char *text __unused) { if (header_status == ERASE) @@ -849,11 +797,7 @@ char *text __unused; /* ignored */ */ void -i_process(line, thisline) - -int line; -char *thisline; - +i_process(int line, char *thisline) { char *p; char *base; @@ -880,11 +824,7 @@ char *thisline; } void -u_process(line, newline) - -int line; -char *newline; - +u_process(int line, char *newline) { char *optr; int screen_line = line + Header_lines; @@ -928,10 +868,7 @@ char *newline; } void -u_endscreen(hi) - -int hi; - +u_endscreen(int hi) { int screen_line = hi + Header_lines; int i; @@ -1044,8 +981,7 @@ new_message(int type, char *msgfmt, ...) } void -clear_message() - +clear_message(void) { if (clear_eol(msglen) == 1) { @@ -1054,12 +990,7 @@ clear_message() } int -readline(buffer, size, numeric) - -char *buffer; -int size; -int numeric; - +readline(char *buffer, int size, int numeric) { char *ptr = buffer; char ch; @@ -1209,13 +1140,8 @@ static void summary_format(char *str, int *numbers, ch } } -static void line_update(old, new, start, line) - -char *old; -char *new; -int start; -int line; - +static void +line_update(char *old, char *new, int start, int line) { int ch; int diff; @@ -1336,10 +1262,8 @@ int line; * to the original buffer is returned. */ -char *printable(str) - -char *str; - +char * +printable(char str[]) { char *ptr; char ch; @@ -1357,11 +1281,7 @@ char *str; } void -i_uptime(bt, tod) - -struct timeval* bt; -time_t *tod; - +i_uptime(struct timeval *bt, time_t *tod) { time_t uptime; int days, hrs, mins, secs; Modified: head/usr.bin/top/machine.h ============================================================================== --- head/usr.bin/top/machine.h Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/machine.h Sat Jun 2 00:02:15 2018 (r334509) @@ -83,7 +83,6 @@ int machine_init(struct statics *statics); int proc_owner(int pid); /* non-int routines typically used by the machine dependent module */ -char *printable(char *string); extern struct process_select ps; void * Modified: head/usr.bin/top/screen.c ============================================================================== --- head/usr.bin/top/screen.c Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/screen.c Sat Jun 2 00:02:15 2018 (r334509) @@ -61,10 +61,7 @@ static char is_a_terminal = No; #define STDERR 2 void -init_termcap(interactive) - -int interactive; - +init_termcap(int interactive) { char *bufptr; char *PCptr; @@ -186,8 +183,7 @@ int interactive; } void -init_screen() - +init_screen(void) { /* get the old settings for safe keeping */ if (tcgetattr(STDOUT, &old_settings) != -1) @@ -221,8 +217,7 @@ init_screen() } void -end_screen() - +end_screen(void) { /* move to the lower left, clear the line and send "te" */ if (smart_terminal) @@ -241,8 +236,7 @@ end_screen() } void -reinit_screen() - +reinit_screen(void) { /* install our settings if it is a terminal */ if (is_a_terminal) @@ -258,11 +252,8 @@ reinit_screen() } void -get_screensize() - +get_screensize(void) { - - struct winsize ws; if (ioctl (1, TIOCGWINSZ, &ws) != -1) @@ -299,7 +290,7 @@ top_standout(char *msg) } void -top_clear() +top_clear(void) { if (smart_terminal) { @@ -330,8 +321,7 @@ clear_eol(int len) } void -go_home() - +go_home(void) { if (smart_terminal) { Modified: head/usr.bin/top/top.c ============================================================================== --- head/usr.bin/top/top.c Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/top.c Sat Jun 2 00:02:15 2018 (r334509) @@ -70,15 +70,6 @@ static int max_topn; /* maximum displayable processes struct process_select ps; const char * myname = "top"; -char *username(int); - -time_t time(time_t *tloc); - -/* different routines for displaying the user's identification */ -/* (values assigned to get_userid) */ -char *username(int); -char *itoa7(int); - /* pointers to display routines */ static void (*d_loadave)(int mpid, double *avenrun) = i_loadave; static void (*d_procstates)(int total, int *brkdn) = i_procstates; @@ -1153,8 +1144,7 @@ restart: */ static void -reset_display() - +reset_display(void) { d_loadave = i_loadave; d_procstates = i_procstates; Modified: head/usr.bin/top/username.c ============================================================================== --- head/usr.bin/top/username.c Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/username.c Sat Jun 2 00:02:15 2018 (r334509) @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -58,10 +59,7 @@ struct hash_el { static struct hash_el hash_table[Table_size]; -char *username(uid) - -int uid; - +char *username(int uid) { int hashindex; @@ -74,10 +72,7 @@ int uid; return(hash_table[hashindex].name); } -int userid(username) - -char *username; - +int userid(char username[]) { struct passwd *pwd; @@ -97,12 +92,8 @@ char *username; return(pwd->pw_uid); } -int enter_user(uid, name, wecare) - -int uid; -char *name; -int wecare; /* 1 = enter it always, 0 = nice to have */ - +/* wecare 1 = enter it always, 0 = nice to have */ +int enter_user(int uid, char name[], bool wecare) { int hashindex; Modified: head/usr.bin/top/username.h ============================================================================== --- head/usr.bin/top/username.h Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/username.h Sat Jun 2 00:02:15 2018 (r334509) @@ -11,7 +11,9 @@ #ifndef USERNAME_H #define USERNAME_H -int enter_user(int uid, char *name, int wecare); +#include + +int enter_user(int uid, char *name, bool wecare); int get_user(int uid); void init_hash(void); char *username(int uid); Modified: head/usr.bin/top/utils.c ============================================================================== --- head/usr.bin/top/utils.c Sat Jun 2 00:01:07 2018 (r334508) +++ head/usr.bin/top/utils.c Sat Jun 2 00:02:15 2018 (r334509) @@ -59,10 +59,7 @@ atoiwi(char *str) */ _Static_assert(sizeof(int) <= 4, "buffer too small for this sized int"); -char *itoa(val) - -int val; - +char *itoa(int val) { char *ptr; static char buffer[16]; /* result is built here */ @@ -90,10 +87,7 @@ int val; * a front end to a more general routine for efficiency. */ -char *itoa7(val) - -int val; - +char *itoa7(int val) { char *ptr; static char buffer[16]; /* result is built here */ @@ -124,10 +118,7 @@ int val; * positive numbers. If val <= 0 then digits(val) == 0. */ -int digits(val) - -int val; - +int digits(int val) { int cnt = 0; @@ -155,13 +146,10 @@ strecpy(char *to, char *from) * string_index(string, array) - find string in array and return index */ -int string_index(string, array) - -char *string; -char **array; - +int +string_index(char *string, char *array[]) { - int i = 0; + size_t i = 0; while (*array != NULL) { @@ -182,11 +170,7 @@ char **array; * squat about quotes. */ -char **argparse(line, cntp) - -char *line; -int *cntp; - +char **argparse(char *line, int *cntp) { char *from; char *to; @@ -219,10 +203,10 @@ int *cntp; cnt += 3; /* allocate a char * array to hold the pointers */ - argarray = (char **)malloc(cnt * sizeof(char *)); + argarray = malloc(cnt * sizeof(char *)); /* allocate another array to hold the strings themselves */ - args = (char *)malloc(length+2); + args = malloc(length+2); /* initialization for main loop */ from = line; @@ -264,17 +248,11 @@ int *cntp; * "cnt" is size of each array and "diffs" is used for scratch space. * The array "old" is updated on each call. * The routine assumes modulo arithmetic. This function is especially - * useful on BSD mchines for calculating cpu state percentages. + * useful on for calculating cpu state percentages. */ -long percentages(cnt, out, new, old, diffs) - -int cnt; -int *out; -long *new; -long *old; -long *diffs; - +long +percentages(int cnt, int *out, long *new, long *old, long *diffs) { int i; long change; @@ -336,10 +314,8 @@ long *diffs; exceed 9999.9, we use "???". */ -char *format_time(seconds) - -long seconds; - +char * +format_time(long seconds) { static char result[10];