From: Chris Pressey Date: Sun, 13 Feb 2005 18:57:30 +0000 (+0000) Subject: Clean up: X-Git-Tag: v2.0.1~8790 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/9a362823d7f344452d5721b10966efe1f0c6405e Clean up: - ANSIfy function definitions. - Constify where appropriate and remove `auto' declarations. - Normalize whitespace and placement of braces. - Parentheses around arguments to sizeof. - Explicitly test against NUL character. - Use curses functions instead of accessing internal members of the WINDOW structure. - Eliminate a convoluted and unnecessary goto. - Raise WARNS to 6. Brought-to-my-attention-by: my CPSC 213 lab assignment --- diff --git a/games/hangman/Makefile b/games/hangman/Makefile index f5728a6bb0..cddcbbd1e2 100644 --- a/games/hangman/Makefile +++ b/games/hangman/Makefile @@ -1,8 +1,9 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD: src/games/hangman/Makefile,v 1.2.14.1 2001/04/25 09:28:57 ru Exp $ -# $DragonFly: src/games/hangman/Makefile,v 1.2 2003/06/17 04:25:24 dillon Exp $ +# $DragonFly: src/games/hangman/Makefile,v 1.3 2005/02/13 18:57:30 cpressey Exp $ PROG= hangman +WARNS?= 6 SRCS= endgame.c extern.c getguess.c getword.c main.c playgame.c \ prdata.c prman.c prword.c setup.c MAN= hangman.6 diff --git a/games/hangman/endgame.c b/games/hangman/endgame.c index 7fa38b39b5..e46b7250c7 100644 --- a/games/hangman/endgame.c +++ b/games/hangman/endgame.c @@ -32,17 +32,17 @@ * * @(#)endgame.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/endgame.c,v 1.5 1999/12/10 03:22:59 billf Exp $ - * $DragonFly: src/games/hangman/endgame.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/endgame.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" /* * endgame: * Do what's necessary at the end of the game */ void -endgame() +endgame(void) { char ch; @@ -74,13 +74,3 @@ endgame() deleteln(); deleteln(); } - - - - - - - - - - diff --git a/games/hangman/extern.c b/games/hangman/extern.c index 31e8108289..f1a368dbbe 100644 --- a/games/hangman/extern.c +++ b/games/hangman/extern.c @@ -32,16 +32,17 @@ * * @(#)extern.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/extern.c,v 1.2 1999/11/30 03:48:54 billf Exp $ - * $DragonFly: src/games/hangman/extern.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/extern.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" bool Guessed[26]; char Word[BUFSIZ], - Known[BUFSIZ], - *Noose_pict[] = { + Known[BUFSIZ]; + +const char *Noose_pict[] = { " ______", " | |", " |", diff --git a/games/hangman/getguess.c b/games/hangman/getguess.c index da692e6b57..343df9bdae 100644 --- a/games/hangman/getguess.c +++ b/games/hangman/getguess.c @@ -32,7 +32,7 @@ * * @(#)getguess.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/getguess.c,v 1.6 1999/12/10 03:22:59 billf Exp $ - * $DragonFly: src/games/hangman/getguess.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/getguess.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ #include @@ -43,7 +43,7 @@ * Get another guess */ void -getguess() +getguess(void) { int i; int ch; @@ -51,7 +51,7 @@ getguess() leaveok(stdscr, FALSE); for (;;) { - move(PROMPTY, PROMPTX + sizeof "Guess: "); + move(PROMPTY, PROMPTX + sizeof("Guess: ")); refresh(); ch = readch(); if (isalpha(ch)) { @@ -74,11 +74,12 @@ getguess() Guessed[ch - 'a'] = TRUE; correct = FALSE; - for (i = 0; Word[i] != '\0'; i++) + for (i = 0; Word[i] != '\0'; i++) { if (Word[i] == ch) { Known[i] = ch; correct = TRUE; } + } if (!correct) Errors++; } @@ -88,23 +89,22 @@ getguess() * Read a character from the input */ char -readch() +readch(void) { int cnt; - auto char ch; + char ch; + int x, y; cnt = 0; for (;;) { - if (read(0, &ch, sizeof ch) <= 0) - { + if (read(0, &ch, sizeof(ch)) <= 0) { if (++cnt > 100) die(0); - } - else if (ch == CTRL('L')) { + } else if (ch == CTRL('L')) { wrefresh(curscr); - mvcur(0, 0, curscr->_cury, curscr->_curx); - } - else + getyx(curscr, y, x); + mvcur(0, 0, y, x); + } else return ch; } } diff --git a/games/hangman/getword.c b/games/hangman/getword.c index 8aa6d6023e..c90ba2b4dc 100644 --- a/games/hangman/getword.c +++ b/games/hangman/getword.c @@ -32,7 +32,7 @@ * * @(#)getword.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/getword.c,v 1.6 1999/12/10 03:22:59 billf Exp $ - * $DragonFly: src/games/hangman/getword.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/getword.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ #include "hangman.h" @@ -43,11 +43,11 @@ * Get a valid word out of the dictionary file */ void -getword() +getword(void) { - FILE *inf; - char *wp, *gp; - long pos; + FILE *inf; + char *wp, *gp; + long pos; inf = Dict; for (;;) { @@ -60,15 +60,15 @@ getword() Word[strlen(Word) - 1] = '\0'; if (strlen(Word) < MINLEN) continue; - for (wp = Word; *wp; wp++) + for (wp = Word; *wp != '\0'; wp++) { if (!islower(*wp)) - goto cont; + continue; + } break; -cont: ; } gp = Known; wp = Word; - while (*wp) { + while (*wp != '\0') { *gp++ = '-'; wp++; } diff --git a/games/hangman/hangman.h b/games/hangman/hangman.h index be5726ee56..6123a38f0f 100644 --- a/games/hangman/hangman.h +++ b/games/hangman/hangman.h @@ -32,34 +32,36 @@ * * @(#)hangman.h 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/hangman.h,v 1.3 1999/12/10 03:22:59 billf Exp $ - * $DragonFly: src/games/hangman/hangman.h,v 1.3 2003/11/12 14:53:53 eirikn Exp $ + * $DragonFly: src/games/hangman/hangman.h,v 1.4 2005/02/13 18:57:30 cpressey Exp $ */ -# include -# include -# include -# include -# include -# include -# include -# include -# include "pathnames.h" +#include +#include -# define MINLEN 6 -# define MAXERRS 7 +#include +#include +#include +#include +#include +#include -# define MESGY 12 -# define MESGX 0 -# define PROMPTY 11 -# define PROMPTX 0 -# define KNOWNY 10 -# define KNOWNX 1 -# define NUMBERY 4 -# define NUMBERX (COLS - 1 - 26) -# define AVGY 5 -# define AVGX (COLS - 1 - 26) -# define GUESSY 2 -# define GUESSX (COLS - 1 - 26) +#include "pathnames.h" + +#define MINLEN 6 +#define MAXERRS 7 + +#define MESGY 12 +#define MESGX 0 +#define PROMPTY 11 +#define PROMPTX 0 +#define KNOWNY 10 +#define KNOWNX 1 +#define NUMBERY 4 +#define NUMBERX (COLS - 1 - 26) +#define AVGY 5 +#define AVGX (COLS - 1 - 26) +#define GUESSY 2 +#define GUESSX (COLS - 1 - 26) typedef struct { @@ -69,7 +71,8 @@ typedef struct { extern bool Guessed[]; -extern char Word[], Known[], *Noose_pict[]; +extern char Word[], Known[]; +extern const char *Noose_pict[]; extern int Errors, Wordnum; @@ -81,13 +84,13 @@ extern FILE *Dict; extern off_t Dict_size; -void die (int); -void endgame (void); -void getguess (void); -void getword (void); -void playgame (void); -void prdata (void); -void prman (void); -void prword (void); -char readch (void); -void setup (void); +void die(int); +void endgame(void); +void getguess(void); +void getword(void); +void playgame(void); +void prdata(void); +void prman(void); +void prword(void); +char readch(void); +void setup(void); diff --git a/games/hangman/main.c b/games/hangman/main.c index 16cf88ade9..9641050341 100644 --- a/games/hangman/main.c +++ b/games/hangman/main.c @@ -33,18 +33,17 @@ * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/main.c,v 1.5 1999/12/10 03:22:59 billf Exp $ - * $DragonFly: src/games/hangman/main.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/main.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" /* * This game written by Ken Arnold. */ int -main() +main(void) { - /* revoke */ setgid(getgid()); @@ -65,8 +64,7 @@ main() * Die properly. */ void -die(sig) -int sig; +die(int sig __unused) { mvcur(0, COLS - 1, LINES - 1, 0); endwin(); diff --git a/games/hangman/playgame.c b/games/hangman/playgame.c index 4336411005..fc1772b800 100644 --- a/games/hangman/playgame.c +++ b/games/hangman/playgame.c @@ -32,17 +32,17 @@ * * @(#)playgame.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/playgame.c,v 1.5 1999/12/10 03:23:00 billf Exp $ - * $DragonFly: src/games/hangman/playgame.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/playgame.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" /* * playgame: * play a game */ void -playgame() +playgame(void) { bool *bp; diff --git a/games/hangman/prdata.c b/games/hangman/prdata.c index 98feed556b..02cce4fecb 100644 --- a/games/hangman/prdata.c +++ b/games/hangman/prdata.c @@ -32,28 +32,30 @@ * * @(#)prdata.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/prdata.c,v 1.5 1999/12/10 03:23:00 billf Exp $ - * $DragonFly: src/games/hangman/prdata.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/prdata.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" /* * prdata: * Print out the current guesses */ void -prdata() +prdata(void) { bool *bp; - move(GUESSY, GUESSX + sizeof "Guessed: "); + move(GUESSY, GUESSX + sizeof("Guessed: ")); bp = Guessed; while (bp < &Guessed[26]) - if (*bp++) + if (*bp++ != '\0') addch((bp - Guessed) + 'a' - 1); clrtoeol(); - mvprintw(NUMBERY, NUMBERX + sizeof "Word #: ", "%d", Wordnum); - mvprintw(AVGY, AVGX + sizeof "Current Average: ", "%.3f", - (Average * (Wordnum - 1) + Errors) / Wordnum); - mvprintw(AVGY + 1, AVGX + sizeof "Overall Average: ", "%.3f", Average); + mvprintw(NUMBERY, NUMBERX + sizeof("Word #: "), + "%d", Wordnum); + mvprintw(AVGY, AVGX + sizeof("Current Average: "), + "%.3f", (Average * (Wordnum - 1) + Errors) / Wordnum); + mvprintw(AVGY + 1, AVGX + sizeof("Overall Average: "), + "%.3f", Average); } diff --git a/games/hangman/prman.c b/games/hangman/prman.c index 308a5639a1..909e5e4706 100644 --- a/games/hangman/prman.c +++ b/games/hangman/prman.c @@ -32,10 +32,10 @@ * * @(#)prman.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/prman.c,v 1.5 1999/12/10 03:23:00 billf Exp $ - * $DragonFly: src/games/hangman/prman.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/prman.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" /* * prman: @@ -43,7 +43,7 @@ * of incorrect guesses. */ void -prman() +prman(void) { int i; diff --git a/games/hangman/prword.c b/games/hangman/prword.c index a843d5579d..d0538d7be5 100644 --- a/games/hangman/prword.c +++ b/games/hangman/prword.c @@ -32,10 +32,10 @@ * * @(#)prword.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/prword.c,v 1.3 1999/12/10 03:23:00 billf Exp $ - * $DragonFly: src/games/hangman/prword.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/prword.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ -# include "hangman.h" +#include "hangman.h" /* * prword: @@ -44,7 +44,7 @@ void prword() { - move(KNOWNY, KNOWNX + sizeof "Word: "); + move(KNOWNY, KNOWNX + sizeof("Word: ")); addstr(Known); clrtoeol(); } diff --git a/games/hangman/setup.c b/games/hangman/setup.c index 9130f0376e..7a4d1ff5d9 100644 --- a/games/hangman/setup.c +++ b/games/hangman/setup.c @@ -32,7 +32,7 @@ * * @(#)setup.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/hangman/setup.c,v 1.6 1999/12/10 03:23:01 billf Exp $ - * $DragonFly: src/games/hangman/setup.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/hangman/setup.c,v 1.3 2005/02/13 18:57:30 cpressey Exp $ */ # include @@ -43,10 +43,10 @@ * Set up the strings on the screen. */ void -setup() +setup(void) { - char **sp; - static struct stat sbuf; + const char **sp; + static struct stat sbuf; noecho(); crmode();