xref: /freebsd/contrib/libedit/el.h (revision 91f764172e197c82efa97a66cfbc13d2c744b02b)
1*91f76417SBaptiste Daroussin /*	$NetBSD: el.h,v 1.46 2021/08/15 10:08:41 christos Exp $	*/
2d0ef721eSBaptiste Daroussin 
3d0ef721eSBaptiste Daroussin /*-
4d0ef721eSBaptiste Daroussin  * Copyright (c) 1992, 1993
5d0ef721eSBaptiste Daroussin  *	The Regents of the University of California.  All rights reserved.
6d0ef721eSBaptiste Daroussin  *
7d0ef721eSBaptiste Daroussin  * This code is derived from software contributed to Berkeley by
8d0ef721eSBaptiste Daroussin  * Christos Zoulas of Cornell University.
9d0ef721eSBaptiste Daroussin  *
10d0ef721eSBaptiste Daroussin  * Redistribution and use in source and binary forms, with or without
11d0ef721eSBaptiste Daroussin  * modification, are permitted provided that the following conditions
12d0ef721eSBaptiste Daroussin  * are met:
13d0ef721eSBaptiste Daroussin  * 1. Redistributions of source code must retain the above copyright
14d0ef721eSBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer.
15d0ef721eSBaptiste Daroussin  * 2. Redistributions in binary form must reproduce the above copyright
16d0ef721eSBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer in the
17d0ef721eSBaptiste Daroussin  *    documentation and/or other materials provided with the distribution.
18d0ef721eSBaptiste Daroussin  * 3. Neither the name of the University nor the names of its contributors
19d0ef721eSBaptiste Daroussin  *    may be used to endorse or promote products derived from this software
20d0ef721eSBaptiste Daroussin  *    without specific prior written permission.
21d0ef721eSBaptiste Daroussin  *
22d0ef721eSBaptiste Daroussin  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23d0ef721eSBaptiste Daroussin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24d0ef721eSBaptiste Daroussin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25d0ef721eSBaptiste Daroussin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26d0ef721eSBaptiste Daroussin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27d0ef721eSBaptiste Daroussin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28d0ef721eSBaptiste Daroussin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29d0ef721eSBaptiste Daroussin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30d0ef721eSBaptiste Daroussin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31d0ef721eSBaptiste Daroussin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32d0ef721eSBaptiste Daroussin  * SUCH DAMAGE.
33d0ef721eSBaptiste Daroussin  *
34d0ef721eSBaptiste Daroussin  *	@(#)el.h	8.1 (Berkeley) 6/4/93
35d0ef721eSBaptiste Daroussin  */
36d0ef721eSBaptiste Daroussin 
37d0ef721eSBaptiste Daroussin /*
38d0ef721eSBaptiste Daroussin  * el.h: Internal structures.
39d0ef721eSBaptiste Daroussin  */
40d0ef721eSBaptiste Daroussin #ifndef _h_el
41d0ef721eSBaptiste Daroussin #define	_h_el
42d0ef721eSBaptiste Daroussin /*
43d0ef721eSBaptiste Daroussin  * Local defaults
44d0ef721eSBaptiste Daroussin  */
45d0ef721eSBaptiste Daroussin #define	KSHVI
46d0ef721eSBaptiste Daroussin #define	VIDEFAULT
47d0ef721eSBaptiste Daroussin #define	ANCHOR
48d0ef721eSBaptiste Daroussin 
49d0ef721eSBaptiste Daroussin #include "histedit.h"
50d0ef721eSBaptiste Daroussin #include "chartype.h"
51d0ef721eSBaptiste Daroussin 
52d0ef721eSBaptiste Daroussin #define	EL_BUFSIZ	((size_t)1024)	/* Maximum line size		*/
53d0ef721eSBaptiste Daroussin 
54*91f76417SBaptiste Daroussin #define	HANDLE_SIGNALS	0x001
55*91f76417SBaptiste Daroussin #define	NO_TTY		0x002
56*91f76417SBaptiste Daroussin #define	EDIT_DISABLED	0x004
57*91f76417SBaptiste Daroussin #define	UNBUFFERED	0x008
58*91f76417SBaptiste Daroussin #define	NARROW_HISTORY	0x040
59*91f76417SBaptiste Daroussin #define	NO_RESET	0x080
60*91f76417SBaptiste Daroussin #define	FIXIO		0x100
61d0ef721eSBaptiste Daroussin 
62d0ef721eSBaptiste Daroussin typedef unsigned char el_action_t;	/* Index to command array	*/
63d0ef721eSBaptiste Daroussin 
64d0ef721eSBaptiste Daroussin typedef struct coord_t {		/* Position on the screen	*/
65d0ef721eSBaptiste Daroussin 	int	h;
66d0ef721eSBaptiste Daroussin 	int	v;
67d0ef721eSBaptiste Daroussin } coord_t;
68d0ef721eSBaptiste Daroussin 
69d0ef721eSBaptiste Daroussin typedef struct el_line_t {
70d0ef721eSBaptiste Daroussin 	wchar_t		*buffer;	/* Input line			*/
71d0ef721eSBaptiste Daroussin 	wchar_t	        *cursor;	/* Cursor position		*/
72d0ef721eSBaptiste Daroussin 	wchar_t	        *lastchar;	/* Last character		*/
73d0ef721eSBaptiste Daroussin 	const wchar_t	*limit;		/* Max position			*/
74d0ef721eSBaptiste Daroussin } el_line_t;
75d0ef721eSBaptiste Daroussin 
76d0ef721eSBaptiste Daroussin /*
77d0ef721eSBaptiste Daroussin  * Editor state
78d0ef721eSBaptiste Daroussin  */
79d0ef721eSBaptiste Daroussin typedef struct el_state_t {
80d0ef721eSBaptiste Daroussin 	int		inputmode;	/* What mode are we in?		*/
81d0ef721eSBaptiste Daroussin 	int		doingarg;	/* Are we getting an argument?	*/
82d0ef721eSBaptiste Daroussin 	int		argument;	/* Numeric argument		*/
83d0ef721eSBaptiste Daroussin 	int		metanext;	/* Is the next char a meta char */
84d0ef721eSBaptiste Daroussin 	el_action_t	lastcmd;	/* Previous command		*/
85d0ef721eSBaptiste Daroussin 	el_action_t	thiscmd;	/* this command			*/
86d0ef721eSBaptiste Daroussin 	wchar_t		thisch;		/* char that generated it	*/
87d0ef721eSBaptiste Daroussin } el_state_t;
88d0ef721eSBaptiste Daroussin 
89d0ef721eSBaptiste Daroussin /*
90d0ef721eSBaptiste Daroussin  * Until we come up with something better...
91d0ef721eSBaptiste Daroussin  */
92d0ef721eSBaptiste Daroussin #define	el_malloc(a)	malloc(a)
93d0ef721eSBaptiste Daroussin #define	el_calloc(a,b)	calloc(a, b)
94d0ef721eSBaptiste Daroussin #define	el_realloc(a,b)	realloc(a, b)
95d0ef721eSBaptiste Daroussin #define	el_free(a)	free(a)
96d0ef721eSBaptiste Daroussin 
97d0ef721eSBaptiste Daroussin #include "tty.h"
98d0ef721eSBaptiste Daroussin #include "prompt.h"
99d0ef721eSBaptiste Daroussin #include "literal.h"
100d0ef721eSBaptiste Daroussin #include "keymacro.h"
101d0ef721eSBaptiste Daroussin #include "terminal.h"
102d0ef721eSBaptiste Daroussin #include "refresh.h"
103d0ef721eSBaptiste Daroussin #include "chared.h"
104d0ef721eSBaptiste Daroussin #include "search.h"
105d0ef721eSBaptiste Daroussin #include "hist.h"
106d0ef721eSBaptiste Daroussin #include "map.h"
107d0ef721eSBaptiste Daroussin #include "sig.h"
108d0ef721eSBaptiste Daroussin 
109d0ef721eSBaptiste Daroussin struct el_read_t;
110d0ef721eSBaptiste Daroussin 
111d0ef721eSBaptiste Daroussin struct editline {
112d0ef721eSBaptiste Daroussin 	wchar_t		 *el_prog;	/* the program name		*/
113d0ef721eSBaptiste Daroussin 	FILE		 *el_infile;	/* Stdio stuff			*/
114d0ef721eSBaptiste Daroussin 	FILE		 *el_outfile;	/* Stdio stuff			*/
115d0ef721eSBaptiste Daroussin 	FILE		 *el_errfile;	/* Stdio stuff			*/
116d0ef721eSBaptiste Daroussin 	int		  el_infd;	/* Input file descriptor	*/
117d0ef721eSBaptiste Daroussin 	int		  el_outfd;	/* Output file descriptor	*/
118d0ef721eSBaptiste Daroussin 	int		  el_errfd;	/* Error file descriptor	*/
119d0ef721eSBaptiste Daroussin 	int		  el_flags;	/* Various flags.		*/
120d0ef721eSBaptiste Daroussin 	coord_t		  el_cursor;	/* Cursor location		*/
121d0ef721eSBaptiste Daroussin 	wint_t		**el_display;	/* Real screen image = what is there */
122d0ef721eSBaptiste Daroussin 	wint_t		**el_vdisplay;	/* Virtual screen image = what we see */
123d0ef721eSBaptiste Daroussin 	void		 *el_data;	/* Client data			*/
124d0ef721eSBaptiste Daroussin 	el_line_t	  el_line;	/* The current line information	*/
125d0ef721eSBaptiste Daroussin 	el_state_t	  el_state;	/* Current editor state		*/
126d0ef721eSBaptiste Daroussin 	el_terminal_t	  el_terminal;	/* Terminal dependent stuff	*/
127d0ef721eSBaptiste Daroussin 	el_tty_t	  el_tty;	/* Tty dependent stuff		*/
128d0ef721eSBaptiste Daroussin 	el_refresh_t	  el_refresh;	/* Refresh stuff		*/
129d0ef721eSBaptiste Daroussin 	el_prompt_t	  el_prompt;	/* Prompt stuff			*/
130d0ef721eSBaptiste Daroussin 	el_prompt_t	  el_rprompt;	/* Prompt stuff			*/
131d0ef721eSBaptiste Daroussin 	el_literal_t	  el_literal;	/* prompt literal bits		*/
132d0ef721eSBaptiste Daroussin 	el_chared_t	  el_chared;	/* Characted editor stuff	*/
133d0ef721eSBaptiste Daroussin 	el_map_t	  el_map;	/* Key mapping stuff		*/
134d0ef721eSBaptiste Daroussin 	el_keymacro_t	  el_keymacro;	/* Key binding stuff		*/
135d0ef721eSBaptiste Daroussin 	el_history_t	  el_history;	/* History stuff		*/
136d0ef721eSBaptiste Daroussin 	el_search_t	  el_search;	/* Search stuff			*/
137d0ef721eSBaptiste Daroussin 	el_signal_t	  el_signal;	/* Signal handling stuff	*/
138d0ef721eSBaptiste Daroussin 	struct el_read_t *el_read;	/* Character reading stuff	*/
139d0ef721eSBaptiste Daroussin 	ct_buffer_t       el_visual;    /* Buffer for displayable str	*/
140d0ef721eSBaptiste Daroussin 	ct_buffer_t       el_scratch;   /* Scratch conversion buffer    */
141d0ef721eSBaptiste Daroussin 	ct_buffer_t       el_lgcyconv;  /* Buffer for legacy wrappers   */
142d0ef721eSBaptiste Daroussin 	LineInfo          el_lgcylinfo; /* Legacy LineInfo buffer       */
143d0ef721eSBaptiste Daroussin };
144d0ef721eSBaptiste Daroussin 
145d0ef721eSBaptiste Daroussin libedit_private int	el_editmode(EditLine *, int, const wchar_t **);
146d0ef721eSBaptiste Daroussin libedit_private EditLine *el_init_internal(const char *, FILE *, FILE *,
147d0ef721eSBaptiste Daroussin     FILE *, int, int, int, int);
148d0ef721eSBaptiste Daroussin 
149d0ef721eSBaptiste Daroussin #ifdef DEBUG
150d0ef721eSBaptiste Daroussin #define	EL_ABORT(a)	do { \
151d0ef721eSBaptiste Daroussin 				fprintf(el->el_errfile, "%s, %d: ", \
152d0ef721eSBaptiste Daroussin 					 __FILE__, __LINE__); \
153d0ef721eSBaptiste Daroussin 				fprintf a; \
154d0ef721eSBaptiste Daroussin 				abort(); \
155d0ef721eSBaptiste Daroussin 			} while( /*CONSTCOND*/0);
156d0ef721eSBaptiste Daroussin #else
157d0ef721eSBaptiste Daroussin #define EL_ABORT(a)	abort()
158d0ef721eSBaptiste Daroussin #endif
159d0ef721eSBaptiste Daroussin #endif /* _h_el */
160