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