1/* Header: term.h,v 7.0.1.2 86/12/12 17:05:15 lwall Exp */ 2 3/* Log: term.h,v 4 * Revision 7.0.1.2 86/12/12 17:05:15 lwall 5 * Baseline for net release. 6 * 7 * Revision 7.0.1.1 86/10/16 10:53:33 lwall 8 * Added Damage. Fixed random bugs. 9 * 10 * Revision 7.0 86/10/08 15:14:07 lwall 11 * Split into separate files. Added amoebas and pirates. 12 * 13 */ 14 15#ifndef TERM_H 16#define TERM_H 17 18#include "util.h" 19 20/* Compat with old termios. */ 21#ifndef ECHO 22#define ECHO 8 23#endif 24 25/* warp will still work without the following, but may get ahead at low speed */ 26#ifdef TIOCOUTQ /* chars left in output queue */ 27#define output_pending() (ioctl(1, TIOCOUTQ, &iocount),iocount) 28#endif 29 30/* If some of the following look something like curses calls, it is because 31 * warp used to use curses but doesn't now. Warp was neither as efficient nor 32 * as portable with curses, and since the program had to cheat on curses all 33 * over the place anyway, we ripped it out. 34 */ 35#define setimage(of,to) (mvaddch(of->posy+1,of->posx*2,of->image=(to))) 36 37#define mvaddch(y,x,ch) move((y),(x),(ch)) 38/* #define addch(ch) (tmpchr=(ch), write(1,&tmpchr,1), real_x++) */ 39#define mvaddc(y,x,ch) move((y),(x),(ch)) 40#define addc(ch) (write(1,&(ch),1), real_x++) 41#define addspace() (write(1," ",1), real_x++) 42#define mvaddstr(y,x,s) (move((y),(x),0), tmpstr = (s), \ 43 tmplen = strlen(tmpstr), write(1, tmpstr, tmplen), real_x += tmplen) 44 45EXT size_t tmplen; 46EXT const char *tmpstr; 47/* EXT char tmpchr; */ 48 49/* The following macros are like the pseudo-curses macros above, but do 50 * certain amount of controlled output buffering. 51 * 52 * NOTE: a beg_qwrite()..end_qwrite() sequence must NOT contain a cursor 53 * movement (move), because the move() routine uses beg_qwrite()..end_qwrite() 54 * itself. 55 */ 56 57#define beg_qwrite() (maxcmstring = cmbuffer) 58#ifdef vax 59#define qwrite() asm("movc3 _gfillen,_filler,*_maxcmstring"); maxcmstring += gfillen 60#else 61#define qwrite() (movc3(gfillen,filler,maxcmstring), maxcmstring += gfillen) 62#endif 63#define qaddc(ch) (*maxcmstring++ = (ch), real_x++) 64#define qaddch(ch) (*maxcmstring++ = (ch), real_x++) 65#define qaddspace() (*maxcmstring++ = ' ', real_x++) 66#define end_qwrite() (write(1,cmbuffer,maxcmstring-cmbuffer)) 67 68/* setting a ??size to infinity forces cursor addressing in that direction */ 69 70EXT int CMsize; 71EXT int BCsize INIT(1); 72EXT int DOsize INIT(1000); 73EXT int UPsize INIT(1000); 74EXT int NDsize INIT(1000); 75 76EXT int charsperhalfsec; 77 78EXT int real_y INIT(-100); 79EXT int real_x INIT(-100); 80 81#ifdef DOINIT 82char filler[] = {0,'\b',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 83#else 84EXT char filler[]; 85#endif 86 87EXT char *bsptr INIT(filler+1); 88 89EXT char term[12]; 90 91EXT char gfillen INIT(25); 92 93EXT char *maxcmstring; 94EXT char cmbuffer[512]; 95 96#define BREAKCH '\0' 97 98EXT char INTRCH INIT('\03'); 99 100#ifdef PUSHBACK 101 EXT char circlebuf[PUSHSIZE]; 102 EXT int nextin INIT(0); 103 EXT int nextout INIT(0); 104# ifdef PENDING 105# ifdef FIONREAD 106 EXT long iocount INIT(0); 107# ifndef lint 108# define input_pending() (nextin!=nextout || \ 109(ioctl(0, FIONREAD, &iocount),(int)iocount)) 110# else 111# define input_pending() bizarre 112# endif /* lint */ 113# else /* FIONREAD */ 114 int circfill(); 115# ifdef RDCHK 116# ifndef lint 117# define input_pending() rdchk(0) 118# else /* lint */ 119# define input_pending() bizarre 120# endif /* lint */ 121# else /* RDCHK */ 122# ifndef O_NDELAY /* assert O_NDELAY */ 123 ??? PENDING is not defined correctly in warp.h 124# endif 125 EXT int devtty INIT(0); 126# ifndef lint 127# define input_pending() (nextin!=nextout || circfill()) 128# else 129# define input_pending() bizarre 130# endif /* lint */ 131# endif /* RDCHK */ 132# endif /* FIONREAD */ 133# else /* PENDING */ 134# ??? warp will not work without PENDING 135# ifndef lint 136# define input_pending() (nextin!=nextout) 137# else 138# define input_pending() bizarre 139# endif /* lint */ 140# endif /* PENDING */ 141#else /* PUSHBACK */ 142# ifdef PENDING 143# ifdef FIONREAD /* must have FIONREAD or O_NDELAY for input_pending() */ 144# define read_tty(addr,size) read(0,addr,size) 145# ifndef lint 146# define input_pending() (ioctl(0, FIONREAD, &iocount), \ 147(int)iocount) 148# else 149# define input_pending() bizarre 150# endif /* lint */ 151 EXT long iocount INIT(0); 152# else /* FIONREAD */ 153# ifdef RDCHK /* actually, they can have rdchk() too */ 154# define read_tty(addr,size) read(0,addr,size) 155# ifndef lint 156# define input_pending() rdchk(0) 157# else /* lint */ 158# define input_pending() bizarre 159# endif /* lint */ 160# else /* RDCHK */ 161# ifndef O_NDELAY /* assert O_NDELAY */ 162 ??? PENDING is not defined correctly in warp.h 163# endif 164 EXT int devtty INIT(0); 165 EXT bool is_input INIT(false); 166 EXT char pending_ch INIT(0); 167# ifndef lint 168# define input_pending() (is_input || \ 169(is_input=read(devtty,&pending_ch,1))) 170# else 171# define input_pending() bizarre 172# endif /* lint */ 173# endif /* RDCHK */ 174# endif /* FIONREAD */ 175# else /* PENDING */ 176 ??? warp will not work without PENDING 177# define read_tty(addr,size) read(0,addr,size) 178# define input_pending() (false) 179# endif /* PENDING */ 180#endif /* PUSHBACK */ 181 182/* stuff wanted by terminal mode diddling routines */ 183 184#ifdef TERMIOS 185EXT struct termios _tty, _oldtty; 186#elif defined(TERMIO) 187typedef int speed_t; 188EXT struct termio _tty, _oldtty; 189#define tcsetattr(fd, how, ti) ioctl(fd, how, ti) 190#define tcgetattr(fd, ti) ioctl(fd, TCGETA, ti) 191#define cfgetospeed(ti) ((ti)->c_cflag & CBAUD) 192#else 193typedef int speed_t; 194EXT struct sgttyb _tty; 195EXT int _res_flg INIT(0); 196#endif 197 198EXT int _tty_ch INIT(2); 199EXT bool bizarre INIT(false); /* do we need to restore terminal? */ 200 201/* terminal mode diddling routines */ 202 203#if defined(TERMIO) || defined(TERMIOS) 204 205#define raw() ((bizarre=1),_tty.c_lflag &=~ISIG,_tty.c_cc[VMIN] = 1,tcsetattr(_tty_ch,TCSAFLUSH,&_tty)) 206#define noraw() ((bizarre=1),_tty.c_lflag |= ISIG,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch,TCSAFLUSH,&_tty)) 207#define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,tcsetattr(_tty_ch,TCSAFLUSH,&_tty)) 208#define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch,TCSAFLUSH,&_tty)) 209#define echo() ((bizarre=1),_tty.c_lflag |= ECHO, tcsetattr(_tty_ch, TCSANOW, &_tty)) 210#define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, tcsetattr(_tty_ch, TCSANOW, &_tty)) 211#define nl() ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,tcsetattr(_tty_ch, TCSANOW, &_tty)) 212#define nonl() ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,tcsetattr(_tty_ch, TCSANOW, &_tty)) 213#define savetty() (tcgetattr(_tty_ch, &_oldtty),tcgetattr(_tty_ch, &_tty)) 214#define resetty() ((bizarre=0),tcsetattr(_tty_ch, TCSAFLUSH, &_oldtty)) 215#define unflush_output() 216 217#else 218 219#define raw() ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty)) 220#define noraw() ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty)) 221#define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty)) 222#define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty)) 223#define echo() ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty)) 224#define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty)) 225#define nl() ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty)) 226#define nonl() ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty)) 227#define savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags) 228#define resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty)) 229#endif /* TERMIO */ 230 231#ifdef TIOCSTI 232#ifdef lint 233#define forceme(c) ioctl(_tty_ch,TIOCSTI,Null(long*)) /* ghad! */ 234#else 235#define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */ 236#endif /* lint */ 237#else 238#define forceme(c) 239#endif 240 241/* termcap stuff */ 242 243/* 244 * NOTE: if you don't have termlib you'll have to define these strings, 245 * the tputs routine, and the tgoto routine. 246 * The tgoto routine simply produces a cursor addressing string for a given 247 * x and y. The 1st argument is a generic string to be interpreted. 248 * If you are hardwiring it you might just ignore the 1st argument. 249 * The tputs routine interprets any leading number as a padding factor, possibly 250 * scaled by the number of lines (2nd argument), puts out the string (1st arg) 251 * and the padding using the routine specified as the 3rd argument. 252 */ 253 254#ifdef HAVETERMLIB 255#if 0 256EXT char *BC INIT(NULL); /* backspace character */ 257EXT char *UP INIT(NULL); /* move cursor up one line */ 258#endif 259EXT char *myUP; 260EXT char *ND INIT(NULL); /* non-destructive cursor right */ 261EXT char *myND; 262EXT char *DO INIT(NULL); /* move cursor down one line */ 263EXT char *myDO; 264EXT char *CR INIT(NULL); /* get to left margin, somehow */ 265EXT char *VB INIT(NULL); /* visible bell */ 266EXT char *CL INIT(NULL); /* home and clear screen */ 267EXT char *CE INIT(NULL); /* clear to end of line */ 268EXT char *CM INIT(NULL); /* cursor motion -- PWP */ 269EXT char *HO INIT(NULL); /* home cursor -- PWP */ 270EXT char *CD INIT(NULL); /* clear to end of display -- PWP */ 271EXT char *SO INIT(NULL); /* begin standout mode */ 272EXT char *SE INIT(NULL); /* end standout mode */ 273EXT int SG INIT(0); /* blanks left by SO and SE */ 274EXT char *US INIT(NULL); /* start underline mode */ 275EXT char *UE INIT(NULL); /* end underline mode */ 276EXT char *UC INIT(NULL); /* underline a character, if that's how it's done */ 277EXT int UG INIT(0); /* blanks left by US and UE */ 278EXT bool AM INIT(false); /* does terminal have automatic margins? */ 279EXT bool XN INIT(false); /* does it eat 1st newline after automatic wrap? */ 280#if 0 281EXT char PC INIT(0); /* pad character for use by tputs() */ 282EXT short ospeed INIT(0); /* terminal output speed, for use by tputs() */ 283#endif 284EXT int LINES INIT(0), COLS INIT(0); /* size of screen */ 285EXT int just_a_sec INIT(960); /* 1 sec at current baud rate */ 286 /* (number of nulls) */ 287EXT char ERASECH; /* rubout character */ 288EXT char KILLCH; /* line delete character */ 289 290/* define a few handy macros */ 291 292#define clear() (do_tc(CL,LINES),real_y=real_x=0) 293#define erase_eol() do_tc(CE,1) 294#define backspace() (do_tc(BC,0),real_x--) 295#define clear_rest() do_tc(CD,LINES) 296#define underline() do_tc(US,1) 297#define un_underline() do_tc(UE,1) 298#define underchar() do_tc(UC,0) 299#define standout() do_tc(SO,1) 300#define un_standout() do_tc(SE,1) 301#define up_line() do_tc(UP,1) 302#define dingaling() do_tc(VB,1) 303#else 304 ???????? /* up to you */ 305#endif 306 307void term_init(void); 308void term_set(char *); 309#ifdef PUSHBACK 310void pushchar(int); 311void mac_init(char *); 312void mac_line(char *, char *, size_t); 313#endif 314void page(const char *filename, size_t); 315void move(int, int, int); 316void do_tc(const char *, int); 317int comp_tc(char *, const char *, int); 318void helper(void); 319void rewrite(void); 320int cmstore(int); 321void eat_typeahead(void); 322void settle_down(void); 323#ifndef read_tty 324int read_tty(char *, ssize_t); 325#endif 326int read_nd(char *, size_t); 327void getcmd(char *); 328void pushstring(char *); 329 330#endif 331