home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XT.ZIP / RN / TERM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-21  |  10.9 KB  |  326 lines

  1. /* $Header: E:\SRC\UUPC\RN\RCS/TERM.H 1.1 1992/11/21 06:14:58 ahd Exp $
  2.  *
  3.  * $Log: TERM.H $
  4.  * Revision 1.1  1992/11/21  06:14:58  ahd
  5.  * Initial
  6.  *
  7.  *
  8.  *    Rev 1.0   18 Nov 1990  0:22:34
  9.  * Initial revision.
  10.  * Revision 4.3.2.2  90/04/06  20:35:34  sob
  11.  * Added fixes for SCO Xenix sent by ronald@robobar.co.uk.
  12.  *
  13.  * Revision 4.3.2.1  89/11/28  01:54:03  sob
  14.  * Added better support for SIGWINCH.
  15.  *
  16.  * Revision 4.3.1.2  85/05/13  15:52:05  lwall
  17.  * Declared devtty on TERMIO system.
  18.  *
  19.  * Revision 4.3.1.1  85/05/10  11:41:24  lwall
  20.  * Branch for patches.
  21.  *
  22.  * Revision 4.3  85/05/01  11:51:36  lwall
  23.  * Baseline for release with 4.3bsd.
  24.  *
  25.  */
  26.  
  27. #ifdef PUSHBACK
  28.   EXT char circlebuf[PUSHSIZE];
  29.   EXT int nextin INIT(0);
  30.   EXT int nextout INIT(0);
  31. # ifdef PENDING
  32.  
  33. #   ifdef FIONREAD
  34.       EXT long iocount INIT(0);
  35. #     ifndef lint
  36. #       define input_pending() (nextin!=nextout || (ioctl(0, FIONREAD, &iocount),(int)iocount))
  37. #     else
  38. #       define input_pending() bizarre
  39. #     endif /* lint */
  40. #     define PEND_OK
  41. #   endif /* FIONREAD */
  42.  
  43. #   if   defined(RDCHK) && !defined(PEND_OK)
  44. #     define input_pending() (rdchk(0) > 0)     /* boolean only */
  45. #     define PEND_OK
  46. #   endif /*  RDCHK */
  47.  
  48. #   if defined(msdos) && !defined(PEND_OK)
  49. #     define input_pending() kbhit()
  50. #     define PEND_OK
  51. #   endif /* msdos */
  52.  
  53. #   ifndef PEND_OK
  54.       int circfill();
  55.       EXT int devtty INIT(0);
  56. #     ifndef lint
  57. #       define input_pending() (nextin!=nextout || circfill())
  58. #     else
  59. #       define input_pending() bizarre
  60. #     endif /* lint */
  61. #   endif /* PEND_OK */
  62.  
  63. # else /* PENDING */
  64. #   ifndef lint
  65. #     define input_pending() (nextin!=nextout)
  66. #   else
  67. #     define input_pending() bizarre
  68. #   endif /* lint */
  69. # endif /* PENDING */
  70.  
  71. #else /* PUSHBACK */
  72. # ifdef PENDING
  73. #   ifdef FIONREAD   /* must have FIONREAD or O_NDELAY for input_pending() */
  74. #     define read_tty(addr,size) read(0,addr,size)
  75. #     ifndef lint
  76. #       define input_pending() (ioctl(0, FIONREAD, &iocount),(int)iocount)
  77. #     else
  78. #       define input_pending() bizarre
  79. #     endif /* lint */
  80.       EXT long iocount INIT(0);
  81. #     define PEND_OK
  82. #   endif /* FIONREAD */
  83.  
  84. #   if defined(RDCHK) && !defined(PEND_OK)
  85. #     define input_pending() (rdchk(0) > 0)     /* boolean only */
  86. #     define PEND_OK
  87. #   endif /*  RDCHK */
  88. #   if defined(msdos) && !defined(PEND_OK)
  89. #     define input_pending() kbhit()
  90. #     define PEND_OK
  91. #   endif /* msdos */
  92.  
  93. #   ifndef PEND_OK
  94.       EXT int devtty INIT(0);
  95.       EXT bool is_input INIT(FALSE);
  96.       EXT char pending_ch INIT(0);
  97. #     ifndef lint
  98. #       define input_pending() (is_input || (is_input=read(devtty,&pending_ch,1)))
  99. #     else
  100. #       define input_pending() bizarre
  101. #     endif /* lint */
  102. #   endif /*  PEND_OK */
  103.  
  104. # else /* PENDING */
  105. #   define read_tty(addr,size) read(0,addr,size)
  106. #   define input_pending() (FALSE)
  107. # endif /* PENDING */
  108. #endif /* PUSHBACK */
  109.  
  110. /* stuff wanted by terminal mode diddling routines */
  111.  
  112. #ifdef TERMIO
  113. EXT struct termio _tty, _oldtty;
  114. #else
  115. #ifndef msdos
  116. EXT struct sgttyb _tty;
  117. EXT int _res_flg INIT(0);
  118. #endif
  119. #endif
  120.  
  121. EXT int _tty_ch INIT(2);
  122. EXT bool bizarre INIT(FALSE);       /* do we need to restore terminal? */
  123.  
  124. /* terminal mode diddling routines */
  125.  
  126. #if   unix
  127. #ifdef TERMIO
  128.  
  129. #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
  130. #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,stty(_tty_ch,&_tty))
  131. #define echo()  ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  132. #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  133. #define nl()    ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
  134. #define nonl()  ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
  135. #define  savetty() (ioctl(_tty_ch, TCGETA, &_oldtty),ioctl(_tty_ch, TCGETA, &_tty))
  136. #define  resetty() ((bizarre=0),ioctl(_tty_ch, TCSETAF, &_oldtty))
  137. #define unflush_output()
  138.  
  139. #else
  140.  
  141. #define raw()   ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty))
  142. #define noraw()    ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty))
  143. #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty))
  144. #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty))
  145. #define echo()  ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty))
  146. #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty))
  147. #define nl()    ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty))
  148. #define nonl()  ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty))
  149. #define  savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
  150. #define  resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))
  151. #ifdef LFLUSHO
  152. #ifndef lint
  153. EXT int lflusho INIT(LFLUSHO);
  154. #else
  155. EXT long lflusho INIT(LFLUSHO);
  156. #endif /* lint */
  157. #define unflush_output() (ioctl(_tty_ch,TIOCLBIC,&lflusho))
  158. #else
  159. #define unflush_output()
  160. #endif /* LFLUSHO */
  161. #endif /* TERMIO */
  162. #endif   /* unix */
  163.  
  164. #ifdef TIOCSTI
  165. #ifdef lint
  166. #define forceme(c) ioctl(_tty_ch,TIOCSTI,Null(long*)) /* ghad! */
  167. #else
  168. #define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */
  169. #endif /* lint */
  170. #else
  171. #define forceme(c)
  172. #endif
  173.  
  174. /* termcap stuff */
  175.  
  176. /*
  177.  * NOTE: if you don't have termlib you'll either have to define these strings
  178.  *    and the tputs routine, or you'll have to redefine the macros below
  179.  */
  180.  
  181. #ifdef HAVETERMLIB
  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. #ifdef CLEAREOL
  189. EXT char *CM INIT(Nullch);    /* cursor motion -- PWP */
  190. EXT char *HO INIT(Nullch);    /* home cursor -- PWP */
  191. EXT char *CD INIT(Nullch);    /* clear to end of display -- PWP */
  192. #endif /* CLEAREOL */
  193. EXT char *SO INIT(Nullch);    /* begin standout mode */
  194. EXT char *SE INIT(Nullch);    /* end standout mode */
  195. EXT int SG INIT(0);     /* blanks left by SO and SE */
  196. EXT char *US INIT(Nullch);    /* start underline mode */
  197. EXT char *UE INIT(Nullch);    /* end underline mode */
  198. EXT char *UC INIT(Nullch);    /* underline a character, if that's how it's done */
  199. EXT int UG INIT(0);     /* blanks left by US and UE */
  200. EXT bool AM INIT(FALSE);      /* does terminal have automatic margins? */
  201. EXT bool XN INIT(FALSE);      /* does it eat 1st newline after automatic wrap? */
  202. EXT char PC INIT(0);    /* pad character for use by tputs() */
  203. EXT short ospeed INIT(0);  /* terminal output speed, for use by tputs() */
  204. EXT int LINES INIT(0), COLS INIT(0);   /* size of screen */
  205. EXT int just_a_sec INIT(960);       /* 1 sec at current baud rate */
  206.                /* (number of nulls) */
  207.  
  208. /* define a few handy macros */
  209.  
  210. #define backspace() tputs(BC,0,putchr) FLUSH
  211. #define clear() tputs(CL,LINES,putchr) FLUSH
  212. #define erase_eol() tputs(CE,1,putchr) FLUSH
  213. #ifdef CLEAREOL
  214. #define clear_rest() tputs(CD,LINES,putchr) FLUSH  /* PWP */
  215. #define maybe_eol() if(erase_screen&&can_home_clear)tputs(CE,1,putchr) FLUSH
  216. #endif /* CLEAREOL */
  217. #define underline() tputs(US,1,putchr) FLUSH
  218. #define un_underline() tputs(UE,1,putchr) FLUSH
  219. #define underchar() tputs(UC,0,putchr) FLUSH
  220. #define standout() tputs(SO,1,putchr) FLUSH
  221. #define un_standout() tputs(SE,1,putchr) FLUSH
  222. #define up_line() tputs(UP,1,putchr) FLUSH
  223. #define carriage_return() tputs(CR,1,putchr) FLUSH
  224. #define dingaling() tputs(VB,1,putchr) FLUSH
  225. #else
  226. #ifdef   msdos
  227. EXT int LINES INIT(25), COLS INIT(80); /* size of screen */
  228. #define BC "\b"      /* backspace character */
  229. #define UP "\033[A"     /* move cursor up one line */
  230. #define CR "\r"      /* get to left margin, somehow */
  231. #define VB "\007"    /* visible bell */
  232. #define CL "\033[H\033[J"     /* home and clear screen */
  233. #define CE "\033[K"     /* clear to end of line */
  234. #ifdef CLEAREOL
  235. #define CM ""        /* cursor motion -- PWP */
  236. #define HO "\033[H"     /* home cursor -- PWP */
  237. #define CD "\033[J"     /* clear to end of display -- PWP */
  238. #endif /* CLEAREOL */
  239. #define SO "\033[1m"    /* begin standout mode */
  240. #define SE "\033[0m"    /* end standout mode */
  241. #define SG 0      /* blanks left by SO and SE */
  242. #define US "\033[1m"    /* start underline mode */
  243. #define UE "\033[0m"    /* end underline mode */
  244. #define UC ""     /* underline a character, if that's how it's done */
  245. #define UG 0      /* blanks left by US and UE */
  246. #define AM 1      /* does terminal have automatic margins? */
  247. #define XN 0      /* does it eat 1st newline after automatic wrap? */
  248. #define ospeed B19200   /* terminal output speed, for use by tputs() */
  249. #define  just_a_sec 1000         /* pad takes units of ms */
  250. #define backspace() tputs(BC,0,putchr) FLUSH
  251. #define clear() tputs(CL,LINES,putchr) FLUSH
  252. #define erase_eol() tputs(CE,1,putchr) FLUSH
  253. #ifdef CLEAREOL
  254. #define clear_rest() tputs(CD,LINES,putchr) FLUSH  /* PWP */
  255. #define maybe_eol() if(erase_screen&&can_home_clear)tputs(CE,1,putchr) FLUSH
  256. #endif /* CLEAREOL */
  257. #define underline() tputs(US,1,putchr) FLUSH
  258. #define un_underline() tputs(UE,1,putchr) FLUSH
  259. #define underchar() tputs(UC,0,putchr) FLUSH
  260. #define standout() tputs(SO,1,putchr) FLUSH
  261. #define un_standout() tputs(SE,1,putchr) FLUSH
  262. #define up_line() tputs(UP,1,putchr) FLUSH
  263. #define carriage_return() tputs(CR,1,putchr) FLUSH
  264. #define dingaling() tputs(VB,1,putchr) FLUSH
  265. #define  tputs(s, npad, f) fputs(s, stdout)
  266. #else
  267.   ????????     /* up to you */
  268. #endif
  269. #endif
  270.  
  271. EXT int page_line INIT(1); /* line number for paging in print_line (origin 1) */
  272.  
  273. void  term_init();
  274. void  term_set();
  275. #ifdef PUSHBACK
  276. void  pushchar();
  277. void  mac_init();
  278. void  mac_line();
  279. void  show_macros();
  280. #endif
  281. char  putchr();   /* routine for tputs to call */
  282. bool  finish_command();
  283. void  eat_typeahead();
  284. void  settle_down();
  285. #ifndef read_tty
  286.     int     read_tty();
  287. #endif
  288. void  underprint();
  289. #ifdef NOFIREWORKS
  290.     void no_sofire();
  291.     void no_ulfire();
  292. #endif
  293. void  getcmd();
  294. int   get_anything();
  295. void  in_char();
  296. int   print_lines();
  297. void  page_init();
  298. void  pad();
  299. void  printcmd();
  300. void  rubout();
  301. void  reprint();
  302. #ifdef CLEAREOL
  303. void  home_cursor();
  304. #endif /* CLEAREOL */
  305. #ifdef SIGWINCH
  306. int   winch_catcher();
  307. #endif /* SIGWINCH */
  308.  
  309. #ifdef   msdos
  310. #define  B19200   19200
  311. #define  B9600 9600
  312. #define  B4800 4800
  313. #endif   /* msdos */
  314.  
  315. /*--------------------------------------------------------------------*/
  316. /*                         Defined in TERM.C                          */
  317. /*--------------------------------------------------------------------*/
  318.  
  319. extern stripcr( char *s);
  320. extern noecho( void );
  321. char *tgoto(char *common, int x, int y);
  322. extern crmode( void );
  323. extern unflush_output( void );
  324. extern savetty( void );
  325. extern resetty( void );
  326.