|
|
1.1 root 1: /*
2: * Copyright (c) 1981 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: *
17: * @(#)curses.h 5.4 (Berkeley) 6/30/88
18: */
19:
20: # ifndef WINDOW
21:
22: # include <stdio.h>
23: # include <sgtty.h>
24: # include <unctrl.h>
25:
26: # define uchar unsigned char
27: # define bool char
28: # define reg register
29:
30: # define TRUE (1)
31: # define FALSE (0)
32: # define ERR (0)
33: # define OK (1)
34:
35: # define _ENDLINE 001
36: # define _FULLWIN 002
37: # define _SCROLLWIN 004
38: # define _FLUSH 010
39: # define _FULLLINE 020
40: # define _IDLINE 040
41: # define _STANDOUT 0200
42: # define _NOCHANGE -1
43:
44: /*
45: * The COHERENT Tputs(s,n,f) macro attempts to ensure string output will be
46: * atomic by flushing the stdio output buffer in _need(s) if required. This
47: * should prevent the splitting of escape sequences by other terminal output,
48: * provided that the terminal drive guarantees atomicity of writes.
49: */
50: #ifdef COHERENT
51: # define Tputs(s,n,f) (_need(s), tputs(s, n, f))
52: #else
53: # define Tputs(s,n,f) tputs(s, n, f)
54: #endif
55:
56: # define _puts(s) Tputs(s, 0, _putchar)
57:
58: typedef struct sgttyb SGTTY;
59: typedef short chtype; /* Character + Attributes */
60:
61: /*
62: * Capabilities from termcap remapped by INETCO into System V capabilities.
63: */
64:
65: #define CS change_scroll_region
66: #define VE cursor_normal
67: #define VS cursor_visible
68: #define SO enter_standout_mode
69: #define SE exit_standout_mode
70: #define US enter_underline_mode
71: #define VB flash_screen
72: #define K0 key_f0
73: #define K1 key_f1
74: #define K2 key_f2
75: #define K3 key_f3
76: #define K4 key_f4
77: #define K5 key_f5
78: #define K6 key_f6
79: #define K7 key_f7
80: #define K8 key_f8
81: #define K9 key_f9
82: #define KD key_down
83: #define KH key_home
84: #define KL key_left
85: #define KR key_right
86: #define KU key_up
87:
88: /*
89: * Capabilities from termcap
90: */
91:
92: extern bool AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL,
93: XB, XN, XT, XS, XX;
94:
95: extern uchar *AL,
96: *BC, *BT,
97: *CD, *CE, *CL, *CM, *CR, *CS,
98: *DC, *DL, *DM, *DO,
99: *ED, *EI,
100: *HO,
101: *IC, *IM, *IP,
102: *KE, *KS,
103: *LL,
104: *MA,
105: *ND, *NL,
106: *RC,
107: *SC, *SE, *SF, *SO, *SR,
108: *TA, *TE, *TI,
109: *UC, *UE, *UP,
110: *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM,
111: *LEFT_PARM, *RIGHT_PARM;
112: extern uchar PC;
113:
114:
115: /*
116: * System V Capabilities added by INETCO to termcap.
117: */
118: extern bool prtr_silent, xon_xoff;
119:
120: extern uchar *bell,
121: *cursor_invisible, *cursor_normal, *cursor_visible,
122: *enter_am_mode, *enter_blink_mode, *enter_bold_mode,
123: *enter_delete_mode, *enter_dim_mode, *enter_protected_mode,
124: *enter_reverse_mode, *enter_secure_mode,
125: *enter_standout_mode, *enter_underline_mode,
126: *exit_am_mode, *exit_attribute_mode,
127: *flash_screen,
128: *init_1string, *init_2string, *init_3string,
129: *key_a1, *key_a3,
130: *key_b2, *key_backspace, *key_beg, *key_btab,
131: *key_c1, *key_c3, *key_cancel, *key_catab, *key_clear,
132: *key_close, *key_command, *key_copy, *key_create, *key_ctab,
133: *key_dc, *key_dl, *key_down,
134: *key_eic, *key_end, *key_enter, *key_eol, *key_eos, *key_exit,
135: *key_f0, *key_f1, *key_f2, *key_f3, *key_f4,
136: *key_f5, *key_f6, *key_f7, *key_f8, *key_f9,
137: *key_f10, *key_f11, *key_f12, *key_f13, *key_f14,
138: *key_f15, *key_f16, *key_f17, *key_f18, *key_f19,
139: *key_f20, *key_f21, *key_f22, *key_f23, *key_f24,
140: *key_f25, *key_f26, *key_f27, *key_f28, *key_f29,
141: *key_f30, *key_f31, *key_f32, *key_f33, *key_f34,
142: *key_f35, *key_f36, *key_f37, *key_f38, *key_f39,
143: *key_f40, *key_f41, *key_f42, *key_f43, *key_f44,
144: *key_f45, *key_f46, *key_f47, *key_f48, *key_f49,
145: *key_f50, *key_f51, *key_f52, *key_f53, *key_f54,
146: *key_f55, *key_f56, *key_f57, *key_f58, *key_f59,
147: *key_f60, *key_f61, *key_f62, *key_f63,
148: *key_find,
149: *key_help, *key_home,
150: *key_ic, *key_il,
151: *key_left, *key_ll,
152: *key_mark, *key_message, *key_move,
153: *key_next, *key_npage,
154: *key_open, *key_options,
155: *key_ppage, *key_previous, *key_print,
156: *key_redo, *key_reference, *key_refresh, *key_replace,
157: *key_restart, *key_resume, *key_right,
158: *key_save, *key_sbeg, *key_scancel, *key_scommand, *key_scopy,
159: *key_screate, *key_sdc, *key_sdl, *key_select, *key_send,
160: *key_seol, *key_sexit, *key_sf, *key_sfind, *key_shelp,
161: *key_shome, *key_sic, *key_sleft, *key_smessage, *key_smove,
162: *key_snext, *key_soptions, *key_sprevious, *key_sprint,
163: *key_sr, *key_sredo, *key_sreplace, *key_sright, *key_srsume,
164: *key_ssave, *key_ssuspend, *key_stab, *key_sundo, *key_suspend,
165: *key_undo, *key_up,
166: *prtr_off, *prtr_on,
167: *reset_1string, *reset_2string, *reset_3string,
168: *xoff_character, *xon_character;
169:
170: /*
171: * From the tty modes...
172: */
173:
174: extern bool GT, NONL, UPPERCASE, normtty, _pfast;
175:
176: struct _win_st {
177: short _cury, _curx;
178: short _maxy, _maxx;
179: short _begy, _begx;
180: short _flags;
181: short _attrs;
182: short _ch_off;
183: bool _clear;
184: bool _leave;
185: bool _scroll;
186: bool _use_keypad; /* 0=no, 1=yes, 2=yes/timeout */
187: bool _nodelay; /* T=don't wait for tty input */
188: uchar **_y;
189: short *_firstch;
190: short *_lastch;
191: struct _win_st *_nextp, *_orig;
192: };
193:
194: # define WINDOW struct _win_st
195:
196: /*
197: * Translation table entry: Termcap field name into address of a boolean var.
198: */
199: typedef struct tflgent_s {
200: uchar id[2]; /* termcap code */
201: bool *bp; /* pointer to boolean var */
202: } tflgent_t;
203:
204: /*
205: * Translation table entry: keyboard token into address of a string variable.
206: */
207: typedef struct tkeyent_s {
208: short id; /* key code */
209: uchar **cpp; /* pointer to var which in turn points to string */
210: } tkeyent_t;
211:
212: /*
213: * Translation table entry: Termcap field name into address of a string var.
214: */
215: typedef struct tstrent_s {
216: uchar id[2]; /* termcap code */
217: uchar **cpp; /* pointer to var which in turn points to string */
218: } tstrent_t;
219:
220: /*
221: * Types added by INETCO for System V compatibility.
222: */
223: #define SCREEN uchar
224:
225: /*
226: * Default Translation Tables.
227: * End of table is signified by an id byte of 0.
228: */
229: extern tflgent_t tflgtab[]; /* Default boolean translation table */
230: extern tkeyent_t tkeytab[]; /* Default keyboard translation table */
231: extern tstrent_t tstrtab[]; /* Default string translation table */
232: extern tflgent_t * tflgmap; /* Current boolean translation table */
233: extern tkeyent_t * tkeymap; /* Current keyboard translation table */
234: extern tstrent_t * tstrmap; /* Current string translation table */
235:
236: extern bool My_term, _echoit, _rawmode, _endwin;
237:
238: extern uchar *Def_term, ttytype[];
239:
240: extern int LINES, COLS, _tty_ch, _res_flg;
241: extern int magic_cookie_glitch;
242:
243: extern SGTTY _tty;
244:
245: extern WINDOW *stdscr, *curscr;
246:
247: /*
248: * Define VOID to stop lint from generating "null effect"
249: * comments.
250: */
251: # ifdef lint
252: int __void__;
253: # define VOID(x) (__void__ = (int) (x))
254: # else
255: # define VOID(x) (x)
256: # endif
257:
258: /*
259: * psuedo functions for standard screen
260: */
261: # define addch(ch) VOID(waddch(stdscr, ch))
262: # define getch() VOID(wgetch(stdscr))
263: # define addbytes(da,co) VOID(waddbytes(stdscr, da,co))
264: # define addstr(str) VOID(waddbytes(stdscr, str, strlen(str)))
265: # define getstr(str) VOID(wgetstr(stdscr, str))
266: # define move(y, x) VOID(wmove(stdscr, y, x))
267: # define clear() VOID(wclear(stdscr))
268: # define erase() VOID(werase(stdscr))
269: # define clrtobot() VOID(wclrtobot(stdscr))
270: # define clrtoeol() VOID(wclrtoeol(stdscr))
271: # define insertln() VOID(winsertln(stdscr))
272: # define deleteln() VOID(wdeleteln(stdscr))
273: # define refresh() VOID(wrefresh(stdscr))
274: # define inch() VOID(winch(stdscr))
275: # define insch(c) VOID(winsch(stdscr,c))
276: # define delch() VOID(wdelch(stdscr))
277: # define standout() VOID(wstandout(stdscr))
278: # define standend() VOID(wstandend(stdscr))
279: # define attron(at) wattron(stdscr,at)
280: # define attroff(at) wattroff(stdscr,at)
281: # define attrset(at) wattrset(stdscr,at)
282:
283: /*
284: * mv functions
285: */
286: #define mvwaddch(win,y,x,ch) VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
287: #define mvwgetch(win,y,x) VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
288: #define mvwaddbytes(win,y,x,da,co) \
289: VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
290: #define mvwaddstr(win,y,x,str) \
291: VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,str,strlen(str)))
292: #define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
293: #define mvwinch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
294: #define mvwdelch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
295: #define mvwinsch(win,y,x,c) VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c))
296: #define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch)
297: #define mvgetch(y,x) mvwgetch(stdscr,y,x)
298: #define mvaddbytes(y,x,da,co) mvwaddbytes(stdscr,y,x,da,co)
299: #define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str)
300: #define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str)
301: #define mvinch(y,x) mvwinch(stdscr,y,x)
302: #define mvdelch(y,x) mvwdelch(stdscr,y,x)
303: #define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c)
304:
305: /*
306: * psuedo functions
307: */
308:
309: #define clearok(win,bf) (win->_clear = bf)
310: #define keypad(win,bf) (win->_use_keypad = bf)
311: #define leaveok(win,bf) (win->_leave = bf)
312: #define nodelay(win,bf) (win->_nodelay = bf)
313: #define scrollok(win,bf) (win->_scroll = bf)
314: #define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
315: #define getyx(win,y,x) y = win->_cury, x = win->_curx
316: #define winch(win) (win->_y[win->_cury][win->_curx] & 0177)
317:
318: #define raw() (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, stty(_tty_ch,&_tty))
319: #define noraw() (_tty.sg_flags&=~RAW,_rawmode=FALSE,_pfast=!(_tty.sg_flags&CRMOD),stty(_tty_ch,&_tty))
320: #define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, stty(_tty_ch,&_tty))
321: #define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE,stty(_tty_ch,&_tty))
322: #define crmode() cbreak() /* backwards compatability */
323: #define nocrmode() nocbreak() /* backwards compatability */
324: #define echo() (_tty.sg_flags |= ECHO, _echoit = TRUE, stty(_tty_ch, &_tty))
325: #define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, stty(_tty_ch, &_tty))
326: #define nl() (_tty.sg_flags |= CRMOD,_pfast = _rawmode,stty(_tty_ch, &_tty))
327: #define nonl() (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, stty(_tty_ch, &_tty))
328: #define savetty() ((void) gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
329: #define resetty() (_tty.sg_flags = _res_flg, (void) stty(_tty_ch, &_tty))
330:
331: #define erasechar() (_tty.sg_erase)
332: #define killchar() (_tty.sg_kill)
333: #define baudrate() (_tty.sg_ospeed)
334:
335: WINDOW *initscr(), *newwin(), *subwin();
336: uchar *longname(), *getcap();
337:
338: /*
339: * Various video attributes - A_STANDOUT is only sure bet.
340: */
341: #define A_STANDOUT 0000200
342: #define A_UNDERLINE 0000400
343: #define A_REVERSE 0001000
344: #define A_BLINK 0002000
345: #define A_DIM 0004000
346: #define A_BOLD 0010000
347:
348: #define A_NORMAL 0000000
349: #define A_ATTRIBUTES 0177600 /* Mask to extract video attributes */
350: #define A_CHARTEXT 0000177 /* Mask to extract character value */
351:
352: /*
353: * Funny "characters" enabled for various special function keys for input
354: */
355: #define KEY_BREAK 0401 /* break key (unreliable) */
356: #define KEY_DOWN 0402 /* The four arrow keys ... */
357: #define KEY_UP 0403
358: #define KEY_LEFT 0404
359: #define KEY_RIGHT 0405 /* ... */
360: #define KEY_HOME 0406 /* Home key (upward+left arrow) */
361: #define KEY_BACKSPACE 0407 /* backspace (unreliable) */
362: #define KEY_F0 0410 /* Function keys. Space for 64 */
363: #define KEY_F(n) (KEY_F0+(n)) /* keys is reserved. */
364: #define KEY_DL 0510 /* Delete line */
365: #define KEY_IL 0511 /* Insert line */
366: #define KEY_DC 0512 /* Delete character */
367: #define KEY_IC 0513 /* Insert char or enter insert mode */
368: #define KEY_EIC 0514 /* Exit insert char mode */
369: #define KEY_CLEAR 0515 /* Clear screen */
370: #define KEY_EOS 0516 /* Clear to end of screen */
371: #define KEY_EOL 0517 /* Clear to end of line */
372: #define KEY_SF 0520 /* Scroll 1 line forward */
373: #define KEY_SR 0521 /* Scroll 1 line backwards (reverse) */
374: #define KEY_NPAGE 0522 /* Next page */
375: #define KEY_PPAGE 0523 /* Previous page */
376: #define KEY_STAB 0524 /* Set tab */
377: #define KEY_CTAB 0525 /* Clear tab */
378: #define KEY_CATAB 0526 /* Clear all tabs */
379: #define KEY_ENTER 0527 /* Enter or send (unreliable) */
380: #define KEY_SRESET 0530 /* soft (partial) reset (unreliable) */
381: #define KEY_RESET 0531 /* reset or hard reset (unreliable) */
382: #define KEY_PRINT 0532 /* print or copy */
383: #define KEY_LL 0533 /* home down or bottom (lower left) */
384: /* The keypad is arranged like this: */
385: /* a1 up a3 */
386: /* left b2 right */
387: /* c1 down c3 */
388: #define KEY_A1 0534 /* upper left of keypad */
389: #define KEY_A3 0535 /* upper right of keypad */
390: #define KEY_B2 0536 /* center of keypad */
391: #define KEY_C1 0537 /* lower left of keypad */
392: #define KEY_C3 0540 /* lower right of keypad */
393: #define KEY_BTAB 0541 /* back tab key */
394: #define KEY_BEG 0542 /* beg(inning) key */
395: #define KEY_CANCEL 0543 /* cancel key */
396: #define KEY_CLOSE 0544 /* close key */
397: #define KEY_COMMAND 0545 /* cmd (command) key */
398: #define KEY_COPY 0546 /* copy key */
399: #define KEY_CREATE 0547 /* create key */
400: #define KEY_END 0550 /* end key */
401: #define KEY_EXIT 0551 /* exit key */
402: #define KEY_FIND 0552 /* find key */
403: #define KEY_HELP 0553 /* help key */
404: #define KEY_MARK 0554 /* mark key */
405: #define KEY_MESSAGE 0555 /* message key */
406: #define KEY_MOVE 0556 /* move key */
407: #define KEY_NEXT 0557 /* next object key */
408: #define KEY_OPEN 0560 /* open key */
409: #define KEY_OPTIONS 0561 /* options key */
410: #define KEY_PREVIOUS 0562 /* previous object key */
411: #define KEY_REDO 0563 /* redo key */
412: #define KEY_REFERENCE 0564 /* ref(erence) key */
413: #define KEY_REFRESH 0565 /* refresh key */
414: #define KEY_REPLACE 0566 /* replace key */
415: #define KEY_RESTART 0567 /* restart key */
416: #define KEY_RESUME 0570 /* resume key */
417: #define KEY_SAVE 0571 /* save key */
418: #define KEY_SBEG 0572 /* shifted beginning key */
419: #define KEY_SCANCEL 0573 /* shifted cancel key */
420: #define KEY_SCOMMAND 0574 /* shifted command key */
421: #define KEY_SCOPY 0575 /* shifted copy key */
422: #define KEY_SCREATE 0576 /* shifted create key */
423: #define KEY_SDC 0577 /* shifted delete char key */
424: #define KEY_SDL 0600 /* shifted delete line key */
425: #define KEY_SELECT 0601 /* select key */
426: #define KEY_SEND 0602 /* shifted end key */
427: #define KEY_SEOL 0603 /* shifted clear line key */
428: #define KEY_SEXIT 0604 /* shifted exit key */
429: #define KEY_SFIND 0605 /* shifted find key */
430: #define KEY_SHELP 0606 /* shifted help key */
431: #define KEY_SHOME 0607 /* shifted home key */
432: #define KEY_SIC 0610 /* shifted input key */
433: #define KEY_SLEFT 0611 /* shifted left arrow key */
434: #define KEY_SMESSAGE 0612 /* shifted message key */
435: #define KEY_SMOVE 0613 /* shifted move key */
436: #define KEY_SNEXT 0614 /* shifted next key */
437: #define KEY_SOPTIONS 0615 /* shifted options key */
438: #define KEY_SPREVIOUS 0616 /* shifted prev key */
439: #define KEY_SPRINT 0617 /* shifted print key */
440: #define KEY_SREDO 0620 /* shifted redo key */
441: #define KEY_SREPLACE 0621 /* shifted replace key */
442: #define KEY_SRIGHT 0622 /* shifted right-arrow key */
443: #define KEY_SRSUME 0623 /* shifted resume key */
444: #define KEY_SSAVE 0624 /* shifted save key */
445: #define KEY_SSUSPEND 0625 /* shifted suspend key */
446: #define KEY_SUNDO 0626 /* shifted undo key */
447: #define KEY_SUSPEND 0627 /* suspend key */
448: #define KEY_UNDO 0630 /* undo key */
449:
450: # endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.