me%brandeis.csnet@csnet-relay.arpa (Elias Israel) (08/13/85)
I'm already cringing at the thought of the hate mail that I am going to get but here goes: Hi there! Some time ago I said that I would send out my versions of hack.tty.c, hack.termcap.c, and an appropriate makefile to convert regular hack into hack for sysV. It has been a while since I said I would send this, so please forgive. I hope that you are able to incoporate these sources easily enough. I have been using them for a while now (about a month) and they seem to do the right thing for AT&T SysVRel2. At some point in the future (don't exactly hold your breath) I will finish the port so that this stuff will run under Venix System V. Happy hacking, eli me%brandeis.csnet@csnet-relay -- remove this and all lines above (you didn't want my ramblings anyway) -- #! /bin/sh # this is a sh shell archive, use it to extract the following files: # # Makefile # hack.tty.c # hack.termcap.c # echo x - Makefile sed 's/^XX//' << 'EOF' > Makefile XX# Hack or Quest Makefile. XX XX# on some systems the termcap library is in -ltermcap XX#TERMLIB = -ltermlib XXTERMLIB = -lcurses XX XX# make hack XXGAME = hack XXCAPGAME = HACK XXGAMEDIR = ../tmp XXCFLAGS = -O -DSYSV XXHACKCSRC = hack.Decl.c\ XX hack.apply.c hack.bones.c hack.c hack.cmdlist.c hack.do.c\ XX hack.do_name.c hack.do_wear.c hack.dog.c hack.eat.c hack.end.c\ XX hack.engrave.c hack.fight.c hack.invent.c hack.ioctl.c\ XX hack.lev.c hack.main.c hack.makemon.c\ XX hack.mkobj.c hack.mhitu.c\ XX hack.mon.c hack.monst.c hack.o_init.c hack.objnam.c\ XX hack.options.c\ XX hack.pri.c hack.read.c hack.rip.c hack.rumors.c\ XX hack.save.c\ XX hack.search.c hack.shk.c hack.stat.c hack.steal.c\ XX hack.termcap.c hack.timeout.c hack.topl.c\ XX hack.track.c hack.trap.c hack.tty.c hack.u_init.c hack.vault.c\ XX hack.whatis.c hack.wield.c hack.worm.c hack.worn.c hack.zap.c\ XX hack.version.c rnd.c alloc.c XX XXCSOURCES = $(HACKCSRC) mklev.c mklv.shk.c mklv.shknam.c mklv.makemaz.c\ XX makedefs.c XX XXHSOURCES = savelev.h\ XX mklev.h hack.h hack.mfndpos.h config.h\ XX def.edog.h def.eshk.h def.func_tab.h def.gen.h def.objclass.h\ XX def.monst.h def.obj.h def.permonst.h def.trap.h def.wseg.h\ XX def.objects.h XX XXSOURCES = $(CSOURCES) $(HSOURCES) XX XXAUX = data help hh rumors hack.6 hack.sh XX XXHOBJ = hack.Decl.o hack.apply.o hack.bones.o hack.o hack.cmdlist.o hack.do.o\ XX hack.do_name.o hack.do_wear.o hack.dog.o hack.eat.o hack.end.o\ XX hack.engrave.o hack.fight.o hack.invent.o hack.ioctl.o\ XX hack.lev.o hack.main.o hack.makemon.o\ XX hack.mkobj.o hack.mhitu.o hack.mon.o\ XX hack.monst.o hack.o_init.o hack.objnam.o hack.options.o hack.pri.o\ XX hack.read.o hack.rip.o\ XX hack.rumors.o hack.save.o\ XX hack.search.o\ XX hack.shk.o hack.stat.o hack.steal.o hack.termcap.o\ XX hack.timeout.o hack.topl.o\ XX hack.track.o hack.trap.o\ XX hack.tty.o hack.u_init.o hack.vault.o hack.whatis.o hack.wield.o\ XX hack.worm.o hack.worn.o hack.zap.o\ XX hack.version.o XX XXGOBJ = rnd.o alloc.o XX XXall: $(GAME) mklev XX @echo "Made Hack." XX XX$(GAME): $(HOBJ) $(GOBJ) Makefile XX @echo "Loading ..." XX @cc -o $(GAME) $(GOBJ) $(HOBJ) $(TERMLIB) XX XXmakedefs: makedefs.c XX cc -o makedefs makedefs.c XX XX XXhack.onames.h: makedefs def.objects.h XX makedefs > hack.onames.h XXmklv.mkobj.o: mklev.h hack.onames.h hack.mkobj.c XX rm -f mklv.mkobj.c XX /bin/ln hack.mkobj.c mklv.mkobj.c XX cc -c $(CFLAGS) -DMKLEV mklv.mkobj.c XX rm -f mklv.mkobj.c XXmklv.makemon.o: mklev.h hack.makemon.c XX rm -f mklv.makemon.c XX /bin/ln hack.makemon.c mklv.makemon.c XX cc -c $(CFLAGS) -DMKLEV mklv.makemon.c XX rm -f mklv.makemon.c XXmklv.o_init.o: hack.o_init.c def.objects.h hack.onames.h XX rm -f mklv.o_init.c XX /bin/ln hack.o_init.c mklv.o_init.c XX cc -c $(CFLAGS) -DMKLEV mklv.o_init.c XX rm -f mklv.o_init.c XXmklev.o: XX cc -c $(CFLAGS) -DMKLEV mklev.c XXMKLOBJ = mklev.o hack.monst.o mklv.o_init.o mklv.mkobj.o mklv.shk.o\ XX mklv.shknam.o mklv.makemon.o mklv.makemaz.o $(GOBJ) XXmklev: $(MKLOBJ) XX cc -o mklev $(MKLOBJ) XX XXlint: lint_h lint_m XX @echo "Lint done." XX XXlint_h: XX# lint cannot have -p here because (i) capitals are meaningful: XX# [Ww]izard, (ii) identifiers may coincide in the first six places: XX# doweararm() versus dowearring(). XX# _flsbuf comes from <stdio.h>, a bug in the system libraries. XX lint -axbh -DLINT $(HACKCSRC) | sed '/_flsbuf/d' > olint_h XX cat olint_h | sed '/never used/d;/warning/d' XX XXlint_m: XX lint -axbh -DLINT -DMKLEV mklev.c hack.makemon.c hack.monst.c\ XX hack.o_init.c hack.mkobj.c mklv.shk.c mklv.makemaz.c alloc.c\ XX rnd.c XX XX XXprint: XX print *.h Makefile $(AUX) XX print mklev.c mklev.*.c rnd.c alloc.c hack.c XX print hack.Decl.c Hack.magic.C hack.[a-m]*.c XX print hack.[n-z]*.c XX print show.c makedefs.c XX XXdiff: XX @- for i in $(SOURCES) $(AUX) ; do \ XX echo ; echo diff $D/$$i $$i ; \ XX diff $D/$$i $$i ; done XX XXdistribution: Makefile XX @- for i in READ_ME $(SOURCES) $(AUX) Makefile date.h hack.onames.h\ XX ; do \ XX cmp -s $$i $D/$$i || \ XX ( echo cp $$i $D ; cp $$i $D ) ; done XX# the distribution directory also contains the empty files XX# perm and record, and the informative files Porting and Bugs. XX XX XXinstall: XX rm -f /usr/games/$(CAPGAME) XX cp $(GAME) /usr/games/$(CAPGAME) XX# chmod 0710 /usr/games/$(CAPGAME) XX chmod 04711 /usr/games/$(CAPGAME) XX rm -f $(GAMEDIR)/mklev XX cp mklev $(GAMEDIR)/mklev XX# chmod 0750 $(GAMEDIR)/mklev XX chmod 0751 $(GAMEDIR)/mklev XX rm -f $(GAMEDIR)/bones* XX XXdepend: XX# For the moment we are lazy and disregard /usr/include files because XX# the sources contain them conditionally. Perhaps we should use cpp. XX# -e 's,<\(.*\)>,"/usr/include/\1",' \ XX# XX for i in ${CSOURCES}; do \ XX ( /bin/grep '^#[ ]*include' $$i | sed -n \ XX -e '/<.*>/d' \ XX -e 's/[^"]*"\([^"]*\)".*/\1/' \ XX -e H -e '$$g' -e '$$s/\n/ /g' \ XX -e '$$s/.*/'$$i': &/' -e '$$s/\.c:/.o:/p' \ XX >> makedep); done XX for i in ${HSOURCES}; do \ XX ( /bin/grep '^#[ ]*include' $$i | sed -n \ XX -e '/<.*>/d' \ XX -e 's/[^"]*"\([^"]*\)".*/\1/' \ XX -e H -e '$$g' -e '$$s/\n/ /g' \ XX -e '$$s/.*/'$$i': &\ XX touch '$$i/p \ XX >> makedep); done XX @echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep XX @echo '$$r makedep' >>eddep XX @echo 'w' >>eddep XX @cp Makefile Makefile.bak XX ed - Makefile < eddep XX rm eddep makedep XX @echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile XX @echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile XX @echo '# see make depend above' >> Makefile XX - diff Makefile Makefile.bak XX @rm -f Makefile.bak XX XX# DO NOT DELETE THIS LINE XX XXhack.Decl.o: hack.h XXhack.apply.o: hack.h def.edog.h XXhack.bones.o: hack.h XXhack.o: hack.h def.trap.h XXhack.cmdlist.o: config.h def.objclass.h def.func_tab.h XXhack.dog.o: hack.h hack.mfndpos.h def.edog.h XXhack.eat.o: hack.h XXhack.engrave.o: hack.h XXhack.fight.o: hack.h XXhack.invent.o: hack.h def.wseg.h XXhack.main.o: hack.h XXhack.makemon.o: mklev.h hack.h XXhack.mkobj.o: mklev.h hack.h hack.onames.h XXhack.mhitu.o: hack.h XXhack.mon.o: hack.h hack.mfndpos.h XXhack.monst.o: mklev.h def.eshk.h XXhack.o_init.o: config.h def.objects.h hack.onames.h XXhack.objnam.o: hack.h XXhack.options.o: config.h hack.h XXhack.pri.o: hack.h def.wseg.h XXhack.read.o: hack.h XXhack.rumors.o: config.h XXhack.search.o: hack.h def.trap.h XXhack.shk.o: hack.h hack.mfndpos.h def.eshk.h XXhack.steal.o: hack.h XXhack.termcap.o: config.h XXhack.timeout.o: hack.h XXhack.track.o: hack.h XXhack.trap.o: hack.h def.trap.h XXhack.vault.o: hack.h XXhack.whatis.o: hack.h XXhack.wield.o: hack.h XXhack.worm.o: hack.h def.wseg.h XXhack.worn.o: hack.h XXhack.zap.o: hack.h XXhack.version.o: date.h XXmklev.o: mklev.h def.trap.h savelev.h XXmklv.shk.o: mklev.h def.eshk.h XXmklv.shknam.o: mklev.h XXmklv.makemaz.o: mklev.h XXmklev.h: config.h def.objclass.h def.monst.h def.gen.h def.obj.h def.permonst.h XX touch mklev.h XXhack.h: mklev.h hack.onames.h XX touch hack.h XXdef.objects.h: def.objclass.h XX touch def.objects.h XX# DEPENDENCIES MUST END AT END OF FILE XX# IF YOU PUT STUFF HERE IT WILL GO AWAY XX# see make depend above EOF echo x - hack.termcap.c sed 's/^XX//' << 'EOF' > hack.termcap.c XX/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ XX XX#include <stdio.h> XX#include "config.h" /* for ROWNO and COLNO */ XXextern char *tgetstr(), *tgoto(), *getenv(); XXextern long *alloc(); XX XXshort ospeed; /* terminal baudrate; used by tputs */ XXchar tbuf[512]; XXchar *HO, *CL, *CE, *UP, *CM, *ND, *XD, *BC, *SO, *SE; XXchar PC = '\0'; XX XXstartup() XX{ XX register char *tmp; XX register char *tptr; XX char *tbufptr, *pc; XX XX gettty(); /* sets ospeed */ XX XX tptr = (char *) alloc(1024); XX XX tbufptr = tbuf; XX if(!(tmp = getenv("TERM"))) XX error("Can't get TERM."); XX if(tgetent(tptr,tmp) < 1) XX error("Unknown terminal type: %s.", tmp); XX if(pc = tgetstr("pc",&tbufptr)) XX PC = *pc; XX#ifdef SYSV XX if(!(BC = tgetstr("le", &tbufptr))) { XX#else XX if(!(BC = tgetstr("bc",&tbufptr))) { XX if(!tgetflag("bs")) XX error("Terminal must backspace."); XX#endif XX BC = tbufptr; XX tbufptr += 2; XX *BC = '\b'; XX } XX HO = tgetstr("ho", &tbufptr); XX if(tgetnum("co") < COLNO || tgetnum("li") < ROWNO+2) XX error("Screen must be at least %d by %d!", XX ROWNO+2, COLNO); XX if(!(CL = tgetstr("cl",&tbufptr)) || !(CE = tgetstr("ce",&tbufptr)) || XX !(ND = tgetstr("nd", &tbufptr)) || XX !(UP = tgetstr("up",&tbufptr)) || tgetflag("os")) XX error("Hack needs CL, CE, UP, ND, and no OS."); XX if(!(CM = tgetstr("cm",&tbufptr))) XX printf("Use of hack on terminals without CM is suspect...\n"); XX XD = tgetstr("xd",&tbufptr); XX SO = tgetstr("so",&tbufptr); XX SE = tgetstr("se",&tbufptr); XX if(!SO || !SE) SO = SE = 0; XX if(tbufptr-tbuf > sizeof(tbuf)) error("TERMCAP entry too big...\n"); XX free(tptr); XX} XX XX/* Cursor movements */ XXextern xchar curx, cury; XX XXcurs(x,y) XXregister int x,y; /* not xchar: perhaps xchar is unsigned and XX curx-x would be unsigned as well */ XX{ XX XX if (y == cury && x == curx) return; XX if(abs(cury-y)<= 3 && abs(curx-x)<= 3) nocmov(x,y); XX else if((x <= 3 && abs(cury-y)<= 3) || (!CM && x<abs(curx-x))) { XX (void) putchar('\r'); XX curx = 1; XX nocmov(x,y); XX } else if(!CM) nocmov(x,y); XX else cmov(x,y); XX} XX XXnocmov(x,y) XX{ XX if (curx < x) { /* Go to the right. */ XX while (curx < x) { XX xputs(ND); XX curx++; XX } XX } else if (curx > x) { XX while (curx > x) { /* Go to the left. */ XX xputs(BC); XX curx--; XX } XX } XX if (cury > y) { XX if(UP) { XX while (cury > y) { /* Go up. */ XX xputs(UP); XX cury--; XX } XX } else cmov(x,y); XX } else if (cury < y) { XX if(XD) { XX while(cury<y) { XX xputs(XD); XX cury++; XX } XX } else cmov(x,y); XX } XX} XX XXcmov(x,y) XXregister x,y; XX{ XX if(!CM) error("Tries to cmov from %d %d to %d %d\n",curx,cury,x,y); XX xputs(tgoto(CM,x-1,y-1)); XX cury = y; XX curx = x; XX} XX XXxputc(c) char c; { XX (void) fputc(c,stdout); XX} XX XXxputs(s) char *s; { XX tputs(s, 1, xputc); XX} XX XXcl_end() { XX xputs(CE); XX} XX XXclear_screen() { XX xputs(CL); XX curx = cury = 1; XX} XX XXhome() XX{ XX if(HO) xputs(HO); XX else xputs(tgoto(CM,0,0)); XX curx = cury = 1; XX} XX XXstandoutbeg() XX{ XX if(SO) xputs(SO); XX} XX XXstandoutend() XX{ XX if(SE) xputs(SE); XX} XX XXbacksp() XX{ XX xputs(BC); XX curx--; XX} XX XXbell() XX{ XX putsym('\007'); XX} XX XXdelay_output() { XX /* delay 40 ms - could also use a 'nap'-system call */ XX#ifdef SYSV XX tputs("$<40>",1,xputc); XX#else XX tputs("40", 1, xputc); XX#endif XX} EOF echo x - hack.tty.c sed 's/^XX//' << 'EOF' > hack.tty.c XX/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ XX XX#include "hack.h" XX#include <stdio.h> XX#ifdef SYSV XX#include <ctype.h> XX#include <sys/termio.h> XXstruct termio inittyb, curttyb; XX#else XX#include <sgtty.h> XXstruct sgttyb inittyb, curttyb; XX#endif XX XXextern short ospeed; XX XXgettty(){ XX#ifdef SYSV XX ioctl(0, TCGETA, &inittyb); XX ioctl(0, TCGETA, &curttyb); XX ospeed = inittyb.c_cflag&CBAUD; XX#else XX (void) gtty(0, &inittyb); XX (void) gtty(0, &curttyb); XX ospeed = inittyb.sg_ospeed; XX getioctls(); XX#endif XX XX/* XX if(ospeed <= B300) flags.oneline = 1; XX*/ XX xtabs(); XX} XX XX/* reset terminal to original state */ XXsettty(s) char *s; { XX clear_screen(); XX if(s) printf(s); XX (void) fflush(stdout); XX#ifdef SYSV XX if (ioctl(0, TCSETAW, &inittyb) == -1) puts("Cannot Change tty"); XX flags.echo = inittyb.c_lflag&ECHO? ON: OFF; XX flags.cbreak = inittyb.c_lflag&ICANON? OFF:ON; XX#else XX if(stty(0, &inittyb) == -1) puts("Cannot change tty"); XX flags.echo = (inittyb.sg_flags & ECHO) ? ON : OFF; XX flags.cbreak = (inittyb.sg_flags & CBREAK) ? ON : OFF; XX setioctls(); XX#endif XX} XX XXsetctty(){ XX#ifdef SYSV XX if(ioctl(0,TCSETAW, &curttyb) == -1) puts("Cannot change tty"); XX#else XX if(stty(0, &curttyb) == -1) puts("Cannot change tty"); XX#endif XX} XX#ifdef SYSV XX XXsetftty() XX{ XXregister int echo = flags.echo? ECHO: 0; XXregister int canon = flags.cbreak? 0:ICANON; XXregister int change = 0; XX XX if (echo != (curttyb.c_lflag&ECHO)) { XX curttyb.c_lflag &= ~ECHO; XX curttyb.c_lflag |= echo; XX change++; XX } XX if (canon != (curttyb.c_lflag&ICANON)) { XX if (canon) { XX curttyb.c_lflag |= ICANON; XX curttyb.c_cc[VEOF] = 04; /* give back ctrl-D */ XX } XX else { XX curttyb.c_lflag &= ~ICANON; XX curttyb.c_cc[VEOF] = 1; /* buffer only one character */ XX } XX change++; XX } XX if (change) setctty(); XX} XX XX#else XX XXsetftty(){ XXregister int ef = (flags.echo == ON) ? ECHO : 0; XXregister int cf = (flags.cbreak == ON) ? CBREAK : 0; XXregister int change = 0; XX if((curttyb.sg_flags & ECHO) != ef){ XX curttyb.sg_flags &= ~ECHO; XX curttyb.sg_flags |= ef; XX change++; XX } XX if((curttyb.sg_flags & CBREAK) != cf){ XX curttyb.sg_flags &= ~CBREAK; XX curttyb.sg_flags |= cf; XX change++; XX } XX if(change){ XX setctty(); XX } XX} XX#endif SYSV XX XXecho(n) XXregister n; XX{ XX XX /* (void) gtty(0,&curttyb); */ XX#ifdef SYSV XX if (n==ON) XX curttyb.c_lflag |= ECHO; XX else XX curttyb.c_lflag &= ~ECHO; XX#else XX if(n == ON) XX curttyb.sg_flags |= ECHO; XX else XX curttyb.sg_flags &= ~ECHO; XX#endif XX setctty(); XX} XX XX/* always want to expand tabs, or to send a clear line char before XX printing something on topline */ XXxtabs() XX{ XX XX /* (void) gtty(0, &curttyb); */ XX#ifdef SYSV XX curttyb.c_oflag |= TAB3; XX#else XX curttyb.sg_flags |= XTABS; XX#endif XX setctty(); XX} XX XX#ifdef LONG_CMD XXcbreak(n) XXregister n; XX{ XX /* (void) gtty(0,&curttyb); */ XX#ifdef SYSV XX if (n!=ON) XX curttyb.c_lflag |= ICANON; XX else { XX curttyb.c_lflag &= ~ICANON; XX curttyb.c_cc[VEOF] = 1; XX } XX#else XX if(n == ON) XX curttyb.sg_flags |= CBREAK; XX else XX curttyb.sg_flags &= ~CBREAK; XX#endif XX setctty(); XX} XX#endif LONG_CMD XX XXgetlin(bufp) XXregister char *bufp; XX{ XX register char *obufp = bufp; XX register int c; XX XX flags.topl = 2; /* nonempty, no --More-- required */ XX for(;;) { XX (void) fflush(stdout); XX if((c = getchar()) == EOF) { XX *bufp = 0; XX return; XX } XX if(c == '\b') { XX if(bufp != obufp) { XX bufp--; XX putstr("\b \b"); /* putsym converts \b */ XX } else bell(); XX } else if(c == '\n') { XX *bufp = 0; XX return; XX } else { XX *bufp = c; XX bufp[1] = 0; XX putstr(bufp); XX if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO) XX bufp++; XX } XX } XX} XX XXgetret() { XX xgetret(TRUE); XX} XX XXcgetret() { XX xgetret(FALSE); XX} XX XXxgetret(spaceflag) XXboolean spaceflag; /* TRUE if space (return) required */ XX{ XX printf("\nHit %s to continue: ", XX flags.cbreak ? "space" : "return"); XX xwaitforspace(spaceflag); XX} XX XXchar morc; /* tell the outside world what char he used */ XX XXxwaitforspace(spaceflag) XXboolean spaceflag; XX{ XXregister int c; XX XX (void) fflush(stdout); XX morc = 0; XX XX while((c = getchar()) != '\n') { XX if(c == EOF) { XX settty("End of input?\n"); XX exit(0); XX } XX if(flags.cbreak) { XX if(c == ' ') break; XX if(!spaceflag && letter(c)) { XX morc = c; XX break; XX } XX } XX } XX} XX XXchar * XXparse() XX{ XX static char inline[COLNO]; XX register foo; XX XX flags.move = 1; XX if(!Invis) curs(u.ux,u.uy+2); else home(); XX (void) fflush(stdout); XX while((foo = getchar()) >= '0' && foo <= '9') XX multi += 10*multi+foo-'0'; XX if(multi) { XX multi--; XX save_cm = inline; XX } XX inline[0] = foo; XX inline[1] = 0; XX if(foo == EOF) { XX#ifdef SYSV XX clearerr(stdin); XX if ( (foo = getchar()) == EOF) { XX#endif XX settty("End of input?\n"); XX exit(0); XX#ifdef SYSV XX } XX else if (iscntrl(foo)) XX foo = getchar(); XX#endif XX } XX if(foo == 'f' || foo == 'F'){ XX inline[1] = getchar(); XX#ifdef QUEST XX if(inline[1] == foo) inline[2] = getchar(); else XX#endif QUEST XX inline[2] = 0; XX } XX if(foo == 'm' || foo == 'M'){ XX inline[1] = getchar(); XX inline[2] = 0; XX } XX clrlin(); XX return(inline); XX} XX XXchar XXreadchar() { XX register int sym; XX (void) fflush(stdout); XX if((sym = getchar()) == EOF) { XX#ifdef SYSV XX clearerr(stdin); XX if ((sym = getchar()) == EOF) { XX#endif XX settty("End of input?\n"); XX exit(0); XX#ifdef SYSV XX } XX#endif XX } XX if(flags.topl == 1) flags.topl = 2; XX return((char) sym); XX} EOF exit