2 * Copyright (c) 1981, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * @(#)curses.h 8.3 (Berkeley) 7/27/94
39 #include <sys/types.h>
40 #include <sys/cdefs.h>
45 #define _BSD_VA_LIST_ char *
49 * The following #defines and #includes are present for backward
50 * compatibility only. They should not be used in future code.
52 * START BACKWARD COMPATIBILITY ONLY.
54 #ifndef _CURSES_PRIVATE
56 /* This stuff needed for those pgms which include <sgtty.h> */
57 /* Undef things manually to avoid redefinition */
80 #include <sys/ioctl.h>
81 #include <sys/ioctl_compat.h> /* For sgttyb and related */
93 #define _puts(s) tputs(s, 0, __cputchar)
95 /* Old-style terminal modes access. */
96 #define baudrate() (cfgetospeed(&__baset))
97 #define crmode() cbreak()
98 #define erasechar() (__baset.c_cc[VERASE])
99 #define killchar() (__baset.c_cc[VKILL])
100 #define nocrmode() nocbreak()
101 #define ospeed (cfgetospeed(&__baset))
103 /* WINDOW structure members name compatibility */
113 #endif /* _CURSES_PRIVATE */
115 extern char GT; /* Gtty indicates tabs. */
116 extern char NONL; /* Term can't hack LF doing a CR. */
117 extern char UPPERCASE; /* Terminal is uppercase only. */
119 extern int My_term; /* Use Def_term regardless. */
120 extern char *Def_term; /* Default terminal type. */
122 /* Termcap capabilities. */
123 extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS,
124 PC, UL, XB, XN, XT, XS, XX;
125 extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
126 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
127 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
128 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
129 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
130 *VE, *al, *dl, *sf, *sr,
131 *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
134 /* END BACKWARD COMPATIBILITY ONLY. */
136 /* 8-bit ASCII characters. */
137 #define unctrl(c) __unctrl[(c) & 0xff]
138 #define unctrllen(ch) __unctrllen[(ch) & 0xff]
140 extern char *__unctrl[256]; /* Control strings. */
141 extern char __unctrllen[256]; /* Control strings length. */
144 * A window an array of __LINE structures pointed to by the 'lines' pointer.
145 * A line is an array of __LDATA structures pointed to by the 'line' pointer.
147 * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
148 * fields are added -- padding fields with *constant values* should ensure
149 * that the compiler will not generate any padding when storing an array of
150 * __LDATA structures. This is to enable consistent use of memcmp, and memcpy
151 * for comparing and copying arrays.
154 char ch; /* the actual character */
156 #define __STANDOUT 0x01 /* Added characters are standout. */
157 char attr; /* attributes of character */
160 #define __LDATASIZE (sizeof(__LDATA))
163 #define __ISDIRTY 0x01 /* Line is dirty. */
164 #define __ISPASTEOL 0x02 /* Cursor is past end of line */
165 #define __FORCEPAINT 0x04 /* Force a repaint of the line */
167 u_int hash; /* Hash value for the line. */
168 size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */
169 size_t firstch, lastch; /* First and last changed columns. */
170 __LDATA *line; /* Pointer to the line text. */
173 typedef struct __window { /* Window structure. */
174 struct __window *nextp, *orig; /* Subwindows list and parent. */
175 size_t begy, begx; /* Window home. */
176 size_t cury, curx; /* Current x, y coordinates. */
177 size_t maxy, maxx; /* Maximum values for curx, cury. */
178 short ch_off; /* x offset for firstch/lastch. */
179 __LINE **lines; /* Array of pointers to the lines */
180 __LINE *lspace; /* line space (for cleanup) */
181 __LDATA *wspace; /* window space (for cleanup) */
183 #define __ENDLINE 0x001 /* End of screen. */
184 #define __FLUSH 0x002 /* Fflush(stdout) after refresh. */
185 #define __FULLWIN 0x004 /* Window is a screen. */
186 #define __IDLINE 0x008 /* Insert/delete sequences. */
187 #define __SCROLLWIN 0x010 /* Last char will scroll window. */
188 #define __SCROLLOK 0x020 /* Scrolling ok. */
189 #define __CLEAROK 0x040 /* Clear on next refresh. */
190 #define __WSTANDOUT 0x080 /* Standout window */
191 #define __LEAVEOK 0x100 /* If curser left */
192 #define __FULLLINE 0x200 /* Line width = terminal width. */
196 /* Curses external declarations. */
197 extern WINDOW *curscr; /* Current screen. */
198 extern WINDOW *stdscr; /* Standard screen. */
200 typedef struct termios SGTTY;
202 extern SGTTY __orig_termios; /* Terminal state before curses */
203 extern SGTTY __baset; /* Our base terminal state */
204 extern int __tcaction; /* If terminal hardware set. */
205 extern int __tty_fileno; /* Terminal file descriptor */
207 extern int COLS; /* Columns on the screen. */
208 extern int LINES; /* Lines on the screen. */
210 extern char *ttytype; /* Full name of current terminal. */
212 #define ERR (0) /* Error return. */
213 #define OK (1) /* Success return. */
215 /* Standard screen pseudo functions. */
216 #define addbytes(s, n) __waddbytes(stdscr, s, n, 0)
217 #define addch(ch) waddch(stdscr, ch)
218 #define addnstr(s, n) waddnstr(stdscr, s, n)
219 #define addstr(s) __waddbytes(stdscr, s, strlen(s), 0)
220 #define clear() wclear(stdscr)
221 #define clrtobot() wclrtobot(stdscr)
222 #define clrtoeol() wclrtoeol(stdscr)
223 #define delch() wdelch(stdscr)
224 #define deleteln() wdeleteln(stdscr)
225 #define erase() werase(stdscr)
226 #define getch() wgetch(stdscr)
227 #define getstr(s) wgetstr(stdscr, s)
228 #define inch() winch(stdscr)
229 #define insch(ch) winsch(stdscr, ch)
230 #define insertln() winsertln(stdscr)
231 #define move(y, x) wmove(stdscr, y, x)
232 #define refresh() wrefresh(stdscr)
233 #define standend() wstandend(stdscr)
234 #define standout() wstandout(stdscr)
235 #define waddbytes(w, s, n) __waddbytes(w, s, n, 0)
236 #define waddstr(w, s) __waddbytes(w, s, strlen(s), 0)
238 /* Standard screen plus movement pseudo functions. */
239 #define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n)
240 #define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch)
241 #define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n)
242 #define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s)
243 #define mvdelch(y, x) mvwdelch(stdscr, y, x)
244 #define mvgetch(y, x) mvwgetch(stdscr, y, x)
245 #define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s)
246 #define mvinch(y, x) mvwinch(stdscr, y, x)
247 #define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c)
248 #define mvwaddbytes(w, y, x, s, n) \
249 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
250 #define mvwaddch(w, y, x, ch) \
251 (wmove(w, y, x) == ERR ? ERR : waddch(w, ch))
252 #define mvwaddnstr(w, y, x, s, n) \
253 (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n))
254 #define mvwaddstr(w, y, x, s) \
255 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0))
256 #define mvwdelch(w, y, x) \
257 (wmove(w, y, x) == ERR ? ERR : wdelch(w))
258 #define mvwgetch(w, y, x) \
259 (wmove(w, y, x) == ERR ? ERR : wgetch(w))
260 #define mvwgetstr(w, y, x, s) \
261 (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
262 #define mvwinch(w, y, x) \
263 (wmove(w, y, x) == ERR ? ERR : winch(w))
264 #define mvwinsch(w, y, x, c) \
265 (wmove(w, y, x) == ERR ? ERR : winsch(w, c))
267 /* Psuedo functions. */
268 #define clearok(w, bf) \
269 ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK))
270 #define flushok(w, bf) \
271 ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH))
272 #define getyx(w, y, x) \
273 (y) = (w)->cury, (x) = (w)->curx
274 #define leaveok(w, bf) \
275 ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK))
276 #define scrollok(w, bf) \
277 ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK))
279 ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0377)
281 /* Public function prototypes. */
282 int box __P((WINDOW *, int, int));
283 int cbreak __P((void));
284 int delwin __P((WINDOW *));
285 int echo __P((void));
286 int endwin __P((void));
287 char *fullname __P((char *, char *));
288 char *getcap __P((char *));
289 int gettmode __P((void));
290 void idlok __P((WINDOW *, int));
291 WINDOW *initscr __P((void));
292 char *longname __P((char *, char *));
293 int mvcur __P((int, int, int, int));
294 int mvprintw __P((int, int, const char *, ...));
295 int mvscanw __P((int, int, const char *, ...));
296 int mvwin __P((WINDOW *, int, int));
297 int mvwprintw __P((WINDOW *, int, int, const char *, ...));
298 int mvwscanw __P((WINDOW *, int, int, const char *, ...));
299 WINDOW *newwin __P((int, int, int, int));
301 int nocbreak __P((void));
302 int noecho __P((void));
303 int nonl __P((void));
304 int noraw __P((void));
305 int overlay __P((WINDOW *, WINDOW *));
306 int overwrite __P((WINDOW *, WINDOW *));
307 int printw __P((const char *, ...));
309 int resetty __P((void));
310 int savetty __P((void));
311 int scanw __P((const char *, ...));
312 int scroll __P((WINDOW *));
313 int setterm __P((char *));
314 int sscans __P((WINDOW *, const char *, ...));
315 WINDOW *subwin __P((WINDOW *, int, int, int, int));
316 int suspendwin __P((void));
317 int touchline __P((WINDOW *, int, int, int));
318 int touchoverlap __P((WINDOW *, WINDOW *));
319 int touchwin __P((WINDOW *));
320 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
321 int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_));
322 int waddch __P((WINDOW *, int));
323 int waddnstr __P((WINDOW *, const char *, int));
324 int wclear __P((WINDOW *));
325 int wclrtobot __P((WINDOW *));
326 int wclrtoeol __P((WINDOW *));
327 int wdelch __P((WINDOW *));
328 int wdeleteln __P((WINDOW *));
329 int werase __P((WINDOW *));
330 int wgetch __P((WINDOW *));
331 int wgetstr __P((WINDOW *, char *));
332 int winsch __P((WINDOW *, int));
333 int winsertln __P((WINDOW *));
334 int wmove __P((WINDOW *, int, int));
335 int wprintw __P((WINDOW *, const char *, ...));
336 int wrefresh __P((WINDOW *));
337 int wscanw __P((WINDOW *, const char *, ...));
338 int wstandend __P((WINDOW *));
339 int wstandout __P((WINDOW *));
340 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
342 /* Private functions that are needed for user programs prototypes. */
343 void __cputchar __P((int));
344 int _putchar __P((int));
345 int __waddbytes __P((WINDOW *, const char *, int, int));
347 /* Private functions. */
348 #ifdef _CURSES_PRIVATE
349 void __CTRACE __P((const char *, ...));
350 u_int __hash __P((char *, int));
351 void __id_subwins __P((WINDOW *));
352 int __mvcur __P((int, int, int, int, int));
353 void __restore_stophandler __P((void));
354 void __set_stophandler __P((void));
355 void __set_subwin __P((WINDOW *, WINDOW *));
356 void __set_scroll_region __P((int, int, int, int));
357 void __startwin __P((void));
358 void __stop_signal_handler __P((int));
359 void __swflags __P((WINDOW *));
360 int __touchline __P((WINDOW *, int, int, int, int));
361 int __touchwin __P((WINDOW *));
362 char *__tscroll __P((const char *, int, int));
363 int __waddch __P((WINDOW *, __LDATA *));
365 /* Private #defines. */
366 #define min(a,b) (a < b ? a : b)
367 #define max(a,b) (a > b ? a : b)
369 /* Private externs. */
374 extern int __rawmode;
378 int tputs __P((const char *, int, void (*)(int)));
382 int tputs __P((const char *, int, int (*)(int)));
386 /* Termcap functions. */
387 int tgetent __P((char *, const char *));
388 int tgetnum __P((const char *));
389 int tgetflag __P((const char *));
390 char *tgetstr __P((const char *, char **));
391 char *tgoto __P((const char *, int, int));
393 #endif /* !_CURSES_H_ */