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