xref: /freebsd/contrib/tcsh/ed.h (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
1 /* $Header: /src/pub/tcsh/ed.h,v 3.28 1998/11/24 18:17:21 christos Exp $ */
2 /*
3  * ed.h: Editor declarations and globals
4  */
5 /*-
6  * Copyright (c) 1980, 1991 The Regents of the University of California.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37 #ifndef _h_ed
38 #define _h_ed
39 
40 #ifndef EXTERN
41 # define EXTERN extern
42 #endif
43 
44 #define TABSIZE		8	/* usually 8 spaces/tab */
45 #define MAXMACROLEVELS	10	/* max number of nested kbd macros */
46 
47 #ifndef WINNT
48 # define NT_NUM_KEYS	256
49 #endif /* WINNT */
50 
51 extern int errno;
52 
53 /****************************************************************************/
54 /* stuff for the different states returned by the character editor routines */
55 /****************************************************************************/
56 
57 #define CCRETVAL	char	/* size needed for the different char editor */
58  /* return values */
59 
60 #define KEYCMD   unsigned char	/* size needed to index into CcFuncTbl */
61  /* Must be unsigned 		       */
62 
63 typedef CCRETVAL(*PFCmd) __P((int));	/* pointer to function returning CCRETVAL */
64 
65 struct KeyFuncs {		/* for the "bind" shell command */
66     char   *name;		/* function name for bind command */
67     int     func;		/* function numeric value */
68     char   *desc;		/* description of function */
69 };
70 
71 extern PFCmd CcFuncTbl[];	/* table of available commands */
72 extern KEYCMD CcKeyMap[];	/* keymap table, each index into above tbl */
73 extern KEYCMD CcAltMap[];	/* Alt keymap table */
74 extern KEYCMD CcEmacsMap[];	/* keymap table for Emacs default bindings */
75 extern KEYCMD CcViCmdMap[];	/* for Vi command mode defaults */
76 extern struct KeyFuncs FuncNames[];	/* string names vs. CcFuncTbl indices */
77 
78 extern KEYCMD NumFuns;		/* number of KEYCMDs in above table */
79 
80 #define	CC_ERROR		100	/* there should NOT be 100 different... */
81 #define CC_FATAL		101	/* fatal error: inconsistant, must
82 					 * reset */
83 #define	CC_NORM			0
84 #define	CC_NEWLINE		1
85 #define	CC_EOF			2
86 #define	CC_COMPLETE		3
87 #define	CC_LIST_CHOICES		4
88 #define	CC_LIST_GLOB		5
89 #define CC_EXPAND_GLOB		6
90 #define	CC_HELPME		9
91 #define CC_CORRECT		10
92 #define CC_WHICH		11
93 #define CC_ARGHACK		12
94 #define CC_CORRECT_L		13
95 #define CC_REFRESH		14
96 #define CC_EXPAND_VARS		15
97 #define CC_NORMALIZE_PATH	16
98 #define CC_LIST_ALL		17
99 #define CC_COMPLETE_ALL		18
100 #define CC_COMPLETE_FWD		19
101 #define CC_COMPLETE_BACK	20
102 #define CC_NORMALIZE_COMMAND	21
103 
104 typedef struct {
105     Char *buf;
106     int   len;
107 } CStr;
108 
109 typedef union Xmapval {		/* value passed to the Xkey routines */
110     KEYCMD cmd;
111     CStr str;
112 } XmapVal;
113 
114 #define XK_NOD	-1		/* Internal tree node */
115 #define XK_CMD	 0		/* X-key was an editor command */
116 #define XK_STR	 1		/* X-key was a string macro */
117 #define XK_EXE	 2		/* X-key was a unix command */
118 
119 /****************************/
120 /* Editor state and buffers */
121 /****************************/
122 
123 EXTERN KEYCMD *CurrentKeyMap;	/* current command key map */
124 EXTERN int inputmode;		/* insert, replace, replace1 mode */
125 EXTERN Char GettingInput;	/* true if getting an input line (mostly) */
126 EXTERN Char NeedsRedraw;	/* for editor and twenex error messages */
127 EXTERN Char InputBuf[INBUFSIZE];	/* the real input data */
128 EXTERN Char *LastChar, *Cursor;	/* point to the next open space */
129 EXTERN Char *InputLim;		/* limit of size of InputBuf */
130 EXTERN Char MetaNext;		/* flags for ^V and ^[ functions */
131 EXTERN Char AltKeyMap;		/* Using alternative command map (for vi mode) */
132 EXTERN Char VImode;		/* true if running in vi mode (PWP 6-27-88) */
133 EXTERN Char *Mark;		/* the emacs "mark" (dot is Cursor) */
134 EXTERN Char DoingArg;		/* true if we have an argument */
135 EXTERN int Argument;		/* "universal" argument value */
136 EXTERN KEYCMD LastCmd;		/* previous command executed */
137 EXTERN Char KillBuf[INBUFSIZE];	/* kill buffer */
138 EXTERN Char *LastKill;		/* points to end of kill buffer */
139 
140 EXTERN Char UndoBuf[INBUFSIZE];
141 EXTERN Char *UndoPtr;
142 EXTERN int  UndoSize;
143 EXTERN int  UndoAction;
144 
145 EXTERN Char HistBuf[INBUFSIZE];	/* history buffer */
146 EXTERN Char *LastHist;		/* points to end of history buffer */
147 EXTERN int Hist_num;		/* what point up the history we are at now. */
148 EXTERN Char WhichBuf[INBUFSIZE];	/* buffer for which command */
149 EXTERN Char *LastWhich;		/* points to end of which buffer */
150 EXTERN Char *CursWhich;		/* points to the cursor point in which buf */
151 EXTERN int HistWhich;		/* Hist_num is saved in this */
152 EXTERN char Expand;		/* true if we are expanding a line */
153 extern Char HistLit;		/* true if history lines are shown literal */
154 EXTERN Char CurrentHistLit;	/* Literal status of current show history line */
155 
156 /*
157  * These are truly extern
158  */
159 extern int MacroLvl;
160 
161 EXTERN Char *KeyMacro[MAXMACROLEVELS];
162 
163 EXTERN Char **Display;		/* display buffer seed vector */
164 EXTERN int CursorV,		/* real cursor vertical (line) */
165         CursorH,		/* real cursor horisontal (column) */
166         TermV,			/* number of real screen lines
167 				 * (sizeof(DisplayBuf) / width */
168         TermH;			/* screen width */
169 EXTERN Char **Vdisplay;		/* new buffer */
170 
171 /* Variables that describe terminal ability */
172 EXTERN int T_Lines, T_Cols;	/* Rows and Cols of the terminal */
173 EXTERN Char T_CanIns;		/* true if I can insert characters */
174 EXTERN Char T_CanDel;		/* dito for delete characters */
175 EXTERN Char T_Tabs;		/* true if tty interface is passing tabs */
176 EXTERN Char T_Margin;
177 #define MARGIN_AUTO  1		/* term has auto margins */
178 #define MARGIN_MAGIC 2		/* concept glitch */
179 EXTERN speed_t T_Speed;		/* Tty input Baud rate */
180 EXTERN Char T_CanCEOL;		/* true if we can clear to end of line */
181 EXTERN Char T_CanUP;		/* true if this term can do reverse linefeen */
182 EXTERN Char T_HasMeta;		/* true if we have a meta key */
183 
184 /* note the extra characters in the Strchr() call in this macro */
185 #define isword(c)	(Isalpha(c)||Isdigit(c)||Strchr(word_chars,c))
186 #define min(x,y)	(((x)<(y))?(x):(y))
187 #define max(x,y)	(((x)>(y))?(x):(y))
188 
189 /*
190  * Terminal dependend data structures
191  */
192 typedef struct {
193 #ifdef WINNT
194     int dummy;
195 #else /* !WINNT */
196 # if defined(POSIX) || defined(TERMIO)
197 #  ifdef POSIX
198     struct termios d_t;
199 #  else
200     struct termio d_t;
201 #  endif /* POSIX */
202 # else /* SGTTY */
203 #  ifdef TIOCGETP
204     struct sgttyb d_t;
205 #  endif /* TIOCGETP */
206 #  ifdef TIOCGETC
207     struct tchars d_tc;
208 #  endif /* TIOCGETC */
209 #  ifdef TIOCGPAGE
210     struct ttypagestat d_pc;
211 #  endif /* TIOCGPAGE */
212 #  ifdef TIOCLGET
213     int d_lb;
214 #  endif /* TIOCLGET */
215 # endif /* POSIX || TERMIO */
216 # ifdef TIOCGLTC
217     struct ltchars d_ltc;
218 # endif /* TIOCGLTC */
219 #endif /* WINNT */
220 } ttydata_t;
221 
222 #define MODE_INSERT	0
223 #define MODE_REPLACE	1
224 #define MODE_REPLACE_1	2
225 
226 #define EX_IO	0	/* while we are executing	*/
227 #define ED_IO	1	/* while we are editing		*/
228 #define TS_IO	2	/* new mode from terminal	*/
229 #define QU_IO	2	/* used only for quoted chars	*/
230 #define NN_IO	3	/* The number of entries	*/
231 
232 #if defined(POSIX) || defined(TERMIO)
233 # define M_INPUT	0
234 # define M_OUTPUT	1
235 # define M_CONTROL	2
236 # define M_LINED	3
237 # define M_CHAR		4
238 # define M_NN		5
239 #else /* GSTTY */
240 # define M_CONTROL	0
241 # define M_LOCAL	1
242 # define M_CHAR		2
243 # define M_NN		3
244 #endif /* TERMIO */
245 typedef struct {
246     char *t_name;
247     int  t_setmask;
248     int  t_clrmask;
249 } ttyperm_t[NN_IO][M_NN];
250 
251 extern ttyperm_t ttylist;
252 #include "ed.decls.h"
253 
254 #endif /* _h_ed */
255