xref: /dflybsd-src/contrib/libedit/src/el.h (revision 698e9e6cd5f042847de67460caaa3fde98cdfe99)
1*cdf8408cSAntonio Huete Jimenez /*	$NetBSD: el.h,v 1.46 2021/08/15 10:08:41 christos Exp $	*/
232fe07f8SJohn Marino 
332fe07f8SJohn Marino /*-
432fe07f8SJohn Marino  * Copyright (c) 1992, 1993
532fe07f8SJohn Marino  *	The Regents of the University of California.  All rights reserved.
632fe07f8SJohn Marino  *
732fe07f8SJohn Marino  * This code is derived from software contributed to Berkeley by
832fe07f8SJohn Marino  * Christos Zoulas of Cornell University.
932fe07f8SJohn Marino  *
1032fe07f8SJohn Marino  * Redistribution and use in source and binary forms, with or without
1132fe07f8SJohn Marino  * modification, are permitted provided that the following conditions
1232fe07f8SJohn Marino  * are met:
1332fe07f8SJohn Marino  * 1. Redistributions of source code must retain the above copyright
1432fe07f8SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1532fe07f8SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1632fe07f8SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1732fe07f8SJohn Marino  *    documentation and/or other materials provided with the distribution.
1832fe07f8SJohn Marino  * 3. Neither the name of the University nor the names of its contributors
1932fe07f8SJohn Marino  *    may be used to endorse or promote products derived from this software
2032fe07f8SJohn Marino  *    without specific prior written permission.
2132fe07f8SJohn Marino  *
2232fe07f8SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2332fe07f8SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2432fe07f8SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2532fe07f8SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2632fe07f8SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2732fe07f8SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2832fe07f8SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2932fe07f8SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3032fe07f8SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3132fe07f8SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3232fe07f8SJohn Marino  * SUCH DAMAGE.
3332fe07f8SJohn Marino  *
3432fe07f8SJohn Marino  *	@(#)el.h	8.1 (Berkeley) 6/4/93
3532fe07f8SJohn Marino  */
3632fe07f8SJohn Marino 
3732fe07f8SJohn Marino /*
3832fe07f8SJohn Marino  * el.h: Internal structures.
3932fe07f8SJohn Marino  */
4032fe07f8SJohn Marino #ifndef _h_el
4132fe07f8SJohn Marino #define	_h_el
4232fe07f8SJohn Marino /*
4332fe07f8SJohn Marino  * Local defaults
4432fe07f8SJohn Marino  */
4532fe07f8SJohn Marino #define	KSHVI
4632fe07f8SJohn Marino #define	VIDEFAULT
4732fe07f8SJohn Marino #define	ANCHOR
4832fe07f8SJohn Marino 
4932fe07f8SJohn Marino #include "histedit.h"
5032fe07f8SJohn Marino #include "chartype.h"
5132fe07f8SJohn Marino 
5232fe07f8SJohn Marino #define	EL_BUFSIZ	((size_t)1024)	/* Maximum line size		*/
5332fe07f8SJohn Marino 
54*cdf8408cSAntonio Huete Jimenez #define	HANDLE_SIGNALS	0x001
55*cdf8408cSAntonio Huete Jimenez #define	NO_TTY		0x002
56*cdf8408cSAntonio Huete Jimenez #define	EDIT_DISABLED	0x004
57*cdf8408cSAntonio Huete Jimenez #define	UNBUFFERED	0x008
58*cdf8408cSAntonio Huete Jimenez #define	NARROW_HISTORY	0x040
59*cdf8408cSAntonio Huete Jimenez #define	NO_RESET	0x080
60*cdf8408cSAntonio Huete Jimenez #define	FIXIO		0x100
6132fe07f8SJohn Marino 
6232fe07f8SJohn Marino typedef unsigned char el_action_t;	/* Index to command array	*/
6332fe07f8SJohn Marino 
6432fe07f8SJohn Marino typedef struct coord_t {		/* Position on the screen	*/
6532fe07f8SJohn Marino 	int	h;
6632fe07f8SJohn Marino 	int	v;
6732fe07f8SJohn Marino } coord_t;
6832fe07f8SJohn Marino 
6932fe07f8SJohn Marino typedef struct el_line_t {
7012db70c8Szrj 	wchar_t		*buffer;	/* Input line			*/
7112db70c8Szrj 	wchar_t	        *cursor;	/* Cursor position		*/
7212db70c8Szrj 	wchar_t	        *lastchar;	/* Last character		*/
7312db70c8Szrj 	const wchar_t	*limit;		/* Max position			*/
7432fe07f8SJohn Marino } el_line_t;
7532fe07f8SJohn Marino 
7632fe07f8SJohn Marino /*
7732fe07f8SJohn Marino  * Editor state
7832fe07f8SJohn Marino  */
7932fe07f8SJohn Marino typedef struct el_state_t {
8032fe07f8SJohn Marino 	int		inputmode;	/* What mode are we in?		*/
8132fe07f8SJohn Marino 	int		doingarg;	/* Are we getting an argument?	*/
8232fe07f8SJohn Marino 	int		argument;	/* Numeric argument		*/
8332fe07f8SJohn Marino 	int		metanext;	/* Is the next char a meta char */
8432fe07f8SJohn Marino 	el_action_t	lastcmd;	/* Previous command		*/
8532fe07f8SJohn Marino 	el_action_t	thiscmd;	/* this command			*/
8612db70c8Szrj 	wchar_t		thisch;		/* char that generated it	*/
8732fe07f8SJohn Marino } el_state_t;
8832fe07f8SJohn Marino 
8932fe07f8SJohn Marino /*
9032fe07f8SJohn Marino  * Until we come up with something better...
9132fe07f8SJohn Marino  */
9232fe07f8SJohn Marino #define	el_malloc(a)	malloc(a)
9360ecde0cSDaniel Fojt #define	el_calloc(a,b)	calloc(a, b)
9432fe07f8SJohn Marino #define	el_realloc(a,b)	realloc(a, b)
9532fe07f8SJohn Marino #define	el_free(a)	free(a)
9632fe07f8SJohn Marino 
9732fe07f8SJohn Marino #include "tty.h"
9832fe07f8SJohn Marino #include "prompt.h"
99ae19eda8Szrj #include "literal.h"
10032fe07f8SJohn Marino #include "keymacro.h"
10132fe07f8SJohn Marino #include "terminal.h"
10232fe07f8SJohn Marino #include "refresh.h"
10332fe07f8SJohn Marino #include "chared.h"
10432fe07f8SJohn Marino #include "search.h"
10532fe07f8SJohn Marino #include "hist.h"
10632fe07f8SJohn Marino #include "map.h"
10732fe07f8SJohn Marino #include "sig.h"
10812db70c8Szrj 
10912db70c8Szrj struct el_read_t;
11032fe07f8SJohn Marino 
11132fe07f8SJohn Marino struct editline {
11212db70c8Szrj 	wchar_t		 *el_prog;	/* the program name		*/
11332fe07f8SJohn Marino 	FILE		 *el_infile;	/* Stdio stuff			*/
11432fe07f8SJohn Marino 	FILE		 *el_outfile;	/* Stdio stuff			*/
11532fe07f8SJohn Marino 	FILE		 *el_errfile;	/* Stdio stuff			*/
11632fe07f8SJohn Marino 	int		  el_infd;	/* Input file descriptor	*/
11732fe07f8SJohn Marino 	int		  el_outfd;	/* Output file descriptor	*/
11832fe07f8SJohn Marino 	int		  el_errfd;	/* Error file descriptor	*/
11932fe07f8SJohn Marino 	int		  el_flags;	/* Various flags.		*/
12032fe07f8SJohn Marino 	coord_t		  el_cursor;	/* Cursor location		*/
121ae19eda8Szrj 	wint_t		**el_display;	/* Real screen image = what is there */
122ae19eda8Szrj 	wint_t		**el_vdisplay;	/* Virtual screen image = what we see */
12332fe07f8SJohn Marino 	void		 *el_data;	/* Client data			*/
12432fe07f8SJohn Marino 	el_line_t	  el_line;	/* The current line information	*/
12532fe07f8SJohn Marino 	el_state_t	  el_state;	/* Current editor state		*/
12632fe07f8SJohn Marino 	el_terminal_t	  el_terminal;	/* Terminal dependent stuff	*/
12732fe07f8SJohn Marino 	el_tty_t	  el_tty;	/* Tty dependent stuff		*/
12832fe07f8SJohn Marino 	el_refresh_t	  el_refresh;	/* Refresh stuff		*/
12932fe07f8SJohn Marino 	el_prompt_t	  el_prompt;	/* Prompt stuff			*/
13032fe07f8SJohn Marino 	el_prompt_t	  el_rprompt;	/* Prompt stuff			*/
131ae19eda8Szrj 	el_literal_t	  el_literal;	/* prompt literal bits		*/
13232fe07f8SJohn Marino 	el_chared_t	  el_chared;	/* Characted editor stuff	*/
13332fe07f8SJohn Marino 	el_map_t	  el_map;	/* Key mapping stuff		*/
13432fe07f8SJohn Marino 	el_keymacro_t	  el_keymacro;	/* Key binding stuff		*/
13532fe07f8SJohn Marino 	el_history_t	  el_history;	/* History stuff		*/
13632fe07f8SJohn Marino 	el_search_t	  el_search;	/* Search stuff			*/
13732fe07f8SJohn Marino 	el_signal_t	  el_signal;	/* Signal handling stuff	*/
13812db70c8Szrj 	struct el_read_t *el_read;	/* Character reading stuff	*/
13912db70c8Szrj 	ct_buffer_t       el_visual;    /* Buffer for displayable str	*/
14032fe07f8SJohn Marino 	ct_buffer_t       el_scratch;   /* Scratch conversion buffer    */
14132fe07f8SJohn Marino 	ct_buffer_t       el_lgcyconv;  /* Buffer for legacy wrappers   */
14232fe07f8SJohn Marino 	LineInfo          el_lgcylinfo; /* Legacy LineInfo buffer       */
14332fe07f8SJohn Marino };
14432fe07f8SJohn Marino 
14512db70c8Szrj libedit_private int	el_editmode(EditLine *, int, const wchar_t **);
146ae19eda8Szrj libedit_private EditLine *el_init_internal(const char *, FILE *, FILE *,
147ae19eda8Szrj     FILE *, int, int, int, int);
14832fe07f8SJohn Marino 
14932fe07f8SJohn Marino #ifdef DEBUG
15032fe07f8SJohn Marino #define	EL_ABORT(a)	do { \
15132fe07f8SJohn Marino 				fprintf(el->el_errfile, "%s, %d: ", \
15232fe07f8SJohn Marino 					 __FILE__, __LINE__); \
15332fe07f8SJohn Marino 				fprintf a; \
15432fe07f8SJohn Marino 				abort(); \
15532fe07f8SJohn Marino 			} while( /*CONSTCOND*/0);
15632fe07f8SJohn Marino #else
15732fe07f8SJohn Marino #define EL_ABORT(a)	abort()
15832fe07f8SJohn Marino #endif
15932fe07f8SJohn Marino #endif /* _h_el */
160