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