home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 388_01 / curses / curses.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-01  |  5.2 KB  |  202 lines

  1. /*
  2.  * curses.h    
  3.  *
  4.  * Stdscr Curses for PC Class Machines.
  5.  *
  6.  * Copyright 1990, 1993 by Anthony Howe.  All rights reserved.  No warranty.
  7.  */
  8.  
  9. #ifndef __curses_h__
  10. #define __curses_h__    1
  11.  
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14. #include <fbios.h>
  15.  
  16. #undef _
  17. #if __STDC__
  18. #define _(x)    x
  19. #else
  20. #define _(x)    ()
  21. #endif
  22.  
  23. #undef CTRL
  24. #define CTRL(x)        ((x) & 0x1f)
  25.  
  26. #ifndef FALSE
  27. #define FALSE    0
  28. #define TRUE    !FALSE
  29. #endif
  30.  
  31. typedef struct {
  32.     int page;        /* DOS Bios display page */
  33.     int mode;        /* Video mode */
  34.     unsigned short seg;    /* Screen memory base segment */
  35.     int height, width;    /* Screen dimensions */
  36.     int _cbreak : 1;
  37.     int _crlf : 1;        /* 1 = nl to crlf, 0 = nl to lf */
  38.     int _echo : 1;
  39.     int _raw : 1;
  40. } SCREEN;
  41.  
  42. typedef struct {
  43.     short row, col;            /* Cursor logical location */
  44.     short brow, bcol;        /* Window location */
  45.     short mrow, mcol;        /* Max indexs */
  46.     short flags;
  47.     chtype attr;
  48.     chtype back;
  49.     chtype far **display;
  50. } WINDOW;
  51.  
  52. /*
  53.  * Flags
  54.  */
  55. #define _CLEAROK    0x0001
  56. #define _IDLOK        0x0002
  57. #define _KEYPAD        0x0004
  58. #define _LEAVEOK    0x0008
  59. #define _SCROLLOK    0x0010
  60. #define _FULLWIN    0x0020
  61. #define _SUBWIN        0x0040
  62. #define _MEMMAP        0x8000
  63.  
  64. #if 0
  65. #define A_NORMAL    0x0700
  66. #define A_REVERSE    0x7000
  67. #else
  68. /* 
  69.  * Read-only variables initialised by initscr(). 
  70.  * It will correspond to the bottom-left hand corner attributes.
  71.  */
  72. extern chtype A_NORMAL;
  73. extern chtype A_REVERSE;
  74. #endif
  75.  
  76. #define A_ATTRIBUTES    0xff00
  77. #define A_CHARTEXT    0x00ff
  78. #define A_BLINK        0x8000
  79. #define A_BOLD        0x0800
  80. #define A_DIM        0
  81. #define A_PROTECT    0
  82. #define A_STANDOUT    A_REVERSE
  83. #define A_UNDERLINE    0x0100
  84.  
  85. #define OK    0
  86. #define ERR    (-1)
  87.  
  88. /*    Single Line Box Characters */
  89. #define ACS_ULCORNER    0xda
  90. #define ACS_URCORNER    0xbf
  91. #define ACS_BLCORNER    0xc0
  92. #define ACS_BRCORNER    0xd9
  93. #define ACS_HLINE    0xc4
  94. #define ACS_VLINE    0xb3
  95. #define ACS_TTEE    0xc2
  96. #define ACS_BTEE    0xc1
  97. #define ACS_LTEE    0xc3
  98. #define ACS_RTEE    0xb4
  99.  
  100. /*    Double Line Box Characters */
  101. #define ACS_DULCORNER    0xc9
  102. #define ACS_DURCORNER    0xbb
  103. #define ACS_DBLCORNER    0xc8
  104. #define ACS_DBRCORNER    0xbc
  105. #define ACS_DHLINE    0xcd
  106. #define ACS_DVLINE    0xba
  107. #define ACS_DTTEE    0xcb
  108. #define ACS_DBTEE    0xca
  109. #define ACS_DLTEE    0xcc
  110. #define ACS_DRTEE    0xb9
  111.  
  112. /*    Some (not all) KEY_xxxx Macros */
  113. #define    KEY_DOWN    0x0150        /* The four arrow keys */
  114. #define    KEY_UP        0x0148
  115. #define    KEY_LEFT    0x014B
  116. #define    KEY_RIGHT    0x014D
  117. #define    KEY_HOME    0x0147        /* Home key */
  118. #define    KEY_BACKSPACE    0x010E        /* Backspace key */
  119. #define    KEY_DC        0x0153        /* Del key */
  120. #define    KEY_IC        0x0152        /* Ins key */
  121. #define    KEY_EIC        0x0152        /* Exit insert char mode */
  122. #define    KEY_CLEAR    0x0177        /* Clear screen key */
  123. #define    KEY_EOS        0x0176        /* Clear to end of screen */
  124. #define    KEY_EOL        0x0175        /* Clear to end of line */
  125. #define    KEY_NPAGE    0x0151        /* Next page PgDn */
  126. #define    KEY_PPAGE    0x0149        /* Previous page PgUp */
  127. #define    KEY_END        0x014F        /* End key */
  128.  
  129. #define    KEY_F0        (-1)        /* No real F0 */
  130.                     /* F1..F10 == 3B00..4400 */
  131.                     /* F11..F40 == 5400..7100 */
  132. #define    KEY_F(n)    (0x013A+(n)+((n)-11+30)/30*(0x54-0x45))
  133. #define    KEY_SH_FN(n)    KEY_F((n)+10)
  134. #define    KEY_CTRL_FN(n)    KEY_F((n)+20)
  135. #define    KEY_ALT_FN(n)    KEY_F((n)+30)
  136.  
  137.  
  138. /* Obscure Globals */
  139. extern SCREEN _tty;
  140. extern WINDOW _stdscr;
  141.  
  142. /* 
  143.  * Globals 
  144.  */
  145. extern int clearok _((WINDOW *, int));
  146. extern int keypad _((WINDOW *, int));
  147. extern int leaveok _((WINDOW *, int));
  148. extern int idlok _((WINDOW *, int));
  149. extern int scrollok _((WINDOW *, int));
  150.  
  151. extern int addch _((chtype));
  152. extern int addnstr _((char *, int));
  153. extern int beep _((void));
  154. extern int clrtobot _((void));
  155. extern int clrtoeol _((void));
  156. extern int endwin _((void));
  157. extern int getch _((void));
  158. extern int getnstr _((char *, int));
  159. /*extern int mvcur _((int, int, int, int));*/
  160. extern int printw _((char *, ...));
  161. extern int mvprintw _((int, int, char *, ...));
  162. extern int vwprintw _((WINDOW *, char *, va_list)); 
  163. extern int refresh _((void));
  164. extern WINDOW *initscr _((void));
  165.  
  166. #define curscr            stdscr
  167. #define stdscr            (&_stdscr)
  168. #define LINES            _tty.height
  169. #define COLS            _tty.width
  170.  
  171. #define erasechar()        '\b'
  172. #define killchar()        '\030'
  173. #define mvcur(a,b,r,c)        SetCursorPos(_tty.page,r,c)
  174.  
  175. #define cbreak()        (_tty._cbreak = 1)    
  176. #define echo()            (_tty._echo = 1)
  177. #define nl()            (_tty._crlf = 1)
  178. #define raw()            (_tty._raw = 1)
  179. #define nocbreak()        (_tty._cbreak = 0)
  180. #define noecho()        (_tty._echo = 0)
  181. #define nonl()            (_tty._crlf = 0)
  182. #define noraw()            (_tty._raw = 0)
  183.  
  184. #define getyx(w,y,x)        ((y) = _stdscr.row, (x) = _stdscr.col)
  185. #define getbegyx(w,y,x)        ((y) = _stdscr.brow, (x) = _stdscr.bcol)
  186. #define getmaxyx(w,y,x)        ((y) = _stdscr.mrow, (x) = _stdscr.mcol)
  187.  
  188. #define addstr(s)        addnstr(s,-1)
  189. #define clear()            (clearok(stdscr, TRUE), erase())
  190. #define doupdate()        OK
  191. #define erase()            (move(0,0),clrtobot())
  192. #define getstr(b)        getnstr(b,-1)
  193. #define move(r,c)        (_stdscr.row=r,_stdscr.col=c,OK)
  194. #define mvaddch(r,c,ch)        (move(r,c),addch(ch))
  195. #define mvaddnstr(r,c,n,s)    (move(r,c),addnstr(n,s))
  196. #define mvaddstr(r,c,s)        (move(r,c),addstr(s))
  197. #define mvgetch(r,c)        (move(r,c),getch())
  198. #define standend()        (_stdscr.attr = A_NORMAL)
  199. #define standout()        (_stdscr.attr = A_STANDOUT)
  200.  
  201. #endif /* __curses_h__ */
  202.