From 037853325081b53767df0c034cda3c14ea99dc0d Mon Sep 17 00:00:00 2001 From: ngie Date: Sun, 22 May 2016 04:17:00 +0000 Subject: [PATCH] Silence top(1) compiler warnings The contrib/top code is no longer maintained upstream (last pulled 16 years ago). The K&R-style followed by the code spews -Wimplicit-int and -Wreturn-type warnings, amongst others. This silences 131 warnings with as little modification as possible by adding necessary return types, definitions, headers, and header guards, and missing header includes. The 5 warnings that remain are due to undeclared ncurses references. I didn't include curses.h and term.h because there are several local functions and macros that conflict with those definitions. MFC after: 3 weeks Reviewed by: cem, ngie Submitted by: Randy Westlund Differential Revision: https://reviews.freebsd.org/D6468 --- contrib/top/commands.c | 20 ++++++++++++--- contrib/top/commands.h | 21 ++++++++++++++++ contrib/top/display.c | 44 +++++++++++++++++++++++++++------ contrib/top/display.h | 34 ++++++++++++++++++++++++++ contrib/top/machine.h | 16 +++++++++--- contrib/top/screen.c | 10 +++++++- contrib/top/screen.h | 12 ++++++++- contrib/top/top.c | 55 +++++++++++++++++------------------------- contrib/top/top.h | 5 ++++ contrib/top/username.c | 16 ++++++++---- contrib/top/username.h | 23 ++++++++++++++++++ contrib/top/utils.h | 2 ++ contrib/top/version.c | 3 +++ 13 files changed, 207 insertions(+), 54 deletions(-) create mode 100644 contrib/top/commands.h create mode 100644 contrib/top/username.h diff --git a/contrib/top/commands.c b/contrib/top/commands.c index 707366d8aa48..53a45eeaea5b 100644 --- a/contrib/top/commands.c +++ b/contrib/top/commands.c @@ -19,16 +19,21 @@ */ #include "os.h" -#include -#include -#include + #include #include +#include +#include +#include +#include + +#include "commands.h" #include "sigdesc.h" /* generated automatically */ #include "top.h" #include "boolean.h" #include "utils.h" +#include "machine.h" extern int errno; @@ -39,12 +44,15 @@ extern int overstrike; int err_compar(); 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 * either 'h' or '?'. */ +void show_help() { @@ -123,6 +131,7 @@ register char *str; return(*str == '\0' ? NULL : str); } +int scanint(str, intp) char *str; @@ -262,6 +271,7 @@ char *err_string() * the string "str". */ +static int str_adderr(str, len, err) char *str; @@ -289,6 +299,7 @@ int err; * is set (indicating that a comma should NOT be added to the front). */ +static int str_addarg(str, len, arg, first) char *str; @@ -321,6 +332,7 @@ int first; * for sorting errors. */ +int err_compar(p1, p2) register struct errs *p1, *p2; @@ -339,6 +351,7 @@ register struct errs *p1, *p2; * error_count() - return the number of errors currently logged. */ +int error_count() { @@ -349,6 +362,7 @@ error_count() * show_errors() - display on stdout the current log of errors. */ +void show_errors() { diff --git a/contrib/top/commands.h b/contrib/top/commands.h new file mode 100644 index 000000000000..7e5f3e996004 --- /dev/null +++ b/contrib/top/commands.h @@ -0,0 +1,21 @@ +/* + * Top users/processes display for Unix + * Version 3 + * + * This program may be freely redistributed, + * but this entire comment MUST remain intact. + * + * Copyright (c) 1984, 1989, William LeFebvre, Rice University + * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University + * Copyright (c) 2016, Randy Westlund + * + * $FreeBSD$ + */ +#ifndef COMMANDS_H +#define COMMANDS_H + +void show_errors(void); +int error_count(void); +void show_help(void); + +#endif /* COMMANDS_H */ diff --git a/contrib/top/display.c b/contrib/top/display.c index e65ae24f528f..ade61d660726 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -29,9 +29,12 @@ */ #include "os.h" + +#include + #include #include -#include +#include #include "screen.h" /* interface to screen package */ #include "layout.h" /* defines for screen position layout */ @@ -56,7 +59,6 @@ static int display_width = MAX_COLS; #define lineindex(l) ((l)*display_width) -char *printable(); /* things initialized by display_init and used thruout */ @@ -239,6 +241,7 @@ struct statics *statics; return(lines); } +void i_loadave(mpid, avenrun) int mpid; @@ -267,6 +270,7 @@ double *avenrun; lmpid = mpid; } +void u_loadave(mpid, avenrun) int mpid; @@ -306,6 +310,7 @@ double *avenrun; } } +void i_timeofday(tod) time_t *tod; @@ -351,6 +356,7 @@ static char procstates_buffer[MAX_COLS]; * lastline is valid */ +void i_procstates(total, brkdn) int total; @@ -378,6 +384,7 @@ int *brkdn; memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); } +void u_procstates(total, brkdn) int total; @@ -460,9 +467,10 @@ char *cpustates_tag() } #endif +void i_cpustates(states) -register int *states; +int *states; { register int i = 0; @@ -505,9 +513,10 @@ for (cpu = 0; cpu < num_cpus; cpu++) { memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus); } +void u_cpustates(states) -register int *states; +int *states; { register int value; @@ -557,6 +566,7 @@ for (cpu = 0; cpu < num_cpus; cpu++) { } } +void z_cpustates() { @@ -606,6 +616,7 @@ for (cpu = 0; cpu < num_cpus; cpu++) { char memory_buffer[MAX_COLS]; +void i_memory(stats) int *stats; @@ -619,6 +630,7 @@ int *stats; fputs(memory_buffer, stdout); } +void u_memory(stats) int *stats; @@ -639,13 +651,14 @@ int *stats; */ char arc_buffer[MAX_COLS]; +void i_arc(stats) int *stats; { if (arc_names == NULL) - return (0); + return; fputs("\nARC: ", stdout); lastline++; @@ -655,6 +668,7 @@ int *stats; fputs(arc_buffer, stdout); } +void u_arc(stats) int *stats; @@ -663,7 +677,7 @@ int *stats; static char new[MAX_COLS]; if (arc_names == NULL) - return (0); + return; /* format the new line */ summary_format(new, stats, arc_names); @@ -680,6 +694,7 @@ int *stats; char swap_buffer[MAX_COLS]; +void i_swap(stats) int *stats; @@ -693,6 +708,7 @@ int *stats; fputs(swap_buffer, stdout); } +void u_swap(stats) int *stats; @@ -724,6 +740,7 @@ static int msglen = 0; /* Invariant: msglen is always the length of the message currently displayed on the screen (even when next_msg doesn't contain that message). */ +void i_message() { @@ -745,6 +762,7 @@ i_message() } } +void u_message() { @@ -786,6 +804,7 @@ char *text; * Assumptions: cursor is on the previous line and lastline is consistent */ +void i_header(text) char *text; @@ -811,9 +830,10 @@ char *text; } /*ARGSUSED*/ +void u_header(text) -char *text; /* ignored */ +char *text __unused; /* ignored */ { @@ -832,6 +852,7 @@ char *text; /* ignored */ * Assumptions: lastline is consistent */ +void i_process(line, thisline) int line; @@ -862,6 +883,7 @@ char *thisline; memzero(p, display_width - (p - base)); } +void u_process(line, newline) int line; @@ -909,9 +931,10 @@ char *newline; } } +void u_endscreen(hi) -register int hi; +int hi; { register int screen_line = hi + Header_lines; @@ -969,6 +992,7 @@ register int hi; } } +void display_header(t) int t; @@ -985,6 +1009,7 @@ int t; } /*VARARGS2*/ +void new_message(type, msgfmt, a1, a2, a3) int type; @@ -1025,6 +1050,7 @@ caddr_t a1, a2, a3; } } +void clear_message() { @@ -1034,6 +1060,7 @@ clear_message() } } +int readline(buffer, size, numeric) char *buffer; @@ -1336,6 +1363,7 @@ char *str; return(str); } +void i_uptime(bt, tod) struct timeval* bt; diff --git a/contrib/top/display.h b/contrib/top/display.h index 4bd7ce77e08c..5d5a07a1aece 100644 --- a/contrib/top/display.h +++ b/contrib/top/display.h @@ -5,3 +5,37 @@ #define MT_standout 1 #define MT_delayed 2 +#include "machine.h" + +int display_updatecpus(struct statics *statics); +void clear_message(void); +int display_resize(void); +void i_header(char *text); +char *printable(char *string); +char *cpustates_tag(void); +void display_header(int t); +int display_init(struct statics *statics); +void i_arc(int *stats); +void i_cpustates(int *states); +void i_loadave(int mpid, double *avenrun); +void i_memory(int *stats); +void i_message(void); +void i_process(int line, char *thisline); +void i_procstates(int total, int *brkdn); +void i_swap(int *stats); +void i_timeofday(time_t *tod); +void i_uptime(struct timeval *bt, time_t *tod); +void new_message(); +int readline(char *buffer, int size, int numeric); +char *trim_header(char *text); +void u_arc(int *stats); +void u_cpustates(int *states); +void u_endscreen(int hi); +void u_header(char *text); +void u_loadave(int mpid, double *avenrun); +void u_memory(int *stats); +void u_message(void); +void u_process(int line, char *newline); +void u_procstates(int total, int *brkdn); +void u_swap(int *stats); +void z_cpustates(void); diff --git a/contrib/top/machine.h b/contrib/top/machine.h index 41da6008647b..3aad75886b45 100644 --- a/contrib/top/machine.h +++ b/contrib/top/machine.h @@ -7,6 +7,10 @@ * module. It is NOT machine dependent and should not need to be changed * for any specific machine. */ +#ifndef MACHINE_H +#define MACHINE_H + +#include "top.h" /* * the statics struct is filled in by machine_init @@ -74,8 +78,14 @@ struct process_select /* routines defined by the machine dependent module */ -char *format_header(); -char *format_next_process(); +char *format_header(); +char *format_next_process(); +void toggle_pcpustats(void); +void get_system_info(struct system_info *si); +int machine_init(struct statics *statics, char do_unames); +int proc_owner(int pid); /* non-int routines typically used by the machine dependent module */ -char *printable(); +char *printable(); + +#endif /* MACHINE_H */ diff --git a/contrib/top/screen.c b/contrib/top/screen.c index 8eb1ccd1b43c..cd0590e89764 100644 --- a/contrib/top/screen.c +++ b/contrib/top/screen.c @@ -50,7 +50,6 @@ extern char *myname; -int putstdout(); int overstrike; int screen_length; @@ -236,6 +235,7 @@ int interactive; #endif } +void init_screen() { @@ -326,6 +326,7 @@ init_screen() } } +void end_screen() { @@ -356,6 +357,7 @@ end_screen() } } +void reinit_screen() { @@ -383,6 +385,7 @@ reinit_screen() } } +void get_screensize() { @@ -428,6 +431,7 @@ get_screensize() lower_left[sizeof(lower_left) - 1] = '\0'; } +void standout(msg) char *msg; @@ -445,6 +449,7 @@ char *msg; } } +void clear() { @@ -454,6 +459,7 @@ clear() } } +int clear_eol(len) int len; @@ -478,6 +484,7 @@ int len; return(-1); } +void go_home() { @@ -489,6 +496,7 @@ go_home() /* This has to be defined as a subroutine for tputs (instead of a macro) */ +void putstdout(ch) char ch; diff --git a/contrib/top/screen.h b/contrib/top/screen.h index 50105e4390ad..856a1cf58413 100644 --- a/contrib/top/screen.h +++ b/contrib/top/screen.h @@ -28,4 +28,14 @@ extern int screen_length; extern int screen_width; /* a function that puts a single character on stdout */ -int putstdout(); +void putstdout(char ch); +int clear_eol(int len); +void standout(char *msg); +void clear(void); +void go_home(void); +void reinit_screen(void); +void get_screensize(void); +void init_termcap(int interactive); +void end_screen(void); +void init_screen(void); + diff --git a/contrib/top/top.c b/contrib/top/top.c index ebb06e5f8923..64c3d5f28f6f 100644 --- a/contrib/top/top.c +++ b/contrib/top/top.c @@ -34,15 +34,19 @@ char *copyright = */ #include "os.h" -#include -#include -#include -#include + #include #include + +#include +#include #include +#include +#include +#include /* includes specific to top */ +#include "commands.h" #include "display.h" /* interface to display package */ #include "screen.h" /* interface to screen package */ #include "top.h" @@ -50,6 +54,7 @@ char *copyright = #include "boolean.h" #include "machine.h" #include "utils.h" +#include "username.h" /* Size of the stdio buffer given to stdout */ #define Buffersize 2048 @@ -114,38 +119,21 @@ caddr_t get_process_info(); char *username(); char *itoa7(); -/* display routines that need to be predeclared */ -int i_loadave(); -int u_loadave(); -int i_procstates(); -int u_procstates(); -int i_cpustates(); -int u_cpustates(); -int i_memory(); -int u_memory(); -int i_arc(); -int u_arc(); -int i_swap(); -int u_swap(); -int i_message(); -int u_message(); -int i_header(); -int u_header(); -int i_process(); -int u_process(); - /* pointers to display routines */ -int (*d_loadave)() = i_loadave; -int (*d_procstates)() = i_procstates; -int (*d_cpustates)() = i_cpustates; -int (*d_memory)() = i_memory; -int (*d_arc)() = i_arc; -int (*d_swap)() = i_swap; -int (*d_message)() = i_message; -int (*d_header)() = i_header; -int (*d_process)() = i_process; +void (*d_loadave)() = i_loadave; +void (*d_procstates)() = i_procstates; +void (*d_cpustates)() = i_cpustates; +void (*d_memory)() = i_memory; +void (*d_arc)() = i_arc; +void (*d_swap)() = i_swap; +void (*d_message)() = i_message; +void (*d_header)() = i_header; +void (*d_process)() = i_process; + +void reset_display(void); +int main(argc, argv) int argc; @@ -1178,6 +1166,7 @@ char *argv[]; * screen will get redrawn. */ +void reset_display() { diff --git a/contrib/top/top.h b/contrib/top/top.h index c51485a558d5..e4f8c49bdb7d 100644 --- a/contrib/top/top.h +++ b/contrib/top/top.h @@ -7,6 +7,9 @@ * General (global) definitions */ +#ifndef TOP_H +#define TOP_H + /* Current major version number */ #define VERSION 3 @@ -47,3 +50,5 @@ enum displaymodes { DISP_CPU = 0, DISP_IO, DISP_MAX }; extern enum displaymodes displaymode; extern int pcpu_stats; + +#endif /* TOP_H */ diff --git a/contrib/top/username.c b/contrib/top/username.c index 77f1517b706d..c6134d98b51e 100644 --- a/contrib/top/username.c +++ b/contrib/top/username.c @@ -32,11 +32,15 @@ #include #include -#include + #include +#include +#include +#include #include "top.local.h" #include "utils.h" +#include "username.h" struct hash_el { int uid; @@ -55,6 +59,8 @@ struct hash_el { /* We depend on that for hash_table and YOUR compiler had BETTER do it! */ struct hash_el hash_table[Table_size]; + +void init_hash() { @@ -67,7 +73,7 @@ init_hash() char *username(uid) -register int uid; +int uid; { register int hashindex; @@ -106,8 +112,8 @@ char *username; int enter_user(uid, name, wecare) -register int uid; -register char *name; +int uid; +char *name; int wecare; /* 1 = enter it always, 0 = nice to have */ { @@ -142,7 +148,7 @@ int wecare; /* 1 = enter it always, 0 = nice to have */ int get_user(uid) -register int uid; +int uid; { struct passwd *pwd; diff --git a/contrib/top/username.h b/contrib/top/username.h new file mode 100644 index 000000000000..40541dd404a2 --- /dev/null +++ b/contrib/top/username.h @@ -0,0 +1,23 @@ +/* + * Top users/processes display for Unix + * Version 3 + * + * This program may be freely redistributed, + * but this entire comment MUST remain intact. + * + * Copyright (c) 1984, 1989, William LeFebvre, Rice University + * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University + * Copyright (c) 2016, Randy Westlund + * + * $FreeBSD$ + */ +#ifndef USERNAME_H +#define USERNAME_H + +int enter_user(int uid, char *name, int wecare); +int get_user(int uid); +void init_hash(void); +char *username(int uid); +int userid(char *username); + +#endif /* USERNAME_H */ diff --git a/contrib/top/utils.h b/contrib/top/utils.h index 12a6c76c6492..6710e85e3ff0 100644 --- a/contrib/top/utils.h +++ b/contrib/top/utils.h @@ -22,3 +22,5 @@ char *errmsg(); char *format_time(); char *format_k(); char *format_k2(unsigned long long); +int string_index(char *string, char **array); + diff --git a/contrib/top/version.c b/contrib/top/version.c index 5f360fd32fe4..ea6b630f6dba 100644 --- a/contrib/top/version.c +++ b/contrib/top/version.c @@ -9,6 +9,9 @@ * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University */ +#include +#include + #include "top.h" #include "patchlevel.h"