1 /* term.h 2 */ 3 /* This software is copyrighted as detailed in the LICENSE file. */ 4 5 6 EXT char ERASECH; /* rubout character */ 7 EXT char KILLCH; /* line delete character */ 8 EXT char circlebuf[PUSHSIZE]; 9 EXT int nextin INIT(0); 10 EXT int nextout INIT(0); 11 EXT unsigned char lastchar; 12 13 /* stuff wanted by terminal mode diddling routines */ 14 15 #ifdef I_TERMIO 16 EXT struct termio _tty, _oldtty; 17 #else 18 # ifdef I_TERMIOS 19 EXT struct termios _tty, _oldtty; 20 # else 21 # ifdef I_SGTTY 22 EXT struct sgttyb _tty; 23 EXT int _res_flg INIT(0); 24 # endif 25 # endif 26 #endif 27 28 EXT int _tty_ch INIT(2); 29 EXT bool bizarre INIT(FALSE); /* do we need to restore terminal? */ 30 31 /* terminal mode diddling routines */ 32 33 #ifdef I_TERMIO 34 35 #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty)) 36 #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,stty(_tty_ch,&_tty)) 37 #define echo() ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETA, &_tty)) 38 #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETA, &_tty)) 39 #define nl() ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty)) 40 #define nonl() ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,ioctl(_tty_ch, TCSETAW, &_tty)) 41 #define savetty() (ioctl(_tty_ch, TCGETA, &_oldtty),ioctl(_tty_ch, TCGETA, &_tty)) 42 #define resetty() ((bizarre=0),ioctl(_tty_ch, TCSETAF, &_oldtty)) 43 #define unflush_output() 44 45 #else /* !I_TERMIO */ 46 # ifdef I_TERMIOS 47 48 #define crmode() ((bizarre=1), _tty.c_lflag &= ~ICANON,_tty.c_cc[VMIN]=1,tcsetattr(_tty_ch, TCSAFLUSH, &_tty)) 49 #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch, TCSAFLUSH,&_tty)) 50 #define echo() ((bizarre=1),_tty.c_lflag |= ECHO, tcsetattr(_tty_ch, TCSAFLUSH, &_tty)) 51 #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, tcsetattr(_tty_ch, TCSAFLUSH, &_tty)) 52 #define nl() ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,tcsetattr(_tty_ch, TCSAFLUSH, &_tty)) 53 #define nonl() ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,tcsetattr(_tty_ch, TCSAFLUSH, &_tty)) 54 #define savetty() (tcgetattr(_tty_ch, &_oldtty),tcgetattr(_tty_ch, &_tty)) 55 #define resetty() ((bizarre=0),tcsetattr(_tty_ch, TCSAFLUSH, &_oldtty)) 56 #define unflush_output() 57 58 # else /* !I_TERMIOS */ 59 # ifdef I_SGTTY 60 61 #define raw() ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty)) 62 #define noraw() ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty)) 63 #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty)) 64 #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty)) 65 #define echo() ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty)) 66 #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty)) 67 #define nl() ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty)) 68 #define nonl() ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty)) 69 #define savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags) 70 #define resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty)) 71 # ifdef LFLUSHO 72 EXT int lflusho INIT(LFLUSHO); 73 #define unflush_output() (ioctl(_tty_ch,TIOCLBIC,&lflusho)) 74 # else /*! LFLUSHO */ 75 #define unflush_output() 76 # endif 77 # else 78 # ifdef MSDOS 79 80 #define crmode() (bizarre=1) 81 #define nocrmode() (bizarre=1) 82 #define echo() (bizarre=1) 83 #define noecho() (bizarre=1) 84 #define nl() (bizarre=1) 85 #define nonl() (bizarre=1) 86 #define savetty() 87 #define resetty() (bizarre=0) 88 #define unflush_output() 89 # else /* !MSDOS */ 90 ..."Don't know how to define the term macros!" 91 # endif /* !MSDOS */ 92 # endif /* !I_SGTTY */ 93 # endif /* !I_TERMIOS */ 94 95 #endif /* !I_TERMIO */ 96 97 #ifdef TIOCSTI 98 #define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */ 99 #else 100 #define forceme(c) 101 #endif 102 103 /* termcap stuff */ 104 105 /* 106 * NOTE: if you don't have termlib you'll either have to define these strings 107 * and the tputs routine, or you'll have to redefine the macros below 108 */ 109 110 #ifdef HAS_TERMLIB 111 EXT int tc_GT; /* hardware tabs */ 112 EXT char* tc_BC INIT(NULL); /* backspace character */ 113 EXT char* tc_UP INIT(NULL); /* move cursor up one line */ 114 EXT char* tc_CR INIT(NULL); /* get to left margin, somehow */ 115 EXT char* tc_VB INIT(NULL); /* visible bell */ 116 EXT char* tc_CL INIT(NULL); /* home and clear screen */ 117 EXT char* tc_CE INIT(NULL); /* clear to end of line */ 118 EXT char* tc_TI INIT(NULL); /* initialize terminal */ 119 EXT char* tc_TE INIT(NULL); /* reset terminal */ 120 EXT char* tc_KS INIT(NULL); /* enter `keypad transmit' mode */ 121 EXT char* tc_KE INIT(NULL); /* exit `keypad transmit' mode */ 122 EXT char* tc_CM INIT(NULL); /* cursor motion */ 123 EXT char* tc_HO INIT(NULL); /* home cursor */ 124 EXT char* tc_IL INIT(NULL); /* insert line */ 125 EXT char* tc_CD INIT(NULL); /* clear to end of display */ 126 EXT char* tc_SO INIT(NULL); /* begin standout mode */ 127 EXT char* tc_SE INIT(NULL); /* end standout mode */ 128 EXT int tc_SG INIT(0); /* blanks left by SO and SE */ 129 EXT char* tc_US INIT(NULL); /* start underline mode */ 130 EXT char* tc_UE INIT(NULL); /* end underline mode */ 131 EXT char* tc_UC INIT(NULL); /* underline a character, 132 if that's how it's done */ 133 EXT int tc_UG INIT(0); /* blanks left by US and UE */ 134 EXT bool tc_AM INIT(FALSE); /* does terminal have automatic 135 margins? */ 136 EXT bool tc_XN INIT(FALSE); /* does it eat 1st newline after 137 automatic wrap? */ 138 EXT char tc_PC INIT(0); /* pad character for use by tputs() */ 139 140 #ifdef _POSIX_SOURCE 141 EXT speed_t outspeed INIT(0); /* terminal output speed, */ 142 #else 143 EXT long outspeed INIT(0); /* for use by tputs() */ 144 #endif 145 146 EXT int fire_is_out INIT(1); 147 EXT int tc_LINES INIT(0), tc_COLS INIT(0);/* size of screen */ 148 EXT int term_line, term_col; /* position of cursor */ 149 EXT int term_scrolled; /* how many lines scrolled away */ 150 EXT int just_a_sec INIT(960); /* 1 sec at current baud rate */ 151 /* (number of nulls) */ 152 153 /* define a few handy macros */ 154 155 #define termdown(x) term_line+=(x), term_col=0 156 #define newline() term_line++, term_col=0, putchar('\n') FLUSH 157 #define backspace() tputs(tc_BC,0,putchr) FLUSH 158 #define erase_eol() tputs(tc_CE,1,putchr) FLUSH 159 #define clear_rest() tputs(tc_CD,tc_LINES,putchr) FLUSH 160 #define maybe_eol() if(erase_screen&&erase_each_line)tputs(tc_CE,1,putchr) FLUSH 161 #define underline() tputs(tc_US,1,putchr) FLUSH 162 #define un_underline() fire_is_out|=UNDERLINE, tputs(tc_UE,1,putchr) FLUSH 163 #define underchar() tputs(tc_UC,0,putchr) FLUSH 164 #define standout() tputs(tc_SO,1,putchr) FLUSH 165 #define un_standout() fire_is_out|=STANDOUT, tputs(tc_SE,1,putchr) FLUSH 166 #define up_line() term_line--, tputs(tc_UP,1,putchr) FLUSH 167 #define insert_line() tputs(tc_IL,1,putchr) FLUSH 168 #define carriage_return() term_col=0, tputs(tc_CR,1,putchr) FLUSH 169 #define dingaling() tputs(tc_VB,1,putchr) FLUSH 170 #else /* !HAS_TERMLIB */ 171 ..."Don't know how to define the term macros!" 172 #endif /* !HAS_TERMLIB */ 173 174 #define input_pending() finput_pending(TRUE) 175 #define macro_pending() finput_pending(FALSE) 176 177 EXT int page_line INIT(1); /* line number for paging in 178 print_line (origin 1) */ 179 EXT bool error_occurred INIT(FALSE); 180 181 EXT char* mousebar_btns; 182 EXT int mousebar_cnt INIT(0); 183 EXT int mousebar_start INIT(0); 184 EXT int mousebar_width INIT(0); 185 EXT bool xmouse_is_on INIT(FALSE); 186 EXT bool mouse_is_down INIT(FALSE); 187 188 /* DON'T EDIT BELOW THIS LINE OR YOUR CHANGES WILL BE LOST! */ 189 190 void term_init _((void)); 191 void term_set _((char*)); 192 void set_macro _((char*,char*)); 193 void arrow_macros _((char*)); 194 void mac_line _((char*,char*,int)); 195 void show_macros _((void)); 196 void set_mode _((char_int,char_int)); 197 int putchr _((char_int)); 198 void hide_pending _((void)); 199 bool finput_pending _((bool_int)); 200 bool finish_command _((int)); 201 char* edit_buf _((char*,char*)); 202 bool finish_dblchar _((void)); 203 void eat_typeahead _((void)); 204 void save_typeahead _((char*,int)); 205 void settle_down _((void)); 206 Signal_t alarm_catcher _((int)); 207 int read_tty _((char*,int)); 208 #if !defined(FIONREAD) && !defined(HAS_RDCHK) && !defined(MSDOS) 209 int circfill _((void)); 210 #endif 211 void pushchar _((char_int)); 212 void underprint _((char*)); 213 #ifdef NOFIREWORKS 214 void no_sofire _((void)); 215 void no_ulfire _((void)); 216 #endif 217 void getcmd _((char*)); 218 void pushstring _((char*,char_int)); 219 int get_anything _((void)); 220 int pause_getcmd _((void)); 221 void in_char _((char*,char_int,char*)); 222 void in_answer _((char*,char_int)); 223 bool in_choice _((char*,char*,char*,char_int)); 224 int print_lines _((char*,int)); 225 int check_page_line _((void)); 226 void page_start _((void)); 227 void errormsg _((char*)); 228 void warnmsg _((char*)); 229 void pad _((int)); 230 #ifdef VERIFY 231 void printcmd _((void)); 232 #endif 233 void rubout _((void)); 234 void reprint _((void)); 235 void erase_line _((bool_int)); 236 void clear _((void)); 237 void home_cursor _((void)); 238 void goto_xy _((int,int)); 239 #ifdef SIGWINCH 240 Signal_t winch_catcher _((int)); 241 #endif 242 void termlib_init _((void)); 243 void termlib_reset _((void)); 244 #ifdef NBG_SIGIO 245 Signal_t waitkey_sig_handler _((int)); 246 #endif 247 bool wait_key_pause _((int)); 248 void xmouse_init _((char*)); 249 void xmouse_check _((void)); 250 void xmouse_on _((void)); 251 void xmouse_off _((void)); 252 void draw_mousebar _((int,bool_int)); 253 bool check_mousebar _((int,int,int,int,int,int)); 254 void add_tc_string _((char*,char*)); 255 char* tc_color_capability _((char*)); 256 #ifdef MSDOS 257 int tputs _((char*,int,int(*) _((char_int)))); 258 char* tgoto _((char*,int,int)); 259 #endif 260