Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!zephyr!tektronix!tekgen!tekred!saab!billr From: billr@saab.CNA.TEK.COM (Bill Randle) Newsgroups: comp.sources.games Subject: v07i003: ularn - ultra-larn, an enhancement of the larn adventure game, Part03/08 Message-ID: <4196@tekred.CNA.TEK.COM> Date: 6 Jul 89 14:01:07 GMT Sender: news@tekred.CNA.TEK.COM Lines: 1908 Approved: billr@saab.CNA.TEK.COM Submitted-by: "Philip A. Cordier" Posting-number: Volume 7, Issue 3 Archive-name: ularn/Part03 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'data.c' <<'END_OF_FILE' X/* data.c */ X#include "header.h" X X/* X class[c[LEVEL]-1] gives the correct name of the players experience level X */ Xstatic char aa1[] = " mighty evil master"; Xstatic char aa2[] = "apprentice demi-god"; Xstatic char aa3[] = " minor demi-god "; Xstatic char aa4[] = " major demi-god "; Xstatic char aa5[] = " minor deity "; Xstatic char aa6[] = " major deity "; Xstatic char aa7[] = " novice guardian "; Xstatic char aa8[] = "apprentice guardian"; Xstatic char aa9[] = " The Creator "; Xchar *class[]= X{ X" novice explorer ", "apprentice explorer", " practiced explorer",/* -3*/ X" expert explorer ", " novice adventurer", " adventurer ",/* -6*/ X"apprentice conjurer", " conjurer ", " master conjurer ",/* -9*/ X" apprentice mage ", " mage ", " experienced mage ",/* -12*/ X" master mage ", " apprentice warlord", " novice warlord ",/* -15*/ X" expert warlord ", " master warlord ", " apprentice gorgon ",/* -18*/ X" gorgon ", " practiced gorgon ", " master gorgon ",/* -21*/ X" demi-gorgon ", " evil master ", " great evil master ",/* -24*/ X aa1 , aa1 , aa1 ,/* -27*/ X aa1 , aa1 , aa1 ,/* -30*/ X aa1 , aa1 , aa1 ,/* -33*/ X aa1 , aa1 , aa1 ,/* -36*/ X aa1 , aa1 , aa1 ,/* -39*/ X aa2 , aa2 , aa2 ,/* -42*/ X aa2 , aa2 , aa2 ,/* -45*/ X aa2 , aa2 , aa2 ,/* -48*/ X aa3 , aa3 , aa3 ,/* -51*/ X aa3 , aa3 , aa3 ,/* -54*/ X aa3 , aa3 , aa3 ,/* -57*/ X aa4 , aa4 , aa4 ,/* -60*/ X aa4 , aa4 , aa4 ,/* -63*/ X aa4 , aa4 , aa4 ,/* -66*/ X aa5 , aa5 , aa5 ,/* -69*/ X aa5 , aa5 , aa5 ,/* -72*/ X aa5 , aa5 , aa5 ,/* -75*/ X aa6 , aa6 , aa6 ,/* -78*/ X aa6 , aa6 , aa6 ,/* -81*/ X aa6 , aa6 , aa6 ,/* -84*/ X aa7 , aa7 , aa7 ,/* -87*/ X aa8 , aa8 , aa8 ,/* -90*/ X aa8 , aa8 , aa8 ,/* -93*/ X" earth guardian ", " air guardian ", " fire guardian ",/* -96*/ X" water guardian ", " time guardian ", " ethereal guardian ",/* -99*/ X aa9 , aa9 , aa9 ,/* -102*/ X}; X X/* X table of experience needed to be a certain level of player X skill[c[LEVEL]] is the experience required to attain the next level X */ X#define MEG 1000000 Xlong skill[] = { X0, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, /* 1-11 */ X10240, 20480, 40960, 100000, 200000, 400000, 700000, 1*MEG, /* 12-19 */ X2*MEG,3*MEG,4*MEG,5*MEG,6*MEG,8*MEG,10*MEG, /* 20-26 */ X12*MEG,14*MEG,16*MEG,18*MEG,20*MEG,22*MEG,24*MEG,26*MEG,28*MEG, /* 27-35 */ X30*MEG,32*MEG,34*MEG,36*MEG,38*MEG,40*MEG,42*MEG,44*MEG,46*MEG, /* 36-44 */ X48*MEG,50*MEG,52*MEG,54*MEG,56*MEG,58*MEG,60*MEG,62*MEG,64*MEG, /* 45-53 */ X66*MEG,68*MEG,70*MEG,72*MEG,74*MEG,76*MEG,78*MEG,80*MEG,82*MEG, /* 54-62 */ X84*MEG,86*MEG,88*MEG,90*MEG,92*MEG,94*MEG,96*MEG,98*MEG,100*MEG, /* 63-71 */ X105*MEG,110*MEG,115*MEG,120*MEG, 125*MEG, 130*MEG, 135*MEG, 140*MEG, /* 72-79 */ X145*MEG,150*MEG,155*MEG,160*MEG, 165*MEG, 170*MEG, 175*MEG, 180*MEG, /* 80-87 */ X185*MEG,190*MEG,195*MEG,200*MEG, 210*MEG, 220*MEG, 230*MEG, 240*MEG, /* 88-95 */ X 260*MEG,280*MEG,300*MEG,320*MEG, 340*MEG, 370*MEG /* 96-101*/ X}; X#undef MEG X Xchar *lpbuf,*lpnt, X *inbuffer,*lpend; /* input/output pointers to the buffers */ Xstruct cel *cell; /* pointer to the dungeon storage */ Xshort hitp[MAXX][MAXY]; /* monster hp on level */ Xshort iarg[MAXX][MAXY]; /* arg for the item array */ Xchar item[MAXX][MAXY]; /* objects in maze if any */ Xchar know[MAXX][MAXY]; /* 1 or 0 if here before */ Xchar mitem[MAXX][MAXY]; /* monster item array */ Xchar moved[MAXX][MAXY]; /* monster movement flags */ Xchar stealth[MAXX][MAXY];/* 0=sleeping 1=awake monst */ Xchar iven[26]; /* inventory for player */ Xshort ivenarg[26]; /* inventory args for player */ Xchar lastmonst[40]; /*this has the name of the current monster*/ Xchar beenhere[MAXLEVEL+MAXVLEVEL]={0}; /* 1 if have been on this level */ Xchar nosignal=0; /* set to 1 to disable the signals from doing anything*/ Xchar predostuff=0; /* 2 means that the trap handling routines must do a X showplayer() after a trap. 0 means don't showplayer() X 0 - we are in create player screen X 1 - we are in welcome screen X 2 - we are in the normal game */ Xchar loginname[20]; /* players login name */ Xchar logname[LOGNAMESIZE]; /* players name storage for scoring */ Xchar sex=1; /* default is a man 0=woman */ Xchar boldon=1; /* 1=bold objects 0=inverse objects */ Xchar ckpflag=0; /*1 if want checkpointing of game, 0 otherwise */ Xchar cheat=0; /*1 if the player has fudged save file */ Xchar level=0; /* cavelevel player is on = c[CAVELEVEL]*/ Xchar wizard=0; /* the wizard mode flag */ Xchar char_class[20]; /* character class */ Xshort lastnum=0; /* the number of the monster last hitting player*/ Xshort hitflag=0; /* flag for if player has been hit when running */ Xshort hit2flag=0; /* flag for if player has been hit when running */ Xshort hit3flag=0; /* flag for if player has been hit flush input*/ Xshort playerx,playery; /* the room on the present level of the player*/ Xshort lastpx,lastpy; /* 0 --- MAXX-1 or 0 --- MAXY-1 */ Xshort oldx,oldy; Xshort lasthx=0,lasthy=0;/* location of monster last hit by player*/ Xshort nobeep=0; /* true if program is not to beep*/ Xunsigned long randx=33601; /* the random number seed */ Xlong initialtime=0; /* time playing began */ Xlong gtime=0; /* the clock for the game */ Xlong outstanding_taxes=0; /* present tax bill from score file */ Xlong c[100],cbak[100]; /* the character description arrays*/ Xint enable_scroll=0; /* constant for enabled/disabled scrolling regn */ Xchar aborted[] = " aborted"; Xstruct sphere *spheres=0; /*pointer to linked list for spheres of annihilation*/ X Xchar *levelname[]= { X" H"," 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10","11","12","13","14","15", X"V1","V2","V3","V4","V5"}; X Xchar monstnamelist[]=" lGHJKOScjtAELNQRZabhiCTYdegmvzFWflorXV pqsyUkMwDDPxnDDuD .............................................................."; X Xchar objnamelist[]=" AToP%^F&^+M=%^$$f*OD#~][[)))(((||||||||{?!BC.o...<<<'io.c' <<'END_OF_FILE' X/* io.c X * X * Below are the functions in this file: X * X * setupvt100() Subroutine to set up terminal in correct mode for game X * clearvt100() Subroutine to clean up terminal when the game is over X * getcharacter() Routine to read in one character from the terminal X * scbr() Function to set cbreak -echo for the terminal X * sncbr() Function to set -cbreak echo for the terminal X * newgame() Subroutine to save the initial time and seed rnd() X * X * FILE OUTPUT ROUTINES X * X * lprintf(format,args . . .) printf to the output buffer X * lprint(integer) send binary integer to output buffer X * lwrite(buf,len) write a buffer to the output buffer X * lprcat(str) sent string to output buffer X * X * FILE OUTPUT MACROS (in header.h) X * X * lprc(character) put the character into the output buffer X * X * FILE INPUT ROUTINES X * X * long lgetc() read one character from input buffer X * long lrint() read one integer from input buffer X * lrfill(address,number) put input bytes into a buffer X * char *lgetw() get a whitespace ended word from input X * char *lgetl() get a \n or EOF ended line from input X * X * FILE OPEN / CLOSE ROUTINES X * X * lcreat(filename) create a new file for write X * lopen(filename) open a file for read X * lappend(filename) open for append to an existing file X * lrclose() close the input file X * lwclose() close output file X * lflush() flush the output buffer X * X * Other Routines X * X * cursor(x,y) position cursor at [x,y] X * cursors() position cursor at [1,24] (saves memory) X * cl_line(x,y) Clear line at [1,y] and leave cursor at [x,y] X * cl_up(x,y) Clear screen from [x,1] to current line. X * cl_dn(x,y) Clear screen from [1,y] to end of display. X * standout(str) Print the string in standout mode. X * set_score_output() Called when output should be literally printed. X ** putcharacter(ch) Print one character in decoded output buffer. X ** flush_buf() Flush buffer with decoded output. X ** init_term() Terminal initialization -- setup termcap info X **char *tmcapcnv(sd,ss) Routine to convert vt100 \33's to termcap format X * beep() Routine to emit a beep if enabled (see no-beep in .Ularnopts) X * X * Note: ** entries are available only in termcap mode. X */ X#include "header.h" X X#ifdef BSD X# define GTTY(arg) (ioctl(0, TIOCGETP, arg)) X# define STTY(arg) (ioctl(0, TIOCSETP, arg)) X static struct sgttyb inittyb, curttyb; X#else /* SYSV */ X# define GTTY(arg) (ioctl(0, TCGETA, arg)) X# define STTY(arg) (ioctl(0, TCSETAW, arg)) X# define SPEED(x) ((x).c_cflag & CBAUD) X static struct termio inittyb, curttyb; X#endif /* BSD */ X X#define ON 1 X#define OFF 0 X Xextern short ospeed; X X#define LINBUFSIZE 128 /* size of the lgetw() and lgetl() buffer */ Xint lfd; /* output file numbers */ Xint fd; /* input file numbers */ Xstatic int ipoint=MAXIBUF,iepoint=MAXIBUF; /* input buffering pointers */ Xstatic char lgetwbuf[LINBUFSIZE]; /* get line (word) buffer*/ X X/* X * setupvt100() X * Subroutine to set up terminal in correct mode for game X * Attributes off, clear screen, set scrolling region, set tty mode X */ Xsetupvt100() X{ X clear(); X setscroll(); X gettty(); X} X X/* X * clearvt100() X * Subroutine to clean up terminal when the game is over X * Attributes off, clear screen, unset scrolling region, restore tty mode X */ Xclearvt100() X{ X resetscroll(); X clear(); X settty(); X} X X/* X** gettty X** X** Get initial state of terminal, set ospeed (for termcap routines) X** and switch off tab expansion X*/ Xgettty() X{ X if(GTTY(&inittyb) < 0) { X fprintf(stderr, "OOPS: gettty failed\n"); X fflush(stderr); X return; X } X curttyb = inittyb; X#ifndef BSD X ospeed = SPEED(inittyb); X /* do not expand tabs - they might be needed inside a cm sequence */ X if(curttyb.c_oflag & TAB3) { X curttyb.c_oflag &= ~TAB3; X setctty(); X } X#endif /* BSD */ X setuptty(); X} X X/* X** settty X** X** reset terminal to original state X*/ Xsettty() X{ X if(STTY(&inittyb) < 0) { X fprintf(stderr, "OOPS: settty failed\n"); X fflush(stderr); X } X} X X/* X** setctty X** X** set current tty X*/ Xsetctty(){ X if(STTY(&curttyb) < 0) { X fprintf(stderr, "OOPS: setctty failed\n"); X fflush(stderr); X } X} X X X/* X** X** function to setup all required terminal modes for game X*/ Xsetuptty(){ X int change = 0; X#ifdef BSD X scbr(); X#else /* SYSV */ X if((curttyb.c_lflag & ECHO) != OFF){ X curttyb.c_lflag &= ~ECHO; X change++; X } X if((curttyb.c_lflag & ICANON) != !(ICANON)){ X curttyb.c_lflag &= ~ICANON; X curttyb.c_lflag |= !(ICANON); X /* be satisfied with one character; no timeout */ X curttyb.c_cc[VMIN] = 1; /* was VEOF */ X curttyb.c_cc[VTIME] = 0; /* was VEOL */ X change++; X } X if(change) X setctty(); X#endif /* BSD */ X} X X/* X * scbr() Function to set cbreak -echo for the terminal X * X * like: system("stty cbreak -echo") X */ Xscbr() X{ X#ifdef BSD X curttyb.sg_flags |= CBREAK; X curttyb.sg_flags &= ~ECHO; X#else /* SYSV */ X curttyb.c_lflag &= ~ECHO; X curttyb.c_lflag &= ~ICANON; X#endif /* BSD */ X setctty(); X} X X/* X * sncbr() Function to set -cbreak echo for the terminal X * X * like: system("stty -cbreak echo") X */ Xsncbr() X{ X#ifdef BSD X curttyb.sg_flags &= ~CBREAK; X curttyb.sg_flags |= ECHO; X#else /* SYSV */ X curttyb.c_lflag |= ECHO; X curttyb.c_lflag |= ICANON; X#endif /* BSD */ X setctty(); X} X X/* X * getcharacter() Routine to read in one character from the terminal X */ Xgetcharacter() X{ X char byt; X X lflush(); /* be sure output buffer is flushed */ X read(0,&byt,1); /* get byte from terminal */ X return(byt); X} X X/* X * newgame() X * Subroutine to save the initial time and seed rnd() X */ Xnewgame() X{ X register long *p,*pe; X X for (p=c,pe=c+100; p= lpend) lflush(); X outb = lpnt; X for ( ; ; ) { X while (*fmt != '%') X if (*fmt) *outb++ = *fmt++; X else { X lpnt=outb; X return; X } X wide = 0; X left = 1; X cont=1; X while (cont) X switch(*(++fmt)) { X case 'd': X n = va_arg(ap, long); X if (n<0) { X n = -n; X *outb++ = '-'; X if (wide) --wide; X } X tmpb = db+11; X *tmpb = (char)(n % 10 + '0'); X while (n>9) X *(--tmpb) = (char)((n /= 10) % 10+'0'); X if (wide==0) X while (tmpb < db+12) X *outb++ = *tmpb++; X else { X wide -= db-tmpb+12; X if (left) X while (wide-- > 0) X *outb++ = ' '; X while (tmpb < db+12) X *outb++ = *tmpb++; X if (left==0) X while (wide-- > 0) X *outb++ = ' '; X } X cont=0; X break; X X case 's': X tmpb = va_arg(ap, char *); X if (wide==0) { X while (*outb++ = *tmpb++); X --outb; X } X else { X n = wide - strlen(tmpb); X if (left) X while (n-- > 0) X *outb++ = ' '; X while (*outb++ = *tmpb++) X ; X --outb; X if (left==0) X while (n-- > 0) X *outb++ = ' '; X } X cont=0; X break; X X case 'c': X *outb++ = va_arg(ap, int); X cont=0; X break; X X case '0': X case '1': X case '2': X case '3': X case '4': X case '5': X case '6': X case '7': X case '8': X case '9': X wide = 10*wide + *fmt - '0'; X break; X case '-': X left = 0; X break; X default: X *outb++ = *fmt; X cont=0; X break; X }; X fmt++; X } X va_end(ap); X} X X/* X * lprint(long-integer) X * long integer; X * X * send binary integer to output buffer X * X * +---------+---------+---------+---------+ X * | high | | | low | X * | order | | | order | X * | byte | | | byte | X * +---------+---------+---------+---------+ X * 31 --- 24 23 --- 16 15 --- 8 7 --- 0 X * X * The save order is low order first, to high order (4 bytes total) X * and is written to be system independent. X * No checking for output buffer overflow is done, but flushes if needed! X * Returns nothing of value. X */ Xlprint(x) Xlong x; X{ X if (lpnt >= lpend) X lflush(); X *lpnt++ = 255 & x; X *lpnt++ = 255 & (x>>8); X *lpnt++ = 255 & (x>>16); X *lpnt++ = 255 & (x>>24); X} X X/* X * lwrite(buf,len) X * char *buf; X * int len; X * X * write a buffer to the output buffer X * X * Enter with the address and number of bytes to write out X * Returns nothing of value X */ Xlwrite(buf,len) Xchar *buf; Xint len; X{ X register char *str; X register int num2; X X if (len > 399) /* don't copy data if can just write it */ X { X for (str=buf; len>0; --len) X lprc(*str++); X lflush(); X write(lfd,buf,len); X } X else while (len) { X if (lpnt >= lpend) X lflush(); /* if buffer is full flush it */ X X /* # bytes left in output buffer */ X num2 = lpbuf+BUFBIG-lpnt; X X if (num2 > len) num2=len; X str = lpnt; X len -= num2; X while (num2--) *str++ = *buf++; /* copy in the bytes */ X lpnt = str; X } X} X X/* X * long lgetc() Read one character from input buffer X * X * Returns 0 if EOF, otherwise the character X */ Xlong lgetc() X{ X int i; X X if (ipoint != iepoint) X return(inbuffer[ipoint++]); X if (iepoint!=MAXIBUF) X return(0); X if ((i=read(fd,inbuffer,MAXIBUF))<=0) { X if (i!=0) X fprintf(stderr,"error reading from input file\n"); X iepoint = ipoint = 0; X return(0); X } X ipoint=1; X iepoint=i; X return(*inbuffer); X} X X/* X * long lrint() Read one integer from input buffer X * X * +---------+---------+---------+---------+ X * | high | | | low | X * | order | | | order | X * | byte | | | byte | X * +---------+---------+---------+---------+ X * 31 --- 24 23 --- 16 15 --- 8 7 --- 0 X * X * The save order is low order first, to high order (4 bytes total) X * Returns the int read X */ Xlong lrint() X{ X unsigned long i; X X i = 255 & lgetc(); X i |= (255 & lgetc()) << 8; X i |= (255 & lgetc()) << 16; X i |= (255 & lgetc()) << 24; X return(i); X} X X/* X * lrfill(address,number) put input bytes into a buffer X * char *address; X * int number; X * X * Reads "number" bytes into the buffer pointed to by "address". X * Returns nothing of value X */ Xlrfill(adr,num) Xchar *adr; Xint num; X{ X char *pnt; X int num2; X X while (num) { X if (iepoint == ipoint) { X if (num>5) { X if (read(fd,adr,num) != num) X fprintf(stderr,"error reading from input file\n"); X num=0; X } X else { X *adr++ = lgetc(); X --num; X } X } X else { X /* # of bytes left in the buffer */ X num2 = iepoint-ipoint; X X if (num2 > num) X num2=num; X pnt = inbuffer+ipoint; X num -= num2; X ipoint += num2; X while (num2--) X *adr++ = *pnt++; X } X } X} X X/* X * char *lgetw() Get a whitespace ended word from input X * X * Returns pointer to a buffer that contains word. If EOF, returns a 0 X */ Xchar *lgetw() X{ X char *lgp,cc; X int n=LINBUFSIZE,quote=0; X X lgp = lgetwbuf; X X do X cc=lgetc(); X while ((cc <= ' ') && (cc > 0)); /* eat whitespace */ X X for ( ; ; --n,cc=lgetc()) { X if ((cc==0) && (lgp==lgetwbuf)) return(0); /* EOF */ X if ((n<=1) || ((cc<=32) && (quote==0))) { X *lgp=0; X return(lgetwbuf); X } X if (cc != '"') *lgp++ = cc; X else quote ^= 1; X } X} X X/* X * char *lgetl() X * Function to read in a line ended by newline or EOF X * X *Returns pointer to a buffer that contains the line. If EOF, returns 0 X */ Xchar *lgetl() X{ X int i=LINBUFSIZE,ch; X char *str=lgetwbuf; X X for ( ; ; --i) { X if ((*str++ = ch = lgetc()) == 0) { X if (str == lgetwbuf+1) return(0); /* EOF */ Xot: X *str = 0; X return(lgetwbuf); /* line ended by EOF */ X } X if ((ch=='\n') || (i<=1)) X goto ot; /* line ended by \n */ X } X} X X/* X * lcreat(filename) Create a new file for write X * char *filename; X * X * lcreat((char*)0); means to the terminal X * Returns -1 if error, otherwise the file descriptor opened. X */ Xlcreat(str) Xchar *str; X{ X lpnt = lpbuf; X lpend = lpbuf+BUFBIG; X if (str==0) return(lfd=1); X if ((lfd=creat(str,0644)) < 0) { X lfd=1; X lprintf("error creating file <%s>\n",str); X lflush(); X return(-1); X } X return(lfd); X} X X/* X * lopen(filename) Open a file for read X * char *filename; X * X * lopen(0) means from the terminal X * Returns -1 if error, otherwise the file descriptor opened. X */ Xlopen(str) Xchar *str; X{ X ipoint = iepoint = MAXIBUF; X if (str==0) return(fd=0); X if ((fd=open(str,0)) < 0) { X lwclose(); X lfd=1; X lpnt=lpbuf; X return(-1); X } X return(fd); X} X X/* X * lappend(filename) Open for append to an existing file X * char *filename; X * X * lappend(0) means to the terminal X * Returns -1 if error, otherwise the file descriptor opened. X */ Xlappend(str) Xchar *str; X{ X lpnt = lpbuf; X lpend = lpbuf+BUFBIG; X if (str==0) return(lfd=1); X if ((lfd=open(str,2)) < 0) { X lfd=1; X return(-1); X } X lseek(lfd,0,2); /* seek to end of file */ X return(lfd); X} X X/* X * lrclose() X * close the input file X * X * Returns nothing of value. X */ Xlrclose() X{ X if (fd > 0) close(fd); X} X X/* X * lwclose() close output file flushing if needed X * X * Returns nothing of value. X */ Xlwclose() X{ X lflush(); X if (lfd > 2) close(lfd); X} X X/* X * lprcat(string) append a string to the output buffer X * avoids calls to lprintf (time consuming) X */ Xlprcat(str) Xchar *str; X{ X char *str2; X X if (lpnt >= lpend) X lflush(); X str2 = lpnt; X while (*str2++ = *str++) X ; X lpnt = str2 - 1; X} X X/* X * cursor(x,y) Put cursor at specified coordinates staring at [1,1] (termcap) X */ Xcursor (x,y) Xint x,y; X{ X if (lpnt >= lpend) lflush (); X X *lpnt++ = CURSOR; X *lpnt++ = x; X *lpnt++ = y; X} X X/* X * Routine to position cursor at beginning of 24th line X */ Xcursors() X{ X cursor(1,24); X} X X/* X * Warning: ringing the bell is control code 7. Don't use in defines. X * Don't change the order of these defines. X * Also used in helpfiles. Codes used in helpfiles should be \E[1 to \E[7 with X * obvious meanings. X */ X Xstatic char cap[256]; Xchar *CM, *CE, *CD, *CL, *SO, *SE, *AL, *DL;/* Termcap capabilities */ Xstatic char *outbuf=0; /* translated output buffer */ X Xint putcharacter (); X X/* X * init_term() Terminal initialization -- setup termcap info X */ Xinit_term() X{ X char termbuf[1024]; X char *capptr = cap+10; X char *term; X X switch (tgetent(termbuf, term = getenv("TERM"))) { X case -1: X fprintf(stderr, "Cannot open termcap file.\n"); X fflush(stderr); X exit(1); X case 0: X fprintf(stderr, "Cannot find entry of "); X fprintf(stderr, term); X fprintf(stderr, " in termcap\n"); X fflush(stderr); X exit(1); X }; X X CM = tgetstr("cm", &capptr); /* Cursor motion */ X CE = tgetstr("ce", &capptr); /* Clear to eoln */ X CL = tgetstr("cl", &capptr); /* Clear screen */ X X /* OPTIONAL */ X AL = tgetstr("al", &capptr); /* Insert line */ X DL = tgetstr("dl", &capptr); /* Delete line */ X SO = tgetstr("so", &capptr); /* Begin standout mode */ X SE = tgetstr("se", &capptr); /* End standout mode */ X CD = tgetstr("cd", &capptr); /* Clear to end of display */ X X if (!CM) /* can't find cursor motion entry */ X { X fprintf(stderr, "Sorry, for a "); X fprintf(stderr, term); X fprintf(stderr, ", I can't find the cursor motion entry in termcap\n"); X fflush(stderr); X exit(1); X } X if (!CE) /* can't find clear to end of line entry */ X { X fprintf(stderr, "Sorry, for a "); X fprintf(stderr, term); X fprintf(stderr,", I can't find the clear to end of line entry in termcap\n"); X fflush(stderr); X exit(1); X } X if (!CL) /* can't find clear entire screen entry */ X { X fprintf(stderr, "Sorry, for a "); X fprintf(stderr, term); X fprintf(stderr, ", I can't find the clear entire screen entry in termcap\n"); X fflush(stderr); X exit(1); X } X /* get memory for decoded output buffer*/ X if ((outbuf=malloc(BUFBIG+16))==0) { X fprintf(stderr,"Error malloc'ing memory for decoded output buffer\n"); X fflush(stderr); X died(-285); /* malloc() failure */ X } X} X X/* X * cl_line(x,y) Clear the whole line indicated by 'y' and leave cursor at [x,y] X */ Xcl_line(x,y) Xint x,y; X{ X cursor(1,y); X *lpnt++ = CL_LINE; X cursor(x,y); X} X X/* X * cl_up(x,y) Clear screen from [x,1] to current position. Leave cursor at [x,y] X */ Xcl_up(x,y) Xregister int x,y; X{ X register int i; X cursor(1,1); X for (i=1; i<=y; i++) { X *lpnt++ = CL_LINE; X *lpnt++ = '\n'; X } X cursor(x,y); X} X X/* X * cl_dn(x,y) Clear screen from [1,y] to end of display. Leave cursor at [x,y] X */ Xcl_dn(x,y) Xint x,y; X{ X int i; X X cursor(1,y); X if (!CD) { X *lpnt++ = CL_LINE; X for (i=y; i<=24; i++) { X *lpnt++ = CL_LINE; X if (i!=24) *lpnt++ = '\n'; X } X cursor(x,y); X } X else X *lpnt++ = CL_DOWN; X cursor(x,y); X} X X/* X * standout(str) Print the argument string in inverse video (standout mode). X */ Xstandout(str) Xregister char *str; X{ X if (boldon == 0) { X lprcat(str); X return; X } X *lpnt++ = ST_START; X while (*str) X *lpnt++ = *str++; X *lpnt++ = ST_END; X} X X/* X * set_score_output() Called when output should be literally printed. X */ Xset_score_output() X{ X enable_scroll = -1; X} X X/* X * lflush() Flush the output buffer X * X * Returns nothing of value. X * for termcap version: Flush output in output buffer according to output X * status as indicated by `enable_scroll' X */ Xstatic int scrline=18; /* line # for wraparound instead of scrolling if no DL */ Xlflush () X{ X int lpoint; X char *str; X static int curx = 0; X static int cury = 0; X X if ((lpoint = lpnt - lpbuf) > 0) { X if (enable_scroll <= -1) { X flush_buf(); X if (write(lfd,lpbuf,lpoint) != lpoint) { X fprintf(stderr,"error writing to output file\n"); X fflush(stderr); X } X lpnt = lpbuf; /* point back to beginning of buffer */ X return; X } X for (str = lpbuf; str < lpnt; str++) { X if (*str>=32) { X putcharacter (*str); X curx++; X } X else switch (*str) { X case CLEAR: X tputs (CL, 0, putcharacter); X curx = cury = 0; X break; X X case CL_LINE: X tputs (CE, 0, putcharacter); X break; X X case CL_DOWN: X tputs (CD, 0, putcharacter); X break; X X case ST_START: X tputs (SO, 0, putcharacter); X break; X X case ST_END: X tputs (SE, 0, putcharacter); X break; X X case CURSOR: X curx = *++str - 1; X cury = *++str - 1; X tputs (tgoto (CM, curx, cury), 0, putcharacter); X break; X case '\n': X if ((cury == 23) && enable_scroll) { X if (!DL || !AL) { X if (++scrline > 23) scrline=19; X if (++scrline > 23) scrline=19; X tputs (tgoto (CM, 0, scrline), 0, putcharacter); X tputs (CE, 0, putcharacter); X X if (--scrline < 19) scrline=23; X tputs (tgoto (CM, 0, scrline), 0, putcharacter); X tputs (CE, 0, putcharacter); X } X else { X tputs (tgoto (CM, 0, 19), 0, putcharacter); X tputs (DL, 0, putcharacter); X tputs (tgoto (CM, 0, 23), 0, putcharacter); X } X } X else { X putcharacter ('\n'); X cury++; X } X curx = 0; X break; X X default: X putcharacter (*str); X curx++; X }; X } X } X lpnt = lpbuf; X flush_buf(); /* flush real output buffer now */ X} X Xstatic int index=0; X X/* X * putcharacter(ch) Print one character in decoded output buffer. X */ Xint putcharacter(c) Xint c; X{ X outbuf[index++] = c; X if (index >= BUFBIG) X flush_buf(); X} X X/* X * flush_buf() Flush buffer with decoded output. X */ Xflush_buf() X{ X if (index) X write(lfd, outbuf, index); X index = 0; X} X X/* X * char *tmcapcnv(sd,ss) X * Routine to convert vt100 escapes to termcap format X * X * Processes only the \33[#m sequence (converts . files for termcap use X */ Xchar *tmcapcnv(sd,ss) Xchar *sd,*ss; X{ X int tmstate=0; /* 0=normal, 1=\33 2=[ 3=# */ X char tmdigit=0; /* the # in \33[#m */ X X while (*ss) { X switch(tmstate) { X case 0: X if (*ss=='\33') { X tmstate++; X break; X } Xign: X *sd++ = *ss; Xign2: X tmstate = 0; X break; X case 1: X if (*ss!='[') goto ign; X tmstate++; X break; X case 2: X if (isdigit(*ss)) { X tmdigit= *ss-'0'; X tmstate++; X break; X } X if (*ss == 'm') { X *sd++ = ST_END; X goto ign2; X } X goto ign; X case 3: X if (*ss == 'm') { X if (tmdigit) *sd++ = ST_START; X else *sd++ = ST_END; X goto ign2; X } X default: X goto ign; X }; X ss++; X } X *sd=0; /* 0 terminator */ X return(sd); X} X X/* X * beep() Routine to emit a beep if enabled (see no-beep in .Ularnopts) X */ Xbeep() X{ X if (!nobeep) *lpnt++ = '\7'; X} END_OF_FILE if test 20742 -ne `wc -c <'io.c'`; then echo shar: \"'io.c'\" unpacked with wrong size! fi # end of 'io.c' fi if test -f 'to_ansi.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'to_ansi.c'\" else echo shar: Extracting \"'to_ansi.c'\" \(410 characters\) sed "s/^X//" >'to_ansi.c' <<'END_OF_FILE' X/* X * convert ascii sequence '^[' into escape characters X */ X#include X Xmain() X{ X int c, c2; X X while ((c = getc(stdin)) != EOF) { X if (c == '^') { X if ((c2 = getc(stdin)) != EOF) { X if (c2 == '[') X putc('\033', stdout); X else { X putc((char)c, stdout); X putc((char)c2, stdout); X } X } else { X putc((char)c, stdout); X exit(0); X } X } else X putc((char)c, stdout); X } X} END_OF_FILE if test 410 -ne `wc -c <'to_ansi.c'`; then echo shar: \"'to_ansi.c'\" unpacked with wrong size! fi # end of 'to_ansi.c' fi echo shar: End of archive 3 \(of 8\). cp /dev/null ark3isdone MISSING="" for I in 1 2 3 4 5 6 7 8 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 8 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0