Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 May 2016 04:17:01 +0000 (UTC)
From:      Garrett Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300395 - head/contrib/top
Message-ID:  <201605220417.u4M4H12O020940@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Sun May 22 04:17:00 2016
New Revision: 300395
URL: https://svnweb.freebsd.org/changeset/base/300395

Log:
  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 <rwestlun@gmail.com>
  Differential Revision: https://reviews.freebsd.org/D6468

Added:
  head/contrib/top/commands.h   (contents, props changed)
  head/contrib/top/username.h   (contents, props changed)
Modified:
  head/contrib/top/commands.c
  head/contrib/top/display.c
  head/contrib/top/display.h
  head/contrib/top/machine.h
  head/contrib/top/screen.c
  head/contrib/top/screen.h
  head/contrib/top/top.c
  head/contrib/top/top.h
  head/contrib/top/username.c
  head/contrib/top/utils.h
  head/contrib/top/version.c

Modified: head/contrib/top/commands.c
==============================================================================
--- head/contrib/top/commands.c	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/commands.c	Sun May 22 04:17:00 2016	(r300395)
@@ -19,16 +19,21 @@
  */
 
 #include "os.h"
-#include <ctype.h>
-#include <signal.h>
-#include <errno.h>
+
 #include <sys/time.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 "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()
 
 {

Added: head/contrib/top/commands.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/contrib/top/commands.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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 */

Modified: head/contrib/top/display.c
==============================================================================
--- head/contrib/top/display.c	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/display.c	Sun May 22 04:17:00 2016	(r300395)
@@ -29,9 +29,12 @@
  */
 
 #include "os.h"
+
+#include <sys/time.h>
+
 #include <ctype.h>
 #include <time.h>
-#include <sys/time.h>
+#include <unistd.h>
 
 #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;

Modified: head/contrib/top/display.h
==============================================================================
--- head/contrib/top/display.h	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/display.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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);

Modified: head/contrib/top/machine.h
==============================================================================
--- head/contrib/top/machine.h	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/machine.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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 */

Modified: head/contrib/top/screen.c
==============================================================================
--- head/contrib/top/screen.c	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/screen.c	Sun May 22 04:17:00 2016	(r300395)
@@ -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;

Modified: head/contrib/top/screen.h
==============================================================================
--- head/contrib/top/screen.h	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/screen.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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);
+

Modified: head/contrib/top/top.c
==============================================================================
--- head/contrib/top/top.c	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/top.c	Sun May 22 04:17:00 2016	(r300395)
@@ -34,15 +34,19 @@ char *copyright =
  */
 
 #include "os.h"
-#include <errno.h>
-#include <signal.h>
-#include <setjmp.h>
-#include <ctype.h>
+
 #include <sys/jail.h>
 #include <sys/time.h>
+
+#include <ctype.h>
+#include <errno.h>
 #include <jail.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <unistd.h>
 
 /* 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 @@ restart:
  *	screen will get redrawn.
  */
 
+void
 reset_display()
 
 {

Modified: head/contrib/top/top.h
==============================================================================
--- head/contrib/top/top.h	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/top.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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_I
 extern enum displaymodes displaymode;
 
 extern int pcpu_stats;
+
+#endif /* TOP_H */

Modified: head/contrib/top/username.c
==============================================================================
--- head/contrib/top/username.c	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/username.c	Sun May 22 04:17:00 2016	(r300395)
@@ -32,11 +32,15 @@
 
 #include <sys/param.h>
 #include <sys/types.h>
-#include <stdio.h>
+
 #include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #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 =
 
 int get_user(uid)
 
-register int uid;
+int uid;
 
 {
     struct passwd *pwd;

Added: head/contrib/top/username.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/contrib/top/username.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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 */

Modified: head/contrib/top/utils.h
==============================================================================
--- head/contrib/top/utils.h	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/utils.h	Sun May 22 04:17:00 2016	(r300395)
@@ -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);
+

Modified: head/contrib/top/version.c
==============================================================================
--- head/contrib/top/version.c	Sun May 22 04:09:05 2016	(r300394)
+++ head/contrib/top/version.c	Sun May 22 04:17:00 2016	(r300395)
@@ -9,6 +9,9 @@
  *  Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
  */
 
+#include <stdio.h>
+#include <string.h>
+
 #include "top.h"
 #include "patchlevel.h"
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605220417.u4M4H12O020940>