curses.h revision 1.20 1 /* $NetBSD: curses.h,v 1.20 1997/10/13 16:10:36 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1981, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)curses.h 8.4 (Berkeley) 8/10/94
36 */
37
38 #ifndef _CURSES_H_
39 #define _CURSES_H_
40
41 #include <sys/types.h>
42 #include <sys/cdefs.h>
43
44 #include <stdio.h>
45 #include <termcap.h>
46
47 /*
48 * The following #defines and #includes are present for backward
49 * compatibility only. They should not be used in future code.
50 *
51 * START BACKWARD COMPATIBILITY ONLY.
52 */
53 #ifndef _CURSES_PRIVATE
54 #define bool char
55 #define reg register
56
57 #ifndef TRUE
58 #define TRUE (1)
59 #endif
60 #ifndef FALSE
61 #define FALSE (0)
62 #endif
63
64 #define _puts(s) tputs(s, 0, __cputchar)
65 #define _putchar(c) __cputchar(c)
66
67 /* Old-style terminal modes access. */
68 #define baudrate() (cfgetospeed(&__baset))
69 #define crmode() cbreak()
70 #define erasechar() (__baset.c_cc[VERASE])
71 #define killchar() (__baset.c_cc[VKILL])
72 #define nocrmode() nocbreak()
73 #define ospeed (cfgetospeed(&__baset))
74 #endif /* _CURSES_PRIVATE */
75
76 extern char GT; /* Gtty indicates tabs. */
77 extern char NONL; /* Term can't hack LF doing a CR. */
78 extern char UPPERCASE; /* Terminal is uppercase only. */
79
80 extern int My_term; /* Use Def_term regardless. */
81 extern char *Def_term; /* Default terminal type. */
82
83 /* Termcap capabilities. */
84 extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS,
85 PC, UL, XB, XN, XT, XS, XX;
86 extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
87 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
88 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
89 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
90 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
91 *VE, *al, *dl, *sf, *sr,
92 *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
93 *RIGHT_PARM;
94
95 /* END BACKWARD COMPATIBILITY ONLY. */
96
97 /* 8-bit ASCII characters. */
98 #define unctrl(c) __unctrl[(c) & 0xff]
99 #define unctrllen(ch) __unctrllen[(ch) & 0xff]
100
101 extern char *__unctrl[256]; /* Control strings. */
102 extern char __unctrllen[256]; /* Control strings length. */
103
104 /*
105 * A window an array of __LINE structures pointed to by the 'lines' pointer.
106 * A line is an array of __LDATA structures pointed to by the 'line' pointer.
107 *
108 * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
109 * fields are added -- padding fields with *constant values* should ensure
110 * that the compiler will not generate any padding when storing an array of
111 * __LDATA structures. This is to enable consistent use of memcmp, and memcpy
112 * for comparing and copying arrays.
113 */
114 typedef struct {
115 char ch; /* the actual character */
116
117 #define __STANDOUT 0x01 /* Added characters are standout. */
118 char attr; /* attributes of character */
119 } __LDATA;
120
121 #define __LDATASIZE (sizeof(__LDATA))
122
123 typedef struct {
124 #define __ISDIRTY 0x01 /* Line is dirty. */
125 #define __ISPASTEOL 0x02 /* Cursor is past end of line */
126 #define __FORCEPAINT 0x04 /* Force a repaint of the line */
127 unsigned int flags;
128 unsigned int hash; /* Hash value for the line. */
129 size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */
130 size_t firstch, lastch; /* First and last changed columns. */
131 __LDATA *line; /* Pointer to the line text. */
132 } __LINE;
133
134 typedef struct __window { /* Window structure. */
135 struct __window *nextp, *orig; /* Subwindows list and parent. */
136 size_t begy, begx; /* Window home. */
137 size_t cury, curx; /* Current x, y coordinates. */
138 size_t maxy, maxx; /* Maximum values for curx, cury. */
139 short ch_off; /* x offset for firstch/lastch. */
140 __LINE **lines; /* Array of pointers to the lines */
141 __LINE *lspace; /* line space (for cleanup) */
142 __LDATA *wspace; /* window space (for cleanup) */
143
144 #define __ENDLINE 0x001 /* End of screen. */
145 #define __FLUSH 0x002 /* Fflush(stdout) after refresh. */
146 #define __FULLWIN 0x004 /* Window is a screen. */
147 #define __IDLINE 0x008 /* Insert/delete sequences. */
148 #define __SCROLLWIN 0x010 /* Last char will scroll window. */
149 #define __SCROLLOK 0x020 /* Scrolling ok. */
150 #define __CLEAROK 0x040 /* Clear on next refresh. */
151 #define __WSTANDOUT 0x080 /* Standout window */
152 #define __LEAVEOK 0x100 /* If curser left */
153 unsigned int flags;
154 } WINDOW;
155
156 /* Curses external declarations. */
157 extern WINDOW *curscr; /* Current screen. */
158 extern WINDOW *stdscr; /* Standard screen. */
159
160 extern struct termios __orig_termios; /* Terminal state before curses */
161 extern struct termios __baset; /* Our base terminal state */
162 extern int __tcaction; /* If terminal hardware set. */
163
164 extern int COLS; /* Columns on the screen. */
165 extern int LINES; /* Lines on the screen. */
166
167 extern char *ttytype; /* Full name of current terminal. */
168
169 #define ERR (0) /* Error return. */
170 #define OK (1) /* Success return. */
171
172 /* Standard screen pseudo functions. */
173 #define addbytes(s, n) __waddbytes(stdscr, s, n, 0)
174 #define addch(ch) waddch(stdscr, ch)
175 #define addnstr(s, n) waddnstr(stdscr, s, n)
176 #define addstr(s) __waddbytes(stdscr, s, strlen(s), 0)
177 #define clear() wclear(stdscr)
178 #define clrtobot() wclrtobot(stdscr)
179 #define clrtoeol() wclrtoeol(stdscr)
180 #define delch() wdelch(stdscr)
181 #define deleteln() wdeleteln(stdscr)
182 #define erase() werase(stdscr)
183 #define getch() wgetch(stdscr)
184 #define getstr(s) wgetstr(stdscr, s)
185 #define inch() winch(stdscr)
186 #define insch(ch) winsch(stdscr, ch)
187 #define insertln() winsertln(stdscr)
188 #define move(y, x) wmove(stdscr, y, x)
189 #define refresh() wrefresh(stdscr)
190 #define standend() wstandend(stdscr)
191 #define standout() wstandout(stdscr)
192 #define waddbytes(w, s, n) __waddbytes(w, s, n, 0)
193 #define waddstr(w, s) __waddbytes(w, s, strlen(s), 0)
194
195 /* Standard screen plus movement pseudo functions. */
196 #define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n)
197 #define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch)
198 #define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n)
199 #define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s)
200 #define mvdelch(y, x) mvwdelch(stdscr, y, x)
201 #define mvgetch(y, x) mvwgetch(stdscr, y, x)
202 #define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s)
203 #define mvinch(y, x) mvwinch(stdscr, y, x)
204 #define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c)
205 #define mvwaddbytes(w, y, x, s, n) \
206 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
207 #define mvwaddch(w, y, x, ch) \
208 (wmove(w, y, x) == ERR ? ERR : waddch(w, ch))
209 #define mvwaddnstr(w, y, x, s, n) \
210 (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n))
211 #define mvwaddstr(w, y, x, s) \
212 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0))
213 #define mvwdelch(w, y, x) \
214 (wmove(w, y, x) == ERR ? ERR : wdelch(w))
215 #define mvwgetch(w, y, x) \
216 (wmove(w, y, x) == ERR ? ERR : wgetch(w))
217 #define mvwgetstr(w, y, x, s) \
218 (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
219 #define mvwinch(w, y, x) \
220 (wmove(w, y, x) == ERR ? ERR : winch(w))
221 #define mvwinsch(w, y, x, c) \
222 (wmove(w, y, x) == ERR ? ERR : winsch(w, c))
223
224
225 /* Psuedo functions. */
226 #define clearok(w, bf) \
227 ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK))
228 #define flushok(w, bf) \
229 ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH))
230 #define leaveok(w, bf) \
231 ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK))
232 #define scrollok(w, bf) \
233 ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK))
234 #define winch(w) \
235 ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177)
236
237 #define getyx(w, y, x) (y) = getcury(w), (x) = getcurx(w)
238 #define getbegyx(w, y, x) (y) = getbegy(w), (x) = getbegx(w)
239 #define getmaxyx(w, y, x) (y) = getmaxy(w), (x) = getmaxx(w)
240 #define getcury(w) ((w)->cury)
241 #define getcurx(w) ((w)->curx)
242 #define getbegy(w) ((w)->begy)
243 #define getbegx(w) ((w)->begx)
244 #define getmaxy(w) ((w)->maxy)
245 #define getmaxx(w) ((w)->maxx)
246
247 /* Public function prototypes. */
248 __BEGIN_DECLS
249 int box __P((WINDOW *, int, int));
250 int cbreak __P((void));
251 int delwin __P((WINDOW *));
252 int echo __P((void));
253 int endwin __P((void));
254 char *fullname __P((char *, char *));
255 char *getcap __P((char *));
256 int gettmode __P((void));
257 void idlok __P((WINDOW *, int));
258 WINDOW *initscr __P((void));
259 char *longname __P((char *, char *));
260 int mvcur __P((int, int, int, int));
261 int mvprintw __P((int, int, const char *, ...));
262 int mvscanw __P((int, int, const char *, ...));
263 int mvwin __P((WINDOW *, int, int));
264 int mvwprintw __P((WINDOW *, int, int, const char *, ...));
265 int mvwscanw __P((WINDOW *, int, int, const char *, ...));
266 WINDOW *newwin __P((int, int, int, int));
267 int nl __P((void));
268 int nocbreak __P((void));
269 int noecho __P((void));
270 int nonl __P((void));
271 int noraw __P((void));
272 int overlay __P((WINDOW *, WINDOW *));
273 int overwrite __P((WINDOW *, WINDOW *));
274 int printw __P((const char *, ...));
275 int raw __P((void));
276 int resetty __P((void));
277 int savetty __P((void));
278 int scanw __P((const char *, ...));
279 int scroll __P((WINDOW *));
280 int setterm __P((char *));
281 int sscans __P((WINDOW *, const char *, ...));
282 WINDOW *subwin __P((WINDOW *, int, int, int, int));
283 int suspendwin __P((void));
284 int touchline __P((WINDOW *, int, int, int));
285 int touchoverlap __P((WINDOW *, WINDOW *));
286 int touchwin __P((WINDOW *));
287 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
288 int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_));
289 int waddch __P((WINDOW *, int));
290 int waddnstr __P((WINDOW *, const char *, int));
291 int wclear __P((WINDOW *));
292 int wclrtobot __P((WINDOW *));
293 int wclrtoeol __P((WINDOW *));
294 int wdelch __P((WINDOW *));
295 int wdeleteln __P((WINDOW *));
296 int werase __P((WINDOW *));
297 int wgetch __P((WINDOW *));
298 int wgetstr __P((WINDOW *, char *));
299 int winsch __P((WINDOW *, int));
300 int winsertln __P((WINDOW *));
301 int wmove __P((WINDOW *, int, int));
302 int wprintw __P((WINDOW *, const char *, ...));
303 int wrefresh __P((WINDOW *));
304 int wscanw __P((WINDOW *, const char *, ...));
305 int wstandend __P((WINDOW *));
306 int wstandout __P((WINDOW *));
307 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
308
309 /* Private functions that are needed for user programs prototypes. */
310 void __cputchar __P((int));
311 int __waddbytes __P((WINDOW *, const char *, int, int));
312 __END_DECLS
313
314 /* Private functions. */
315 #ifdef _CURSES_PRIVATE
316 void __CTRACE __P((const char *, ...));
317 unsigned int __hash __P((char *, int));
318 void __id_subwins __P((WINDOW *));
319 int __mvcur __P((int, int, int, int, int));
320 void __restore_stophandler __P((void));
321 void __set_stophandler __P((void));
322 void __set_subwin __P((WINDOW *, WINDOW *));
323 void __startwin __P((void));
324 void __stop_signal_handler __P((int));
325 void __swflags __P((WINDOW *));
326 int __touchline __P((WINDOW *, int, int, int, int));
327 int __touchwin __P((WINDOW *));
328 char *__tscroll __P((const char *, int, int));
329 int __waddch __P((WINDOW *, __LDATA *));
330 int __stopwin __P((void));
331 void __restartwin __P((void));
332
333 /* Private #defines. */
334 #define min(a,b) (a < b ? a : b)
335 #define max(a,b) (a > b ? a : b)
336
337 /* Private externs. */
338 extern int __echoit;
339 extern int __endwin;
340 extern int __pfast;
341 extern int __rawmode;
342 extern int __noqch;
343 #endif
344
345 #endif /* !_CURSES_H_ */
346