Home | History | Annotate | Line # | Download | only in warp
term.h revision 1.4
      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 
     45 EXT size_t tmplen;
     46 EXT 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 
     70 EXT int CMsize;
     71 EXT int BCsize INIT(1);
     72 EXT int DOsize INIT(1000);
     73 EXT int UPsize INIT(1000);
     74 EXT int NDsize INIT(1000);
     75 
     76 EXT int charsperhalfsec;
     77 
     78 EXT int real_y INIT(-100);
     79 EXT int real_x INIT(-100);
     80 
     81 #ifdef DOINIT
     82 char 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
     84 EXT char filler[];
     85 #endif
     86 
     87 EXT char *bsptr INIT(filler+1);
     88 
     89 EXT char term[12];
     90 
     91 EXT char gfillen INIT(25);
     92 
     93 EXT char *maxcmstring;
     94 EXT char cmbuffer[512];
     95 
     96 #define BREAKCH '\0'
     97 
     98 EXT 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 TERMIO
    185 EXT struct termio _tty, _oldtty;
    186 #else
    187 EXT struct sgttyb _tty;
    188 EXT int _res_flg INIT(0);
    189 #endif
    190 
    191 EXT int _tty_ch INIT(2);
    192 EXT bool bizarre INIT(false);			/* do we need to restore terminal? */
    193 
    194 /* terminal mode diddling routines */
    195 
    196 #ifdef TERMIO
    197 
    198 #define raw() ((bizarre=1),_tty.c_lflag &=~ISIG,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
    199 #define noraw() ((bizarre=1),_tty.c_lflag |= ISIG,_tty.c_cc[VEOF] = CEOF,ioctl(_tty_ch,TCSETAF,&_tty))
    200 #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
    201 #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,ioctl(_tty_ch,TCSETAF,&_tty))
    202 #define echo()	 ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETAW, &_tty))
    203 #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETAW, &_tty))
    204 #define nl()	 ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
    205 #define nonl()	 ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
    206 #define	savetty() (ioctl(_tty_ch, TCGETA, &_oldtty),ioctl(_tty_ch, TCGETA, &_tty))
    207 #define	resetty() ((bizarre=0),ioctl(_tty_ch, TCSETAF, &_oldtty))
    208 #define unflush_output()
    209 
    210 #else
    211 
    212 #define raw()	 ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty))
    213 #define noraw()	 ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty))
    214 #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty))
    215 #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty))
    216 #define echo()	 ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty))
    217 #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty))
    218 #define nl()	 ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty))
    219 #define nonl()	 ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty))
    220 #define	savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
    221 #define	resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))
    222 #endif /* TERMIO */
    223 
    224 #ifdef TIOCSTI
    225 #ifdef lint
    226 #define forceme(c) ioctl(_tty_ch,TIOCSTI,Null(long*))	/* ghad! */
    227 #else
    228 #define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */
    229 #endif /* lint */
    230 #else
    231 #define forceme(c)
    232 #endif
    233 
    234 /* termcap stuff */
    235 
    236 /*
    237  * NOTE: if you don't have termlib you'll have to define these strings,
    238  *    the tputs routine, and the tgoto routine.
    239  * The tgoto routine simply produces a cursor addressing string for a given
    240  * x and y.  The 1st argument is a generic string to be interpreted.
    241  * If you are hardwiring it you might just ignore the 1st argument.
    242  * The tputs routine interprets any leading number as a padding factor, possibly
    243  * scaled by the number of lines (2nd argument), puts out the string (1st arg)
    244  * and the padding using the routine specified as the 3rd argument.
    245  */
    246 
    247 #ifdef HAVETERMLIB
    248 EXT char *BC INIT(NULL);		/* backspace character */
    249 EXT char *UP INIT(NULL);		/* move cursor up one line */
    250 EXT char *myUP;
    251 EXT char *ND INIT(NULL);		/* non-destructive cursor right */
    252 EXT char *myND;
    253 EXT char *DO INIT(NULL);		/* move cursor down one line */
    254 EXT char *myDO;
    255 EXT char *CR INIT(NULL);		/* get to left margin, somehow */
    256 EXT char *VB INIT(NULL);		/* visible bell */
    257 EXT char *CL INIT(NULL);		/* home and clear screen */
    258 EXT char *CE INIT(NULL);		/* clear to end of line */
    259 EXT char *CM INIT(NULL);		/* cursor motion -- PWP */
    260 EXT char *HO INIT(NULL);		/* home cursor -- PWP */
    261 EXT char *CD INIT(NULL);		/* clear to end of display -- PWP */
    262 EXT char *SO INIT(NULL);		/* begin standout mode */
    263 EXT char *SE INIT(NULL);		/* end standout mode */
    264 EXT int SG INIT(0);		/* blanks left by SO and SE */
    265 EXT char *US INIT(NULL);		/* start underline mode */
    266 EXT char *UE INIT(NULL);		/* end underline mode */
    267 EXT char *UC INIT(NULL);		/* underline a character, if that's how it's done */
    268 EXT int UG INIT(0);		/* blanks left by US and UE */
    269 EXT bool AM INIT(false);		/* does terminal have automatic margins? */
    270 EXT bool XN INIT(false);		/* does it eat 1st newline after automatic wrap? */
    271 EXT char PC INIT(0);		/* pad character for use by tputs() */
    272 EXT short ospeed INIT(0);	/* terminal output speed, for use by tputs() */
    273 EXT int LINES INIT(0), COLS INIT(0);	/* size of screen */
    274 EXT int just_a_sec INIT(960);			/* 1 sec at current baud rate */
    275 					/* (number of nulls) */
    276 EXT char ERASECH;		/* rubout character */
    277 EXT char KILLCH;		/* line delete character */
    278 
    279 /* define a few handy macros */
    280 
    281 #define clear() (do_tc(CL,LINES),real_y=real_x=0)
    282 #define erase_eol() do_tc(CE,1)
    283 #define backspace() (do_tc(BC,0),real_x--)
    284 #define clear_rest() do_tc(CD,LINES)
    285 #define underline() do_tc(US,1)
    286 #define un_underline() do_tc(UE,1)
    287 #define underchar() do_tc(UC,0)
    288 #define standout() do_tc(SO,1)
    289 #define un_standout() do_tc(SE,1)
    290 #define up_line() do_tc(UP,1)
    291 #define dingaling() do_tc(VB,1)
    292 #else
    293   ????????		/* up to you */
    294 #endif
    295 
    296 void term_init(void);
    297 void term_set(char *);
    298 #ifdef PUSHBACK
    299 void pushchar(int);
    300 void mac_init(char *);
    301 void mac_line(char *, char *, size_t);
    302 #endif
    303 void page(const char *filename, size_t);
    304 void move(int, int, int);
    305 void do_tc(const char *, int);
    306 int comp_tc(char *, const char *, int);
    307 void helper(void);
    308 void rewrite(void);
    309 int cmstore(int);
    310 void eat_typeahead(void);
    311 void settle_down(void);
    312 #ifndef read_tty
    313 int read_tty(char *, ssize_t);
    314 #endif
    315 int read_nd(char *, size_t);
    316 void getcmd(char *);
    317 void pushstring(char *);
    318 
    319 #endif
    320