1 /*- 2 * Copyright (c) 1992, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1992, 1993, 1994, 1995, 1996 5 * Keith Bostic. All rights reserved. 6 * 7 * See the LICENSE file for redistribution information. 8 * 9 * $Id: ex.h,v 10.31 2012/10/03 02:33:24 zy Exp $ 10 */ 11 12 #define PROMPTCHAR ':' /* Prompt using a colon. */ 13 14 typedef struct _excmdlist { /* Ex command table structure. */ 15 CHAR_T *name; /* Command name, underlying function. */ 16 int (*fn)(SCR *, EXCMD *); 17 18 #define E_ADDR1 0x00000001 /* One address. */ 19 #define E_ADDR2 0x00000002 /* Two addresses. */ 20 #define E_ADDR2_ALL 0x00000004 /* Zero/two addresses; zero == all. */ 21 #define E_ADDR2_NONE 0x00000008 /* Zero/two addresses; zero == none. */ 22 #define E_ADDR_ZERO 0x00000010 /* 0 is a legal addr1. */ 23 #define E_ADDR_ZERODEF 0x00000020 /* 0 is default addr1 of empty files. */ 24 #define E_AUTOPRINT 0x00000040 /* Command always sets autoprint. */ 25 #define E_CLRFLAG 0x00000080 /* Clear the print (#, l, p) flags. */ 26 #define E_NEWSCREEN 0x00000100 /* Create a new screen. */ 27 #define E_SECURE 0x00000200 /* Permission denied if O_SECURE set. */ 28 #define E_VIONLY 0x00000400 /* Meaningful only in vi. */ 29 #define __INUSE1 0xfffff800 /* Same name space as EX_PRIVATE. */ 30 u_int16_t flags; 31 32 char *syntax; /* Syntax script. */ 33 char *usage; /* Usage line. */ 34 char *help; /* Help line. */ 35 } EXCMDLIST; 36 37 #define MAXCMDNAMELEN 12 /* Longest command name. */ 38 extern EXCMDLIST const cmds[]; /* Table of ex commands. */ 39 40 /* 41 * !!! 42 * QUOTING NOTE: 43 * 44 * Historically, .exrc files and EXINIT variables could only use ^V as an 45 * escape character, neither ^Q or a user specified character worked. We 46 * enforce that here, just in case someone depends on it. 47 */ 48 #define IS_ESCAPE(sp, cmdp, ch) \ 49 (F_ISSET(cmdp, E_VLITONLY) ? \ 50 (ch) == CH_LITERAL : KEY_VAL(sp, ch) == K_VLNEXT) 51 52 #define IS_SHELLMETA(sp, ch) \ 53 ((ch) <= CHAR_MAX && strchr(O_STR(sp, O_SHELLMETA), ch) != NULL) 54 55 /* 56 * File state must be checked for each command -- any ex command may be entered 57 * at any time, and most of them won't work well if a file hasn't yet been read 58 * in. Historic vi generally took the easy way out and dropped core. 59 */ 60 #define NEEDFILE(sp, cmdp) { \ 61 if ((sp)->ep == NULL) { \ 62 ex_wemsg(sp, (cmdp)->cmd->name, EXM_NOFILEYET); \ 63 return (1); \ 64 } \ 65 } 66 67 /* Range structures for global and @ commands. */ 68 typedef struct _range RANGE; 69 struct _range { /* Global command range. */ 70 TAILQ_ENTRY(_range) q; /* Linked list of ranges. */ 71 recno_t start, stop; /* Start/stop of the range. */ 72 }; 73 74 /* Ex command structure. */ 75 struct _excmd { 76 SLIST_ENTRY(_excmd) q; /* Linked list of commands. */ 77 78 char *if_name; /* Associated file. */ 79 recno_t if_lno; /* Associated line number. */ 80 81 /* Clear the structure for the ex parser. */ 82 #define CLEAR_EX_PARSER(cmdp) \ 83 memset(&((cmdp)->cp), 0, ((char *)&(cmdp)->flags - \ 84 (char *)&((cmdp)->cp)) + sizeof((cmdp)->flags)) 85 86 CHAR_T *cp; /* Current command text. */ 87 size_t clen; /* Current command length. */ 88 89 CHAR_T *save_cmd; /* Remaining command. */ 90 size_t save_cmdlen; /* Remaining command length. */ 91 92 EXCMDLIST const *cmd; /* Command: entry in command table. */ 93 EXCMDLIST rcmd; /* Command: table entry/replacement. */ 94 95 TAILQ_HEAD(_rh, _range) rq[1]; /* @/global range: linked list. */ 96 recno_t range_lno; /* @/global range: set line number. */ 97 CHAR_T *o_cp; /* Original @/global command. */ 98 size_t o_clen; /* Original @/global command length. */ 99 #define AGV_AT 0x01 /* @ buffer execution. */ 100 #define AGV_AT_NORANGE 0x02 /* @ buffer execution without range. */ 101 #define AGV_GLOBAL 0x04 /* global command. */ 102 #define AGV_V 0x08 /* v command. */ 103 #define AGV_ALL (AGV_AT | AGV_AT_NORANGE | AGV_GLOBAL | AGV_V) 104 u_int8_t agv_flags; 105 106 /* Clear the structure before each ex command. */ 107 #define CLEAR_EX_CMD(cmdp) { \ 108 u_int32_t L__f = F_ISSET(cmdp, E_PRESERVE); \ 109 memset(&((cmdp)->buffer), 0, ((char *)&(cmdp)->flags - \ 110 (char *)&((cmdp)->buffer)) + sizeof((cmdp)->flags)); \ 111 F_SET(cmdp, L__f); \ 112 } 113 114 CHAR_T buffer; /* Command: named buffer. */ 115 recno_t lineno; /* Command: line number. */ 116 long count; /* Command: signed count. */ 117 long flagoff; /* Command: signed flag offset. */ 118 int addrcnt; /* Command: addresses (0, 1 or 2). */ 119 MARK addr1; /* Command: 1st address. */ 120 MARK addr2; /* Command: 2nd address. */ 121 ARGS **argv; /* Command: array of arguments. */ 122 int argc; /* Command: count of arguments. */ 123 124 #define E_C_BUFFER 0x00001 /* Buffer name specified. */ 125 #define E_C_CARAT 0x00002 /* ^ flag. */ 126 #define E_C_COUNT 0x00004 /* Count specified. */ 127 #define E_C_COUNT_NEG 0x00008 /* Count was signed negative. */ 128 #define E_C_COUNT_POS 0x00010 /* Count was signed positive. */ 129 #define E_C_DASH 0x00020 /* - flag. */ 130 #define E_C_DOT 0x00040 /* . flag. */ 131 #define E_C_EQUAL 0x00080 /* = flag. */ 132 #define E_C_FORCE 0x00100 /* ! flag. */ 133 #define E_C_HASH 0x00200 /* # flag. */ 134 #define E_C_LIST 0x00400 /* l flag. */ 135 #define E_C_PLUS 0x00800 /* + flag. */ 136 #define E_C_PRINT 0x01000 /* p flag. */ 137 u_int16_t iflags; /* User input information. */ 138 139 #define __INUSE2 0x000007ff /* Same name space as EXCMDLIST. */ 140 #define E_BLIGNORE 0x00000800 /* Ignore blank lines. */ 141 #define E_NAMEDISCARD 0x00001000 /* Free/discard the name. */ 142 #define E_NOAUTO 0x00002000 /* Don't do autoprint output. */ 143 #define E_NOPRDEF 0x00004000 /* Don't print as default. */ 144 #define E_NRSEP 0x00008000 /* Need to line adjust ex output. */ 145 #define E_OPTNUM 0x00010000 /* Number edit option affected. */ 146 #define E_VLITONLY 0x00020000 /* Use ^V quoting only. */ 147 #define E_PRESERVE 0x0003f800 /* Bits to preserve across commands. */ 148 149 #define E_ABSMARK 0x00040000 /* Set the absolute mark. */ 150 #define E_ADDR_DEF 0x00080000 /* Default addresses used. */ 151 #define E_DELTA 0x00100000 /* Search address with delta. */ 152 #define E_MODIFY 0x00200000 /* File name expansion modified arg. */ 153 #define E_MOVETOEND 0x00400000 /* Move to the end of the file first. */ 154 #define E_NEWLINE 0x00800000 /* Found ending <newline>. */ 155 #define E_SEARCH_WMSG 0x01000000 /* Display search-wrapped message. */ 156 #define E_USELASTCMD 0x02000000 /* Use the last command. */ 157 #define E_VISEARCH 0x04000000 /* It's really a vi search command. */ 158 u_int32_t flags; /* Current flags. */ 159 }; 160 161 /* Ex private, per-screen memory. */ 162 typedef struct _ex_private { 163 /* Tag file list. */ 164 TAILQ_HEAD(_tagfh, _tagf) tagfq[1]; 165 TAILQ_HEAD(_tqh, _tagq) tq[1]; /* Tag queue. */ 166 SLIST_HEAD(_csch, _csc) cscq[1];/* Cscope connection list. */ 167 CHAR_T *tag_last; /* Saved last tag string. */ 168 169 CHAR_T *lastbcomm; /* Last bang command. */ 170 171 ARGS **args; /* Command: argument list. */ 172 int argscnt; /* Command: argument list count. */ 173 int argsoff; /* Command: offset into arguments. */ 174 175 u_int32_t fdef; /* Saved E_C_* default command flags. */ 176 177 char *ibp; /* File line input buffer. */ 178 size_t ibp_len; /* File line input buffer length. */ 179 CONVWIN ibcw; /* File line input conversion buffer. */ 180 181 /* 182 * Buffers for the ex output. The screen/vi support doesn't do any 183 * character buffering of any kind. We do it here so that we're not 184 * calling the screen output routines on every character. 185 * 186 * XXX 187 * Change to grow dynamically. 188 */ 189 char obp[1024]; /* Ex output buffer. */ 190 size_t obp_len; /* Ex output buffer length. */ 191 192 #define EXP_CSCINIT 0x01 /* Cscope initialized. */ 193 u_int8_t flags; 194 } EX_PRIVATE; 195 #define EXP(sp) ((EX_PRIVATE *)((sp)->ex_private)) 196 197 /* 198 * Filter actions: 199 * 200 * FILTER_BANG !: filter text through the utility. 201 * FILTER_RBANG !: read from the utility (without stdin). 202 * FILTER_READ read: read from the utility (with stdin). 203 * FILTER_WRITE write: write to the utility, display its output. 204 */ 205 enum filtertype { FILTER_BANG, FILTER_RBANG, FILTER_READ, FILTER_WRITE }; 206 207 /* Ex common error messages. */ 208 typedef enum { 209 EXM_EMPTYBUF, /* Empty buffer. */ 210 EXM_FILECOUNT, /* Too many file names. */ 211 EXM_NOCANON, /* No terminal interface. */ 212 EXM_NOCANON_F, /* EXM_NOCANO: filter version. */ 213 EXM_NOFILEYET, /* Illegal until a file read in. */ 214 EXM_NOPREVBUF, /* No previous buffer specified. */ 215 EXM_NOPREVRE, /* No previous RE specified. */ 216 EXM_NOSUSPEND, /* No suspension. */ 217 EXM_SECURE, /* Illegal if secure edit option set. */ 218 EXM_SECURE_F, /* EXM_SECURE: filter version */ 219 EXM_USAGE /* Standard usage message. */ 220 } exm_t; 221 222 /* Ex address error types. */ 223 enum badaddr { A_COMBO, A_EMPTY, A_EOF, A_NOTSET, A_ZERO }; 224 225 /* Ex common tag error messages. */ 226 typedef enum { 227 TAG_BADLNO, /* Tag line doesn't exist. */ 228 TAG_EMPTY, /* Tags stack is empty. */ 229 TAG_SEARCH /* Tags search pattern wasn't found. */ 230 } tagmsg_t; 231 232 #include "ex_def.h" 233 #include "extern.h" 234