-+-+-+-+-+-+-+-+ START OF PART 14 -+-+-+-+-+-+-+-+ X ipoint=1; iepoint=i; return(*inbuffer); X`7D X X/* X * long lrint() Read one integer from input buffer X * X * +---------+---------+---------+---------+ X * `7C high `7C `7C `7C low `7C X * `7C order `7C `7C `7C order `7C X * `7C byte `7C `7C `7C byte `7C 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 `7B X register unsigned long i; X i = 255 & lgetc(); i `7C= (255 & lgetc()) << 8; X i `7C= (255 & lgetc()) << 16; i `7C= (255 & lgetc()) << 24; X return(i); X `7D 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) X register char *adr; X int num; X `7B X register char *pnt; X register int num2; X while (num) X `7B X if (iepoint == ipoint) X `7B X if (num>5) /* fast way */ X `7B X if (vread(fd,adr,num) != num) X write(2,"error reading from input file\n",30); X num=0; X `7D X else `7B *adr++ = lgetc(); --num; `7D X `7D X else X `7B X num2 = iepoint-ipoint; /* # of bytes left in the buffer */ X if (num2 > num) num2=num; X pnt = inbuffer+ipoint; num -= num2; ipoint += num2; X while (num2--) *adr++ = *pnt++; X `7D X `7D X `7D 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 NULL X */ Xchar *lgetw() X `7B X register char *lgp,cc; X register int n=LINBUFSIZE,quote=0; X lgp = lgetwbuf; X do cc=lgetc(); while ((cc <= 32) && (cc > NULL)); /* eat whitespace */ X for ( ; ; --n,cc=lgetc()) X `7B X if ((cc==NULL) && (lgp==lgetwbuf)) return(NULL); /* EOF */ X if ((n<=1) `7C`7C ((cc<=32) && (quote==0))) `7B *lgp=NULL; return(lg Vetwbuf); `7D X if (cc != '"') *lgp++ = cc; else quote `5E= 1; X `7D X `7D X X/* X * char *lgetl() 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 NUL VL X */ Xchar *lgetl() X`7B X register int i=LINBUFSIZE,ch; X register char *str=lgetwbuf; X for ( ; ; --i) `7B X *str++ = ch = lgetc(); X if (ch == 0) `7B X if (str == lgetwbuf+1) X return(NULL); /* EOF */ X ot: *str = 0; X return(lgetwbuf); /* line ended by EOF */ X `7D X if ((ch=='\n') `7C`7C (i<=1)) X goto ot; /* line ended by \n */ X `7D X`7D 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) X char *str; X `7B X lpnt = lpbuf; lpend = lpbuf+BUFBIG; X if (str==NULL) return(lfd=1); X if ((lfd=creat(str,0644)) < 0)`20 X `7B X lfd=1; lprintf("error creating file <%s>\n",str); lflush(); return(- V1); X `7D X# ifdef MSDOS X setmode(lfd, O_BINARY); X# endif X return(lfd); X `7D 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) X char *str; X `7B X ipoint = iepoint = MAXIBUF; X if (str==NULL) return(fd=0); X if ((fd=open(str,0)) < 0) X `7B X lwclose(); lfd=1; lpnt=lpbuf; return(-1); X `7D X# ifdef MSDOS X setmode(fd, O_BINARY); X# endif X return(fd); X `7D 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) X char *str; X `7B X lpnt = lpbuf; lpend = lpbuf+BUFBIG; X if (str==NULL) return(lfd=1); X if ((lfd=open(str,2)) < 0) X `7B X lfd=1; return(-1); X `7D X# ifdef MSDOS X setmode(lfd, O_BINARY); X# endif X lseek(lfd,0L,2); /* seek to end of file */ X return(lfd); X `7D X X/* X * lrclose() close the input file X * X * Returns nothing of value. X */ Xlrclose() X `7B X if (fd > 0) close(fd); X `7D X X/* X * lwclose() close output file flushing if needed X * X * Returns nothing of value. X */ Xlwclose() X `7B X lflush(); if (lfd > 2) close(lfd); X `7D X X/* X * lprcat(string) append a string to the output buffer X * avoids calls to lprintf (time consuming) X */ Xlprcat(str) X register char *str; X `7B X register char *str2; X if (lpnt >= lpend) lflush();`20 X str2 = lpnt; X while (*str2++ = *str++); X lpnt = str2 - 1; X `7D X X#ifdef VT100 X/* X * cursor(x,y) Subroutine to set the cursor position X * X * x and y are the cursor coordinates, and lpbuff is the output buffer wher Ve X * escape sequence will be placed.`20 X */ Xstatic char *y_num`5B`5D= `7B "\33`5B","\33`5B","\33`5B2","\33`5B3","\33`5B4 V","\33`5B5","\33`5B6", X "\33`5B7","\33`5B8","\33`5B9","\33`5B10","\33`5B11","\33`5B12","\33`5B13 V","\33`5B14", X "\33`5B15","\33`5B16","\33`5B17","\33`5B18","\33`5B19","\33`5B20","\33`5 VB21","\33`5B22", X "\33`5B23","\33`5B24" `7D; X Xstatic char *x_num`5B`5D= `7B "H","H",";2H",";3H",";4H",";5H",";6H",";7H","; V8H",";9H", X ";10H",";11H",";12H",";13H",";14H",";15H",";16H",";17H",";18H",";19H", X ";20H",";21H",";22H",";23H",";24H",";25H",";26H",";27H",";28H",";29H", X ";30H",";31H",";32H",";33H",";34H",";35H",";36H",";37H",";38H",";39H", X ";40H",";41H",";42H",";43H",";44H",";45H",";46H",";47H",";48H",";49H", X ";50H",";51H",";52H",";53H",";54H",";55H",";56H",";57H",";58H",";59H", X ";60H",";61H",";62H",";63H",";64H",";65H",";66H",";67H",";68H",";69H", X ";70H",";71H",";72H",";73H",";74H",";75H",";76H",";77H",";78H",";79H", X ";80H" `7D; X Xcursor(x,y) X int x,y; X `7B X register char *p; X if (lpnt >= lpend) lflush(); X X p = y_num`5By`5D; /* get the string to print */ X while (*p) *lpnt++ = *p++; /* print the string */ X X p = x_num`5Bx`5D; /* get the string to print */ X while (*p) *lpnt++ = *p++; /* print the string */ X `7D X#else VT100 X/* X * cursor(x,y) Put cursor at specified coordinates staring at `5B1,1`5D ( Vtermcap) X */ Xcursor (x,y) X int x,y; X `7B X if (lpnt >= lpend) lflush (); X X *lpnt++ = CURSOR; *lpnt++ = x; *lpnt++ = y; X `7D X#endif VT100 X X/* X * Routine to position cursor at beginning of 24th line X */ Xcursors() X `7B X cursor(1,24); X `7D X X#ifndef VT100 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`5B1 to \E`5B V7 with X * obvious meanings. X */ X Xstatic char cap`5B256`5D; Xstatic char *CM, *CE, *CD, *CL, *SO, *SE, *AL, *DL, *TI, *TE;/* Termcap capa Vbilities */ Xstatic char *outbuf=0; /* translated output buffer */ X Xstatic int ttputch (); X X/* X * init_term() Terminal initialization -- setup termcap info X */ Xinit_term() X `7B X char termbuf`5B1024`5D; X char *capptr = cap+10; X char *term; X X# ifdef MSDOS X term = getenv("TERM"); X if (term == NULL) X term = "ibmpc-mono"; X switch (tgetent(termbuf, term)) X# else X# ifdef VMS X term = getenv("TERM"); X if (term == NULL) X term = getenv("TERMINAL"); X switch (tgetent(termbuf, term)) X# else X switch (tgetent(termbuf, term = getenv("TERM"))) X# endif X# endif X `7B X case -1:`20 X write(2, "Cannot open termcap file.\n", 26); exit(); X case 0:`20 X write(2, "Cannot find entry of ", 21); X write(2, term, strlen (term)); X write(2, " in termcap\n", 12); X exit(); X `7D; 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 TI = tgetstr("ti", &capptr); /* Terminal initialization */ X TE = tgetstr("te", &capptr); /* Terminal end */ X X if (!CM) /* can't find cursor motion entry */ X `7B X write(2, "Sorry, for a ",13); write(2, term, strlen(term)); X write(2, ", I can't find the cursor motion entry in termcap\n",50); X exit(); X `7D X if (!CE) /* can't find clear to end of line entry */ X `7B X write(2, "Sorry, for a ",13); write(2, term, strlen(term)); X write(2,", I can't find the clear to end of line entry in termcap\n" V,57); X exit(); X `7D X if (!CL) /* can't find clear entire screen entry */ X `7B X write(2, "Sorry, for a ",13); write(2, term, strlen(term)); X write(2, ", I can't find the clear entire screen entry in termcap\n" V,56); X exit(); X `7D X if ((outbuf=(char *)malloc(BUFBIG+16))==0) /* get memory for decoded out Vput buffer*/ X `7B X write(2,"Error malloc'ing memory for decoded output buffer\n",50); X died(-285); /* malloc() failure */ X `7D X `7D X#endif VT100 X X/* X * cl_line(x,y) Clear the whole line indicated by 'y' and leave cursor at ` V5Bx,y`5D X */ Xcl_line(x,y) X int x,y; X `7B X#ifdef VT100 X cursor(x,y); lprcat("\33`5B2K"); X#else VT100 X cursor(1,y); *lpnt++ = CL_LINE; cursor(x,y); X#endif VT100 X `7D X X/* X * cl_up(x,y) Clear screen from `5Bx,1`5D to current position. Leave cursor V at `5Bx,y`5D X */ Xcl_up(x,y) X register int x,y; X `7B X#ifdef VT100 X cursor(x,y); lprcat("\33`5B1J\33`5B2K"); X#else VT100 X register int i; X cursor(1,1); X for (i=1; i<=y; i++) `7B *lpnt++ = CL_LINE; *lpnt++ = '\n'; `7D X cursor(x,y); X#endif VT100 X `7D X X/* X * cl_dn(x,y) Clear screen from `5B1,y`5D to end of display. Leave cursor V at `5Bx,y`5D X */ Xcl_dn(x,y) X register int x,y; X `7B X#ifdef VT100 X cursor(x,y); lprcat("\33`5BJ\33`5B2K"); X#else VT100 X register int i; X cursor(1,y); X if (!CD) X `7B X *lpnt++ = CL_LINE; X for (i=y; i<=24; i++) `7B *lpnt++ = CL_LINE; if (i!=24) *lpnt++ = ' V\n'; `7D X cursor(x,y); X `7D X else X *lpnt++ = CL_DOWN; X cursor(x,y); X#endif VT100 X `7D X X/* X * standout(str) Print the argument string in inverse video (standout mod Ve). X */ Xstandout(str) X register char *str; X `7B X#ifdef VT100 X setbold(); X while (*str) X *lpnt++ = *str++; X resetbold(); X#else VT100 X *lpnt++ = ST_START; X while (*str) X *lpnt++ = *str++; X *lpnt++ = ST_END; X#endif VT100 X `7D X X/* X * set_score_output() Called when output should be literally printed. X */ Xset_score_output() X `7B X enable_scroll = -1; X `7D 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 `60enable_scroll' X */ X#ifndef VT100 Xstatic int scrline=18; /* line # for wraparound instead of scrolling if no D VL */ Xlflush () X `7B X register int lpoint; X register char *str; X static int curx = 0; X static int cury = 0; X X if ((lpoint = lpnt - lpbuf) > 0) X `7B X#ifdef EXTRA X c`5BBYTESOUT`5D += lpoint; X#endif X if (enable_scroll <= -1) `7B X flush_buf(); X# ifdef MSDOS X /* Catch write errors on save files X */ X if (write(lfd,lpbuf,lpoint) != lpoint) `7B X if (save_mode) X longjmp(save_jbuf, -1); X else X warn("Error writing output file\n"); X `7D X# else X if (write(lfd,lpbuf,lpoint) != lpoint) X write(2,"error writing to output file\n",29); X# endif X lpnt = lpbuf; /* point back to beginning of buffer */ X return; X `7D X for (str = lpbuf; str < lpnt; str++) X `7B X if (*str>=32) `7B ttputch (*str); curx++; `7D X else switch (*str) `7B X case CLEAR: tputs (CL, 1, ttputch); curx = cury = 0; X break; X X case CL_LINE: tputs (CE, 1, ttputch); X break; X X case CL_DOWN: tputs (CD, 1, ttputch); X break; X X case ST_START: tputs (SO, 1, ttputch); X break; X X case ST_END: tputs (SE, 1, ttputch); X break; X X case CURSOR: curx = *++str - 1; cury = *++str - 1; X tputs (tgoto (CM, curx, cury), 1, ttputch); X break; X X case '\n': if ((cury == 23) && enable_scroll) X `7B X if (!DL `7C`7C !AL) /* wraparound or scrol Vl? */ X `7B +-+-+-+-+-+-+-+- END OF PART 14 +-+-+-+-+-+-+-+-