xref: /onnv-gate/usr/src/lib/libshell/common/include/edit.h (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                  David Korn <dgk@research.att.com>                   *
184887Schin *                                                                      *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin #ifndef SEARCHSIZE
224887Schin /*
234887Schin  *  edit.h -  common data structure for vi and emacs edit options
244887Schin  *
254887Schin  *   David Korn
264887Schin  *   AT&T Labs
274887Schin  *
284887Schin  */
294887Schin 
304887Schin #define SEARCHSIZE	80
314887Schin 
324887Schin #include	"FEATURE/options"
334887Schin #include        "FEATURE/locale"
344887Schin #if !SHOPT_VSH && !SHOPT_ESH
354887Schin #   define ed_winsize()	(SEARCHSIZE)
364887Schin #else
374887Schin 
384887Schin #if !KSHELL
394887Schin #   include	<setjmp.h>
404887Schin #   include	<sig.h>
414887Schin #   include	<ctype.h>
424887Schin #endif /* KSHELL */
434887Schin 
444887Schin #include	"FEATURE/setjmp"
454887Schin #include	"terminal.h"
464887Schin 
474887Schin #define STRIP		0377
484887Schin #define LOOKAHEAD	80
494887Schin 
504887Schin #if SHOPT_MULTIBYTE
514887Schin #   ifndef ESS_MAXCHAR
524887Schin #	include	"national.h"
534887Schin #   endif /* ESS_MAXCHAR */
544887Schin     typedef wchar_t genchar;
554887Schin #   define CHARSIZE	(sizeof(wchar_t)<=2?3:sizeof(wchar_t))
564887Schin #else
574887Schin     typedef char genchar;
584887Schin #   define CHARSIZE	1
594887Schin #endif /* SHOPT_MULTIBYTE */
604887Schin 
614887Schin #define TABSIZE	8
624887Schin #define PRSIZE	160
634887Schin #define MAXLINE	1024		/* longest edit line permitted */
644887Schin 
654887Schin typedef struct _edit_pos
664887Schin {
674887Schin 	unsigned short line;
684887Schin 	unsigned short col;
694887Schin } Edpos_t;
704887Schin 
714887Schin typedef struct edit
724887Schin {
734887Schin 	sigjmp_buf e_env;
744887Schin 	int	e_kill;
754887Schin 	int	e_erase;
764887Schin 	int	e_werase;
774887Schin 	int	e_eof;
784887Schin 	int	e_lnext;
794887Schin 	int	e_fchar;
804887Schin 	int	e_plen;		/* length of prompt string */
818462SApril.Chin@Sun.COM 	char	e_crlf;		/* zero if cannot return to beginning of line */
828462SApril.Chin@Sun.COM 	char	e_nocrnl;	/* don't put a new-line with ^L */
834887Schin 	int	e_llimit;	/* line length limit */
844887Schin 	int	e_hline;	/* current history line number */
854887Schin 	int	e_hloff;	/* line number offset for command */
864887Schin 	int	e_hismin;	/* minimum history line number */
874887Schin 	int	e_hismax;	/* maximum history line number */
884887Schin 	int	e_raw;		/* set when in raw mode or alt mode */
894887Schin 	int	e_cur;		/* current line position */
904887Schin 	int	e_eol;		/* end-of-line position */
914887Schin 	int	e_pcur;		/* current physical line position */
924887Schin 	int	e_peol;		/* end of physical line position */
934887Schin 	int	e_mode;		/* edit mode */
944887Schin 	int	e_lookahead;	/* index in look-ahead buffer */
954887Schin 	int	e_repeat;
964887Schin 	int	e_saved;
974887Schin 	int	e_fcol;		/* first column */
984887Schin 	int	e_ucol;		/* column for undo */
994887Schin 	int	e_wsize;	/* width of display window */
1004887Schin 	char	*e_outbase;	/* pointer to start of output buffer */
1014887Schin 	char	*e_outptr;	/* pointer to position in output buffer */
1024887Schin 	char	*e_outlast;	/* pointer to end of output buffer */
1034887Schin 	genchar	*e_inbuf;	/* pointer to input buffer */
1044887Schin 	char	*e_prompt;	/* pointer to buffer containing the prompt */
1054887Schin 	genchar	*e_ubuf;	/* pointer to the undo buffer */
1064887Schin 	genchar	*e_killbuf;	/* pointer to delete buffer */
1074887Schin 	char	e_search[SEARCHSIZE];	/* search string */
1084887Schin 	genchar	*e_Ubuf;	/* temporary workspace buffer */
1094887Schin 	genchar	*e_physbuf;	/* temporary workspace buffer */
1104887Schin 	int	e_lbuf[LOOKAHEAD];/* pointer to look-ahead buffer */
1114887Schin 	int	e_fd;		/* file descriptor */
1124887Schin 	int	e_ttyspeed;	/* line speed, also indicates tty parms are valid */
1134887Schin 	int	e_tabcount;
1144887Schin #ifdef _hdr_utime
1154887Schin 	ino_t	e_tty_ino;
1164887Schin 	dev_t	e_tty_dev;
1174887Schin 	char	*e_tty;
1184887Schin #endif
1194887Schin #if SHOPT_OLDTERMIO
1204887Schin 	char	e_echoctl;
1214887Schin 	char	e_tcgeta;
1224887Schin 	struct termio e_ott;
1234887Schin #endif
1244887Schin #if SHOPT_MULTIBYTE
1254887Schin 	int	e_curchar;
1264887Schin 	int	e_cursize;
1274887Schin #endif
1284887Schin 	int	*e_globals;	/* global variables */
1294887Schin 	genchar	*e_window;	/* display window  image */
1304887Schin 	char	e_inmacro;	/* processing macro expansion */
1314887Schin #if KSHELL
1324887Schin 	char	e_vi_insert[2];	/* for sh_keytrap */
1334887Schin 	int32_t e_col;		/* for sh_keytrap */
1344887Schin #else
1354887Schin 	char	e_prbuff[PRSIZE]; /* prompt buffer */
1364887Schin #endif /* KSHELL */
1374887Schin 	struct termios	e_ttyparm;      /* initial tty parameters */
1384887Schin 	struct termios	e_nttyparm;     /* raw tty parameters */
1394887Schin 	struct termios e_savetty;	/* saved terminal state */
1404887Schin 	int	e_savefd;	/* file descriptor for saved terminal state */
1414887Schin 	char	e_macro[4];	/* macro buffer */
1424887Schin 	void	*e_vi;		/* vi specific data */
1434887Schin 	void	*e_emacs;	/* emacs specific data */
1444887Schin 	Shell_t	*sh;		/* interpreter pointer */
1454887Schin 	char	*e_stkptr;	/* saved stack pointer */
1464887Schin 	int	e_stkoff;	/* saved stack offset */
1474887Schin 	char	**e_clist;	/* completion list after <ESC>= */
1484887Schin 	int	e_nlist;	/* number of elements on completion list */
1494887Schin 	int	e_multiline;	/* allow multiple lines for editing */
1504887Schin 	int	e_winsz;	/* columns in window */
1514887Schin 	Edpos_t	e_curpos;	/* cursor line and column */
1524887Schin 	Namval_t *e_default;	/* variable containing default value */
1534887Schin 	Namval_t *e_term;	/* TERM variable */
1544887Schin 	char 	e_termname[80];	/* terminal name */
1554887Schin } Edit_t;
1564887Schin 
1574887Schin #undef MAXWINDOW
1584887Schin #define MAXWINDOW	300	/* maximum width window */
1594887Schin #define FAST	2
1604887Schin #define SLOW	1
1614887Schin #define ESC	cntl('[')
1624887Schin #define	UEOF	-2			/* user eof char synonym */
1634887Schin #define	UINTR	-3			/* user intr char synonym */
1644887Schin #define	UERASE	-4			/* user erase char synonym */
1654887Schin #define	UKILL	-5			/* user kill char synonym */
1664887Schin #define	UWERASE	-6			/* user word erase char synonym */
1674887Schin #define	ULNEXT	-7			/* user next literal char synonym */
1684887Schin 
1694887Schin #if ( 'a' == 97) /* ASCII? */
1704887Schin #   define	cntl(x)		(x&037)
1714887Schin #else
1724887Schin #   define cntl(c) (c=='D'?55:(c=='E'?45:(c=='F'?46:(c=='G'?'\a':(c=='H'?'\b': \
1734887Schin 		(c=='I'?'\t':(c=='J'?'\n':(c=='T'?60:(c=='U'?61:(c=='V'?50: \
1744887Schin 		(c=='W'?38:(c=='Z'?63:(c=='['?39:(c==']'?29: \
1754887Schin 		(c<'J'?c+1-'A':(c+10-'J'))))))))))))))))
1764887Schin #endif
1774887Schin 
1784887Schin #if !KSHELL
1794887Schin #   define STRIP	0377
1804887Schin #   define GMACS	1
1814887Schin #   define EMACS	2
1824887Schin #   define VIRAW	4
1834887Schin #   define EDITVI	8
1844887Schin #   define NOHIST	16
1854887Schin #   define EDITMASK	15
1864887Schin #   define is_option(m)	(opt_flag&(m))
1874887Schin     extern char opt_flag;
1884887Schin #   ifdef SYSCALL
1894887Schin #	define read(fd,buff,n)	syscall(3,fd,buff,n)
1904887Schin #   else
1914887Schin #	define read(fd,buff,n)	rEAd(fd,buff,n)
1924887Schin #   endif /* SYSCALL */
1934887Schin #endif	/* KSHELL */
1944887Schin 
1954887Schin extern void	ed_crlf(Edit_t*);
1964887Schin extern void	ed_putchar(Edit_t*, int);
1974887Schin extern void	ed_ringbell(void);
1984887Schin extern void	ed_setup(Edit_t*,int, int);
1994887Schin extern void	ed_flush(Edit_t*);
2004887Schin extern int	ed_getchar(Edit_t*,int);
2014887Schin extern int	ed_virt_to_phys(Edit_t*,genchar*,genchar*,int,int,int);
2024887Schin extern int	ed_window(void);
2034887Schin extern void	ed_ungetchar(Edit_t*,int);
2044887Schin extern int	ed_viread(void*, int, char*, int, int);
2054887Schin extern int	ed_read(void*, int, char*, int, int);
2064887Schin extern int	ed_emacsread(void*, int, char*, int, int);
2074887Schin extern Edpos_t	ed_curpos(Edit_t*, genchar*, int, int, Edpos_t);
2084887Schin extern int	ed_setcursor(Edit_t*, genchar*, int, int, int);
2094887Schin #if KSHELL
2104887Schin 	extern int	ed_macro(Edit_t*,int);
2114887Schin 	extern int	ed_expand(Edit_t*, char[],int*,int*,int,int);
2124887Schin 	extern int	ed_fulledit(Edit_t*);
2134887Schin 	extern void	*ed_open(Shell_t*);
2144887Schin #endif /* KSHELL */
2154887Schin #   if SHOPT_MULTIBYTE
2164887Schin 	extern int ed_internal(const char*, genchar*);
2174887Schin 	extern int ed_external(const genchar*, char*);
2184887Schin 	extern void ed_gencpy(genchar*,const genchar*);
2194887Schin 	extern void ed_genncpy(genchar*,const genchar*,int);
2204887Schin 	extern int ed_genlen(const genchar*);
2214887Schin 	extern int ed_setwidth(const char*);
2224887Schin #  endif /* SHOPT_MULTIBYTE */
2234887Schin 
2244887Schin extern const char	e_runvi[];
2254887Schin #if !KSHELL
2264887Schin    extern const char	e_version[];
2274887Schin #endif /* KSHELL */
2284887Schin 
2294887Schin #if SHOPT_HISTEXPAND
2304887Schin 
2314887Schin /* flags */
2324887Schin 
2334887Schin #define	HIST_EVENT	0x1	/* event designator seen */
2344887Schin #define HIST_QUESTION	0x2	/* question mark event designator */
2354887Schin #define	HIST_HASH	0x4	/* hash event designator */
2364887Schin #define HIST_WORDDSGN	0x8	/* word designator seen */
2374887Schin #define HIST_QUICKSUBST	0x10	/* quick substition designator seen */
2384887Schin #define HIST_SUBSTITUTE	0x20	/* for substition loop */
2394887Schin #define	HIST_NEWLINE	0x40	/* newline in squashed white space */
2404887Schin 
2414887Schin /* modifier flags */
2424887Schin 
2434887Schin #define	HIST_PRINT		0x100	/* print new command */
2444887Schin #define	HIST_QUOTE		0x200	/* quote resulting history line */
2454887Schin #define	HIST_QUOTE_BR		0x400	/* quote every word on space break */
2464887Schin #define	HIST_GLOBALSUBST	0x800	/* apply substition globally */
2474887Schin 
2484887Schin #define	HIST_ERROR		0x1000	/* an error ocurred */
2494887Schin 
2504887Schin /* flags to be returned */
2514887Schin 
2524887Schin #define	HIST_FLAG_RETURN_MASK	(HIST_EVENT|HIST_PRINT|HIST_ERROR)
2534887Schin 
2544887Schin extern int hist_expand(const char *, char **);
2554887Schin #endif
2564887Schin 
2574887Schin #endif
2584887Schin #endif
259