1195609Smp/* $Header: /p/tcsh/cvsroot/tcsh/ed.h,v 3.50 2007/07/05 14:13:06 christos Exp $ */ 259243Sobrien/* 359243Sobrien * ed.h: Editor declarations and globals 459243Sobrien */ 559243Sobrien/*- 659243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California. 759243Sobrien * All rights reserved. 859243Sobrien * 959243Sobrien * Redistribution and use in source and binary forms, with or without 1059243Sobrien * modification, are permitted provided that the following conditions 1159243Sobrien * are met: 1259243Sobrien * 1. Redistributions of source code must retain the above copyright 1359243Sobrien * notice, this list of conditions and the following disclaimer. 1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1559243Sobrien * notice, this list of conditions and the following disclaimer in the 1659243Sobrien * documentation and/or other materials provided with the distribution. 17100616Smp * 3. Neither the name of the University nor the names of its contributors 1859243Sobrien * may be used to endorse or promote products derived from this software 1959243Sobrien * without specific prior written permission. 2059243Sobrien * 2159243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2259243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2359243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2459243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2559243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2659243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2759243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2859243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2959243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3059243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3159243Sobrien * SUCH DAMAGE. 3259243Sobrien */ 3359243Sobrien#ifndef _h_ed 3459243Sobrien#define _h_ed 3559243Sobrien 3659243Sobrien#ifndef EXTERN 3759243Sobrien# define EXTERN extern 3859243Sobrien#endif 3959243Sobrien 4059243Sobrien#define MAXMACROLEVELS 10 /* max number of nested kbd macros */ 4159243Sobrien 4269408Sache#ifndef WINNT_NATIVE 4359243Sobrien# define NT_NUM_KEYS 256 4469408Sache#endif /* WINNT_NATIVE */ 4559243Sobrien 46195609Smp#ifdef __QNXNTO__ 47195609Smp#undef min 48195609Smp#undef max 49195609Smp#endif 50195609Smp 5159243Sobrien/****************************************************************************/ 5259243Sobrien/* stuff for the different states returned by the character editor routines */ 5359243Sobrien/****************************************************************************/ 5459243Sobrien 5559243Sobrien#define CCRETVAL char /* size needed for the different char editor */ 5659243Sobrien /* return values */ 5759243Sobrien 5859243Sobrien#define KEYCMD unsigned char /* size needed to index into CcFuncTbl */ 5959243Sobrien /* Must be unsigned */ 6059243Sobrien 61167465Smptypedef CCRETVAL(*PFCmd) (Char); /* pointer to function returning CCRETVAL */ 6259243Sobrien 6359243Sobrienstruct KeyFuncs { /* for the "bind" shell command */ 64145479Smp const char *name; /* function name for bind command */ 6559243Sobrien int func; /* function numeric value */ 66145479Smp const char *desc; /* description of function */ 6759243Sobrien}; 6859243Sobrien 6959243Sobrienextern PFCmd CcFuncTbl[]; /* table of available commands */ 7059243Sobrienextern KEYCMD CcKeyMap[]; /* keymap table, each index into above tbl */ 7159243Sobrienextern KEYCMD CcAltMap[]; /* Alt keymap table */ 7259243Sobrienextern KEYCMD CcEmacsMap[]; /* keymap table for Emacs default bindings */ 7359243Sobrienextern KEYCMD CcViCmdMap[]; /* for Vi command mode defaults */ 7459243Sobrienextern struct KeyFuncs FuncNames[]; /* string names vs. CcFuncTbl indices */ 7559243Sobrien 7659243Sobrienextern KEYCMD NumFuns; /* number of KEYCMDs in above table */ 7759243Sobrien 7859243Sobrien#define CC_ERROR 100 /* there should NOT be 100 different... */ 7959243Sobrien#define CC_FATAL 101 /* fatal error: inconsistant, must 8059243Sobrien * reset */ 8159243Sobrien#define CC_NORM 0 8259243Sobrien#define CC_NEWLINE 1 8359243Sobrien#define CC_EOF 2 8459243Sobrien#define CC_COMPLETE 3 8559243Sobrien#define CC_LIST_CHOICES 4 8659243Sobrien#define CC_LIST_GLOB 5 8759243Sobrien#define CC_EXPAND_GLOB 6 8859243Sobrien#define CC_HELPME 9 8959243Sobrien#define CC_CORRECT 10 9059243Sobrien#define CC_WHICH 11 9159243Sobrien#define CC_ARGHACK 12 9259243Sobrien#define CC_CORRECT_L 13 9359243Sobrien#define CC_REFRESH 14 9459243Sobrien#define CC_EXPAND_VARS 15 9559243Sobrien#define CC_NORMALIZE_PATH 16 9659243Sobrien#define CC_LIST_ALL 17 9759243Sobrien#define CC_COMPLETE_ALL 18 9859243Sobrien#define CC_COMPLETE_FWD 19 9959243Sobrien#define CC_COMPLETE_BACK 20 10059243Sobrien#define CC_NORMALIZE_COMMAND 21 10159243Sobrien 10259243Sobrientypedef struct { 10359243Sobrien Char *buf; 10459243Sobrien int len; 10559243Sobrien} CStr; 10659243Sobrien 107167465Smptypedef union { /* value passed to the Xkey routines */ 10859243Sobrien KEYCMD cmd; 10959243Sobrien CStr str; 11059243Sobrien} XmapVal; 11159243Sobrien 11259243Sobrien#define XK_NOD -1 /* Internal tree node */ 11359243Sobrien#define XK_CMD 0 /* X-key was an editor command */ 11459243Sobrien#define XK_STR 1 /* X-key was a string macro */ 11559243Sobrien#define XK_EXE 2 /* X-key was a unix command */ 11659243Sobrien 11759243Sobrien/****************************/ 11859243Sobrien/* Editor state and buffers */ 11959243Sobrien/****************************/ 12059243Sobrien 12159243SobrienEXTERN KEYCMD *CurrentKeyMap; /* current command key map */ 12259243SobrienEXTERN int inputmode; /* insert, replace, replace1 mode */ 12359243SobrienEXTERN Char GettingInput; /* true if getting an input line (mostly) */ 12459243SobrienEXTERN Char NeedsRedraw; /* for editor and twenex error messages */ 125167465SmpEXTERN Char InputBuf[INBUFSIZE]; /* the real input data *//*FIXBUF*/ 12659243SobrienEXTERN Char *LastChar, *Cursor; /* point to the next open space */ 12759243SobrienEXTERN Char *InputLim; /* limit of size of InputBuf */ 12859243SobrienEXTERN Char MetaNext; /* flags for ^V and ^[ functions */ 12959243SobrienEXTERN Char AltKeyMap; /* Using alternative command map (for vi mode) */ 13059243SobrienEXTERN Char VImode; /* true if running in vi mode (PWP 6-27-88) */ 13159243SobrienEXTERN Char *Mark; /* the emacs "mark" (dot is Cursor) */ 132167465SmpEXTERN char MarkIsSet; /* true if the mark has been set explicitly */ 13359243SobrienEXTERN Char DoingArg; /* true if we have an argument */ 13459243SobrienEXTERN int Argument; /* "universal" argument value */ 13559243SobrienEXTERN KEYCMD LastCmd; /* previous command executed */ 13683098SmpEXTERN CStr *KillRing; /* kill ring */ 13783098SmpEXTERN int KillRingMax; /* max length of kill ring */ 13883098SmpEXTERN int KillRingLen; /* current length of kill ring */ 13983098SmpEXTERN int KillPos; /* points to next kill */ 14083098SmpEXTERN int YankPos; /* points to next yank */ 14159243Sobrien 142167465SmpEXTERN Char UndoBuf[INBUFSIZE];/*FIXBUF*/ 14359243SobrienEXTERN Char *UndoPtr; 14459243SobrienEXTERN int UndoSize; 14559243SobrienEXTERN int UndoAction; 14659243Sobrien 147167465SmpEXTERN struct Strbuf HistBuf; /* = Strbuf_INIT; history buffer */ 14859243SobrienEXTERN int Hist_num; /* what point up the history we are at now. */ 149167465Smp/* buffer for which command and others */ 150167465SmpEXTERN struct Strbuf SavedBuf; /* = Strbuf_INIT; */ 151167465SmpEXTERN size_t LastSaved; /* points to end of saved buffer */ 152167465SmpEXTERN size_t CursSaved; /* points to the cursor point in saved buf */ 153167465SmpEXTERN int HistSaved; /* Hist_num is saved in this */ 154167465SmpEXTERN char RestoreSaved; /* true if SavedBuf should be restored */ 155167465SmpEXTERN int IncMatchLen; /* current match length during incremental search */ 15659243SobrienEXTERN char Expand; /* true if we are expanding a line */ 15759243Sobrienextern Char HistLit; /* true if history lines are shown literal */ 15859243SobrienEXTERN Char CurrentHistLit; /* Literal status of current show history line */ 159145479Smpextern int Tty_raw_mode; 16059243Sobrien 16159243Sobrien/* 16259243Sobrien * These are truly extern 16359243Sobrien */ 16459243Sobrienextern int MacroLvl; 165145479Smpextern Char *litptr; /* Entries start at offsets divisible by LIT_FACTOR */ 166145479Smp#define LIT_FACTOR 4 167145479Smpextern int didsetty; 16859243Sobrien 16959243SobrienEXTERN Char *KeyMacro[MAXMACROLEVELS]; 17059243Sobrien 171145479Smp/* CHAR_DBWIDTH in Display and Vdisplay means the non-first column of a character 172145479Smp that is wider than one "regular" position. The cursor should never point 173145479Smp in the middle of a multiple-column character. */ 17459243SobrienEXTERN Char **Display; /* display buffer seed vector */ 17559243SobrienEXTERN int CursorV, /* real cursor vertical (line) */ 17659243Sobrien CursorH, /* real cursor horisontal (column) */ 17759243Sobrien TermV, /* number of real screen lines 17859243Sobrien * (sizeof(DisplayBuf) / width */ 17959243Sobrien TermH; /* screen width */ 180145479SmpEXTERN Char **Vdisplay; /* new buffer */ 18159243Sobrien 18259243Sobrien/* Variables that describe terminal ability */ 18359243SobrienEXTERN int T_Lines, T_Cols; /* Rows and Cols of the terminal */ 18459243SobrienEXTERN Char T_CanIns; /* true if I can insert characters */ 18559243SobrienEXTERN Char T_CanDel; /* dito for delete characters */ 186167465SmpEXTERN char T_Tabs; /* true if tty interface is passing tabs */ 187167465SmpEXTERN char T_Margin; 18859243Sobrien#define MARGIN_AUTO 1 /* term has auto margins */ 18959243Sobrien#define MARGIN_MAGIC 2 /* concept glitch */ 19059243SobrienEXTERN speed_t T_Speed; /* Tty input Baud rate */ 19159243SobrienEXTERN Char T_CanCEOL; /* true if we can clear to end of line */ 19259243SobrienEXTERN Char T_CanUP; /* true if this term can do reverse linefeen */ 193167465SmpEXTERN char T_HasMeta; /* true if we have a meta key */ 19459243Sobrien 19559243Sobrien/* note the extra characters in the Strchr() call in this macro */ 19659243Sobrien#define isword(c) (Isalpha(c)||Isdigit(c)||Strchr(word_chars,c)) 19759243Sobrien#define min(x,y) (((x)<(y))?(x):(y)) 19859243Sobrien#define max(x,y) (((x)>(y))?(x):(y)) 19959243Sobrien 20059243Sobrien#define MODE_INSERT 0 20159243Sobrien#define MODE_REPLACE 1 20259243Sobrien#define MODE_REPLACE_1 2 20359243Sobrien 20459243Sobrien#define EX_IO 0 /* while we are executing */ 20559243Sobrien#define ED_IO 1 /* while we are editing */ 20659243Sobrien#define TS_IO 2 /* new mode from terminal */ 20759243Sobrien#define QU_IO 2 /* used only for quoted chars */ 20859243Sobrien#define NN_IO 3 /* The number of entries */ 20959243Sobrien 21059243Sobrien#if defined(POSIX) || defined(TERMIO) 21159243Sobrien# define M_INPUT 0 21259243Sobrien# define M_OUTPUT 1 21359243Sobrien# define M_CONTROL 2 21459243Sobrien# define M_LINED 3 21559243Sobrien# define M_CHAR 4 21659243Sobrien# define M_NN 5 21759243Sobrien#else /* GSTTY */ 21859243Sobrien# define M_CONTROL 0 21959243Sobrien# define M_LOCAL 1 22059243Sobrien# define M_CHAR 2 22159243Sobrien# define M_NN 3 22259243Sobrien#endif /* TERMIO */ 22359243Sobrientypedef struct { 224145479Smp const char *t_name; 225145479Smp unsigned int t_setmask; 226145479Smp unsigned int t_clrmask; 22759243Sobrien} ttyperm_t[NN_IO][M_NN]; 22859243Sobrien 22959243Sobrienextern ttyperm_t ttylist; 230100616Smp#include "ed.term.h" 23159243Sobrien#include "ed.decls.h" 23259243Sobrien 233145479Smp#ifndef POSIX 234145479Smp/* 235145479Smp * We don't prototype these, cause some systems have them wrong! 236145479Smp */ 237167465Smpextern int tgetent (); 238167465Smpextern char *tgetstr (); 239167465Smpextern int tgetflag (); 240167465Smpextern int tgetnum (); 241167465Smpextern char *tgoto (); 242145479Smp# define PUTPURE putpure 243145479Smp# define PUTRAW putraw 244145479Smp#else 245167465Smpextern int tgetent (char *, const char *); 246167465Smpextern char *tgetstr (const char *, char **); 247167465Smpextern int tgetflag (const char *); 248167465Smpextern int tgetnum (const char *); 249167465Smpextern char *tgoto (const char *, int, int); 250167465Smpextern void tputs (const char *, int, void (*)(int)); 251167465Smp# define PUTPURE ((void (*)(int)) putpure) 252167465Smp# define PUTRAW ((void (*)(int)) putraw) 253145479Smp#endif 254145479Smp 25559243Sobrien#endif /* _h_ed */ 256