ed.h revision 59243
159243Sobrien/* $Header: /src/pub/tcsh/ed.h,v 3.28 1998/11/24 18:17:21 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. 1759243Sobrien * 3. All advertising materials mentioning features or use of this software 1859243Sobrien * must display the following acknowledgement: 1959243Sobrien * This product includes software developed by the University of 2059243Sobrien * California, Berkeley and its contributors. 2159243Sobrien * 4. Neither the name of the University nor the names of its contributors 2259243Sobrien * may be used to endorse or promote products derived from this software 2359243Sobrien * without specific prior written permission. 2459243Sobrien * 2559243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2659243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2759243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2859243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2959243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3059243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3159243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3259243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3359243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3459243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3559243Sobrien * SUCH DAMAGE. 3659243Sobrien */ 3759243Sobrien#ifndef _h_ed 3859243Sobrien#define _h_ed 3959243Sobrien 4059243Sobrien#ifndef EXTERN 4159243Sobrien# define EXTERN extern 4259243Sobrien#endif 4359243Sobrien 4459243Sobrien#define TABSIZE 8 /* usually 8 spaces/tab */ 4559243Sobrien#define MAXMACROLEVELS 10 /* max number of nested kbd macros */ 4659243Sobrien 4759243Sobrien#ifndef WINNT 4859243Sobrien# define NT_NUM_KEYS 256 4959243Sobrien#endif /* WINNT */ 5059243Sobrien 5159243Sobrienextern int errno; 5259243Sobrien 5359243Sobrien/****************************************************************************/ 5459243Sobrien/* stuff for the different states returned by the character editor routines */ 5559243Sobrien/****************************************************************************/ 5659243Sobrien 5759243Sobrien#define CCRETVAL char /* size needed for the different char editor */ 5859243Sobrien /* return values */ 5959243Sobrien 6059243Sobrien#define KEYCMD unsigned char /* size needed to index into CcFuncTbl */ 6159243Sobrien /* Must be unsigned */ 6259243Sobrien 6359243Sobrientypedef CCRETVAL(*PFCmd) __P((int)); /* pointer to function returning CCRETVAL */ 6459243Sobrien 6559243Sobrienstruct KeyFuncs { /* for the "bind" shell command */ 6659243Sobrien char *name; /* function name for bind command */ 6759243Sobrien int func; /* function numeric value */ 6859243Sobrien char *desc; /* description of function */ 6959243Sobrien}; 7059243Sobrien 7159243Sobrienextern PFCmd CcFuncTbl[]; /* table of available commands */ 7259243Sobrienextern KEYCMD CcKeyMap[]; /* keymap table, each index into above tbl */ 7359243Sobrienextern KEYCMD CcAltMap[]; /* Alt keymap table */ 7459243Sobrienextern KEYCMD CcEmacsMap[]; /* keymap table for Emacs default bindings */ 7559243Sobrienextern KEYCMD CcViCmdMap[]; /* for Vi command mode defaults */ 7659243Sobrienextern struct KeyFuncs FuncNames[]; /* string names vs. CcFuncTbl indices */ 7759243Sobrien 7859243Sobrienextern KEYCMD NumFuns; /* number of KEYCMDs in above table */ 7959243Sobrien 8059243Sobrien#define CC_ERROR 100 /* there should NOT be 100 different... */ 8159243Sobrien#define CC_FATAL 101 /* fatal error: inconsistant, must 8259243Sobrien * reset */ 8359243Sobrien#define CC_NORM 0 8459243Sobrien#define CC_NEWLINE 1 8559243Sobrien#define CC_EOF 2 8659243Sobrien#define CC_COMPLETE 3 8759243Sobrien#define CC_LIST_CHOICES 4 8859243Sobrien#define CC_LIST_GLOB 5 8959243Sobrien#define CC_EXPAND_GLOB 6 9059243Sobrien#define CC_HELPME 9 9159243Sobrien#define CC_CORRECT 10 9259243Sobrien#define CC_WHICH 11 9359243Sobrien#define CC_ARGHACK 12 9459243Sobrien#define CC_CORRECT_L 13 9559243Sobrien#define CC_REFRESH 14 9659243Sobrien#define CC_EXPAND_VARS 15 9759243Sobrien#define CC_NORMALIZE_PATH 16 9859243Sobrien#define CC_LIST_ALL 17 9959243Sobrien#define CC_COMPLETE_ALL 18 10059243Sobrien#define CC_COMPLETE_FWD 19 10159243Sobrien#define CC_COMPLETE_BACK 20 10259243Sobrien#define CC_NORMALIZE_COMMAND 21 10359243Sobrien 10459243Sobrientypedef struct { 10559243Sobrien Char *buf; 10659243Sobrien int len; 10759243Sobrien} CStr; 10859243Sobrien 10959243Sobrientypedef union Xmapval { /* value passed to the Xkey routines */ 11059243Sobrien KEYCMD cmd; 11159243Sobrien CStr str; 11259243Sobrien} XmapVal; 11359243Sobrien 11459243Sobrien#define XK_NOD -1 /* Internal tree node */ 11559243Sobrien#define XK_CMD 0 /* X-key was an editor command */ 11659243Sobrien#define XK_STR 1 /* X-key was a string macro */ 11759243Sobrien#define XK_EXE 2 /* X-key was a unix command */ 11859243Sobrien 11959243Sobrien/****************************/ 12059243Sobrien/* Editor state and buffers */ 12159243Sobrien/****************************/ 12259243Sobrien 12359243SobrienEXTERN KEYCMD *CurrentKeyMap; /* current command key map */ 12459243SobrienEXTERN int inputmode; /* insert, replace, replace1 mode */ 12559243SobrienEXTERN Char GettingInput; /* true if getting an input line (mostly) */ 12659243SobrienEXTERN Char NeedsRedraw; /* for editor and twenex error messages */ 12759243SobrienEXTERN Char InputBuf[INBUFSIZE]; /* the real input data */ 12859243SobrienEXTERN Char *LastChar, *Cursor; /* point to the next open space */ 12959243SobrienEXTERN Char *InputLim; /* limit of size of InputBuf */ 13059243SobrienEXTERN Char MetaNext; /* flags for ^V and ^[ functions */ 13159243SobrienEXTERN Char AltKeyMap; /* Using alternative command map (for vi mode) */ 13259243SobrienEXTERN Char VImode; /* true if running in vi mode (PWP 6-27-88) */ 13359243SobrienEXTERN Char *Mark; /* the emacs "mark" (dot is Cursor) */ 13459243SobrienEXTERN Char DoingArg; /* true if we have an argument */ 13559243SobrienEXTERN int Argument; /* "universal" argument value */ 13659243SobrienEXTERN KEYCMD LastCmd; /* previous command executed */ 13759243SobrienEXTERN Char KillBuf[INBUFSIZE]; /* kill buffer */ 13859243SobrienEXTERN Char *LastKill; /* points to end of kill buffer */ 13959243Sobrien 14059243SobrienEXTERN Char UndoBuf[INBUFSIZE]; 14159243SobrienEXTERN Char *UndoPtr; 14259243SobrienEXTERN int UndoSize; 14359243SobrienEXTERN int UndoAction; 14459243Sobrien 14559243SobrienEXTERN Char HistBuf[INBUFSIZE]; /* history buffer */ 14659243SobrienEXTERN Char *LastHist; /* points to end of history buffer */ 14759243SobrienEXTERN int Hist_num; /* what point up the history we are at now. */ 14859243SobrienEXTERN Char WhichBuf[INBUFSIZE]; /* buffer for which command */ 14959243SobrienEXTERN Char *LastWhich; /* points to end of which buffer */ 15059243SobrienEXTERN Char *CursWhich; /* points to the cursor point in which buf */ 15159243SobrienEXTERN int HistWhich; /* Hist_num is saved in this */ 15259243SobrienEXTERN char Expand; /* true if we are expanding a line */ 15359243Sobrienextern Char HistLit; /* true if history lines are shown literal */ 15459243SobrienEXTERN Char CurrentHistLit; /* Literal status of current show history line */ 15559243Sobrien 15659243Sobrien/* 15759243Sobrien * These are truly extern 15859243Sobrien */ 15959243Sobrienextern int MacroLvl; 16059243Sobrien 16159243SobrienEXTERN Char *KeyMacro[MAXMACROLEVELS]; 16259243Sobrien 16359243SobrienEXTERN Char **Display; /* display buffer seed vector */ 16459243SobrienEXTERN int CursorV, /* real cursor vertical (line) */ 16559243Sobrien CursorH, /* real cursor horisontal (column) */ 16659243Sobrien TermV, /* number of real screen lines 16759243Sobrien * (sizeof(DisplayBuf) / width */ 16859243Sobrien TermH; /* screen width */ 16959243SobrienEXTERN Char **Vdisplay; /* new buffer */ 17059243Sobrien 17159243Sobrien/* Variables that describe terminal ability */ 17259243SobrienEXTERN int T_Lines, T_Cols; /* Rows and Cols of the terminal */ 17359243SobrienEXTERN Char T_CanIns; /* true if I can insert characters */ 17459243SobrienEXTERN Char T_CanDel; /* dito for delete characters */ 17559243SobrienEXTERN Char T_Tabs; /* true if tty interface is passing tabs */ 17659243SobrienEXTERN Char T_Margin; 17759243Sobrien#define MARGIN_AUTO 1 /* term has auto margins */ 17859243Sobrien#define MARGIN_MAGIC 2 /* concept glitch */ 17959243SobrienEXTERN speed_t T_Speed; /* Tty input Baud rate */ 18059243SobrienEXTERN Char T_CanCEOL; /* true if we can clear to end of line */ 18159243SobrienEXTERN Char T_CanUP; /* true if this term can do reverse linefeen */ 18259243SobrienEXTERN Char T_HasMeta; /* true if we have a meta key */ 18359243Sobrien 18459243Sobrien/* note the extra characters in the Strchr() call in this macro */ 18559243Sobrien#define isword(c) (Isalpha(c)||Isdigit(c)||Strchr(word_chars,c)) 18659243Sobrien#define min(x,y) (((x)<(y))?(x):(y)) 18759243Sobrien#define max(x,y) (((x)>(y))?(x):(y)) 18859243Sobrien 18959243Sobrien/* 19059243Sobrien * Terminal dependend data structures 19159243Sobrien */ 19259243Sobrientypedef struct { 19359243Sobrien#ifdef WINNT 19459243Sobrien int dummy; 19559243Sobrien#else /* !WINNT */ 19659243Sobrien# if defined(POSIX) || defined(TERMIO) 19759243Sobrien# ifdef POSIX 19859243Sobrien struct termios d_t; 19959243Sobrien# else 20059243Sobrien struct termio d_t; 20159243Sobrien# endif /* POSIX */ 20259243Sobrien# else /* SGTTY */ 20359243Sobrien# ifdef TIOCGETP 20459243Sobrien struct sgttyb d_t; 20559243Sobrien# endif /* TIOCGETP */ 20659243Sobrien# ifdef TIOCGETC 20759243Sobrien struct tchars d_tc; 20859243Sobrien# endif /* TIOCGETC */ 20959243Sobrien# ifdef TIOCGPAGE 21059243Sobrien struct ttypagestat d_pc; 21159243Sobrien# endif /* TIOCGPAGE */ 21259243Sobrien# ifdef TIOCLGET 21359243Sobrien int d_lb; 21459243Sobrien# endif /* TIOCLGET */ 21559243Sobrien# endif /* POSIX || TERMIO */ 21659243Sobrien# ifdef TIOCGLTC 21759243Sobrien struct ltchars d_ltc; 21859243Sobrien# endif /* TIOCGLTC */ 21959243Sobrien#endif /* WINNT */ 22059243Sobrien} ttydata_t; 22159243Sobrien 22259243Sobrien#define MODE_INSERT 0 22359243Sobrien#define MODE_REPLACE 1 22459243Sobrien#define MODE_REPLACE_1 2 22559243Sobrien 22659243Sobrien#define EX_IO 0 /* while we are executing */ 22759243Sobrien#define ED_IO 1 /* while we are editing */ 22859243Sobrien#define TS_IO 2 /* new mode from terminal */ 22959243Sobrien#define QU_IO 2 /* used only for quoted chars */ 23059243Sobrien#define NN_IO 3 /* The number of entries */ 23159243Sobrien 23259243Sobrien#if defined(POSIX) || defined(TERMIO) 23359243Sobrien# define M_INPUT 0 23459243Sobrien# define M_OUTPUT 1 23559243Sobrien# define M_CONTROL 2 23659243Sobrien# define M_LINED 3 23759243Sobrien# define M_CHAR 4 23859243Sobrien# define M_NN 5 23959243Sobrien#else /* GSTTY */ 24059243Sobrien# define M_CONTROL 0 24159243Sobrien# define M_LOCAL 1 24259243Sobrien# define M_CHAR 2 24359243Sobrien# define M_NN 3 24459243Sobrien#endif /* TERMIO */ 24559243Sobrientypedef struct { 24659243Sobrien char *t_name; 24759243Sobrien int t_setmask; 24859243Sobrien int t_clrmask; 24959243Sobrien} ttyperm_t[NN_IO][M_NN]; 25059243Sobrien 25159243Sobrienextern ttyperm_t ttylist; 25259243Sobrien#include "ed.decls.h" 25359243Sobrien 25459243Sobrien#endif /* _h_ed */ 255