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