mday@ohs.UUCP (Matthew T. Day) (06/20/89)
Here's patch #2 to Greed. This patch basically fixes the SYSV porting properly. This might not work on all SYSV machines, since I haven't heard about the unistd.h include file before, but I'll trust John Campbell (who wrote the patch) until told otherwise. This also patches the Makefile to include -ltermlib for all machines, I didn't think such a library existed for all systems, but that should correct the SO+SE problem and now highlight new high scores. If somebody on a generic SYSV machine would like to email me the results of this patch on his/her system, that would be great. Keep those reports coming, we'll get this working pretty slick yet! md -- diff -c greed11b/Makefile greed/Makefile *** greed11b/Makefile Mon Jun 19 15:56:57 1989 --- greed/Makefile Mon Jun 19 15:56:04 1989 *************** *** 1,8 **** ! # Makefile for Greed v1.1a, by Matthew T. Day (mday@ohs.uucp) # Choose BSD for Berkeley 4.[23] Unix, NOTBSD for all others ! SYSDEF=BSD -lcurses -ltermcap ! #SYSDEF=NOTBSD -lcurses # Location of high score file SCOREFILE=/usr/games/lib/greed.hs --- 1,8 ---- ! # Makefile for Greed v1.1c, by Matthew T. Day (mday@ohs.uucp) # Choose BSD for Berkeley 4.[23] Unix, NOTBSD for all others ! SYSDEF=BSD ! #SYSDEF=NOTBSD # Location of high score file SCOREFILE=/usr/games/lib/greed.hs *************** *** 9,15 **** # Location of game executable BIN=/usr/games ! CFLAGS=-O -s -DSCOREFILE=\"$(SCOREFILE)\" -D$(SYSDEF) greed: greed.c cc -o greed greed.c $(CFLAGS) --- 9,15 ---- # Location of game executable BIN=/usr/games ! CFLAGS=-O -s -DSCOREFILE=\"$(SCOREFILE)\" -D$(SYSDEF) -lcurses -ltermlib greed: greed.c cc -o greed greed.c $(CFLAGS) diff -c greed11b/greed.c greed/greed.c *** greed11b/greed.c Mon Jun 19 15:57:14 1989 --- greed/greed.c Mon Jun 19 15:59:46 1989 *************** *** 1,4 **** ! /* greed.c v1.1b - Written by Matthew T. Day (mday@ohs.uucp), 06/17/89 */ #include <curses.h> #include <signal.h> --- 1,4 ---- ! /* greed.c v1.1c - Written by Matthew T. Day (mday@ohs.uucp), 06/19/89 */ #include <curses.h> #include <signal.h> *************** *** 5,10 **** --- 5,11 ---- #include <pwd.h> #ifdef NOTBSD #include <fcntl.h> + #include <unistd.h> #else #include <sys/file.h> #endif *************** *** 77,83 **** (void) wmove(gridwin, y, x); waddstr(botwin, "Score: "); ! mvwaddstr(botwin, 0, 40, "Greed v1.1b - Hit '?' for help."); showscore(); while ((val = tunnel(wgetch(gridwin))) > 0); --- 78,84 ---- (void) wmove(gridwin, y, x); waddstr(botwin, "Score: "); ! mvwaddstr(botwin, 0, 40, "Greed v1.1c - Hit '?' for help."); showscore(); while ((val = tunnel(wgetch(gridwin))) > 0); *************** *** 237,242 **** --- 238,246 ---- struct score *toplist = (struct score *) malloc(FILESIZE); register struct score *ptrtmp, *eof = &toplist[MAXSCORE], *new; extern int _putchar(); + #ifdef NOTBSD + extern struct passwd *getpwuid(); + #endif (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); *************** *** 248,254 **** --- 252,262 ---- exit(1); } + #ifdef NOTBSD + lockf(fd, F_LOCK, 10L); + #else flock(fd, LOCK_EX); + #endif for (ptrtmp=toplist; ptrtmp < eof; ptrtmp++) ptrtmp->score = 0; read(fd, toplist, FILESIZE); if (newscore) { *************** *** 269,280 **** new->score = newscore; strncpy(new->user, getpwuid(getuid())->pw_name, 8); ! (void) lseek(fd, 0, 0); write(fd, toplist, FILESIZE); } } close(fd); flock(fd, LOCK_UN); if (toplist->score) puts("Rank Score Name Percentage"); else puts("No high scores."); --- 277,295 ---- new->score = newscore; strncpy(new->user, getpwuid(getuid())->pw_name, 8); ! (void) lseek(fd, 0L, 0); write(fd, toplist, FILESIZE); } } + + #ifdef NOTBSD + (void) lseek(fd, 0L, 0); + lockf(fd, F_ULOCK, 10L); close(fd); + #else flock(fd, LOCK_UN); + close(fd); + #endif if (toplist->score) puts("Rank Score Name Percentage"); else puts("No high scores."); *************** *** 296,302 **** (void) waddch(helpwin, '+'); mvwaddch(helpwin, 0, 64, '+'); mvwaddch(helpwin, 15, 0, '+'); mvwaddch(helpwin, 15, 64, '+'); ! msg(1, "Welcome to Greed v1.1b, by Matthew T. Day (mday@ohs.uucp)."); msg(3, "The object of Greed is to erase as much of the screen as"); msg(4, "possible by moving around in a grid of numbers. To move your"); msg(5, "cursor, simply use the standard hjklyubn keys or the number"); --- 311,317 ---- (void) waddch(helpwin, '+'); mvwaddch(helpwin, 0, 64, '+'); mvwaddch(helpwin, 15, 0, '+'); mvwaddch(helpwin, 15, 64, '+'); ! msg(1, "Welcome to Greed v1.1c, by Matthew T. Day (mday@ohs.uucp)."); msg(3, "The object of Greed is to erase as much of the screen as"); msg(4, "possible by moving around in a grid of numbers. To move your"); msg(5, "cursor, simply use the standard hjklyubn keys or the number"); -- +----------------------------------------------------------+-----------------+ | Matthew T. Day, Orem High School, Orem, Utah | "He who laughs, | | Internet: mday@ohs.uucp UUCP: ..!uunet!iconsys!ohs!mday | lasts." | +----------------------------------------------------------+-----------------+