1/*	$NetBSD$ */
2
3/*-
4 * Copyright (c) 1996
5 *	Keith Bostic.  All rights reserved.
6 *
7 * See the LICENSE file for redistribution information.
8 *
9 *	Id: ip.h,v 8.29 2000/07/17 21:17:54 skimo Exp (Berkeley) Date: 2000/07/17 21:17:54
10 */
11
12#include <sys/socket.h>
13#include "ipc_def.h"
14
15typedef struct ipcmsghdr {
16	struct	cmsghdr	header;
17	int	__room_for_fd;
18} IPCMSGHDR;
19
20struct _ip_vi_win;
21
22typedef struct _ip_private {
23	int	 i_fd;		/* Input file descriptor. */
24 	int 	 o_fd;		/* Output file descriptor. */
25 	int 	 t_fd;		/* Terminal file descriptor. */
26
27 	int	 argc;
28 	char	**argv;
29
30	size_t	 row;		/* Current row. */
31	size_t	 col;		/* Current column. */
32
33	db_recno_t	 sb_total;	/* scrollbar: total lines in file. */
34	db_recno_t	 sb_top;	/* scrollbar: top line on screen. */
35	size_t	 sb_num;	/* scrollbar: number of lines on screen. */
36
37	size_t	 iblen;		/* Input buffer length. */
38	size_t	 iskip;		/* Returned input buffer. */
39	char	 ibuf[256];	/* Input buffer. */
40
41	CHAR_T 	 tbuf[256];	/* Input keys. */
42
43#define	IP_IN_EX  	0x0001  /* Currently running ex. */
44#define IP_ON_ALTERNATE 0x0002	/* Alternate on. */
45#define	IP_SCR_VI_INIT  0x0004  /* Vi screen initialized. */
46	u_int32_t flags;
47} IP_PRIVATE;
48
49#define	IPP(sp)		((IP_PRIVATE *)((sp)->wp->ip_private))
50#define	WIPP(wp)	((IP_PRIVATE *)((wp)->ip_private))
51
52/* The screen line relative to a specific window. */
53#define	RLNO(sp, lno)	(sp)->roff + (lno)
54#define	RCNO(sp, cno)	(sp)->coff + (cno)
55
56#define	IPO_CODE_LEN	1	/* Length of a code value. */
57#define	IPO_INT_LEN	4	/* Length of an integer. */
58
59/* A structure that can hold the information for any frame. */
60typedef struct _ip_buf {
61	int code;		/* Event code. */
62	const char *str1;	/* String #1. */
63	u_int32_t len1;		/* String #1 length. */
64	const char *str2;	/* String #1. */
65	u_int32_t len2;		/* String #1 length. */
66	u_int32_t val1;		/* Value #1. */
67	u_int32_t val2;		/* Value #2. */
68	u_int32_t val3;		/* Value #3. */
69} IP_BUF;
70
71typedef int (*IPFunc) (struct _ip_vi_win *);
72typedef int (*IPFunc_1) (struct _ip_vi_win *, u_int32_t);
73typedef int (*IPFunc_1a) (struct _ip_vi_win *, u_int32_t, const char *, u_int32_t);
74typedef int (*IPFunc_a) (struct _ip_vi_win *, const char *, u_int32_t);
75typedef int (*IPFunc_ab1) (struct _ip_vi_win *, const char *, u_int32_t,
76			    const char *, u_int32_t, u_int32_t);
77typedef int (*IPFunc_12) (struct _ip_vi_win *, u_int32_t, u_int32_t);
78typedef int (*IPFunc_123) (struct _ip_vi_win *, u_int32_t, u_int32_t, u_int32_t);
79
80typedef int (*IPUnmarshall) (struct _ip_vi_win *, IP_BUF *, IPFunc);
81
82typedef struct _ipfunlist {
83    char       	   *format;
84    IPUnmarshall    unmarshall;
85    size_t	    offset;
86} IPFUNLIST;
87
88typedef struct _vipfunlist {
89    char       	   *format;
90    e_event_t	    e_event;
91} VIPFUNLIST;
92
93typedef struct ip_si_operations {
94    IPFunc_a	addstr;
95    IPFunc_12	attribute;
96    IPFunc      bell;
97    IPFunc      busy_off;
98    IPFunc_a    busy_on;
99    IPFunc      clrtoeol;
100    IPFunc      deleteln;
101    IPFunc      discard;
102    IPFunc_ab1  editopt;
103    IPFunc      insertln;
104    IPFunc_12   move;
105    IPFunc      quit;
106    IPFunc      redraw;
107    IPFunc      refresh;
108    IPFunc_a    rename;
109    IPFunc_1    rewrite;
110    IPFunc_123  scrollbar;
111    IPFunc_a    select;
112    IPFunc      split;
113    IPFunc_a	waddstr;
114} IPSIOPS;
115
116struct _ip_vi;
117typedef struct _ip_vi IPVI;
118
119struct _ip_vi_win;
120typedef struct _ip_vi_win IPVIWIN;
121
122struct _ip_vi {
123    int		ifd;		/* Input file descriptor. */
124    int		ofd;		/* Output file descriptor. */
125    pid_t	pid;
126
127    void	*private_data;
128
129    u_int32_t	flags;
130
131    int		(*run) __P((IPVI*, int, char*[]));
132    int 	(*new_window) __P((IPVI *, IPVIWIN **, int));
133    int		(*close) __P((IPVI*));
134};
135
136struct _ip_vi_win {
137    int		ifd;		/* Input file descriptor. */
138    int		ofd;		/* Output file descriptor. */
139
140    void	*private_data;
141
142    IPSIOPS	 *si_ops;
143
144    int		(*c_bol) __P((IPVIWIN*));
145    int		(*c_bottom) __P((IPVIWIN*));
146    int		(*c_del) __P((IPVIWIN*));
147    int		(*c_eol) __P((IPVIWIN*));
148    int		(*c_insert) __P((IPVIWIN*));
149    int		(*c_left) __P((IPVIWIN*));
150    int		(*c_right) __P((IPVIWIN*));
151    int		(*c_top) __P((IPVIWIN*));
152    int		(*c_settop) __P((IPVIWIN*, u_int32_t));
153
154    int		(*string) __P((IPVIWIN*, const char*, u_int32_t));
155    int		(*wq) __P((IPVIWIN*));
156    int		(*quit) __P((IPVIWIN*));
157    int		(*resize) __P((IPVIWIN*, u_int32_t, u_int32_t));
158
159    int		(*input) __P((IPVIWIN*, int));
160    int		(*close) __P((IPVIWIN*));
161
162    int		(*set_ops) __P((IPVIWIN*, IPSIOPS*));
163};
164
165/*
166 * Screen/editor IP_CODE's.
167 *
168 * The program structure depends on the event loop being able to return
169 * IPO_EOF/IPO_ERR multiple times -- eventually enough things will end
170 * due to the events that vi will reach the command level for the screen,
171 * at which point the exit flags will be set and vi will exit.
172 *
173 * IP events sent from the screen to vi.
174 */
175#define	CODE_OOB	 0	/* Illegal code. */
176#if 0
177#define	VI_C_BOL	 1	/* Cursor to start of line. */
178#define	VI_C_BOTTOM	 2	/* Cursor to bottom. */
179#define	VI_C_DEL	 3	/* Cursor delete. */
180#define	VI_C_DOWN	 4	/* Cursor down N lines: IPO_INT. */
181#define	VI_C_EOL	 5	/* Cursor to end of line. */
182#define	VI_C_INSERT	 6	/* Cursor: enter insert mode. */
183#define	VI_C_LEFT	 7	/* Cursor left. */
184#define	VI_C_PGDOWN	 8	/* Cursor down N pages: IPO_INT. */
185#define	VI_C_PGUP	 9	/* Cursor up N lines: IPO_INT. */
186#define	VI_C_RIGHT	10	/* Cursor right. */
187#define	VI_C_SEARCH	11	/* Cursor: search: IPO_INT, IPO_STR. */
188#define	VI_C_SETTOP	12	/* Cursor: set screen top line: IPO_INT. */
189#define	VI_C_TOP	13	/* Cursor to top. */
190#define	VI_C_UP		14	/* Cursor up N lines: IPO_INT. */
191#define	VI_EDIT		15	/* Edit a file: IPO_STR. */
192#define	VI_EDITOPT	16	/* Edit option: 2 * IPO_STR, IPO_INT. */
193#define	VI_EDITSPLIT	17	/* Split to a file: IPO_STR. */
194#define	VI_EOF		18	/* End of input (NOT ^D). */
195#define	VI_ERR		19	/* Input error. */
196#define	VI_INTERRUPT	20	/* Interrupt. */
197#define	VI_MOUSE_MOVE	21	/* Mouse click move: IPO_INT, IPO_INT. */
198#define	VI_QUIT		22	/* Quit. */
199#define	VI_RESIZE	23	/* Screen resize: IPO_INT, IPO_INT. */
200#define	VI_SEL_END	24	/* Select end: IPO_INT, IPO_INT. */
201#define	VI_SEL_START	25	/* Select start: IPO_INT, IPO_INT. */
202#define	VI_SIGHUP	26	/* SIGHUP. */
203#define	VI_SIGTERM	27	/* SIGTERM. */
204#define	VI_STRING	28	/* Input string: IPO_STR. */
205#define	VI_TAG		29	/* Tag. */
206#define	VI_TAGAS	30	/* Tag to a string: IPO_STR. */
207#define	VI_TAGSPLIT	31	/* Split to a tag. */
208#define	VI_UNDO		32	/* Undo. */
209#define	VI_WQ		33	/* Write and quit. */
210#define	VI_WRITE	34	/* Write. */
211#define	VI_WRITEAS	35	/* Write as another file: IPO_STR. */
212#define VI_FLAGS	36	/* Flags passed to nvi_create */
213#endif
214
215#define	VI_SEARCH_EXT	0x001	/* VI_C_SEARCH: ignore case. */
216#define	VI_SEARCH_IC	0x002	/* VI_C_SEARCH: ignore case. */
217#define	VI_SEARCH_ICL	0x004	/* VI_C_SEARCH: ignore case if lower-case. */
218#define	VI_SEARCH_INCR	0x008	/* VI_C_SEARCH: incremental search. */
219#define	VI_SEARCH_LIT	0x010	/* VI_C_SEARCH: literal string. */
220#define	VI_SEARCH_REV	0x020	/* VI_C_SEARCH: reverse direction. */
221#define	VI_SEARCH_WR	0x040	/* VI_C_SEARCH: wrap at sof/eof. */
222
223/*
224 * IP events sent from vi to the screen.
225 */
226#if 0
227#define	SI_ADDSTR	 1	/* Add a string: IPO_STR. */
228#define	SI_ATTRIBUTE	 2	/* Set screen attribute: 2 * IPO_INT. */
229#define	SI_BELL		 3	/* Beep/bell/flash the terminal. */
230#define	SI_BUSY_OFF	 4	/* Display a busy message: IPO_STR. */
231#define	SI_BUSY_ON	 5	/* Display a busy message: IPO_STR. */
232#define	SI_CLRTOEOL	 6	/* Clear to the end of the line. */
233#define	SI_DELETELN	 7	/* Delete a line. */
234#define	SI_DISCARD	 8	/* Discard the screen. */
235#define	SI_EDITOPT	 9	/* Edit option: 2 * IPO_STR, IPO_INT. */
236#define	SI_INSERTLN	10	/* Insert a line. */
237#define	SI_MOVE		11	/* Move the cursor: 2 * IPO_INT. */
238#define	SI_QUIT		12	/* Quit. */
239#define	SI_REDRAW	13	/* Redraw the screen. */
240#define	SI_REFRESH	14	/* Refresh the screen. */
241#define	SI_RENAME	15	/* Rename the screen: IPO_STR. */
242#define	SI_REPLY	16	/* Reply: IPO_INT (0/1), IPO_STR. */
243#define	SI_REWRITE	17	/* Rewrite a line: IPO_INT. */
244#define	SI_SCROLLBAR	18	/* Reset the scrollbar: 3 * IPO_INT. */
245#define	SI_SELECT	19	/* Select area: IPO_STR. */
246#define	SI_SPLIT	20	/* Split the screen. */
247#define	SI_EVENT_MAX	20
248#endif
249
250#include "extern.h"
251