diff --git a/include/curses.h b/include/curses.h index ba1e5e3..28bf21c 100644 --- a/include/curses.h +++ b/include/curses.h @@ -183,6 +183,8 @@ int wdeleteln (WINDOW *); void mvcur(int ly, int lx, int y, int x); void overwrite(WINDOW *win1, WINDOW *win2); void wclrtobot(WINDOW *win); +int mvprintw(int y, int x, char *fmt, ...); +int mvwprintw(WINDOW *win, int y, int x, char *fmt, ...); /* * Used to be in unctrl.h. diff --git a/rootfs.manifest b/rootfs.manifest index 4bca8b2..f83aa20 100644 --- a/rootfs.manifest +++ b/rootfs.manifest @@ -418,6 +418,7 @@ file /games/cfscores file /games/factor file /games/fish file /games/fortune +file /games/hangman file /games/morse file /games/number file /games/ppt @@ -630,9 +631,12 @@ file /libexec/smlrc default filemode 0444 dir /share +dir /share/dict dir /share/misc file /share/emg.keys file /share/re.help +file /share/dict/words +file /share/misc/more.help # # Files: /share/example @@ -725,6 +729,8 @@ file /share/man/cat6/battlestar.0 file /share/man/cat6/bcd.0 file /share/man/cat6/canfield.0 file /share/man/cat6/fish.0 +file /share/man/cat6/fortune.0 +file /share/man/cat6/hangman.0 file /share/man/cat6/number.0 file /share/man/cat6/rain.0 file /share/man/cat6/rogue.0 diff --git a/src/games/Makefile b/src/games/Makefile index 0242c77..4acdd55 100644 --- a/src/games/Makefile +++ b/src/games/Makefile @@ -12,9 +12,8 @@ CFLAGS += -Werror -Wall -Os # Programs that live in subdirectories, and have makefiles of their own. # SUBDIR = adventure atc backgammon battlestar boggle btlgammon \ - cribbage fortune rogue sail trek -# TODO: hangman hunt mille monop phantasia quiz robots -# sail snake warp + cribbage fortune hangman rogue sail trek +# TODO: mille monop quiz robots snake # C programs that live in the current directory and do not need # explicit make lines. diff --git a/src/games/hangman/.gitignore b/src/games/hangman/.gitignore new file mode 100644 index 0000000..2469edc --- /dev/null +++ b/src/games/hangman/.gitignore @@ -0,0 +1 @@ +hangman diff --git a/src/games/hangman/Makefile b/src/games/hangman/Makefile index 99bd640..4c08ea3 100644 --- a/src/games/hangman/Makefile +++ b/src/games/hangman/Makefile @@ -1,22 +1,28 @@ -OBJS= endgame.o extern.o getguess.o getword.o main.o playgame.o \ - prdata.o prman.o prword.o setup.o -CFILES= endgame.c extern.c getguess.c getword.c main.c playgame.c \ - prdata.c prman.c prword.c setup.c -HDRS= hangman.h -CFLAGS= -O -LDFLAGS= -SEPFLAG= -i +TOPSRC = $(shell cd ../../..; pwd) +include $(TOPSRC)/target.mk +#include $(TOPSRC)/cross.mk -all: hangman +CFLAGS += -Werror -Wall -tags: $(HDRS) $(CFILES) - ctags $(HDRS) $(CFILES) +OBJS = endgame.o extern.o getguess.o getword.o main.o playgame.o \ + prdata.o prman.o prword.o setup.o +MAN = hangman.0 +LIBS = -lcurses -ltermcap -lc -install: hangman - install -s hangman $(DESTDIR)/usr/games/hangman - -hangman: $(OBJS) - $(CC) ${SEPFLAG} $(LDFLAGS) -o hangman $(OBJS) -lcurses -ltermlib +all: hangman $(MAN) + +hangman: $(OBJS) + $(CC) $(LDFLAGS) -o $@.elf $(OBJS) $(LIBS) + $(OBJDUMP) -S $@.elf > $@.dis + $(SIZE) $@.elf + $(ELF2AOUT) $@.elf $@ && rm $@.elf + +$(MAN): hangman.6 + nroff -man $< > $@ clean: - rm -f $(OBJS) hangman ? core + rm -f *.o core hangman *.0 *.dis + +install: all + install hangman $(DESTDIR)/games/ + install -m 644 $(MAN) $(DESTDIR)/share/man/cat6/ diff --git a/src/games/hangman/endgame.c b/src/games/hangman/endgame.c index 4bbe4cb..7a531d4 100644 --- a/src/games/hangman/endgame.c +++ b/src/games/hangman/endgame.c @@ -1,9 +1,10 @@ -# include "hangman.h" +#include "hangman.h" /* * endgame: * Do what's necessary at the end of the game */ +void endgame() { register char ch; @@ -24,7 +25,7 @@ endgame() leaveok(stdscr, FALSE); refresh(); if ((ch = readch()) == 'n') - die(); + die(0); else if (ch == 'y') break; mvaddstr(MESGY + 2, MESGX, "Please type 'y' or 'n'"); diff --git a/src/games/hangman/extern.c b/src/games/hangman/extern.c index 4b4fc47..7d3227f 100644 --- a/src/games/hangman/extern.c +++ b/src/games/hangman/extern.c @@ -1,4 +1,4 @@ -# include "hangman.h" +#include "hangman.h" bool Guessed[26]; diff --git a/src/games/hangman/getguess.c b/src/games/hangman/getguess.c index 3aa31b0..531dba0 100644 --- a/src/games/hangman/getguess.c +++ b/src/games/hangman/getguess.c @@ -1,9 +1,41 @@ -# include "hangman.h" +#include +#include "hangman.h" + +#ifndef CTRL +# define CTRL(c) (c & 037) +#endif + +/* + * readch; + * Read a character from the input + */ +int +readch() +{ + register int cnt; + auto char ch; + + cnt = 0; + for (;;) { + if (read(0, &ch, sizeof ch) <= 0) + { + if (++cnt > 100) + die(0); + } + else if (ch == CTRL('L')) { + wrefresh(curscr); + mvcur(0, 0, curscr->_cury, curscr->_curx); + } + else + return ch; + } +} /* * getguess: * Get another guess */ +void getguess() { register int i; @@ -23,8 +55,8 @@ getguess() else break; } - else if (ch == CTRL(D)) - die(); + else if (ch == CTRL('D')) + die(0); else mvprintw(MESGY, MESGX, "Not a valid guess: '%s'", unctrl(ch)); @@ -43,28 +75,3 @@ getguess() if (!correct) Errors++; } - -/* - * readch; - * Read a character from the input - */ -readch() -{ - register int cnt, r; - auto char ch; - - cnt = 0; - for (;;) { - if (read(0, &ch, sizeof ch) <= 0) - { - if (++cnt > 100) - die(); - } - else if (ch == CTRL(L)) { - wrefresh(curscr); - mvcur(0, 0, curscr->_cury, curscr->_curx); - } - else - return ch; - } -} diff --git a/src/games/hangman/getword.c b/src/games/hangman/getword.c index b28c0ce..0fb6545 100644 --- a/src/games/hangman/getword.c +++ b/src/games/hangman/getword.c @@ -1,15 +1,26 @@ -# include "hangman.h" +#include +#include +#include "hangman.h" -# if pdp11 -# define RN (((off_t) rand() << 16) | (off_t) rand()) -# else -# define RN rand() -# endif +/* + * abs: + * Return the absolute value of an integer + */ +off_t +offabs(i) +off_t i; +{ + if (i < 0) + return -(off_t) i; + else + return (off_t) i; +} /* * getword: * Get a valid word out of the dictionary file */ +void getword() { register FILE *inf; @@ -17,7 +28,7 @@ getword() inf = Dict; for (;;) { - fseek(inf, abs(RN % Dict_size), 0); + fseek(inf, offabs(random() % Dict_size), 0); if (fgets(Word, BUFSIZ, inf) == NULL) continue; if (fgets(Word, BUFSIZ, inf) == NULL) @@ -39,17 +50,3 @@ cont: ; } *gp = '\0'; } - -/* - * abs: - * Return the absolute value of an integer - */ -off_t -abs(i) -off_t i; -{ - if (i < 0) - return -(off_t) i; - else - return (off_t) i; -} diff --git a/src/games/hangman/hangman.h b/src/games/hangman/hangman.h index 78af604..05011e4 100644 --- a/src/games/hangman/hangman.h +++ b/src/games/hangman/hangman.h @@ -1,26 +1,30 @@ -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include -# define MINLEN 6 -# define MAXERRS 7 -# define DICT "/usr/dict/words" - -# 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) +#define MINLEN 6 +#define MAXERRS 7 +#ifdef CROSS +# define DICT "/usr/local/share/dict/words" +#else +# define DICT "/share/dict/words" +#endif +#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 { short y, x; @@ -41,6 +45,15 @@ extern FILE *Dict; extern off_t Dict_size; -int die(); +void die(int); -off_t abs(); +off_t offabs(off_t); +void prman(void); +void prword(void); +void prdata(void); +void setup(void); +void playgame(void); +void getword(void); +void getguess(void); +void endgame(void); +int readch(void); diff --git a/src/games/hangman/main.c b/src/games/hangman/main.c index 5a03d83..3bfc280 100644 --- a/src/games/hangman/main.c +++ b/src/games/hangman/main.c @@ -1,9 +1,22 @@ -# include "hangman.h" +#include +#include "hangman.h" + +/* + * die: + * Die properly. + */ +void die(int sig) +{ + mvcur(0, COLS - 1, LINES - 1, 0); + endwin(); + putchar('\n'); + exit(0); +} /* * This game written by Ken Arnold. */ -main() +int main() { initscr(); signal(SIGINT, die); @@ -15,15 +28,3 @@ main() } /* NOTREACHED */ } - -/* - * die: - * Die properly. - */ -die() -{ - mvcur(0, COLS - 1, LINES - 1, 0); - endwin(); - putchar('\n'); - exit(0); -} diff --git a/src/games/hangman/playgame.c b/src/games/hangman/playgame.c index d0ca809..74166e1 100644 --- a/src/games/hangman/playgame.c +++ b/src/games/hangman/playgame.c @@ -1,9 +1,11 @@ -# include "hangman.h" +#include +#include "hangman.h" /* * playgame: * play a game */ +void playgame() { register bool *bp; diff --git a/src/games/hangman/prdata.c b/src/games/hangman/prdata.c index 8874bca..1bdcd2b 100644 --- a/src/games/hangman/prdata.c +++ b/src/games/hangman/prdata.c @@ -1,9 +1,10 @@ -# include "hangman.h" +#include "hangman.h" /* * prdata: * Print out the current guesses */ +void prdata() { register bool *bp; diff --git a/src/games/hangman/prman.c b/src/games/hangman/prman.c index 4d1d976..eaba163 100644 --- a/src/games/hangman/prman.c +++ b/src/games/hangman/prman.c @@ -1,10 +1,11 @@ -# include "hangman.h" +#include "hangman.h" /* * prman: * Print out the man appropriately for the give number * of incorrect guesses. */ +void prman() { register int i; diff --git a/src/games/hangman/prword.c b/src/games/hangman/prword.c index 1770028..29a8072 100644 --- a/src/games/hangman/prword.c +++ b/src/games/hangman/prword.c @@ -1,9 +1,10 @@ -# include "hangman.h" +#include "hangman.h" /* * prword: * Print out the current state of the word */ +void prword() { move(KNOWNY, KNOWNX + sizeof "Word: "); diff --git a/src/games/hangman/setup.c b/src/games/hangman/setup.c index bda8511..73353e2 100644 --- a/src/games/hangman/setup.c +++ b/src/games/hangman/setup.c @@ -1,9 +1,13 @@ -# include "hangman.h" +#include +#include +#include +#include "hangman.h" /* * setup: * Set up the strings on the screen. */ +void setup() { register char **sp; @@ -24,7 +28,7 @@ setup() addstr(*sp); } - srand(time(NULL) + getpid()); + srandom(time(NULL) + getpid()); if ((Dict = fopen(DICT, "r")) == NULL) { perror(DICT); endwin(); diff --git a/src/libcurses/mvprintw.c b/src/libcurses/mvprintw.c index 1766cff..a13fa53 100644 --- a/src/libcurses/mvprintw.c +++ b/src/libcurses/mvprintw.c @@ -11,20 +11,29 @@ * */ int -mvprintw(y, x, fmt, args) - reg int y, x; - char *fmt; - int args; +mvprintw(int y, int x, char *fmt, ...) { - return move(y, x) == OK ? _sprintw(stdscr, fmt, &args) : ERR; + va_list args; + int ret; + + if (move(y, x) != OK) + return ERR; + va_start (args, fmt); + ret = _sprintw (stdscr, fmt, args); + va_end (args); + return ret; } int -mvwprintw(win, y, x, fmt, args) - reg WINDOW *win; - reg int y, x; - char *fmt; - int args; +mvwprintw(WINDOW *win, int y, int x, char *fmt, ...) { - return wmove(win, y, x) == OK ? _sprintw(win, fmt, &args) : ERR; + va_list args; + int ret; + + if (wmove(win, y, x) != OK) + return ERR; + va_start (args, fmt); + ret = _sprintw (win, fmt, args); + va_end (args); + return ret; }