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