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