xref: /onnv-gate/usr/src/cmd/vi/port/ex_vis.h (revision 3806:38a133f54518)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3806Scf46844  * Common Development and Distribution License (the "License").
6*3806Scf46844  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21802Scf46844 /*
22*3806Scf46844  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23802Scf46844  * Use is subject to license terms.
24802Scf46844  */
25802Scf46844 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
31802Scf46844 
32802Scf46844 #ifndef _EX_VIS_H
33802Scf46844 #define	_EX_VIS_H
34802Scf46844 
35802Scf46844 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36802Scf46844 
37802Scf46844 #ifdef __cplusplus
38802Scf46844 extern "C" {
39802Scf46844 #endif
40802Scf46844 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * Ex version 3
430Sstevel@tonic-gate  *
440Sstevel@tonic-gate  * Open and visual mode definitions.
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * There are actually 4 major states in open/visual modes.  These
470Sstevel@tonic-gate  * are visual, crt open (where the cursor can move about the screen and
480Sstevel@tonic-gate  * the screen can scroll and be erased), one line open (on dumb glass-crt's
490Sstevel@tonic-gate  * like the adm3), and hardcopy open (for everything else).
500Sstevel@tonic-gate  *
510Sstevel@tonic-gate  * The basic state is given by bastate, and the current state by state,
520Sstevel@tonic-gate  * since we can be in pseudo-hardcopy mode if we are on an adm3 and the
530Sstevel@tonic-gate  * line is longer than 80.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate var	short	bastate;
570Sstevel@tonic-gate var	short	state;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #define	VISUAL		0
600Sstevel@tonic-gate #define	CRTOPEN		1
610Sstevel@tonic-gate #define	ONEOPEN		2
620Sstevel@tonic-gate #define	HARDOPEN	3
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * The screen in visual and crtopen is of varying size; the basic
660Sstevel@tonic-gate  * window has top basWTOP and basWLINES lines are thereby implied.
670Sstevel@tonic-gate  * The current window (which may have grown from the basic size)
680Sstevel@tonic-gate  * has top WTOP and WLINES lines.  The top line of the window is WTOP,
690Sstevel@tonic-gate  * and the bottom line WBOT.  The line WECHO is used for messages,
700Sstevel@tonic-gate  * search strings and the like.  If WBOT==WECHO then we are in ONEOPEN
710Sstevel@tonic-gate  * or HARDOPEN and there is no way back to the line we were on if we
720Sstevel@tonic-gate  * go to WECHO (i.e. we will have to scroll before we go there, and
730Sstevel@tonic-gate  * we can't get back).  There are WCOLS columns per line.
740Sstevel@tonic-gate  * If WBOT!=WECHO then WECHO will be the last line on the screen
750Sstevel@tonic-gate  * and WBOT is the line before it.
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate var	short	basWTOP;
780Sstevel@tonic-gate var	short	basWLINES;
790Sstevel@tonic-gate var	short	WTOP;
800Sstevel@tonic-gate var	short	WBOT;
810Sstevel@tonic-gate var	short	WLINES;
820Sstevel@tonic-gate var	short	WCOLS;
830Sstevel@tonic-gate var	short	WECHO;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * When we are dealing with the echo area we consider the window
870Sstevel@tonic-gate  * to be "split" and set the variable splitw.  Otherwise, moving
880Sstevel@tonic-gate  * off the bottom of the screen into WECHO causes a screen rollup.
890Sstevel@tonic-gate  */
900Sstevel@tonic-gate var	bool	splitw;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate  * Information about each line currently on the screen includes
940Sstevel@tonic-gate  * the y coordinate associated with the line, the printing depth
950Sstevel@tonic-gate  * of the line (0 indicates unknown), and a mask which indicates
960Sstevel@tonic-gate  * whether the line is "unclean", i.e. whether we should check
970Sstevel@tonic-gate  * to make sure the line is displayed correctly at the next
980Sstevel@tonic-gate  * appropriate juncture.
990Sstevel@tonic-gate  */
1000Sstevel@tonic-gate struct vlinfo {
1010Sstevel@tonic-gate 	short	vliny;		/* Y coordinate */	/* was char */
1020Sstevel@tonic-gate 	short	vdepth;		/* Depth of displayed line */ /* was char */
1030Sstevel@tonic-gate 	short	vflags;		/* Is line potentially dirty ? */
1040Sstevel@tonic-gate };
1050Sstevel@tonic-gate var	struct vlinfo  vlinfo[TUBELINES + 2];
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define	DEPTH(c)	(vlinfo[c].vdepth)
1080Sstevel@tonic-gate #define	LINE(c)		(vlinfo[c].vliny)
1090Sstevel@tonic-gate #define	FLAGS(c)	(vlinfo[c].vflags)
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate #define	VDIRT	1
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * Hacks to copy vlinfo structures around
1150Sstevel@tonic-gate  */
1160Sstevel@tonic-gate #ifdef	V6
1170Sstevel@tonic-gate 	/* Kludge to make up for no structure assignment */
1180Sstevel@tonic-gate 	struct {
1190Sstevel@tonic-gate 		long	longi;
1200Sstevel@tonic-gate 	};
1210Sstevel@tonic-gate #define	vlcopy(i, j)	i.longi = j.longi
1220Sstevel@tonic-gate #else
1230Sstevel@tonic-gate #define	vlcopy(i, j)	i = j;
1240Sstevel@tonic-gate #endif
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * The current line on the screen is represented by vcline.
1280Sstevel@tonic-gate  * There are vcnt lines on the screen, the last being "vcnt - 1".
1290Sstevel@tonic-gate  * Vcline is intimately tied to the current value of dot,
1300Sstevel@tonic-gate  * and when command mode is used as a subroutine fancy footwork occurs.
1310Sstevel@tonic-gate  */
1320Sstevel@tonic-gate var	short	vcline;
1330Sstevel@tonic-gate var	short	vcnt;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate /*
1360Sstevel@tonic-gate  * To allow many optimizations on output, an exact image of the terminal
1370Sstevel@tonic-gate  * screen is maintained in the space addressed by vtube0.  The vtube
1380Sstevel@tonic-gate  * array indexes this space as lines, and is shuffled on scrolls, insert+delete
1390Sstevel@tonic-gate  * lines and the like rather than (more expensively) shuffling the screen
1400Sstevel@tonic-gate  * data itself.  It is also rearranged during insert mode across line
1410Sstevel@tonic-gate  * boundaries to make incore work easier.
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate var	wchar_t	*vtube[TUBELINES];
1440Sstevel@tonic-gate var	wchar_t	*vtube0;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * The current cursor position within the current line is kept in
1480Sstevel@tonic-gate  * cursor.  The current line is kept in linebuf.  During insertions
1490Sstevel@tonic-gate  * we use the auxiliary array genbuf as scratch area.
1500Sstevel@tonic-gate  * The cursor wcursor and wdot are used in operations within/spanning
1510Sstevel@tonic-gate  * lines to mark the other end of the affected area, or the target
1520Sstevel@tonic-gate  * for a motion.
1530Sstevel@tonic-gate  */
1540Sstevel@tonic-gate var	unsigned char	*cursor;
1550Sstevel@tonic-gate var	unsigned char	*wcursor;
1560Sstevel@tonic-gate var	line	*wdot;
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate  * Undo information is saved in a LBSIZE buffer at "vutmp" for changes
1600Sstevel@tonic-gate  * within the current line, or as for command mode for multi-line changes
1610Sstevel@tonic-gate  * or changes on lines no longer the current line.
1620Sstevel@tonic-gate  * The change kind "VCAPU" is used immediately after a U undo to prevent
1630Sstevel@tonic-gate  * two successive U undo's from destroying the previous state.
1640Sstevel@tonic-gate  */
1650Sstevel@tonic-gate #define	VNONE	0
1660Sstevel@tonic-gate #define	VCHNG	1
1670Sstevel@tonic-gate #define	VMANY	2
1680Sstevel@tonic-gate #define	VCAPU	3
1690Sstevel@tonic-gate #define	VMCHNG	4
1700Sstevel@tonic-gate #define	VMANYINS 5
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate var	short	vundkind;	/* Which kind of undo - from above */
1730Sstevel@tonic-gate var	unsigned char	*vutmp;		/* Prev line image when "VCHNG" */
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate  * State information for undoing of macros.  The basic idea is that
1770Sstevel@tonic-gate  * if the macro does only 1 change or even none, we don't treat it
1780Sstevel@tonic-gate  * specially.  If it does 2 or more changes we want to be able to
1790Sstevel@tonic-gate  * undo it as a unit.  We remember how many changes have been made
1800Sstevel@tonic-gate  * within the current macro.  (Remember macros can be nested.)
1810Sstevel@tonic-gate  */
1820Sstevel@tonic-gate #define VC_NOTINMAC	0	/* Not in a macro */
1830Sstevel@tonic-gate #define VC_NOCHANGE	1	/* In a macro, no changes so far */
1840Sstevel@tonic-gate #define VC_ONECHANGE	2	/* In a macro, one change so far */
1850Sstevel@tonic-gate #define VC_MANYCHANGE	3	/* In a macro, at least 2 changes so far */
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate var	short	vch_mac;	/* Change state - one of the above */
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate /*
1900Sstevel@tonic-gate  * For U undo's the line is grabbed by "vmove" after it first appears
1910Sstevel@tonic-gate  * on that line.  The "vUNDdot" which specifies which line has been
1920Sstevel@tonic-gate  * saved is selectively cleared when changes involving other lines
1930Sstevel@tonic-gate  * are made, i.e. after a 'J' join.  This is because a 'JU' would
1940Sstevel@tonic-gate  * lose completely the text of the line just joined on.
1950Sstevel@tonic-gate  */
1960Sstevel@tonic-gate var	unsigned char	*vUNDcurs;	/* Cursor just before 'U' */
1970Sstevel@tonic-gate var	line	*vUNDdot;	/* The line address of line saved in vUNDsav */
1980Sstevel@tonic-gate var	line	vUNDsav;	/* Grabbed initial "*dot" */
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate #define	killU()		vUNDdot = NOLINE
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate  * There are a number of cases where special behaviour is needed
2040Sstevel@tonic-gate  * from deeply nested routines.  This is accomplished by setting
2050Sstevel@tonic-gate  * the bits of hold, which acts to change the state of the general
2060Sstevel@tonic-gate  * visual editing behaviour in specific ways.
2070Sstevel@tonic-gate  *
2080Sstevel@tonic-gate  * HOLDAT prevents the clreol (clear to end of line) routines from
2090Sstevel@tonic-gate  * putting out @'s or ~'s on empty lines.
2100Sstevel@tonic-gate  *
2110Sstevel@tonic-gate  * HOLDDOL prevents the reopen routine from putting a '$' at the
2120Sstevel@tonic-gate  * end of a reopened line in list mode (for hardcopy mode, e.g.).
2130Sstevel@tonic-gate  *
2140Sstevel@tonic-gate  * HOLDROL prevents spurious blank lines when scrolling in hardcopy
2150Sstevel@tonic-gate  * open mode.
2160Sstevel@tonic-gate  *
2170Sstevel@tonic-gate  * HOLDQIK prevents the fake insert mode during repeated commands.
2180Sstevel@tonic-gate  *
2190Sstevel@tonic-gate  * HOLDPUPD prevents updating of the physical screen image when
2200Sstevel@tonic-gate  * mucking around while in insert mode.
2210Sstevel@tonic-gate  *
2220Sstevel@tonic-gate  * HOLDECH prevents clearing of the echo area while rolling the screen
2230Sstevel@tonic-gate  * backwards (e.g.) in deference to the clearing of the area at the
2240Sstevel@tonic-gate  * end of the scroll (1 time instead of n times).  The fact that this
2250Sstevel@tonic-gate  * is actually needed is recorded in heldech, which says that a clear
2260Sstevel@tonic-gate  * of the echo area was actually held off.
2270Sstevel@tonic-gate  */
2280Sstevel@tonic-gate var	short	hold;
2290Sstevel@tonic-gate var	short	holdupd;	/* Hold off update when echo line is too long */
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate #define	HOLDAT		1
2320Sstevel@tonic-gate #define	HOLDDOL		2
2330Sstevel@tonic-gate #define	HOLDROL		4
2340Sstevel@tonic-gate #define	HOLDQIK		8
2350Sstevel@tonic-gate #define	HOLDPUPD	16
2360Sstevel@tonic-gate #define	HOLDECH		32
2370Sstevel@tonic-gate #define HOLDWIG		64
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /*
2400Sstevel@tonic-gate  * Miscellaneous variables
2410Sstevel@tonic-gate  */
2420Sstevel@tonic-gate var	short	CDCNT;		/* Count of ^D's in insert on this line */
2430Sstevel@tonic-gate var	unsigned char	DEL[VBSIZE+1];	/* Last deleted text */
2440Sstevel@tonic-gate var	bool	HADUP;		/* This insert line started with ^ then ^D */
2450Sstevel@tonic-gate var	bool	HADZERO;	/* This insert line started with 0 then ^D */
2460Sstevel@tonic-gate var	unsigned char	INS[VBSIZE+1];	/* Last inserted text */
2470Sstevel@tonic-gate var	int	Vlines;		/* Number of file lines "before" vi command */
2480Sstevel@tonic-gate var	int	Xcnt;		/* External variable holding last cmd's count */
2490Sstevel@tonic-gate var	bool	Xhadcnt;	/* Last command had explicit count? */
2500Sstevel@tonic-gate var	short	ZERO;
2510Sstevel@tonic-gate var	short	dir;		/* Direction for search (+1 or -1) */
2520Sstevel@tonic-gate var	short	doomed;		/* Disply chars right of cursor to be killed */
2530Sstevel@tonic-gate var	bool	gobblebl;	/* Wrapmargin space generated nl, eat a space */
2540Sstevel@tonic-gate var	bool	hadcnt;		/* (Almost) internal to vmain() */
2550Sstevel@tonic-gate var	bool	heldech;	/* We owe a clear of echo area */
2560Sstevel@tonic-gate var	bool	insmode;	/* Are in character insert mode */
2570Sstevel@tonic-gate var	unsigned char	lastcmd[5];	/* Chars in last command */
2580Sstevel@tonic-gate var	int	lastcnt;	/* Count for last command */
2590Sstevel@tonic-gate var	unsigned char	*lastcp;	/* Save current command here to repeat */
2600Sstevel@tonic-gate var	bool	lasthad;	/* Last command had a count? */
2610Sstevel@tonic-gate var	short	lastvgk;	/* Previous input key, if not from keyboard */
2620Sstevel@tonic-gate var	short	lastreg;	/* Register with last command */
2630Sstevel@tonic-gate var	unsigned char	*ncols['z'-'a'+2];	/* Cursor positions of marks */
2640Sstevel@tonic-gate var	unsigned char	*notenam;	/* Name to be noted with change count */
2650Sstevel@tonic-gate var	unsigned char	*notesgn;	/* Change count from last command */
2660Sstevel@tonic-gate var	unsigned char	op;		/* Operation of current command */
2670Sstevel@tonic-gate var	int	Peekkey;	/* Peek ahead key */
2680Sstevel@tonic-gate var	bool	rubble;		/* Line is filthy (in hardcopy open), redraw! */
2690Sstevel@tonic-gate var	int	vSCROLL;	/* Number lines to scroll on ^D/^U */
2700Sstevel@tonic-gate var	unsigned char	*vglobp;	/* Untyped input (e.g. repeat insert text) */
2710Sstevel@tonic-gate var	unsigned char	vmacbuf[VBSIZE];   /* Text of visual macro, hence nonnestable */
2720Sstevel@tonic-gate var	unsigned char	*vmacp;		/* Like vglobp but for visual macros */
2730Sstevel@tonic-gate var	unsigned char	*vmcurs;	/* Cursor for restore after undo d), e.g. */
2740Sstevel@tonic-gate var	short	vmovcol;	/* Column to try to keep on arrow keys */
2750Sstevel@tonic-gate var	bool	vmoving;	/* Are trying to keep vmovcol */
2760Sstevel@tonic-gate var	short	vreg;		/* Reg for this command */   /* mjm: was char */
2770Sstevel@tonic-gate var	short	wdkind;		/* Liberal/conservative words? */
2780Sstevel@tonic-gate var	unsigned char	workcmd[5];	/* Temporary for lastcmd */
2790Sstevel@tonic-gate var	bool rewrite;
2800Sstevel@tonic-gate #ifdef XPG4
2810Sstevel@tonic-gate var	int	P_cursor_offset;	/* cursor adjust for Put */
2820Sstevel@tonic-gate #endif
2830Sstevel@tonic-gate #ifndef PRESUNEUC
2840Sstevel@tonic-gate var	unsigned char	wcharfiller;	/* Right margin filler for wide char */
2850Sstevel@tonic-gate #endif /* PRESUNEUC */
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate  * Macros
2900Sstevel@tonic-gate  */
2910Sstevel@tonic-gate #define	INF		30000
2920Sstevel@tonic-gate #define	LASTLINE	LINE(vcnt)
2930Sstevel@tonic-gate #define	beep		obeep
2940Sstevel@tonic-gate #define	cindent()	((outline - vlinfo[vcline].vliny) * WCOLS + outcol)
2950Sstevel@tonic-gate #define	vputp(cp, cnt)	tputs(cp, cnt, vputch)
2960Sstevel@tonic-gate #define	vputc(c)	putch(c)
2970Sstevel@tonic-gate #define	_ON	1
2980Sstevel@tonic-gate #define	_OFF	0
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate  * Function types
3010Sstevel@tonic-gate  */
302*3806Scf46844 int	any();
3030Sstevel@tonic-gate int	beep();
304*3806Scf46844 void	fixundo(void);
3050Sstevel@tonic-gate int	qcount();
306802Scf46844 int	vchange(unsigned char);
307802Scf46844 int	vdelete(unsigned char);
3080Sstevel@tonic-gate int	vgrabit();
3090Sstevel@tonic-gate int	vinschar();
3100Sstevel@tonic-gate int	vmove();
3110Sstevel@tonic-gate int	vputchar();
3120Sstevel@tonic-gate int	vshift();
3130Sstevel@tonic-gate int	vyankit();
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate #define FILLER 0177 /* fill positions for multibyte characters */
316802Scf46844 
317802Scf46844 #ifdef __cplusplus
318802Scf46844 }
319802Scf46844 #endif
320802Scf46844 
321802Scf46844 #endif /* _EX_VIS_H */
322