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