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