home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / term.h < prev    next >
C/C++ Source or Header  |  1993-12-04  |  10KB  |  287 lines

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