From mipos3!intelca!amd!amdcad!ames!ucbcad!ucbvax!decvax!tektronix!tekgen!tekred!games-request Thu Aug 6 15:03:39 PDT 1987 Article 83 of comp.sources.games: Path: td2cad!mipos3!intelca!amd!amdcad!ames!ucbcad!ucbvax!decvax!tektronix!tekgen!tekred!games-request From: games-request@tekred.TEK.COM Newsgroups: comp.sources.games Subject: v02i029: cent - centipede video game, Patch1 Message-ID: <1484@tekred.TEK.COM> Date: 5 Aug 87 16:46:31 GMT Sender: billr@tekred.TEK.COM Lines: 1446 Approved: billr@tekred.TEK.COM Submitted by: Nathan Glasser Comp.sources.games: Volume 2, Issue 29 Archive-name: cent/Patch1 [[Several people have asked for fixes to make my centipede game run under System 5. I have received a set of patches from Keith Waclena (..ihnp4!gargoyle!sphinx!kdw1, kdw1@sphinx.UChicago.{EDU,BITNET,MAILNET,CSNET}) for System 5 which apparently correct some incompatibilities with 4.xBsd. I don't vouch for the correctness of these patches. I'm just passing them on. - Nathan Glasser]] #--------Cut here-------------------------------------------------- #! /bin/sh # To extract, remove mail header lines and type "sh filename" echo x - cent-sys5.readme sed -e 's/^X//' > cent-sys5.readme << '!FaR!OuT!' XThese patches fix cent to run under System V. I had to (or chose to): X Xo Remove job control references Xo Change some ioctls (but not much; my SysV has an sgtty.h that X provides some compatibility). Xo Add a setblock() routine (and a lot of calls to it) that turns X blocking reads on and off. Xo Change the load average code (but either I've done it wrong or my X machine doesn't keep track of the load average: it's always 0). X Mostly I just made it explain itself if it screws up. Xo Change the random number generator a bit. Xo Change score.c to use the user's preferred pager instead of assuming X more(1), since most SysV sites a) don't have more(1), and b) most X Unix sites I'm familiar with have multiple pagers available (e.g., X less(1)). Same for the help file display. Xo Change calls to the FIONREAD ioctl() to use a one character X lookahead buffer. Xo Change the keybindings to use hack/vi keys, like all the rest of our X games (just my preference). X XStuff that still doesn't work and that I'd appreciate fixes to: X Xo The redrawscr() function doesn't. Xo Restored games don't redraw the screen, so you only see the things X that have changed since the game restarted (like the centipede, the X spider, yourself, and the shrooms that you zap). X X X[ These patches were produced and concatenated automatically by makepatch.] X XThis file contains all you need to convert the old version of cent Xto the latest version; it contains context diffs that will Xupdate the following files: X XMakefile cent.c Xcent.h input.c Xinterrupts.c la.c Xmove.c rand.c Xsave.c score.c Xstuff.c sys_dep.c Xsys_dep.h X XIf you have Larry Wall's patch program, you can feed this file to it, Xand you're all set. Just cd to the directory where you keep the Xsource code for cent and say: X X patch cent-sys5.patch << '!FaR!OuT!' X------------------------< Makefile >------------------------ XIndex: Makefile X*** cent.orig/Makefile Tue Jul 7 11:55:34 1987 X--- cent/Makefile Tue Jul 7 14:34:19 1987 X*************** X*** 1,7 X # makefile for centipede X # edit sys_dep.c to adjust pathnames for your system X # X! CFLAGS = -O X X OBJECTS = cent.o stuff.o input.o interrupts.o score.o move.o rand.o \ X save.o shoot.o la.o extern.o options.o sys_dep.o X X--- 1,7 ----- X # makefile for centipede X # edit sys_dep.c to adjust pathnames for your system X # X! CFLAGS = -O -DSYSV -Dindex=strchr X X OBJECTS = cent.o stuff.o input.o interrupts.o score.o move.o rand.o \ X save.o shoot.o la.o extern.o options.o sys_dep.o X*************** X*** 7,13 X save.o shoot.o la.o extern.o options.o sys_dep.o X X cent: $(OBJECTS) X! cc -s -x -o cent $(OBJECTS) -lcurses -ltermcap -lm X X cent.o stuff.o input.o move.o shoot.o save.o extern.o options.o: cent.h X input.o options.o: sys_dep.h X X--- 7,13 ----- X save.o shoot.o la.o extern.o options.o sys_dep.o X X cent: $(OBJECTS) X! cc -o cent $(OBJECTS) -lcurses -lm X X cent.o stuff.o input.o move.o shoot.o save.o extern.o options.o: cent.h X input.o options.o: sys_dep.h X X------------------------< cent.c >------------------------ XIndex: cent.c X*** cent.orig/cent.c Tue Jul 7 11:55:35 1987 X--- cent/cent.c Tue Jul 7 11:57:13 1987 X*************** X*** 18,23 X printf("Usage: cent [-s] [savefile]\n"); X exit(0); X } X signal(SIGTSTP,SIG_IGN); X signal(SIGQUIT,quit); X signal(SIGINT,SIG_IGN); X X--- 18,24 ----- X printf("Usage: cent [-s] [savefile]\n"); X exit(0); X } X+ #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X #endif X signal(SIGQUIT,catchint); X*************** X*** 19,25 X exit(0); X } X signal(SIGTSTP,SIG_IGN); X! signal(SIGQUIT,quit); X signal(SIGINT,SIG_IGN); X if (argc == 2 && !strcmp(argv[1],"-s")) X showscores(); X X--- 20,27 ----- X } X #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X! #endif X! signal(SIGQUIT,catchint); X signal(SIGINT,SIG_IGN); X if (argc == 2 && !strcmp(argv[1],"-s")) X showscores(); X*************** X*** 26,32 X dooptions(); X strcpy(name,getlogin()); X #ifdef WIZARD X! author = !strcmp(name,"nathan"); X if (author && getenv("CENTNAME") != NULL) X strcpy(name,getenv("CENTNAME")); X #endif X X--- 28,34 ----- X dooptions(); X strcpy(name,getlogin()); X #ifdef WIZARD X! author = !strcmp(name,"keith"); X if (author && getenv("CENTNAME") != NULL) X strcpy(name,getenv("CENTNAME")); X #endif X*************** X*** 52,57 X else X instructions(); X signal(SIGINT,catchint); X signal(SIGTSTP,catchstop); X signal(SIGALRM,catchalarm); X noecho(); X X--- 54,60 ----- X else X instructions(); X signal(SIGINT,catchint); X+ #ifndef SYSV X signal(SIGTSTP,catchstop); X #endif X signal(SIGALRM,catchalarm); X*************** X*** 53,58 X instructions(); X signal(SIGINT,catchint); X signal(SIGTSTP,catchstop); X signal(SIGALRM,catchalarm); X noecho(); X crmode(); X X--- 56,62 ----- X signal(SIGINT,catchint); X #ifndef SYSV X signal(SIGTSTP,catchstop); X+ #endif X signal(SIGALRM,catchalarm); X noecho(); X crmode(); X X------------------------< cent.h >------------------------ XIndex: cent.h X*** cent.orig/cent.h Tue Jul 7 11:55:38 1987 X--- cent/cent.h Thu Jul 2 15:14:18 1987 X*************** X*** 4,9 X #include X #include X /* stdio.h and sgtty.h are included by curses.h */ X X #define FREEMAN 12000 X #define CENTLENGTH 20 X X--- 4,13 ----- X #include X #include X /* stdio.h and sgtty.h are included by curses.h */ X+ #ifdef SYSV X+ # include X+ # include X+ #endif X X #define FREEMAN 12000 X #define CENTLENGTH 20 X X------------------------< input.c >------------------------ XIndex: input.c X*** cent.orig/input.c Tue Jul 7 11:55:40 1987 X--- cent/input.c Sat Jul 4 14:45:28 1987 X*************** X*** 1,6 X #include "cent.h" X #include "sys_dep.h" X X move_guy() X { X register int y, x, changed = 0; X X--- 1,11 ----- X #include "cent.h" X #include "sys_dep.h" X X+ #ifdef SYSV X+ # undef getchar X+ # define getchar cget X+ #endif X+ X move_guy() X { X register int y, x, changed = 0; X*************** X*** 7,12 X int count,repeat = 0; X char ch; X X ioctl(0,FIONREAD,&count); X while (repeat || count--) X { X X--- 12,18 ----- X int count,repeat = 0; X char ch; X X+ #ifndef SYSV X ioctl(0,FIONREAD,&count); X #else X if (cready()) count = 1; X*************** X*** 8,13 X char ch; X X ioctl(0,FIONREAD,&count); X while (repeat || count--) X { X if (repeat) X X--- 14,23 ----- X X #ifndef SYSV X ioctl(0,FIONREAD,&count); X+ #else X+ if (cready()) count = 1; X+ else count = 0; X+ #endif X while (repeat || count--) X { X if (repeat) X*************** X*** 20,25 X x = guy.x; X switch(ch) X { X case LEFT: X x--; X break; X X--- 30,38 ----- X x = guy.x; X switch(ch) X { X+ case '\014': /* KDW */ X+ redrawscr(); refresh(); X+ break; X case LEFT: X x--; X break; X*************** X*** 113,116 X } X if (changed) X refresh(); X } X X--- 126,193 ----- X } X if (changed) X refresh(); X+ } X+ X+ /* X+ * KDW: setblock, cready and cget from Rochkind. X+ */ X+ X+ #define EMPTY '\0' X+ X+ static char cbuf = EMPTY; X+ X+ #define BOOLEAN int X+ #define FALSE 0 X+ #define TRUE 1 X+ X+ setblock (fd, on) X+ int fd; X+ BOOLEAN on; X+ { X+ static int blockf, nonblockf; X+ static BOOLEAN first = TRUE; X+ int flags; X+ X+ if (first) X+ { X+ first = FALSE; X+ if ((flags = fcntl(fd, F_GETFL, 0)) == -1) X+ perror("fcntl"); X+ blockf = flags & ~O_NDELAY; X+ nonblockf = flags | O_NDELAY; X+ } X+ if (fcntl(fd, F_SETFL, on ? blockf : nonblockf) == -1) X+ perror("fcntl2"); X+ } X+ X+ BOOLEAN cready () X+ { X+ if (cbuf != EMPTY) X+ return TRUE; X+ setblock(0, FALSE); X+ switch (read(0, &cbuf, 1)) X+ { X+ case -1: perror("read"); break; X+ case 0: return FALSE; X+ default: return TRUE; X+ } X+ } X+ X+ int cget () X+ { X+ char c; X+ X+ if (cbuf != EMPTY) X+ { X+ c = cbuf; X+ cbuf = EMPTY; X+ return c & 0377; X+ } X+ setblock(0, TRUE); X+ switch (read(0, &c, 1)) X+ { X+ case -1: perror("read"); break; X+ case 0: return -1; X+ default: return c & 0377; X+ } X } X X------------------------< interrupts.c >------------------------ XIndex: interrupts.c X*** cent.orig/interrupts.c Tue Jul 7 11:55:42 1987 X--- cent/interrupts.c Tue Jul 7 14:37:05 1987 X*************** X*** 19,24 X catchint() X { X signal(SIGINT,SIG_IGN); X signal(SIGTSTP,SIG_IGN); X inter = 1; X } X X--- 19,25 ----- X catchint() X { X signal(SIGINT,SIG_IGN); X+ #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X #endif X inter = 1; X*************** X*** 20,25 X { X signal(SIGINT,SIG_IGN); X signal(SIGTSTP,SIG_IGN); X inter = 1; X } X X X--- 21,27 ----- X signal(SIGINT,SIG_IGN); X #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X+ #endif X inter = 1; X } X X*************** X*** 25,30 X X catchstop() X { X signal(SIGTSTP,SIG_IGN); X signal(SIGINT,SIG_IGN); X stopped = 1; X X--- 27,33 ----- X X catchstop() X { X+ #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X #endif X signal(SIGINT,SIG_IGN); X*************** X*** 26,31 X catchstop() X { X signal(SIGTSTP,SIG_IGN); X signal(SIGINT,SIG_IGN); X stopped = 1; X } X X--- 29,35 ----- X { X #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X+ #endif X signal(SIGINT,SIG_IGN); X stopped = 1; X } X*************** X*** 40,45 X fflush(stdout); X ioctl(0,TIOCGETP,&curseterm); X ioctl(0,TIOCSETP,&origterm); X signal(SIGTSTP,SIG_DFL); X kill(getpid(),SIGTSTP); X signal(SIGTSTP,SIG_IGN); X X--- 44,50 ----- X fflush(stdout); X ioctl(0,TIOCGETP,&curseterm); X ioctl(0,TIOCSETP,&origterm); X+ #ifndef SYSV X signal(SIGTSTP,SIG_DFL); X kill(getpid(),SIGTSTP); X signal(SIGTSTP,SIG_IGN); X*************** X*** 43,48 X signal(SIGTSTP,SIG_DFL); X kill(getpid(),SIGTSTP); X signal(SIGTSTP,SIG_IGN); X stopped = 0; X ioctl(0,TIOCSETP,&curseterm); X redrawscr(); X X--- 48,54 ----- X signal(SIGTSTP,SIG_DFL); X kill(getpid(),SIGTSTP); X signal(SIGTSTP,SIG_IGN); X+ #endif X stopped = 0; X ioctl(0,TIOCSETP,&curseterm); X redrawscr(); X*************** X*** 48,53 X redrawscr(); X ioctl(0,TIOCSETP,&curseterm); /* Just to make sure... */ X waitboard(); X signal(SIGTSTP,catchstop); X signal(SIGINT,catchint); X } X X--- 54,60 ----- X redrawscr(); X ioctl(0,TIOCSETP,&curseterm); /* Just to make sure... */ X waitboard(); X+ #ifndef SYSV X signal(SIGTSTP,catchstop); X #endif X signal(SIGINT,catchint); X*************** X*** 49,54 X ioctl(0,TIOCSETP,&curseterm); /* Just to make sure... */ X waitboard(); X signal(SIGTSTP,catchstop); X signal(SIGINT,catchint); X } X X X--- 56,62 ----- X waitboard(); X #ifndef SYSV X signal(SIGTSTP,catchstop); X+ #endif X signal(SIGINT,catchint); X } X X*************** X*** 59,64 X signal(SIGQUIT,SIG_IGN); X mvaddstr(12,60,"Really quit?"); X refresh(); X ch = getchar(); X move(12,60); X clrtoeol(); X X--- 67,73 ----- X signal(SIGQUIT,SIG_IGN); X mvaddstr(12,60,"Really quit?"); X refresh(); X+ #ifndef SYSV X ch = getchar(); X #else X setblock(0, TRUE); X*************** X*** 60,65 X mvaddstr(12,60,"Really quit?"); X refresh(); X ch = getchar(); X move(12,60); X clrtoeol(); X refresh(); X X--- 69,79 ----- X refresh(); X #ifndef SYSV X ch = getchar(); X+ #else X+ setblock(0, TRUE); X+ ch = getchar(); X+ setblock(0, FALSE); X+ #endif X move(12,60); X clrtoeol(); X refresh(); X*************** X*** 67,72 X endgame(); X inter = 0; X signal(SIGINT,catchint); X signal(SIGTSTP,catchstop); X signal(SIGQUIT,quit); X } X X--- 81,87 ----- X endgame(); X inter = 0; X signal(SIGINT,catchint); X+ #ifndef SYSV X signal(SIGTSTP,catchstop); X #endif X signal(SIGQUIT,catchint); X*************** X*** 68,74 X inter = 0; X signal(SIGINT,catchint); X signal(SIGTSTP,catchstop); X! signal(SIGQUIT,quit); X } X X waitboard() X X--- 83,90 ----- X signal(SIGINT,catchint); X #ifndef SYSV X signal(SIGTSTP,catchstop); X! #endif X! signal(SIGQUIT,catchint); X } X X waitboard() X*************** X*** 75,80 X { X char ch; X X signal(SIGTSTP,SIG_IGN); X signal(SIGINT,SIG_IGN); X mvaddstr(12,60,"Press return"); X X--- 91,97 ----- X { X char ch; X X+ #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X #endif X signal(SIGINT,SIG_IGN); X*************** X*** 76,81 X char ch; X X signal(SIGTSTP,SIG_IGN); X signal(SIGINT,SIG_IGN); X mvaddstr(12,60,"Press return"); X mvaddstr(13,60,"when ready"); X X--- 93,99 ----- X X #ifndef SYSV X signal(SIGTSTP,SIG_IGN); X+ #endif X signal(SIGINT,SIG_IGN); X mvaddstr(12,60,"Press return"); X mvaddstr(13,60,"when ready"); X*************** X*** 80,85 X mvaddstr(12,60,"Press return"); X mvaddstr(13,60,"when ready"); X refresh(); X while ((ch = getchar()) != '\r') X { X #ifdef WIZARD X X--- 98,104 ----- X mvaddstr(12,60,"Press return"); X mvaddstr(13,60,"when ready"); X refresh(); X+ setblock(0, TRUE); X while ((ch = getchar()) != '\r') X { X #ifdef WIZARD X*************** X*** 85,91 X #ifdef WIZARD X if (ch == '\020') X setname(); X! else if (ch == '\014') X #else X if (ch == '\014') X #endif X X--- 104,110 ----- X #ifdef WIZARD X if (ch == '\020') X setname(); X! else if (ch == '\014' || ch == 'r') X #else X if (ch == '\014' || ch == 'r') X #endif X*************** X*** 87,93 X setname(); X else if (ch == '\014') X #else X! if (ch == '\014') X #endif X redrawscr(); X else if (ch == 's' || ch == 'S') X X--- 106,112 ----- X setname(); X else if (ch == '\014' || ch == 'r') X #else X! if (ch == '\014' || ch == 'r') X #endif X redrawscr(); X else if (ch == 's' || ch == 'S') X*************** X*** 93,98 X else if (ch == 's' || ch == 'S') X savegame(); X } X move(12,60); X clrtoeol(); X move(13,60); X X--- 112,118 ----- X else if (ch == 's' || ch == 'S') X savegame(); X } X+ setblock(0, FALSE); X move(12,60); X clrtoeol(); X move(13,60); X*************** X*** 100,105 X move(15,60); X clrtoeol(); X signal(SIGINT,catchint); X signal(SIGTSTP,catchstop); X } X X X--- 120,126 ----- X move(15,60); X clrtoeol(); X signal(SIGINT,catchint); X+ #ifndef SYSV X signal(SIGTSTP,catchstop); X #endif X } X*************** X*** 101,106 X clrtoeol(); X signal(SIGINT,catchint); X signal(SIGTSTP,catchstop); X } X X catchalarm() X X--- 122,128 ----- X signal(SIGINT,catchint); X #ifndef SYSV X signal(SIGTSTP,catchstop); X+ #endif X } X X catchalarm() X*************** X*** 121,123 X touchwin(stdscr); X refresh(); X } X X--- 143,146 ----- X touchwin(stdscr); X refresh(); X } X+ X X------------------------< la.c >------------------------ XIndex: la.c X*** cent.orig/la.c Tue Jul 7 11:55:42 1987 X--- cent/la.c Thu Jul 2 16:28:20 1987 X*************** X*** 1,4 X #include X X loadav(avenrun) /* Function storing 1,5,15 minute load averages in */ X double *avenrun; /* avenrun; should be declared double avenrun[3]; */ X X--- 1,5 ----- X #include X+ #include X X loadav(avenrun) /* Function storing 1,5,15 minute load averages in */ X double *avenrun; /* avenrun; should be declared double avenrun[3]; */ X*************** X*** 12,17 X if (kmem < 0) /* Open necessary files. */ X { X if ((kmem = open("/dev/kmem",0)) == -1) X return(-1); /* Cannot open. */ X nlist("/vmunix", nl); X } X X--- 13,20 ----- X if (kmem < 0) /* Open necessary files. */ X { X if ((kmem = open("/dev/kmem",0)) == -1) X+ { X+ syserror("Can't open /dev/kmem."); X return(-1); /* Cannot open. */ X } X if (nlist("/vmunix", nl) == -1) X*************** X*** 13,19 X { X if ((kmem = open("/dev/kmem",0)) == -1) X return(-1); /* Cannot open. */ X! nlist("/vmunix", nl); X } X if (lseek(kmem,(long)nl[0].n_value, 0) == -1 || X read(kmem,avenrun,3 * sizeof(double)) == -1) X X--- 16,28 ----- X { X syserror("Can't open /dev/kmem."); X return(-1); /* Cannot open. */ X! } X! if (nlist("/vmunix", nl) == -1) X! if (nlist("/unix", nl) == -1) X! { X! error("Can't get avenrun from nlist in kernel."); X! return -1; X! } X } X if (lseek(kmem,(long)nl[0].n_value, 0) == -1) X { X*************** X*** 15,22 X return(-1); /* Cannot open. */ X nlist("/vmunix", nl); X } X! if (lseek(kmem,(long)nl[0].n_value, 0) == -1 || X! read(kmem,avenrun,3 * sizeof(double)) == -1) X return(-1); /* sizeof avenrun is 24. */ X return(0); X } X X--- 24,32 ----- X return -1; X } X } X! if (lseek(kmem,(long)nl[0].n_value, 0) == -1) X! { X! syserror("Can't seek in /dev/kmem."); X return(-1); /* sizeof avenrun is 24. */ X } X if (read(kmem,avenrun,3 * sizeof(double)) == -1) X*************** X*** 18,22 X if (lseek(kmem,(long)nl[0].n_value, 0) == -1 || X read(kmem,avenrun,3 * sizeof(double)) == -1) X return(-1); /* sizeof avenrun is 24. */ X return(0); X } X X--- 28,39 ----- X { X syserror("Can't seek in /dev/kmem."); X return(-1); /* sizeof avenrun is 24. */ X+ } X+ if (read(kmem,avenrun,3 * sizeof(double)) == -1) X+ { X+ syserror("Can't read from /dev/kmem."); X+ return(-1); /* sizeof avenrun is 24. */ X+ } X return(0); X } X X*************** X*** 19,22 X read(kmem,avenrun,3 * sizeof(double)) == -1) X return(-1); /* sizeof avenrun is 24. */ X return(0); X } X X--- 35,52 ----- X return(-1); /* sizeof avenrun is 24. */ X } X return(0); X+ } X+ X+ syserror (str) X+ char *str; X+ { X+ extern int errno; X+ extern char *sys_errlist[]; X+ fprintf(stderr, "%s (%s)\n", str, sys_errlist[errno]); X+ } X+ X+ error (str) X+ char *str; X+ { X+ fprintf(stderr, "%s\n", str); X } X X------------------------< move.c >------------------------ XIndex: move.c X*** cent.orig/move.c Tue Jul 7 11:55:44 1987 X--- cent/move.c Thu Jul 2 14:55:37 1987 X*************** X*** 54,59 X refresh(); X fflush(stdout); X do X ioctl(1,TIOCOUTQ,&count); X while (count > spiderhere * 40); X move_guy(); X X--- 54,60 ----- X refresh(); X fflush(stdout); X do X+ #ifndef SYSV X ioctl(1,TIOCOUTQ,&count); X #else X count = 0; X*************** X*** 55,60 X fflush(stdout); X do X ioctl(1,TIOCOUTQ,&count); X while (count > spiderhere * 40); X move_guy(); X } X X--- 56,64 ----- X do X #ifndef SYSV X ioctl(1,TIOCOUTQ,&count); X+ #else X+ count = 0; X+ #endif X while (count > spiderhere * 40); X move_guy(); X } X X------------------------< rand.c >------------------------ XIndex: rand.c X*** cent.orig/rand.c Tue Jul 7 11:55:46 1987 X--- cent/rand.c Tue Jul 7 14:30:47 1987 X*************** X*** 4,9 X #include X #include X #include X #include X X double RandSeed,floor(),pow(); X X--- 4,10 ----- X #include X #include X #include X+ #ifndef SYSV X #include X #endif X X*************** X*** 5,10 X #include X #include X #include X X double RandSeed,floor(),pow(); X X X--- 6,12 ----- X #include X #ifndef SYSV X #include X+ #endif X X double RandSeed,floor(),pow(); X X*************** X*** 14,19 X return (d-floor(d)); X } X X rninit() /* seed is of form .mmmsss (m = millisecs, s = secs) */ X { X struct timeb tbuf; X X--- 16,28 ----- X return (d-floor(d)); X } X X+ #ifdef SYSV X+ rninit() X+ { X+ RandSeed = (double) time((long *) 0); X+ } X+ X+ #else X rninit() /* seed is of form .mmmsss (m = millisecs, s = secs) */ X { X struct timeb tbuf; X*************** X*** 20,26 X X ftime(&tbuf); X RandSeed = tbuf.millitm/1000.0 + frac(tbuf.time/1000.0) / 1000.0; X! } X X double rn() /* remainder of hairy exponential */ X { X X--- 29,36 ----- X X ftime(&tbuf); X RandSeed = tbuf.millitm/1000.0 + frac(tbuf.time/1000.0) / 1000.0; X! } X! #endif X X double rn() /* remainder of hairy exponential */ X { X*************** X*** 26,28 X { X return (RandSeed = frac(pow(RandSeed*4.32 + 3.52, 3.64))); X } X X--- 36,39 ----- X { X return (RandSeed = frac(pow(RandSeed*4.32 + 3.52, 3.64))); X } X+ X X------------------------< save.c >------------------------ XIndex: save.c X*** cent.orig/save.c Tue Jul 7 11:55:47 1987 X--- cent/save.c Sat Jul 4 14:47:59 1987 X*************** X*** 9,14 X savegame() X { X char fil[100]; X X if (!gamestarted) X { X X--- 9,15 ----- X savegame() X { X char fil[100]; X+ struct sgttyb curseterm; X X strcpy(fil, "cent.save"); X if (!gamestarted) X*************** X*** 10,15 X { X char fil[100]; X X if (!gamestarted) X { X mvaddstr(15,60,"Too early to save"); X X--- 11,17 ----- X char fil[100]; X struct sgttyb curseterm; X X+ strcpy(fil, "cent.save"); X if (!gamestarted) X { X mvaddstr(15,60,"Too early to save"); X*************** X*** 16,21 X refresh(); X return; X } X printf("%s",CL); X nocrmode(); X echo(); X X--- 18,27 ----- X refresh(); X return; X } X+ #ifdef SYSV X+ clear(); X+ refresh(); X+ #else X printf("%s",CL); X #endif X setblock(0, TRUE); X*************** X*** 17,22 X return; X } X printf("%s",CL); X nocrmode(); X echo(); X nl(); X X--- 23,30 ----- X refresh(); X #else X printf("%s",CL); X+ #endif X+ setblock(0, TRUE); X nocrmode(); X echo(); X nl(); X*************** X*** 21,26 X echo(); X nl(); X printf("File name: "); X scanf("%s",fil); X noecho(); X crmode(); X X--- 29,36 ----- X echo(); X nl(); X printf("File name: "); X+ ioctl(0,TIOCGETP,&curseterm); X+ ioctl(0,TIOCSETP,&origterm); X scanf("%s",fil); X ioctl(0,TIOCSETP,&curseterm); X noecho(); X*************** X*** 22,27 X nl(); X printf("File name: "); X scanf("%s",fil); X noecho(); X crmode(); X printf("Saving... "); X X--- 32,38 ----- X ioctl(0,TIOCGETP,&curseterm); X ioctl(0,TIOCSETP,&origterm); X scanf("%s",fil); X+ ioctl(0,TIOCSETP,&curseterm); X noecho(); X crmode(); X printf("Saving... "); X*************** X*** 106,112 X dorest(fil) X { X int fd,n,count,tim; X! register char ch; X register int y,x; X char buf[512]; X PEDE **piece = ¢ipede, *prev = NULL; X X--- 117,123 ----- X dorest(fil) X { X int fd,n,count,tim; X! char ch; /* KDW: was register; blasted for portability */ X register int y,x; X char buf[512]; X PEDE **piece = ¢ipede, *prev = NULL; X X------------------------< score.c >------------------------ XIndex: score.c X*** cent.orig/score.c Tue Jul 7 11:55:48 1987 X--- cent/score.c Tue Jul 7 15:07:33 1987 X*************** X*** 1,5 X #include "cent.h" X X struct score { X char name[10]; X long score; X X--- 1,9 ----- X #include "cent.h" X X+ extern char *def_pager, *def_pager_opts; X+ X+ FILE *getpager (); X+ X struct score { X char name[10]; X long score; X*************** X*** 40,46 X if (wr = needtowrite(scores,numscores,&myscore)) X if ((fd = creat(scorefile,0600)) == -1) X err(); X! if ((morefp = popen("/usr/ucb/more","w")) == NULL) X { X perror("Error popen'ing more"); X exit(1); X X--- 44,50 ----- X if (wr = needtowrite(scores,numscores,&myscore)) X if ((fd = creat(scorefile,0600)) == -1) X err(); X! if ((morefp = getpager()) == NULL) X { X perror("Error popen'ing cat"); X exit(1); X*************** X*** 42,48 X err(); X if ((morefp = popen("/usr/ucb/more","w")) == NULL) X { X! perror("Error popen'ing more"); X exit(1); X } X printf("Centipede Hall of Fame\n"); X X--- 46,52 ----- X err(); X if ((morefp = getpager()) == NULL) X { X! perror("Error popen'ing cat"); X exit(1); X } X printf("Centipede Hall of Fame\n"); X*************** X*** 100,106 X lockscore(); X if ((fd = open(scorefile,0)) == -1) X err(); X! if ((morefp = popen("/usr/ucb/more","w")) == NULL) X { X perror("Error popen'ing more"); X exit(1); X X--- 104,110 ----- X lockscore(); X if ((fd = open(scorefile,0)) == -1) X err(); X! if ((morefp = getpager()) == NULL) X { X perror("Error popen'ing cat"); X exit(1); X*************** X*** 102,108 X err(); X if ((morefp = popen("/usr/ucb/more","w")) == NULL) X { X! perror("Error popen'ing more"); X exit(1); X } X printf("Centipede Hall of Fame\n"); X X--- 106,112 ----- X err(); X if ((morefp = getpager()) == NULL) X { X! perror("Error popen'ing cat"); X exit(1); X } X printf("Centipede Hall of Fame\n"); X*************** X*** 147,150 X perror("Error removing lockfile"); X exit(-1); X } X } X X--- 151,177 ----- X perror("Error removing lockfile"); X exit(-1); X } X+ } X+ X+ /* X+ * KDW: getpager: figure out what pager to use to display the score file, X+ * and open a pipe to it. X+ */ X+ X+ FILE *getpager () X+ { X+ FILE *morefp; X+ char *PAGER; X+ X+ if ((PAGER = getenv("PAGER")) != NULL) X+ { X+ if ((morefp = popen(PAGER, "w")) != NULL) X+ return morefp; X+ } X+ if ((morefp = popen(def_pager, "w")) != NULL) X+ return morefp; X+ if ((morefp = popen("cat", "w")) != NULL) X+ return morefp; X+ else X+ return NULL; X } X X------------------------< stuff.c >------------------------ XIndex: stuff.c X*** cent.orig/stuff.c Tue Jul 7 11:55:50 1987 X--- cent/stuff.c Tue Jul 7 15:11:40 1987 X*************** X*** 1,5 X #include "cent.h" X X rnd(n) X register int n; X { X X--- 1,7 ----- X #include "cent.h" X X+ extern char *def_pager, *def_pager_opts; X+ X rnd(n) X register int n; X { X*************** X*** 221,227 X crmode(); X if ((ch = getchar()) != 'y' && ch != 'Y') X return; X! sprintf(cmd,"/usr/ucb/more %s",helpfile); X system(cmd); X printf("[Hit return to start the game]"); X while (getchar() != '\n'); X X--- 223,232 ----- X crmode(); X if ((ch = getchar()) != 'y' && ch != 'Y') X return; X! if (getenv("PAGER") == NULL) X! sprintf(cmd,"%s %s %s", def_pager, def_pager_opts, helpfile); X! else X! sprintf(cmd,"%s %s", getenv("PAGER"), helpfile); X system(cmd); X printf("[Hit return to start the game]"); X while (getchar() != '\n'); X X------------------------< sys_dep.c >------------------------ XIndex: sys_dep.c X*** cent.orig/sys_dep.c Tue Jul 7 11:55:51 1987 X--- cent/sys_dep.c Tue Jul 7 14:46:43 1987 X*************** X*** 3,9 X X X /* Scorefile: Where the scorefile should live */ X! char scorefile[] = "/usr/games/centipede/scores"; X X X /* Lockfile: Where to create and look for a lockfile controlling access X X--- 3,9 ----- X X X /* Scorefile: Where the scorefile should live */ X! char scorefile[] = "/usr/games/lib/cent/scorefile"; X X X /* Lockfile: Where to create and look for a lockfile controlling access X*************** X*** 8,14 X X /* Lockfile: Where to create and look for a lockfile controlling access X to the scorefile */ X! char lockfile[] = "/usr/games/centipede/lockfile"; X X X /* Helpfile: Where the help file is located */ X X--- 8,14 ----- X X /* Lockfile: Where to create and look for a lockfile controlling access X to the scorefile */ X! char lockfile[] = "/usr/games/lib/cent/lockfile"; X X X /* Helpfile: Where the help file is located */ X*************** X*** 12,18 X X X /* Helpfile: Where the help file is located */ X! char helpfile[] = "/usr/games/centipede/cent.doc"; X X X /* Maxload: The maximum allowed load average for playing */ X X--- 12,18 ----- X X X /* Helpfile: Where the help file is located */ X! char helpfile[] = "/usr/games/lib/cent/cent.doc"; X X X /* Maxload: The maximum allowed load average for playing */ X*************** X*** 21,23 X X /* Niceness: The amount to nice the game by (lower its priority) */ X int niceness = 4; X X--- 21,29 ----- X X /* Niceness: The amount to nice the game by (lower its priority) */ X int niceness = 4; X+ X+ /* def_pager: default pager if we can't otherwise choose one */ X+ char *def_pager = "less"; X+ X+ /* def_pager_opts: options for default pager; include - if you need it */ X+ char *def_pager_opts = "-qew"; X X------------------------< sys_dep.h >------------------------ XIndex: sys_dep.h X*** cent.orig/sys_dep.h Tue Jul 7 11:55:52 1987 X--- cent/sys_dep.h Thu Jul 2 13:55:28 1987 X*************** X*** 1,8 X /* User commands */ X! #define LEFT '1' X! #define RIGHT '3' X! #define UPWARD '5' X! #define DOWN '.' X #define FIRE ' ' X #define UPRIGHT '6' X #define UPLEFT '4' X X--- 1,8 ----- X /* User commands */ X! #define LEFT 'h' X! #define RIGHT 'l' X! #define UPWARD 'k' X! #define DOWN 'j' X #define FIRE ' ' X #define UPRIGHT 'u' X #define UPLEFT 'y' X*************** X*** 4,13 X #define UPWARD '5' X #define DOWN '.' X #define FIRE ' ' X! #define UPRIGHT '6' X! #define UPLEFT '4' X! #define DOWNRIGHT '\r' X! #define DOWNLEFT '0' X! #define FASTLEFT '7' X! #define FASTRIGHT '9' X #define PAUSEKEY '\t' X X--- 4,13 ----- X #define UPWARD 'k' X #define DOWN 'j' X #define FIRE ' ' X! #define UPRIGHT 'u' X! #define UPLEFT 'y' X! #define DOWNRIGHT 'n' X! #define DOWNLEFT 'b' X! #define FASTLEFT 'H' X! #define FASTRIGHT 'L' X #define PAUSEKEY '\t' !FaR!OuT! exit