1 /* 2 * Copyright (c) 1981 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)curses.h 5.32 (Berkeley) 05/07/93 8 */ 9 10 #ifndef _CURSES_H_ 11 #define _CURSES_H_ 12 13 #include <stdio.h> 14 15 /* 16 * The following #defines and #includes are present for backward 17 * compatibility only. They should not be used in future code. 18 * 19 * START BACKWARD COMPATIBILITY ONLY. 20 */ 21 #ifndef _CURSES_PRIVATE 22 #define bool char 23 #define reg register 24 25 #ifndef TRUE 26 #define TRUE (1) 27 #endif 28 #ifndef FALSE 29 #define FALSE (0) 30 #endif 31 32 #define _puts(s) tputs(s, 0, __cputchar) 33 #define _putchar(c) __cputchar(c) 34 35 /* Old-style terminal modes access. */ 36 #define baudrate() (cfgetospeed(&__orig_termios)) 37 #define crmode() cbreak() 38 #define erasechar() (__orig_termios.c_cc[VERASE]) 39 #define killchar() (__orig_termios.c_cc[VKILL]) 40 #define nocrmode() nocbreak() 41 #define ospeed (cfgetospeed(&__orig_termios)) 42 #endif /* _CURSES_PRIVATE */ 43 44 extern char GT; /* Gtty indicates tabs. */ 45 extern char NONL; /* Term can't hack LF doing a CR. */ 46 extern char UPPERCASE; /* Terminal is uppercase only. */ 47 48 extern int My_term; /* Use Def_term regardless. */ 49 extern char *Def_term; /* Default terminal type. */ 50 51 /* Termcap capabilities. */ 52 extern char AM, BS, CA, DA, EO, HC, HZ, IN, MI, MS, NC, NS, OS, 53 PC, UL, XB, XN, XT, XS, XX; 54 extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, 55 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, 56 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, 57 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, 58 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, 59 *VE, *al, *dl, *sf, *sr, 60 *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, 61 *RIGHT_PARM; 62 63 /* END BACKWARD COMPATIBILITY ONLY. */ 64 65 /* 8-bit ASCII characters. */ 66 #define unctrl(c) __unctrl[(c) & 0xff] 67 #define unctrllen(ch) __unctrllen[(ch) & 0xff] 68 69 extern char *__unctrl[256]; /* Control strings. */ 70 extern char __unctrllen[256]; /* Control strings length. */ 71 72 /* 73 * A window an array of __LINE structures pointed to by the 'lines' pointer. 74 * A line is an array of __LDATA structures pointed to by the 'line' pointer. 75 * 76 * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new 77 * fields are added -- padding fields with *constant values* should ensure 78 * that the compiler will not generate any padding when storing an array of 79 * __LDATA structures. This is to enable consistent use of memcmp, and memcpy 80 * for comparing and copying arrays. 81 */ 82 typedef struct { 83 char ch; /* the actual character */ 84 85 #define __STANDOUT 0x01 /* Added characters are standout. */ 86 char attr; /* attributes of character */ 87 } __LDATA; 88 89 #define __LDATASIZE (sizeof(__LDATA)) 90 91 typedef struct { 92 #define __ISDIRTY 0x01 /* Line is dirty. */ 93 #define __ISPASTEOL 0x02 /* Cursor is past end of line */ 94 #define __FORCEPAINT 0x04 /* Force a repaint of the line */ 95 u_int flags; 96 u_int hash; /* Hash value for the line. */ 97 size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */ 98 size_t firstch, lastch; /* First and last changed columns. */ 99 __LDATA *line; /* Pointer to the line text. */ 100 } __LINE; 101 102 typedef struct __window { /* Window structure. */ 103 struct __window *nextp, *orig; /* Subwindows list and parent. */ 104 size_t begy, begx; /* Window home. */ 105 size_t cury, curx; /* Current x, y coordinates. */ 106 size_t maxy, maxx; /* Maximum values for curx, cury. */ 107 short ch_off; /* x offset for firstch/lastch. */ 108 __LINE **lines; /* Array of pointers to the lines */ 109 __LINE *lspace; /* line space (for cleanup) */ 110 __LDATA *wspace; /* window space (for cleanup) */ 111 112 #define __ENDLINE 0x001 /* End of screen. */ 113 #define __FLUSH 0x002 /* Fflush(stdout) after refresh. */ 114 #define __FULLLINE 0x004 /* Line width = terminal width. */ 115 #define __FULLWIN 0x008 /* Window is a screen. */ 116 #define __IDLINE 0x010 /* Insert/delete sequences. */ 117 #define __SCROLLWIN 0x020 /* Last char will scroll window. */ 118 #define __SCROLLOK 0x040 /* Scrolling ok. */ 119 #define __CLEAROK 0x080 /* Clear on next refresh. */ 120 #define __WSTANDOUT 0x100 /* Standout window */ 121 #define __LEAVEOK 0x200 /* If curser left */ 122 u_int flags; 123 } WINDOW; 124 125 /* Curses external declarations. */ 126 extern WINDOW *curscr; /* Current screen. */ 127 extern WINDOW *stdscr; /* Standard screen. */ 128 129 extern struct termios __orig_termios; /* Original terminal modes. */ 130 131 extern int COLS; /* Columns on the screen. */ 132 extern int LINES; /* Lines on the screen. */ 133 134 extern char *ttytype; /* Full name of current terminal. */ 135 136 #define ERR (0) /* Error return. */ 137 #define OK (1) /* Success return. */ 138 139 /* Standard screen pseudo functions. */ 140 #define addbytes(s, n) __waddbytes(stdscr, s, n, 0) 141 #define addch(ch) waddch(stdscr, ch) 142 #define addnstr(s, n) waddnstr(stdscr, s, n) 143 #define addstr(s) __waddbytes(stdscr, s, strlen(s), 0) 144 #define clear() wclear(stdscr) 145 #define clrtobot() wclrtobot(stdscr) 146 #define clrtoeol() wclrtoeol(stdscr) 147 #define delch() wdelch(stdscr) 148 #define deleteln() wdeleteln(stdscr) 149 #define erase() werase(stdscr) 150 #define getch() wgetch(stdscr) 151 #define getstr(s) wgetstr(stdscr, s) 152 #define inch() winch(stdscr) 153 #define insch(ch) winsch(stdscr, ch) 154 #define insertln() winsertln(stdscr) 155 #define move(y, x) wmove(stdscr, y, x) 156 #define refresh() wrefresh(stdscr) 157 #define standend() wstandend(stdscr) 158 #define standout() wstandout(stdscr) 159 #define waddbytes(w, s, n) __waddbytes(w, s, n, 0) 160 #define waddstr(w, s) __waddbytes(w, s, strlen(s), 0) 161 162 /* Standard screen plus movement pseudo functions. */ 163 #define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n) 164 #define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) 165 #define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n) 166 #define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s) 167 #define mvdelch(y, x) mvwdelch(stdscr, y, x) 168 #define mvgetch(y, x) mvwgetch(stdscr, y, x) 169 #define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s) 170 #define mvinch(y, x) mvwinch(stdscr, y, x) 171 #define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) 172 #define mvwaddbytes(w, y, x, s, n) \ 173 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0)) 174 #define mvwaddch(w, y, x, ch) \ 175 (wmove(w, y, x) == ERR ? ERR : waddch(w, ch)) 176 #define mvwaddnstr(w, y, x, s, n) \ 177 (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n)) 178 #define mvwaddstr(w, y, x, s) \ 179 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0)) 180 #define mvwdelch(w, y, x) \ 181 (wmove(w, y, x) == ERR ? ERR : wdelch(w)) 182 #define mvwgetch(w, y, x) \ 183 (wmove(w, y, x) == ERR ? ERR : wgetch(w)) 184 #define mvwgetstr(w, y, x, s) \ 185 (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s)) 186 #define mvwinch(w, y, x) \ 187 (wmove(w, y, x) == ERR ? ERR : winch(w)) 188 #define mvwinsch(w, y, x, c) \ 189 (wmove(w, y, x) == ERR ? ERR : winsch(w, c)) 190 191 /* Psuedo functions. */ 192 #define clearok(w, bf) \ 193 ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK)) 194 #define flushok(w, bf) \ 195 ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH)) 196 #define getyx(w, y, x) \ 197 (y) = (w)->cury, (x) = (w)->curx 198 #define leaveok(w, bf) \ 199 ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK)) 200 #define scrollok(w, bf) \ 201 ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK)) 202 #define winch(w) \ 203 ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177) 204 205 /* Public function prototypes. */ 206 int box __P((WINDOW *, int, int)); 207 int cbreak __P((void)); 208 int delwin __P((WINDOW *)); 209 int echo __P((void)); 210 int endwin __P((void)); 211 char *fullname __P((char *, char *)); 212 char *getcap __P((char *)); 213 int gettmode __P((void)); 214 void idlok __P((WINDOW *, int)); 215 WINDOW *initscr __P((void)); 216 char *longname __P((char *, char *)); 217 int mvcur __P((int, int, int, int)); 218 int mvprintw __P((int, int, const char *, ...)); 219 int mvscanw __P((int, int, const char *, ...)); 220 int mvwin __P((WINDOW *, int, int)); 221 int mvwprintw __P((WINDOW *, int, int, const char *, ...)); 222 int mvwscanw __P((WINDOW *, int, int, const char *, ...)); 223 WINDOW *newwin __P((int, int, int, int)); 224 int nl __P((void)); 225 int nocbreak __P((void)); 226 int noecho __P((void)); 227 int nonl __P((void)); 228 int noraw __P((void)); 229 int overlay __P((WINDOW *, WINDOW *)); 230 int overwrite __P((WINDOW *, WINDOW *)); 231 int printw __P((const char *, ...)); 232 int raw __P((void)); 233 int resetty __P((void)); 234 int savetty __P((void)); 235 int scanw __P((const char *, ...)); 236 int scroll __P((WINDOW *)); 237 int setterm __P((char *)); 238 int sscans __P((WINDOW *, const char *, ...)); 239 WINDOW *subwin __P((WINDOW *, int, int, int, int)); 240 int suspendwin __P((void)); 241 int touchline __P((WINDOW *, int, int, int)); 242 int touchoverlap __P((WINDOW *, WINDOW *)); 243 int touchwin __P((WINDOW *)); 244 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 245 int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 246 int waddch __P((WINDOW *, int)); 247 int waddnstr __P((WINDOW *, const char *, int)); 248 int wclear __P((WINDOW *)); 249 int wclrtobot __P((WINDOW *)); 250 int wclrtoeol __P((WINDOW *)); 251 int wdelch __P((WINDOW *)); 252 int wdeleteln __P((WINDOW *)); 253 int werase __P((WINDOW *)); 254 int wgetch __P((WINDOW *)); 255 int wgetstr __P((WINDOW *, char *)); 256 int winsch __P((WINDOW *, int)); 257 int winsertln __P((WINDOW *)); 258 int wmove __P((WINDOW *, int, int)); 259 int wprintw __P((WINDOW *, const char *, ...)); 260 int wrefresh __P((WINDOW *)); 261 int wscanw __P((WINDOW *, const char *, ...)); 262 char *wstandend __P((WINDOW *)); 263 char *wstandout __P((WINDOW *)); 264 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 265 266 void __cputchar __P((int)); /* Public: backward compatibility */ 267 268 #ifdef _CURSES_PRIVATE 269 /* Private function prototypes. */ 270 void __TRACE __P((const char *, ...)); 271 u_int __hash __P((char *, int)); 272 void __id_subwins __P((WINDOW *)); 273 void __set_subwin __P((WINDOW *, WINDOW *)); 274 void __startwin __P((void)); 275 void __stop_signal_handler __P((int)); 276 void __swflags __P((WINDOW *)); 277 int __touchline __P((WINDOW *, int, int, int, int)); 278 int __touchwin __P((WINDOW *)); 279 char *__tscroll __P((const char *, int)); 280 int __waddbytes __P((WINDOW *, const char *, int, int)); 281 int __waddch __P((WINDOW *, __LDATA *)); 282 283 /* Private #defines. */ 284 #define min(a,b) (a < b ? a : b) 285 #define max(a,b) (a > b ? a : b) 286 287 /* Private externs. */ 288 extern int __echoit; 289 extern int __endwin; 290 extern int __pfast; 291 extern int __rawmode; 292 extern int __noqch; 293 #endif 294 295 /* Termcap functions. */ 296 int tgetent __P((char *, char *)); 297 int tgetnum __P((char *)); 298 int tgetflag __P((char *)); 299 char *tgetstr __P((char *, char **)); 300 char *tgoto __P((char *, int, int)); 301 int tputs __P((char *, int, void (*)(int))); 302 303 #endif /* !_CURSES_H_ */ 304