top: fix warnings from clang/gcc

Add includes for <curses.h> and <termcap.h> where necessary, and
rename a few internal functions to have a "top_" prefix to avoid
clashes with standard names from curses.h/termcap.h headers.

Top now compiles without warnings on both gcc and clang.

Reviewed by:	emaste, imp, jhb
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D15115
This commit is contained in:
Kurt Lidl 2018-04-18 13:17:14 +00:00
parent ffd9d577cc
commit c382392d70
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332671
4 changed files with 26 additions and 35 deletions

View File

@ -32,7 +32,9 @@
#include <sys/time.h>
#include <curses.h>
#include <ctype.h>
#include <termcap.h>
#include <time.h>
#include <unistd.h>
@ -255,7 +257,7 @@ double *avenrun;
register int i;
/* i_loadave also clears the screen, since it is first */
clear();
top_clear();
/* mpid == -1 implies this system doesn't have an _mpid */
if (mpid != -1)
@ -796,7 +798,7 @@ i_message()
}
if (next_msg[0] != '\0')
{
standout(next_msg);
top_standout(next_msg);
msglen = strlen(next_msg);
next_msg[0] = '\0';
}
@ -1076,7 +1078,7 @@ caddr_t a1, a2, a3;
i = strlen(next_msg);
if ((type & MT_delayed) == 0)
{
type & MT_standout ? standout(next_msg) :
type & MT_standout ? top_standout(next_msg) :
fputs(next_msg, stdout);
(void) clear_eol(msglen - i);
msglen = i;
@ -1088,7 +1090,7 @@ caddr_t a1, a2, a3;
{
if ((type & MT_delayed) == 0)
{
type & MT_standout ? standout(next_msg) : fputs(next_msg, stdout);
type & MT_standout ? top_standout(next_msg) : fputs(next_msg, stdout);
msglen = strlen(next_msg);
next_msg[0] = '\0';
}

View File

@ -45,6 +45,8 @@
# endif
# endif
#endif
#include <curses.h>
#include <termcap.h>
#include "screen.h"
#include "boolean.h"
@ -432,10 +434,7 @@ get_screensize()
}
void
standout(msg)
char *msg;
top_standout(char *msg)
{
if (smart_terminal)
{
@ -450,8 +449,7 @@ char *msg;
}
void
clear()
top_clear()
{
if (smart_terminal)
{
@ -460,10 +458,7 @@ clear()
}
int
clear_eol(len)
int len;
clear_eol(int len)
{
if (smart_terminal && !overstrike && len > 0)
{
@ -496,12 +491,8 @@ go_home()
/* This has to be defined as a subroutine for tputs (instead of a macro) */
void
putstdout(ch)
char ch;
int
putstdout(int ch)
{
putchar(ch);
return putchar(ch);
}

View File

@ -28,10 +28,10 @@ extern int screen_length;
extern int screen_width;
/* a function that puts a single character on stdout */
void putstdout(char ch);
int putstdout(int ch);
int clear_eol(int len);
void standout(char *msg);
void clear(void);
void top_standout(char *msg);
void top_clear(void);
void go_home(void);
void reinit_screen(void);
void get_screensize(void);

View File

@ -39,6 +39,7 @@ char *copyright =
#include <sys/time.h>
#include <ctype.h>
#include <curses.h>
#include <errno.h>
#include <jail.h>
#include <setjmp.h>
@ -79,7 +80,7 @@ int pcpu_stats = No;
sigret_t leave();
sigret_t tstop();
#ifdef SIGWINCH
sigret_t winch();
sigret_t top_winch(int);
#endif
volatile sig_atomic_t leaveflag;
@ -682,7 +683,7 @@ char *argv[];
(void) signal(SIGQUIT, leave);
(void) signal(SIGTSTP, tstop);
#ifdef SIGWINCH
(void) signal(SIGWINCH, winch);
(void) signal(SIGWINCH, top_winch);
#endif
#ifdef SIGRELSE
sigrelse(SIGINT);
@ -897,7 +898,7 @@ char *argv[];
max_topn = display_resize();
/* reset the signal handler */
(void) signal(SIGWINCH, winch);
(void) signal(SIGWINCH, top_winch);
reset_display();
winchflag = 0;
@ -971,9 +972,9 @@ char *argv[];
case CMD_help1: /* help */
case CMD_help2:
reset_display();
clear();
top_clear();
show_help();
standout("Hit any key to continue: ");
top_standout("Hit any key to continue: ");
fflush(stdout);
(void) read(0, &ch, 1);
break;
@ -989,9 +990,9 @@ char *argv[];
else
{
reset_display();
clear();
top_clear();
show_errors();
standout("Hit any key to continue: ");
top_standout("Hit any key to continue: ");
fflush(stdout);
(void) read(0, &ch, 1);
}
@ -1300,10 +1301,7 @@ int i;
}
#ifdef SIGWINCH
sigret_t winch(i) /* SIGWINCH handler */
int i;
sigret_t top_winch(int i) /* SIGWINCH handler */
{
winchflag = 1;
}