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 60typedef CCRETVAL(*PFCmd) (Char); /* pointer to function returning CCRETVAL */ 61 62struct 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 68extern PFCmd CcFuncTbl[]; /* table of available commands */ 69extern KEYCMD CcKeyMap[]; /* keymap table, each index into above tbl */ 70extern KEYCMD CcAltMap[]; /* Alt keymap table */ 71extern KEYCMD CcEmacsMap[]; /* keymap table for Emacs default bindings */ 72extern KEYCMD CcViCmdMap[]; /* for Vi command mode defaults */ 73extern struct KeyFuncs FuncNames[]; /* string names vs. CcFuncTbl indices */ 74 75extern 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 101typedef struct { 102 Char *buf; 103 int len; 104} CStr; 105 106typedef 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 120EXTERN KEYCMD *CurrentKeyMap; /* current command key map */ 121EXTERN int inputmode; /* insert, replace, replace1 mode */ 122EXTERN Char GettingInput; /* true if getting an input line (mostly) */ 123EXTERN Char NeedsRedraw; /* for editor and twenex error messages */ 124EXTERN Char InputBuf[INBUFSIZE]; /* the real input data *//*FIXBUF*/ 125EXTERN Char *LastChar, *Cursor; /* point to the next open space */ 126EXTERN Char *InputLim; /* limit of size of InputBuf */ 127EXTERN Char MetaNext; /* flags for ^V and ^[ functions */ 128EXTERN Char AltKeyMap; /* Using alternative command map (for vi mode) */ 129EXTERN Char VImode; /* true if running in vi mode (PWP 6-27-88) */ 130EXTERN Char *Mark; /* the emacs "mark" (dot is Cursor) */ 131EXTERN char MarkIsSet; /* true if the mark has been set explicitly */ 132EXTERN Char DoingArg; /* true if we have an argument */ 133EXTERN int Argument; /* "universal" argument value */ 134EXTERN KEYCMD LastCmd; /* previous command executed */ 135EXTERN CStr *KillRing; /* kill ring */ 136EXTERN int KillRingMax; /* max length of kill ring */ 137EXTERN int KillRingLen; /* current length of kill ring */ 138EXTERN int KillPos; /* points to next kill */ 139EXTERN int YankPos; /* points to next yank */ 140 141EXTERN Char UndoBuf[INBUFSIZE];/*FIXBUF*/ 142EXTERN Char *UndoPtr; 143EXTERN int UndoSize; 144EXTERN int UndoAction; 145 146EXTERN struct Strbuf HistBuf; /* = Strbuf_INIT; history buffer */ 147EXTERN int Hist_num; /* what point up the history we are at now. */ 148/* buffer for which command and others */ 149EXTERN struct Strbuf SavedBuf; /* = Strbuf_INIT; */ 150EXTERN size_t LastSaved; /* points to end of saved buffer */ 151EXTERN size_t CursSaved; /* points to the cursor point in saved buf */ 152EXTERN int HistSaved; /* Hist_num is saved in this */ 153EXTERN char RestoreSaved; /* true if SavedBuf should be restored */ 154EXTERN int IncMatchLen; /* current match length during incremental search */ 155EXTERN char Expand; /* true if we are expanding a line */ 156extern Char HistLit; /* true if history lines are shown literal */ 157EXTERN Char CurrentHistLit; /* Literal status of current show history line */ 158extern int Tty_raw_mode; 159 160/* 161 * These are truly extern 162 */ 163extern int MacroLvl; 164extern Char *litptr; /* Entries start at offsets divisible by LIT_FACTOR */ 165#define LIT_FACTOR 4 166extern int didsetty; 167 168EXTERN 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. */ 173EXTERN Char **Display; /* display buffer seed vector */ 174EXTERN 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 */ 179EXTERN Char **Vdisplay; /* new buffer */ 180 181/* Variables that describe terminal ability */ 182EXTERN int T_Lines, T_Cols; /* Rows and Cols of the terminal */ 183EXTERN Char T_CanIns; /* true if I can insert characters */ 184EXTERN Char T_CanDel; /* dito for delete characters */ 185EXTERN char T_Tabs; /* true if tty interface is passing tabs */ 186EXTERN char T_Margin; 187#define MARGIN_AUTO 1 /* term has auto margins */ 188#define MARGIN_MAGIC 2 /* concept glitch */ 189EXTERN speed_t T_Speed; /* Tty input Baud rate */ 190EXTERN Char T_CanCEOL; /* true if we can clear to end of line */ 191EXTERN Char T_CanUP; /* true if this term can do reverse linefeen */ 192EXTERN 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 */ 222typedef struct { 223 const char *t_name; 224 unsigned int t_setmask; 225 unsigned int t_clrmask; 226} ttyperm_t[NN_IO][M_NN]; 227 228extern 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 */ 236extern int tgetent (); 237extern char *tgetstr (); 238extern int tgetflag (); 239extern int tgetnum (); 240extern char *tgoto (); 241# define PUTPURE putpure 242# define PUTRAW putraw 243#else 244extern int tgetent (char *, const char *); 245extern char *tgetstr (const char *, char **); 246extern int tgetflag (const char *); 247extern int tgetnum (const char *); 248extern char *tgoto (const char *, int, int); 249extern void tputs (const char *, int, void (*)(int)); 250static __inline void PUTPURE(int c) { 251 (void)putpure(c); 252} 253static __inline void PUTRAW(int c) { 254 (void)putraw(c); 255} 256#endif 257 258#endif /* _h_ed */ 259