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