xref: /freebsd/contrib/ee/new_curse.h (revision 10b3b54548f2290bbe8d8f88c59c28d12b7a635d)
172fcea8cSEd Schouten /*
272fcea8cSEd Schouten  |	new_curse.h
372fcea8cSEd Schouten  |
472fcea8cSEd Schouten  |	A subset of curses developed for use with ae.
572fcea8cSEd Schouten  |
672fcea8cSEd Schouten  |	written by Hugh Mahon
772fcea8cSEd Schouten  |
872fcea8cSEd Schouten  |	THIS MATERIAL IS PROVIDED "AS IS".  THERE ARE
972fcea8cSEd Schouten  |	NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
1072fcea8cSEd Schouten  |	MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
1172fcea8cSEd Schouten  |	IMPLIED WARRANTIES OF MERCHANTABILITY AND
1272fcea8cSEd Schouten  |	FITNESS FOR A PARTICULAR PURPOSE.  Neither
1372fcea8cSEd Schouten  |	Hewlett-Packard nor Hugh Mahon shall be liable
1472fcea8cSEd Schouten  |	for errors contained herein, nor for
1572fcea8cSEd Schouten  |	incidental or consequential damages in
1672fcea8cSEd Schouten  |	connection with the furnishing, performance or
1772fcea8cSEd Schouten  |	use of this material.  Neither Hewlett-Packard
1872fcea8cSEd Schouten  |	nor Hugh Mahon assumes any responsibility for
1972fcea8cSEd Schouten  |	the use or reliability of this software or
2072fcea8cSEd Schouten  |	documentation.  This software and
2172fcea8cSEd Schouten  |	documentation is totally UNSUPPORTED.  There
2272fcea8cSEd Schouten  |	is no support contract available.  Hewlett-
2372fcea8cSEd Schouten  |	Packard has done NO Quality Assurance on ANY
2472fcea8cSEd Schouten  |	of the program or documentation.  You may find
2572fcea8cSEd Schouten  |	the quality of the materials inferior to
2672fcea8cSEd Schouten  |	supported materials.
2772fcea8cSEd Schouten  |
2872fcea8cSEd Schouten  |	This software is not a product of Hewlett-Packard, Co., or any
2972fcea8cSEd Schouten  |	other company.  No support is implied or offered with this software.
3072fcea8cSEd Schouten  |	You've got the source, and you're on your own.
3172fcea8cSEd Schouten  |
3272fcea8cSEd Schouten  |	This software may be distributed under the terms of Larry Wall's
3372fcea8cSEd Schouten  |	Artistic license, a copy of which is included in this distribution.
3472fcea8cSEd Schouten  |
3572fcea8cSEd Schouten  |	This notice must be included with this software and any derivatives.
3672fcea8cSEd Schouten  |
3772fcea8cSEd Schouten  |	Copyright (c) 1986, 1987, 1988, 1991, 1995 Hugh Mahon
3872fcea8cSEd Schouten  |	All are rights reserved.
3972fcea8cSEd Schouten  |
4072fcea8cSEd Schouten  */
4172fcea8cSEd Schouten 
4272fcea8cSEd Schouten #include <stdio.h>
4372fcea8cSEd Schouten 
4472fcea8cSEd Schouten #ifdef SYS5
4572fcea8cSEd Schouten #include <termio.h>
4672fcea8cSEd Schouten #else
4772fcea8cSEd Schouten #include <sgtty.h>
4872fcea8cSEd Schouten #include <fcntl.h>
4972fcea8cSEd Schouten #endif
5072fcea8cSEd Schouten 
5172fcea8cSEd Schouten #define KEY_BREAK	0401
5272fcea8cSEd Schouten #define KEY_DOWN	0402
5372fcea8cSEd Schouten #define KEY_UP		0403
5472fcea8cSEd Schouten #define KEY_LEFT	0404
5572fcea8cSEd Schouten #define KEY_RIGHT	0405
5672fcea8cSEd Schouten #define KEY_HOME	0406
5772fcea8cSEd Schouten #define KEY_BACKSPACE	0407
5872fcea8cSEd Schouten #define KEY_F0		0410
5972fcea8cSEd Schouten #define KEY_F(n) 	(KEY_F0+(n))
6072fcea8cSEd Schouten #define KEY_DL		0510
6172fcea8cSEd Schouten #define KEY_IL		0511
6272fcea8cSEd Schouten #define KEY_DC		0512
6372fcea8cSEd Schouten #define KEY_IC		0513
6472fcea8cSEd Schouten #define KEY_EIC		0514
6572fcea8cSEd Schouten #define KEY_CLEAR	0515
6672fcea8cSEd Schouten #define KEY_EOS		0516
6772fcea8cSEd Schouten #define KEY_EOL		0517
6872fcea8cSEd Schouten #define KEY_SF		0520
6972fcea8cSEd Schouten #define KEY_SR		0521
7072fcea8cSEd Schouten #define KEY_NPAGE	0522
7172fcea8cSEd Schouten #define KEY_PPAGE	0523
7272fcea8cSEd Schouten #define KEY_STAB	0524
7372fcea8cSEd Schouten #define KEY_CTAB	0525
7472fcea8cSEd Schouten #define KEY_CATAB	0526
7572fcea8cSEd Schouten #define KEY_ENTER	0527
7672fcea8cSEd Schouten #define KEY_SRESET	0530
7772fcea8cSEd Schouten #define KEY_RESET	0531
7872fcea8cSEd Schouten #define KEY_PRINT	0532
7972fcea8cSEd Schouten #define KEY_LL		0533
8072fcea8cSEd Schouten #define KEY_A1	0534
8172fcea8cSEd Schouten #define KEY_A3	0535
8272fcea8cSEd Schouten #define KEY_B2	0536
8372fcea8cSEd Schouten #define KEY_C1	0537
8472fcea8cSEd Schouten #define KEY_C3	0540
8572fcea8cSEd Schouten #define KEY_BTAB	0541
8672fcea8cSEd Schouten #define KEY_BEG	0542
8772fcea8cSEd Schouten #define KEY_CANCEL	0543
8872fcea8cSEd Schouten #define KEY_CLOSE	0544
8972fcea8cSEd Schouten #define KEY_COMMAND	0545
9072fcea8cSEd Schouten #define KEY_COPY	0546
9172fcea8cSEd Schouten #define KEY_CREATE	0547
9272fcea8cSEd Schouten #define KEY_END	0550
9372fcea8cSEd Schouten #define KEY_EXIT	0551
9472fcea8cSEd Schouten #define KEY_FIND	0552
9572fcea8cSEd Schouten #define KEY_HELP	0553
9672fcea8cSEd Schouten #define KEY_MARK	0554
9772fcea8cSEd Schouten #define KEY_MESSAGE	0555
9872fcea8cSEd Schouten #define KEY_MOVE	0556
9972fcea8cSEd Schouten #define KEY_NEXT	0557
10072fcea8cSEd Schouten #define KEY_OPEN	0560
10172fcea8cSEd Schouten #define KEY_OPTIONS	0561
10272fcea8cSEd Schouten #define KEY_PREVIOUS	0562
10372fcea8cSEd Schouten #define KEY_REDO	0563
10472fcea8cSEd Schouten #define KEY_REFERENCE	0564
10572fcea8cSEd Schouten #define KEY_REFRESH	0565
10672fcea8cSEd Schouten #define KEY_REPLACE	0566
10772fcea8cSEd Schouten #define KEY_RESTART	0567
10872fcea8cSEd Schouten #define KEY_RESUME	0570
10972fcea8cSEd Schouten #define KEY_SAVE	0571
11072fcea8cSEd Schouten #define KEY_SBEG	0572
11172fcea8cSEd Schouten #define KEY_SCANCEL	0573
11272fcea8cSEd Schouten #define KEY_SCOMMAND	0574
11372fcea8cSEd Schouten #define KEY_SCOPY	0575
11472fcea8cSEd Schouten #define KEY_SCREATE	0576
11572fcea8cSEd Schouten #define KEY_SDC	0577
11672fcea8cSEd Schouten #define KEY_SDL	0600
11772fcea8cSEd Schouten #define KEY_SELECT	0601
11872fcea8cSEd Schouten #define KEY_SEND	0602
11972fcea8cSEd Schouten #define KEY_SEOL	0603
12072fcea8cSEd Schouten #define KEY_SEXIT	0604
12172fcea8cSEd Schouten #define KEY_SFIND	0605
12272fcea8cSEd Schouten #define KEY_SHELP	0606
12372fcea8cSEd Schouten #define KEY_SHOME	0607
12472fcea8cSEd Schouten #define KEY_SIC	0610
12572fcea8cSEd Schouten #define KEY_SLEFT	0611
12672fcea8cSEd Schouten #define KEY_SMESSAGE	0612
12772fcea8cSEd Schouten #define KEY_SMOVE	0613
12872fcea8cSEd Schouten #define KEY_SNEXT	0614
12972fcea8cSEd Schouten #define KEY_SOPTIONS	0615
13072fcea8cSEd Schouten #define KEY_SPREVIOUS	0616
13172fcea8cSEd Schouten #define KEY_SPRINT	0617
13272fcea8cSEd Schouten #define KEY_SREDO	0620
13372fcea8cSEd Schouten #define KEY_SREPLACE	0621
13472fcea8cSEd Schouten #define KEY_SRIGHT	0622
13572fcea8cSEd Schouten #define KEY_SRSUME	0623
13672fcea8cSEd Schouten #define KEY_SSAVE	0624
13772fcea8cSEd Schouten #define KEY_SSUSPEND	0625
13872fcea8cSEd Schouten #define KEY_SUNDO	0626
13972fcea8cSEd Schouten #define KEY_SUSPEND	0627
14072fcea8cSEd Schouten #define KEY_UNDO	0630
14172fcea8cSEd Schouten 
14272fcea8cSEd Schouten #define TRUE 1
14372fcea8cSEd Schouten #define FALSE 0
14472fcea8cSEd Schouten 
14572fcea8cSEd Schouten #define A_STANDOUT 0001		/* standout mode		*/
14672fcea8cSEd Schouten #define A_NC_BIG5  0x0100	/* Handle Chinese Big5 characters	*/
14772fcea8cSEd Schouten #define SCROLL 1		/* text has been scrolled	*/
14872fcea8cSEd Schouten #define CLEAR  2		/* window has been cleared	*/
14972fcea8cSEd Schouten #define CHANGE 3		/* window has been changed	*/
15072fcea8cSEd Schouten #define UP 1			/* direction of scroll		*/
15172fcea8cSEd Schouten #define DOWN 2
15272fcea8cSEd Schouten 
15372fcea8cSEd Schouten struct _line {
15472fcea8cSEd Schouten 	struct _line *next_screen;
15572fcea8cSEd Schouten 	struct _line *prev_screen;
15672fcea8cSEd Schouten 	char *row;
15772fcea8cSEd Schouten 	char *attributes;
15872fcea8cSEd Schouten 	int last_char;
15972fcea8cSEd Schouten 	int changed;
16072fcea8cSEd Schouten 	int scroll;
16172fcea8cSEd Schouten 	int number;
16272fcea8cSEd Schouten 	};
16372fcea8cSEd Schouten 
16472fcea8cSEd Schouten struct _line *top_of_win;
16572fcea8cSEd Schouten 
16672fcea8cSEd Schouten typedef struct WIND {
16772fcea8cSEd Schouten 	int SR;		/* starting row		*/
16872fcea8cSEd Schouten 	int SC;		/* starting column	*/
16972fcea8cSEd Schouten 	int LC;		/* last column		*/
17072fcea8cSEd Schouten 	int LX;		/* last cursor column position	*/
17172fcea8cSEd Schouten 	int LY;		/* last cursor row position	*/
17272fcea8cSEd Schouten 	int Attrib;	/* attributes active in window	*/
17372fcea8cSEd Schouten 	int Num_lines;	/* number of lines		*/
17472fcea8cSEd Schouten 	int Num_cols;	/* number of columns		*/
17572fcea8cSEd Schouten 	int scroll_up;	/* number of lines moved	*/
17672fcea8cSEd Schouten 	int scroll_down;
17772fcea8cSEd Schouten 	int SCROLL_CLEAR;	/* indicates that window has been scrolled or cleared	*/
17872fcea8cSEd Schouten 	struct _line *first_line;
17972fcea8cSEd Schouten 	struct _line **line_array;
18072fcea8cSEd Schouten 	} WINDOW;
18172fcea8cSEd Schouten 
18272fcea8cSEd Schouten extern WINDOW *curscr;
18372fcea8cSEd Schouten extern WINDOW *stdscr;
18472fcea8cSEd Schouten 
18572fcea8cSEd Schouten extern int LINES, COLS;
18672fcea8cSEd Schouten 
18772fcea8cSEd Schouten #if defined(__STDC__) || defined(__cplusplus)
18872fcea8cSEd Schouten #define P_(s) s
18972fcea8cSEd Schouten #else
19072fcea8cSEd Schouten #define P_(s) ()
19172fcea8cSEd Schouten #endif
19272fcea8cSEd Schouten 
19372fcea8cSEd Schouten extern void copy_window P_((WINDOW *origin, WINDOW *destination));
19472fcea8cSEd Schouten extern void reinitscr P_((int));
19572fcea8cSEd Schouten extern void initscr P_((void));
19672fcea8cSEd Schouten extern int Get_int P_((void));
19772fcea8cSEd Schouten extern int INFO_PARSE P_((void));
19872fcea8cSEd Schouten extern int AtoI P_((void));
19972fcea8cSEd Schouten extern void Key_Get P_((void));
20072fcea8cSEd Schouten extern void keys_vt100 P_((void));
20172fcea8cSEd Schouten extern struct _line *Screenalloc P_((int columns));
20272fcea8cSEd Schouten extern WINDOW *newwin P_((int lines, int cols, int start_l, int start_c));
20372fcea8cSEd Schouten extern int Operation P_((int Temp_Stack[], int place));
20472fcea8cSEd Schouten extern void Info_Out P_((char *string, int p_list[], int place));
20572fcea8cSEd Schouten extern void wmove P_((WINDOW *window, int row, int column));
20672fcea8cSEd Schouten extern void clear_line P_((struct _line *line, int column, int cols));
20772fcea8cSEd Schouten extern void werase P_((WINDOW *window));
20872fcea8cSEd Schouten extern void wclrtoeol P_((WINDOW *window));
20972fcea8cSEd Schouten extern void wrefresh P_((WINDOW *window));
21072fcea8cSEd Schouten extern void touchwin P_((WINDOW *window));
21172fcea8cSEd Schouten extern void wnoutrefresh P_((WINDOW *window));
21272fcea8cSEd Schouten extern void flushinp P_((void));
21372fcea8cSEd Schouten extern void ungetch P_((int c));
21472fcea8cSEd Schouten extern int wgetch P_((WINDOW *window));
21572fcea8cSEd Schouten extern void Clear P_((int));
21672fcea8cSEd Schouten extern int Get_key P_((int first_char));
21772fcea8cSEd Schouten extern void waddch P_((WINDOW *window, int c));
21872fcea8cSEd Schouten extern void winsertln P_((WINDOW *window));
21972fcea8cSEd Schouten extern void wdeleteln P_((WINDOW *window));
22072fcea8cSEd Schouten extern void wclrtobot P_((WINDOW *window));
22172fcea8cSEd Schouten extern void wstandout P_((WINDOW *window));
22272fcea8cSEd Schouten extern void wstandend P_((WINDOW *window));
22372fcea8cSEd Schouten extern void waddstr P_((WINDOW *window, char *string));
22472fcea8cSEd Schouten extern void clearok P_((WINDOW *window, int flag));
22572fcea8cSEd Schouten extern void echo P_((void));
22672fcea8cSEd Schouten extern void noecho P_((void));
22772fcea8cSEd Schouten extern void raw P_((void));
22872fcea8cSEd Schouten extern void noraw P_((void));
22972fcea8cSEd Schouten extern void nl P_((void));
23072fcea8cSEd Schouten extern void nonl P_((void));
23172fcea8cSEd Schouten extern void saveterm P_((void));
23272fcea8cSEd Schouten extern void fixterm P_((void));
23372fcea8cSEd Schouten extern void resetterm P_((void));
23472fcea8cSEd Schouten extern void nodelay P_((WINDOW *window, int flag));
23572fcea8cSEd Schouten extern void idlok P_((WINDOW *window, int flag));
23672fcea8cSEd Schouten extern void keypad P_((WINDOW *window, int flag));
23772fcea8cSEd Schouten extern void savetty P_((void));
23872fcea8cSEd Schouten extern void resetty P_((void));
23972fcea8cSEd Schouten extern void endwin P_((void));
24072fcea8cSEd Schouten extern void delwin P_((WINDOW *window));
24172fcea8cSEd Schouten extern void wprintw P_((WINDOW *window, const char* format, ...));
24272fcea8cSEd Schouten extern void iout P_((WINDOW *window, int value));
24372fcea8cSEd Schouten extern int Comp_line P_((struct _line *line1, struct _line *line2));
24472fcea8cSEd Schouten extern struct _line *Insert_line P_((int row, int end_row, WINDOW *window));
24572fcea8cSEd Schouten extern struct _line *Delete_line P_((int row, int end_row, WINDOW *window));
24672fcea8cSEd Schouten extern void CLEAR_TO_EOL P_((WINDOW *window, int row, int column));
24772fcea8cSEd Schouten extern int check_delete P_((WINDOW *window, int line, int offset, struct _line *pointer_new, struct _line *pointer_old));
24872fcea8cSEd Schouten extern int check_insert P_((WINDOW *window, int line, int offset, struct _line *pointer_new, struct _line *pointer_old));
24972fcea8cSEd Schouten extern void doupdate P_((void));
25072fcea8cSEd Schouten extern void Position P_((WINDOW *window, int row, int col));
25172fcea8cSEd Schouten extern void Char_del P_((char *line, char *attrib, int offset, int maxlen));
25272fcea8cSEd Schouten extern void Char_ins P_((char *line, char *attrib, int newc, int newatt, int offset, int maxlen));
25372fcea8cSEd Schouten extern void attribute_on P_((void));
25472fcea8cSEd Schouten extern void attribute_off P_((void));
25572fcea8cSEd Schouten extern void Char_out P_((int newc, int newatt, char *line, char *attrib, int offset));
25672fcea8cSEd Schouten 
25772fcea8cSEd Schouten extern void nc_setattrib P_((int));
25872fcea8cSEd Schouten extern void nc_clearattrib P_((int));
25972fcea8cSEd Schouten #undef P_
26072fcea8cSEd Schouten 
261