home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part04 / term.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  9.2 KB  |  281 lines

  1. /* $Id: term.h,v 4.4 1991/09/09 20:27:37 sob Exp sob $
  2.  *
  3.  * $Log: term.h,v $
  4.  * Revision 4.4  1991/09/09  20:27:37  sob
  5.  * release 4.4
  6.  *
  7.  *
  8.  * 
  9.  */
  10. /* This software is Copyright 1991 by Stan Barber. 
  11.  *
  12.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  13.  * use this software as long as: there is no monetary profit gained
  14.  * specifically from the use or reproduction of this software, it is not
  15.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  16.  * included prominently in any copy made. 
  17.  *
  18.  * The author make no claims as to the fitness or correctness of this software
  19.  * for any use whatsoever, and it is provided as is. Any use of this software
  20.  * is at the user's own risk. 
  21.  */
  22.  
  23. #ifdef PUSHBACK
  24. EXT char circlebuf[PUSHSIZE];
  25. EXT int nextin INIT(0);
  26. EXT int nextout INIT(0);
  27. #ifdef PENDING
  28. #ifdef FIONREAD
  29. EXT long iocount INIT(0);
  30. #ifndef lint
  31. #define input_pending() (nextin!=nextout || (ioctl(0, FIONREAD, &iocount),(int)iocount))
  32. #else
  33. #define input_pending() bizarre
  34. #endif /* lint */
  35. #else /* FIONREAD */
  36. #ifdef RDCHK
  37. #define input_pending() (rdchk(0) > 0)        /* boolean only */
  38. #else /*  RDCHK */
  39. int circfill();
  40. EXT int devtty INIT(0);
  41. #ifndef lint
  42. #define input_pending() (nextin!=nextout || circfill())
  43. #else
  44. #define input_pending() bizarre
  45. #endif /* lint */
  46. #endif /* RDCHK */
  47. #endif /* FIONREAD */
  48. #else /* PENDING */
  49. #ifndef lint
  50. #define input_pending() (nextin!=nextout)
  51. #else
  52. #define input_pending() bizarre
  53. #endif /* lint */
  54. #endif /* PENDING */
  55. #else /* PUSHBACK */
  56. #ifdef PENDING
  57. #ifdef FIONREAD    /* must have FIONREAD or O_NDELAY for input_pending() */
  58. #define read_tty(addr,size) read(0,addr,size)
  59. #ifndef lint
  60. #define input_pending() (ioctl(0, FIONREAD, &iocount),(int)iocount)
  61. #else
  62. #define input_pending() bizarre
  63. #endif /* lint */
  64. EXT long iocount INIT(0);
  65.  
  66. #else /* FIONREAD */
  67.  
  68. #ifdef RDCHK
  69. #define input_pending() (rdchk(0) > 0)        /* boolean only */
  70. #else /*  RDCHK */
  71.  
  72. EXT int devtty INIT(0);
  73. EXT bool is_input INIT(FALSE);
  74. EXT char pending_ch INIT(0);
  75. #ifndef lint
  76. #define input_pending() (is_input || (is_input=read(devtty,&pending_ch,1)))
  77. #else
  78. #define input_pending() bizarre
  79. #endif /* lint */
  80. #endif /*  RDCHK */
  81. #endif /* FIONREAD */
  82. #else /* PENDING */
  83. #define read_tty(addr,size) read(0,addr,size)
  84. #define input_pending() (FALSE)
  85. #endif /* PENDING */
  86. #endif /* PUSHBACK */
  87.  
  88. /* stuff wanted by terminal mode diddling routines */
  89.  
  90. #ifdef TERMIO
  91. EXT struct termio _tty, _oldtty;
  92. #else
  93. # ifdef TERMIOS
  94. EXT struct termios _tty, _oldtty;
  95. # else
  96. EXT struct sgttyb _tty;
  97. EXT int _res_flg INIT(0);
  98. # endif
  99. #endif
  100.  
  101. EXT int _tty_ch INIT(2);
  102. EXT bool bizarre INIT(FALSE);            /* do we need to restore terminal? */
  103.  
  104. /* terminal mode diddling routines */
  105.  
  106. #ifdef TERMIO
  107.  
  108. #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
  109. #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,stty(_tty_ch,&_tty))
  110. #define echo()     ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  111. #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  112. #define nl()     ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
  113. #define nonl()     ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
  114. #define    savetty() (ioctl(_tty_ch, TCGETA, &_oldtty),ioctl(_tty_ch, TCGETA, &_tty))
  115. #define    resetty() ((bizarre=0),ioctl(_tty_ch, TCSETAF, &_oldtty))
  116. #define unflush_output()
  117.  
  118. #else /* !TERMIO */
  119. # ifdef TERMIOS
  120.  
  121. #define crmode() ((bizarre=1), _tty.c_lflag &= ~ICANON,_tty.c_cc[VMIN]=1,tcsetattr(_tty_ch, TCSAFLUSH, &_tty))
  122. #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch, TCSAFLUSH,&_tty))
  123. #define echo()     ((bizarre=1),_tty.c_lflag |= ECHO, tcsetattr(_tty_ch, TCSAFLUSH, &_tty))
  124. #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, tcsetattr(_tty_ch, TCSAFLUSH, &_tty))
  125. #define nl()     ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,tcsetattr(_tty_ch, TCSAFLUSH, &_tty))
  126. #define nonl()     ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,tcsetattr(_tty_ch, TCSAFLUSH, &_tty))
  127. #define    savetty() (tcgetattr(_tty_ch, &_oldtty),tcgetattr(_tty_ch, &_tty))
  128. #define    resetty() ((bizarre=0),tcsetattr(_tty_ch, TCSAFLUSH, &_oldtty))
  129. #define unflush_output()
  130.  
  131. # else /* !TERMIOS */
  132.  
  133. #define raw()     ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty))
  134. #define noraw()     ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty))
  135. #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty))
  136. #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty))
  137. #define echo()     ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty))
  138. #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty))
  139. #define nl()     ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty))
  140. #define nonl()     ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty))
  141. #define    savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
  142. #define    resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))
  143. #  ifdef LFLUSHO
  144. #   ifndef lint
  145. EXT int lflusho INIT(LFLUSHO);
  146. #   else
  147. EXT long lflusho INIT(LFLUSHO);
  148. #   endif /* lint */
  149. #define unflush_output() (ioctl(_tty_ch,TIOCLBIC,&lflusho))
  150. #  else
  151. #define unflush_output()
  152. #  endif /* LFLUSHO */
  153. # endif /* TERMIOS */
  154.  
  155. #endif /* TERMIO */
  156.  
  157. #ifdef TIOCSTI
  158. #ifdef lint
  159. #define forceme(c) ioctl(_tty_ch,TIOCSTI,Null(long*))    /* ghad! */
  160. #else
  161. #define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */
  162. #endif /* lint */
  163. #else
  164. #define forceme(c)
  165. #endif
  166.  
  167. /* termcap stuff */
  168.  
  169. /*
  170.  * NOTE: if you don't have termlib you'll either have to define these strings
  171.  *    and the tputs routine, or you'll have to redefine the macros below
  172.  */
  173.  
  174. #ifdef HAVETERMLIB
  175. EXT int GT;                /* hardware tabs */
  176. EXT char *BC INIT(Nullch);        /* backspace character */
  177. EXT char *UP INIT(Nullch);        /* move cursor up one line */
  178. EXT char *CR INIT(Nullch);        /* get to left margin, somehow */
  179. EXT char *VB INIT(Nullch);        /* visible bell */
  180. EXT char *CL INIT(Nullch);        /* home and clear screen */
  181. EXT char *CE INIT(Nullch);        /* clear to end of line */
  182. EXT char *TI INIT(Nullch);        /* initialize terminal */
  183. EXT char *TE INIT(Nullch);        /* reset terminal */
  184. #if defined(CLEAREOL) || defined(USETHREADS)
  185. EXT char *CM INIT(Nullch);        /* cursor motion */
  186. EXT char *HO INIT(Nullch);        /* home cursor */
  187. #endif
  188. #ifdef CLEAREOL
  189. EXT char *CD INIT(Nullch);        /* clear to end of display */
  190. #endif /* CLEAREOL */
  191. EXT char *SO INIT(Nullch);        /* begin standout mode */
  192. EXT char *SE INIT(Nullch);        /* end standout mode */
  193. EXT int SG INIT(0);            /* blanks left by SO and SE */
  194. EXT char *US INIT(Nullch);        /* start underline mode */
  195. EXT char *UE INIT(Nullch);        /* end underline mode */
  196. EXT char *UC INIT(Nullch);        /* underline a character,
  197.                          if that's how it's done */
  198. EXT int UG INIT(0);            /* blanks left by US and UE */
  199. EXT bool AM INIT(FALSE);        /* does terminal have automatic
  200.                                  margins? */
  201. EXT bool XN INIT(FALSE);        /* does it eat 1st newline after
  202.                              automatic wrap? */
  203. EXT char PC INIT(0);            /* pad character for use by tputs() */
  204.  
  205. #ifdef _POSIX_SOURCE
  206. EXT speed_t outspeed INIT(0);        /* terminal output speed, */
  207. #else
  208. EXT long outspeed INIT(0);        /*     for use by tputs() */
  209. #endif
  210.  
  211. EXT int LINES INIT(0), COLS INIT(0);    /* size of screen */
  212. EXT int just_a_sec INIT(960);        /* 1 sec at current baud rate */
  213.                     /* (number of nulls) */
  214.  
  215. /* define a few handy macros */
  216.  
  217. #define backspace() tputs(BC,0,putchr) FLUSH
  218. #define clear() tputs(CL,LINES,putchr) FLUSH
  219. #define erase_eol() tputs(CE,1,putchr) FLUSH
  220. #ifdef CLEAREOL
  221. #define clear_rest() tputs(CD,LINES,putchr) FLUSH
  222. #define maybe_eol() if(erase_screen&&can_home_clear)tputs(CE,1,putchr) FLUSH
  223. #endif /* CLEAREOL */
  224. #define underline() tputs(US,1,putchr) FLUSH
  225. #define un_underline() tputs(UE,1,putchr) FLUSH
  226. #define underchar() tputs(UC,0,putchr) FLUSH
  227. #define standout() tputs(SO,1,putchr) FLUSH
  228. #define un_standout() tputs(SE,1,putchr) FLUSH
  229. #define up_line() tputs(UP,1,putchr) FLUSH
  230. #define carriage_return() tputs(CR,1,putchr) FLUSH
  231. #define dingaling() tputs(VB,1,putchr) FLUSH
  232. #else
  233.   ????????        /* up to you */
  234. #endif
  235.  
  236. EXT int page_line INIT(1);    /* line number for paging in
  237.                          print_line (origin 1) */
  238.  
  239. void    term_init ANSI((void));
  240. void    term_set ANSI((char *));
  241. #ifdef PUSHBACK
  242. void    pushchar ANSI((char_int));
  243. void    mac_init ANSI((char *));
  244. void    mac_line ANSI((char *,char *,int));
  245. void    show_macros ANSI((void));
  246. #endif
  247. char    putchr ANSI((char_int));    /* routine for tputs to call */
  248. bool    finish_command ANSI((int));
  249. void    eat_typeahead ANSI((void));
  250. void    settle_down ANSI((void));
  251. #ifdef HAVETERMLIB
  252. void    termlib_init ANSI((void));
  253. void    termlib_reset ANSI((void));
  254. #endif
  255. #ifndef read_tty
  256.     int        read_tty ANSI((char *,int));
  257. #endif
  258. void    underprint ANSI((char *));
  259. #ifdef NOFIREWORKS
  260.     void    no_sofire ANSI((void));
  261.     void    no_ulfire ANSI((void));
  262. #endif
  263. void    getcmd ANSI((char *));
  264. int    get_anything ANSI((void));
  265. void    in_char ANSI((char *,char_int));
  266. int    print_lines ANSI((char *,int));
  267. void    page_init ANSI((void));
  268. void    pad ANSI((int));
  269. void    printcmd ANSI((void));
  270. void    rubout ANSI((void));
  271. void    reprint ANSI((void));
  272. #if defined(CLEAREOL) || defined(USETHREADS)
  273. void    home_cursor ANSI((void));
  274. #endif
  275. #ifdef USETHREADS
  276. void    goto_line ANSI((int,int));
  277. #endif
  278. #ifdef SIGWINCH
  279. SIGRET    winch_catcher ANSI((void));
  280. #endif /* SIGWINCH */
  281.