From f14dd6d3a0a385ac58a57561f37f5216451c0fd0 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 27 Aug 2006 21:45:07 +0000 Subject: [PATCH] -WARNS6 cleanup (229 warnings) -No need to link -ltermcap and -lcompat -ANSI function declarations -staticize functions -add prototypes for all functions -Remove previously commented out and unused code and variables -Add DragonFly keyword where needed --- games/robots/Makefile | 7 ++++--- games/robots/extern.c | 4 ++-- games/robots/flush_in.c | 7 ++++--- games/robots/init_field.c | 11 ++++------- games/robots/main.c | 31 ++++++++++++------------------- games/robots/make_level.c | 8 ++++---- games/robots/move.c | 33 ++++++++++++++++++++------------- games/robots/move_robs.c | 20 +++++++++----------- games/robots/play_level.c | 6 +++--- games/robots/query.c | 7 +++---- games/robots/rnd_pos.c | 12 ++++++------ games/robots/robots.h | 33 +++++++++++++++++++++------------ games/robots/score.c | 27 +++++++++++++++++---------- 13 files changed, 109 insertions(+), 97 deletions(-) diff --git a/games/robots/Makefile b/games/robots/Makefile index 5b02b04327..e07f3d5328 100644 --- a/games/robots/Makefile +++ b/games/robots/Makefile @@ -1,15 +1,16 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD: src/games/robots/Makefile,v 1.5.2.3 2002/08/07 16:31:42 ru Exp $ -# $DragonFly: src/games/robots/Makefile,v 1.2 2003/06/17 04:25:24 dillon Exp $ +# $DragonFly: src/games/robots/Makefile,v 1.3 2006/08/27 21:45:07 pavalos Exp $ PROG= robots CFLAGS+=-DMAX_PER_UID=5 SRCS= extern.c init_field.c main.c make_level.c move.c move_robs.c \ play_level.c query.c rnd_pos.c score.c flush_in.c MAN= robots.6 -DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBCOMPAT} -LDADD= -lcurses -ltermcap -lcompat +DPADD= ${LIBCURSES} +LDADD= -lcurses HIDEGAME=hidegame +WARNS?= 6 beforeinstall: .if !exists(${DESTDIR}/var/games/robots_roll) diff --git a/games/robots/extern.c b/games/robots/extern.c index 7839ea566c..d47081cbe8 100644 --- a/games/robots/extern.c +++ b/games/robots/extern.c @@ -32,7 +32,7 @@ * * @(#)extern.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/extern.c,v 1.2 1999/11/30 03:49:16 billf Exp $ - * $DragonFly: src/games/robots/extern.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/extern.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ # include "robots.h" @@ -56,7 +56,7 @@ bool Was_bonus = FALSE; /* Was a bonus last level */ char Cnt_move; /* Command which has preceded the count */ char Field[Y_FIELDSIZE][X_FIELDSIZE]; /* the playing field itslef */ char *Next_move; /* Next move to be used in the pattern */ -char *Move_list = "YHBJNLUK";/* List of moves in the pattern */ +const char *Move_list = "YHBJNLUK";/* List of moves in the pattern */ char Run_ch; /* Character for the direction we are running */ int Count = 0; /* Command count */ diff --git a/games/robots/flush_in.c b/games/robots/flush_in.c index 72956bc14e..c57b7c3b86 100644 --- a/games/robots/flush_in.c +++ b/games/robots/flush_in.c @@ -32,16 +32,17 @@ * * @(#)flush_in.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/flush_in.c,v 1.2 1999/11/30 03:49:17 billf Exp $ - * $DragonFly: src/games/robots/flush_in.c,v 1.3 2006/01/22 03:43:37 swildner Exp $ + * $DragonFly: src/games/robots/flush_in.c,v 1.4 2006/08/27 21:45:07 pavalos Exp $ */ -# include +# include "robots.h" /* * flush_in: * Flush all pending input. */ -flush_in() +void +flush_in(void) { # ifdef TIOCFLUSH ioctl(fileno(stdin), TIOCFLUSH, NULL); diff --git a/games/robots/init_field.c b/games/robots/init_field.c index 76efb24673..b73d00423c 100644 --- a/games/robots/init_field.c +++ b/games/robots/init_field.c @@ -32,10 +32,9 @@ * * @(#)init_field.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/init_field.c,v 1.6 1999/11/30 03:49:17 billf Exp $ - * $DragonFly: src/games/robots/init_field.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/init_field.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ -#include # include "robots.h" /* @@ -43,13 +42,12 @@ * Lay down the initial pattern whih is constant across all levels, * and initialize all the global variables. */ -init_field() +void +init_field(void) { int i; - WINDOW *wp; - int j; static bool first = TRUE; - static char *desc[] = { + static const char *desc[] = { "Directions:", "", "y k u", @@ -77,7 +75,6 @@ init_field() Dead = FALSE; Waiting = FALSE; - /* flushok(stdscr, TRUE); */ Score = 0; erase(); diff --git a/games/robots/main.c b/games/robots/main.c index ce3d01c8a7..ca816c8cf3 100644 --- a/games/robots/main.c +++ b/games/robots/main.c @@ -33,24 +33,21 @@ * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/main.c,v 1.7 1999/11/30 03:49:18 billf Exp $ - * $DragonFly: src/games/robots/main.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/main.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ # include "robots.h" # include -# include # include -main(ac, av) -int ac; -char **av; +static bool another(void); + +int +main(int ac, char **av) { char *sp; bool bad_arg; bool show_only; - extern char *Scorefile; - extern int Max_per_uid; - void quit(); show_only = FALSE; if (ac > 1) { @@ -109,7 +106,7 @@ char **av; } initscr(); - signal(SIGINT, quit); + signal(SIGINT, (sig_t)quit); crmode(); noecho(); nonl(); @@ -126,7 +123,7 @@ char **av; srandomdev(); if (Real_time) - signal(SIGALRM, move_robots); + signal(SIGALRM, (sig_t)move_robots); do { init_field(); for (Level = Start_level; !Dead; Level++) { @@ -139,13 +136,8 @@ char **av; score(); } while (another()); quit(); -} - -void -__cputchar(ch) - int ch; -{ - (void)putchar(ch); + /* NOTREACHED */ + return(0); } /* @@ -153,7 +145,7 @@ __cputchar(ch) * Leave the program elegantly. */ void -quit() +quit(void) { endwin(); exit(0); @@ -164,7 +156,8 @@ quit() * another: * See if another game is desired */ -another() +static bool +another(void) { int y; diff --git a/games/robots/make_level.c b/games/robots/make_level.c index c76516540b..2a05497628 100644 --- a/games/robots/make_level.c +++ b/games/robots/make_level.c @@ -32,7 +32,7 @@ * * @(#)make_level.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/make_level.c,v 1.4 1999/11/30 03:49:18 billf Exp $ - * $DragonFly: src/games/robots/make_level.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/make_level.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ # include "robots.h" @@ -41,12 +41,12 @@ * make_level: * Make the current level */ -make_level() +void +make_level(void) { int i; COORD *cp; - WINDOW *wp; - int x, *endp; + int x; reset_count(); for (i = 1; i < Y_FIELDSIZE; i++) diff --git a/games/robots/move.c b/games/robots/move.c index 51b63202db..5e75b514a7 100644 --- a/games/robots/move.c +++ b/games/robots/move.c @@ -32,7 +32,7 @@ * * @(#)move.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/move.c,v 1.6 1999/11/30 03:49:18 billf Exp $ - * $DragonFly: src/games/robots/move.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/move.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ #include @@ -41,16 +41,21 @@ # define ESC '\033' +static bool must_telep(void); +static bool do_move(int, int); +static bool eaten(COORD *); + /* * get_move: * Get and execute a move from the player */ -get_move() +void +get_move(void) { int c; - int y, x, lastmove; - static COORD newpos; - +#ifdef FANCY + int lastmove; +#endif if (Waiting) return; @@ -158,7 +163,6 @@ over: case 'W': Waiting = TRUE; leaveok(stdscr, TRUE); - /* flushok(stdscr, FALSE); */ goto ret; case 't': case 'T': @@ -194,7 +198,8 @@ ret: * Must I teleport; i.e., is there anywhere I can move without * being eaten? */ -must_telep() +static bool +must_telep(void) { int x, y; static COORD newpos; @@ -225,8 +230,8 @@ must_telep() * do_move: * Execute a move */ -do_move(dy, dx) -int dy, dx; +static bool +do_move(int dy, int dx) { static COORD newpos; @@ -261,8 +266,8 @@ int dy, dx; * eaten: * Player would get eaten at this place */ -eaten(pos) -COORD *pos; +static bool +eaten(COORD *pos) { int x, y; @@ -283,7 +288,8 @@ COORD *pos; * reset_count: * Reset the count variables */ -reset_count() +void +reset_count(void) { Count = 0; Running = FALSE; @@ -295,7 +301,8 @@ reset_count() * jumping: * See if we are jumping, i.e., we should not refresh. */ -jumping() +bool +jumping(void) { return (Jump && (Count || Running || Waiting)); } diff --git a/games/robots/move_robs.c b/games/robots/move_robs.c index cc48302003..e777838d2c 100644 --- a/games/robots/move_robs.c +++ b/games/robots/move_robs.c @@ -32,27 +32,25 @@ * * @(#)move_robs.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/move_robs.c,v 1.4 1999/11/30 03:49:19 billf Exp $ - * $DragonFly: src/games/robots/move_robs.c,v 1.3 2006/01/22 03:43:37 swildner Exp $ + * $DragonFly: src/games/robots/move_robs.c,v 1.4 2006/08/27 21:45:07 pavalos Exp $ */ # include "robots.h" # include +static int sign(int); + /* * move_robots: * Move the robots around */ void -move_robots(was_sig) -bool was_sig; +move_robots(bool was_sig) { COORD *rp; - int y, x; - int mindist, d; - static COORD newpos; if (Real_time) - signal(SIGALRM, move_robots); + signal(SIGALRM, (sig_t)move_robots); # ifdef DEBUG move(Min.y, Min.x); addch(inch()); @@ -128,8 +126,8 @@ bool was_sig; * add_score: * Add a score to the overall point total */ -add_score(add) -int add; +void +add_score(int add) { Score += add; move(Y_SCORE, X_SCORE); @@ -140,8 +138,8 @@ int add; * sign: * Return the sign of the number */ -sign(n) -int n; +static int +sign(int n) { if (n < 0) return -1; diff --git a/games/robots/play_level.c b/games/robots/play_level.c index 352e7c9d7e..585bb52833 100644 --- a/games/robots/play_level.c +++ b/games/robots/play_level.c @@ -32,7 +32,7 @@ * * @(#)play_level.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/play_level.c,v 1.4 1999/11/30 03:49:20 billf Exp $ - * $DragonFly: src/games/robots/play_level.c,v 1.3 2006/01/22 03:43:37 swildner Exp $ + * $DragonFly: src/games/robots/play_level.c,v 1.4 2006/08/27 21:45:07 pavalos Exp $ */ # include "robots.h" @@ -41,10 +41,10 @@ * play_level: * Let the player play the current level */ -play_level() +void +play_level(void) { COORD *cp; - int y, x, bonus; move(My_pos.y, My_pos.x); addch(PLAYER); diff --git a/games/robots/query.c b/games/robots/query.c index 3681bd5b6f..657eede940 100644 --- a/games/robots/query.c +++ b/games/robots/query.c @@ -32,18 +32,17 @@ * * @(#)query.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/query.c,v 1.5 1999/11/30 03:49:20 billf Exp $ - * $DragonFly: src/games/robots/query.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/query.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ -#include # include "robots.h" /* * query: * Ask a question and get a yes or no answer. Default is "no". */ -query(prompt) -char *prompt; +int +query(const char *prompt) { int c, retval; int y, x; diff --git a/games/robots/rnd_pos.c b/games/robots/rnd_pos.c index fac5a03e05..7b720759da 100644 --- a/games/robots/rnd_pos.c +++ b/games/robots/rnd_pos.c @@ -32,24 +32,24 @@ * * @(#)rnd_pos.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/rnd_pos.c,v 1.5 1999/11/30 03:49:20 billf Exp $ - * $DragonFly: src/games/robots/rnd_pos.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/rnd_pos.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ -# include # include "robots.h" # define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) +static int rnd(int); + /* * rnd_pos: * Pick a random, unoccupied position */ COORD * -rnd_pos() +rnd_pos(void) { static COORD pos; static int call = 0; - int i = 0; do { pos.y = rnd(Y_FIELDSIZE - 1) + 1; @@ -60,8 +60,8 @@ rnd_pos() return &pos; } -rnd(range) -int range; +static int +rnd(int range) { return random() % range; } diff --git a/games/robots/robots.h b/games/robots/robots.h index 0139a1d110..a66574de39 100644 --- a/games/robots/robots.h +++ b/games/robots/robots.h @@ -31,11 +31,14 @@ * SUCH DAMAGE. * * @(#)robots.h 8.1 (Berkeley) 5/31/93 + * $DragonFly: src/games/robots/robots.h,v 1.2 2006/08/27 21:45:07 pavalos Exp $ */ # include # include - +# include +# include +# include /* * miscellaneous constants */ @@ -84,9 +87,10 @@ extern bool Pattern_roll, Stand_still; #endif extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], *Next_move, - *Move_list, Run_ch; + Run_ch; +extern const char *Move_list, *Scorefile; -extern int Count, Level, Num_robots, Num_scores, Score, +extern int Count, Level, Max_per_uid, Num_robots, Num_scores, Score, Start_level, Wait_bonus; extern COORD Max, Min, My_pos, Robots[]; @@ -96,12 +100,17 @@ extern jmp_buf End_move; /* * functions types */ - -int cmp_sc(); -void move_robots(); - -COORD *rnd_pos(); - - - - +void flush_in(void); +void init_field(void); +void quit(void); +void make_level(void); +void get_move(void); +void reset_count(void); +bool jumping(void); +void move_robots(bool); +void add_score(int); +void play_level(void); +int query(const char *); +COORD *rnd_pos(void); +void score(void); +void show_score(void); diff --git a/games/robots/score.c b/games/robots/score.c index 1aa4ff3f3e..ba14652db4 100644 --- a/games/robots/score.c +++ b/games/robots/score.c @@ -32,10 +32,11 @@ * * @(#)score.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/robots/score.c,v 1.5 1999/11/30 03:49:20 billf Exp $ - * $DragonFly: src/games/robots/score.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/robots/score.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $ */ # include "robots.h" +# include # include # include # include "pathnames.h" @@ -48,18 +49,22 @@ typedef struct { typedef struct passwd PASSWD; -char *Scorefile = _PATH_SCORE; +const char *Scorefile = _PATH_SCORE; int Max_per_uid = MAX_PER_UID; static SCORE Top[MAXSCORES]; +static void set_name(SCORE *); +static int cmp_sc(const void *, const void *); + /* * score: * Post the player's score, if reasonable, and then print out the * top list. */ -score() +void +score(void) { int inf; SCORE *scp; @@ -136,13 +141,14 @@ score() close(inf); } -set_name(scp) -SCORE *scp; +static void +set_name(SCORE *scp) { PASSWD *pp; + static char unk[] = "???"; if ((pp = getpwuid(scp->s_uid)) == NULL) - pp->pw_name = "???"; + pp->pw_name = unk; strncpy(scp->s_name, pp->pw_name, MAXNAME); } @@ -150,17 +156,18 @@ SCORE *scp; * cmp_sc: * Compare two scores. */ -cmp_sc(s1, s2) -SCORE *s1, *s2; +static int +cmp_sc(const void *s1, const void *s2) { - return s2->s_score - s1->s_score; + return (((const SCORE *)s2)->s_score - ((const SCORE *)s1)->s_score); } /* * show_score: * Show the score list for the '-s' option. */ -show_score() +void +show_score(void) { SCORE *scp; int inf; -- 2.41.0