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