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