home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume33 / problem / part01 / display.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-19  |  7.5 KB  |  225 lines

  1. /*
  2. ** external definitions needed for interfacing with display.C
  3. **
  4. ** display.h display.h 1.8   Delta'd: 15:50:52 9/22/92   Mike Lijewski, CNSF
  5. **
  6. ** Copyright (c) 1991, 1992 Cornell University
  7. ** All rights reserved.
  8. **
  9. ** Redistribution and use in source and binary forms are permitted
  10. ** provided that: (1) source distributions retain this entire copyright
  11. ** notice and comment, and (2) distributions including binaries display
  12. ** the following acknowledgement:  ``This product includes software
  13. ** developed by Cornell University'' in the documentation or other
  14. ** materials provided with the distribution and in all advertising
  15. ** materials mentioning features or use of this software. Neither the
  16. ** name of the University nor the names of its contributors may be used
  17. ** to endorse or promote products derived from this software without
  18. ** specific prior written permission.
  19. **
  20. ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  21. ** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  22. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  23. */
  24.  
  25. #ifndef __DISPLAY_H
  26. #define __DISPLAY_H
  27.  
  28. //
  29. // termcap capabilities we'll try to use
  30. //
  31. extern char *AL;               // insert blank line before cursor
  32. extern char *ALN;              // insert N blank lines before cursor
  33. extern int   AM;               // automatic margins?
  34. extern char *BC;               // backspace, if not BS
  35. extern int   BS;               // ASCII backspace works
  36. extern char *CD;               // clear to end of display
  37. extern char *CE;               // clear to end of line
  38. extern char *CL;               // clear screen
  39. extern int   CO;               // number of columns
  40. extern char *CM;               // cursor motion
  41. extern char *CR;               // cursor beginning of line
  42. extern char *CS;               // set scroll region
  43. extern int   DA;               // backing store off top?
  44. extern int   DB;               // backing store off bottom?
  45. extern char *DC;               // delete character at cursor
  46. extern char *DL;               // delete line cursor is on
  47. extern char *DLN;              // delete N lines at cursor
  48. extern char *DM;               // string to enter delete mode
  49. extern char *DO;               // cursor down
  50. extern char *ED;               // string to end delete mode
  51. extern int   HC;               // hardcopy terminal?
  52. extern char *HO;               // cursor home
  53. extern char *IS;               // initialize terminal
  54. extern char *KD;               // down arrow key
  55. extern char *KE;               // de-initialize keypad
  56. extern char *KS;               // initialize keypad (for arrow keys)
  57. extern char *KU;               // up arrrow key
  58. extern char *LE;               // cursor back one column
  59. extern int   LI;               // number of rows
  60. extern char *LL;               // cursor to lower left
  61. extern int   OS;               // terminal overstrikes?
  62. extern char  PC;               // pad character
  63. extern char *PCstr;            // pad string
  64. extern char *SE;               // end standout mode
  65. extern char *SF;               // scroll screen up one line
  66. extern char *SO;               // enter standout mode
  67. extern char *SR;               // scroll screen down one line
  68. extern char *TE;               // end cursor addressing mode
  69. extern char *TI;               // enter cursor addressing mode
  70. extern char *UP;               // cursor up
  71. extern char *VE;               // end visual mode
  72. extern char *VS;               // enter visual mode
  73. extern char *XN;               // strange wrap behaviour
  74.  
  75. // have we just been resumed after being suspended?
  76. extern int resumingAfterSuspension;
  77.  
  78. //
  79. // termcap routines
  80. //
  81. extern "C" {
  82.     extern short ospeed;        // terminal speed - needed by tputs()
  83. #if !defined(__GNUG__) || __GNUG__ == 2
  84.     int    tgetent(const char *buf, const char *name);
  85.     int    tgetflag(const char *);
  86.     int    tgetnum(const char *);
  87.     char  *tgetstr(const char *, char **);
  88.     char  *tgoto(const char *, int, int);
  89.     int    tputs(const char *, int, int (*)(int));
  90. #endif
  91. }
  92.  
  93. //
  94. // functions defined in display.C
  95. //
  96. extern void    clear_display();
  97. extern void    clear_to_end_of_screen(int);
  98. extern void    delete_listing_line(int);
  99. extern void    init_display();
  100. extern int     outputch(int);
  101. extern void    scroll_listing_up_one();
  102. extern void    scroll_listing_down_one();
  103. extern void    scroll_listing_up_N(int);
  104. extern void    scroll_listing_down_N(int);
  105. extern void    scroll_screen_up_one();
  106. extern void    scroll_screen_down_one();
  107. extern void    scroll_screen_up_N(int);
  108. extern void    scroll_screen_down_N(int);
  109. extern void    setraw();
  110. extern void    termcap(const char *);
  111. extern void    term_display();
  112. extern void    termstop(int);
  113. extern void    unsetraw();
  114. extern void    update_screen_line(const char *, const char *, int);
  115.  
  116. /*
  117. ** output_string_capability - output a string capability from termcap
  118. **                             to the terminal. The second argument,
  119. **                             which defaults to 1, is the number
  120. **                             of rows affected.
  121. */
  122.  
  123. inline void output_string_capability(const char *capability, int affected = 1)
  124. {
  125.     if (capability) tputs(capability, affected, outputch);
  126. }
  127.  
  128. inline int rows() { return LI; }
  129.  
  130. inline int columns() { return CO; }
  131.  
  132. inline void initialize_terminal() { output_string_capability(IS); }
  133.  
  134. inline void synch_display() { (void)fflush(stdout); }
  135.  
  136. inline void enter_cursor_addressing_mode() { output_string_capability(TI); }
  137.  
  138. inline void enable_keypad() { output_string_capability(KS); }
  139.  
  140. inline void disable_keypad() { output_string_capability(KE); }
  141.  
  142. inline void enter_visual_mode() { output_string_capability(VS); }
  143.  
  144. inline void end_visual_mode() { output_string_capability(VE); }
  145.  
  146. inline void end_cursor_addressing_mode() { output_string_capability(TE); }
  147.  
  148. inline void enter_standout_mode() { output_string_capability(SO); }
  149.  
  150. inline void end_standout_mode() { output_string_capability(SE); }
  151.  
  152. inline void enter_delete_mode() { output_string_capability(DM); }
  153.  
  154. inline void end_delete_mode() { output_string_capability(ED); }
  155.  
  156. inline void move_cursor(int row, int column)
  157. {
  158.     if (column >= columns()) column = columns()-1;
  159.     output_string_capability(tgoto(CM, column, row));
  160. }
  161.  
  162. inline void cursor_home()
  163. {
  164.     HO ? output_string_capability(HO) : move_cursor(0, 0);
  165. }
  166.  
  167. inline void clear_to_end_of_line() { output_string_capability(CE); }
  168.  
  169. inline void move_to_modeline() { move_cursor(rows() - 2, 0); }
  170.  
  171. inline void move_to_message_line()
  172. {
  173.     if (LL)
  174.         output_string_capability(LL);
  175.     else
  176.         move_cursor(rows()-1, 0); }
  177.  
  178. inline void clear_modeline() { move_to_modeline(); clear_to_end_of_line(); }
  179.  
  180. inline void clear_message_line()
  181. {
  182.     move_to_message_line(); clear_to_end_of_line();
  183. }
  184.  
  185. inline void delete_screen_line(int y)
  186. {
  187.     move_cursor(y, 0);
  188.     output_string_capability(DL, rows()-y);
  189. }
  190.  
  191. inline void backspace() {
  192.     if (BS)
  193.         putchar('\b');
  194.     else if (LE)
  195.         output_string_capability(LE);
  196.     else
  197.         output_string_capability(BC);
  198. }
  199.  
  200. inline void cursor_up() { output_string_capability(UP); }
  201.  
  202. inline void delete_char_at_cursor()
  203. {
  204.     if (DM) output_string_capability(DM);
  205.     output_string_capability(DC);
  206.     if (ED) output_string_capability(ED);
  207. }
  208.  
  209. inline void cursor_down() { output_string_capability(DO); }
  210.  
  211. inline void cursor_beginning_of_line() { output_string_capability(CR); } 
  212.  
  213. inline void cursor_wrap() { cursor_beginning_of_line(); cursor_down(); }
  214.  
  215. inline void ding() {
  216.     //
  217.     // This should be `output('\a')', but some braindead C compilers when
  218.     // used as the backend to Cfront, don't recognize '\a' as the BELL.
  219.     //
  220.     outputch(7);
  221.     synch_display();
  222.  
  223. #endif
  224.