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