ed.h revision 69408
156160Sru/* $Header: /src/pub/tcsh/ed.h,v 3.30 2000/11/11 23:03:34 christos Exp $ */
2114472Sru/*
321495Sjmacd * ed.h: Editor declarations and globals
4114472Sru */
5114472Sru/*-
621495Sjmacd * Copyright (c) 1980, 1991 The Regents of the University of California.
721495Sjmacd * All rights reserved.
821495Sjmacd *
921495Sjmacd * Redistribution and use in source and binary forms, with or without
1021495Sjmacd * modification, are permitted provided that the following conditions
1121495Sjmacd * are met:
1221495Sjmacd * 1. Redistributions of source code must retain the above copyright
1321495Sjmacd *    notice, this list of conditions and the following disclaimer.
1421495Sjmacd * 2. Redistributions in binary form must reproduce the above copyright
1521495Sjmacd *    notice, this list of conditions and the following disclaimer in the
1621495Sjmacd *    documentation and/or other materials provided with the distribution.
1721495Sjmacd * 3. All advertising materials mentioning features or use of this software
1821495Sjmacd *    must display the following acknowledgement:
1921495Sjmacd *	This product includes software developed by the University of
2021495Sjmacd *	California, Berkeley and its contributors.
2121495Sjmacd * 4. Neither the name of the University nor the names of its contributors
2221495Sjmacd *    may be used to endorse or promote products derived from this software
2342660Smarkm *    without specific prior written permission.
2442660Smarkm *
2521495Sjmacd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2621495Sjmacd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2721495Sjmacd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2821495Sjmacd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2921495Sjmacd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3056160Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3121495Sjmacd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3221495Sjmacd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3342660Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3442660Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3521495Sjmacd * SUCH DAMAGE.
3621495Sjmacd */
3721495Sjmacd#ifndef _h_ed
3821495Sjmacd#define _h_ed
3921495Sjmacd
4021495Sjmacd#ifndef EXTERN
4121495Sjmacd# define EXTERN extern
4242660Smarkm#endif
4356160Sru
4456160Sru#define TABSIZE		8	/* usually 8 spaces/tab */
4556160Sru#define MAXMACROLEVELS	10	/* max number of nested kbd macros */
4656160Sru
4756160Sru#ifndef WINNT_NATIVE
4856160Sru# define NT_NUM_KEYS	256
4956160Sru#endif /* WINNT_NATIVE */
5056160Sru
5121495Sjmacd/****************************************************************************/
5221495Sjmacd/* stuff for the different states returned by the character editor routines */
5321495Sjmacd/****************************************************************************/
5456160Sru
5556160Sru#define CCRETVAL	char	/* size needed for the different char editor */
5656160Sru /* return values */
5721495Sjmacd
5821495Sjmacd#define KEYCMD   unsigned char	/* size needed to index into CcFuncTbl */
5956160Sru /* Must be unsigned 		       */
6056160Sru
6156160Srutypedef CCRETVAL(*PFCmd) __P((int));	/* pointer to function returning CCRETVAL */
6256160Sru
6321495Sjmacdstruct KeyFuncs {		/* for the "bind" shell command */
6421495Sjmacd    char   *name;		/* function name for bind command */
6521495Sjmacd    int     func;		/* function numeric value */
6621495Sjmacd    char   *desc;		/* description of function */
6721495Sjmacd};
6821495Sjmacd
6921495Sjmacdextern PFCmd CcFuncTbl[];	/* table of available commands */
7021495Sjmacdextern KEYCMD CcKeyMap[];	/* keymap table, each index into above tbl */
7121495Sjmacdextern KEYCMD CcAltMap[];	/* Alt keymap table */
7221495Sjmacdextern KEYCMD CcEmacsMap[];	/* keymap table for Emacs default bindings */
7321495Sjmacdextern KEYCMD CcViCmdMap[];	/* for Vi command mode defaults */
7421495Sjmacdextern struct KeyFuncs FuncNames[];	/* string names vs. CcFuncTbl indices */
7521495Sjmacd
7621495Sjmacdextern KEYCMD NumFuns;		/* number of KEYCMDs in above table */
7721495Sjmacd
7821495Sjmacd#define	CC_ERROR		100	/* there should NOT be 100 different... */
7921495Sjmacd#define CC_FATAL		101	/* fatal error: inconsistant, must
8021495Sjmacd					 * reset */
8121495Sjmacd#define	CC_NORM			0
8221495Sjmacd#define	CC_NEWLINE		1
8321495Sjmacd#define	CC_EOF			2
8421495Sjmacd#define	CC_COMPLETE		3
8521495Sjmacd#define	CC_LIST_CHOICES		4
8621495Sjmacd#define	CC_LIST_GLOB		5
8721495Sjmacd#define CC_EXPAND_GLOB		6
8821495Sjmacd#define	CC_HELPME		9
8921495Sjmacd#define CC_CORRECT		10
9021495Sjmacd#define CC_WHICH		11
9121495Sjmacd#define CC_ARGHACK		12
9221495Sjmacd#define CC_CORRECT_L		13
9321495Sjmacd#define CC_REFRESH		14
9421495Sjmacd#define CC_EXPAND_VARS		15
9521495Sjmacd#define CC_NORMALIZE_PATH	16
9621495Sjmacd#define CC_LIST_ALL		17
9742660Smarkm#define CC_COMPLETE_ALL		18
9821495Sjmacd#define CC_COMPLETE_FWD		19
9921495Sjmacd#define CC_COMPLETE_BACK	20
10042660Smarkm#define CC_NORMALIZE_COMMAND	21
10142660Smarkm
10256160Srutypedef struct {
10356160Sru    Char *buf;
10421495Sjmacd    int   len;
10542660Smarkm} CStr;
10642660Smarkm
10756160Srutypedef union Xmapval {		/* value passed to the Xkey routines */
10842660Smarkm    KEYCMD cmd;
10956160Sru    CStr str;
11042660Smarkm} XmapVal;
11142660Smarkm
11242660Smarkm#define XK_NOD	-1		/* Internal tree node */
11342660Smarkm#define XK_CMD	 0		/* X-key was an editor command */
11442660Smarkm#define XK_STR	 1		/* X-key was a string macro */
11521495Sjmacd#define XK_EXE	 2		/* X-key was a unix command */
11656160Sru
11756160Sru/****************************/
11842660Smarkm/* Editor state and buffers */
11942660Smarkm/****************************/
12042660Smarkm
12142660SmarkmEXTERN KEYCMD *CurrentKeyMap;	/* current command key map */
12221495SjmacdEXTERN int inputmode;		/* insert, replace, replace1 mode */
12342660SmarkmEXTERN Char GettingInput;	/* true if getting an input line (mostly) */
12421495SjmacdEXTERN Char NeedsRedraw;	/* for editor and twenex error messages */
12542660SmarkmEXTERN Char InputBuf[INBUFSIZE];	/* the real input data */
12621495SjmacdEXTERN Char *LastChar, *Cursor;	/* point to the next open space */
12742660SmarkmEXTERN Char *InputLim;		/* limit of size of InputBuf */
12842660SmarkmEXTERN Char MetaNext;		/* flags for ^V and ^[ functions */
12942660SmarkmEXTERN Char AltKeyMap;		/* Using alternative command map (for vi mode) */
13042660SmarkmEXTERN Char VImode;		/* true if running in vi mode (PWP 6-27-88) */
13121495SjmacdEXTERN Char *Mark;		/* the emacs "mark" (dot is Cursor) */
13242660SmarkmEXTERN Char DoingArg;		/* true if we have an argument */
13342660SmarkmEXTERN int Argument;		/* "universal" argument value */
13456160SruEXTERN KEYCMD LastCmd;		/* previous command executed */
13556160SruEXTERN Char KillBuf[INBUFSIZE];	/* kill buffer */
13656160SruEXTERN Char *LastKill;		/* points to end of kill buffer */
13742660Smarkm
13821495SjmacdEXTERN Char UndoBuf[INBUFSIZE];
13942660SmarkmEXTERN Char *UndoPtr;
14021495SjmacdEXTERN int  UndoSize;
14121495SjmacdEXTERN int  UndoAction;
14242660Smarkm
14342660SmarkmEXTERN Char HistBuf[INBUFSIZE];	/* history buffer */
14442660SmarkmEXTERN Char *LastHist;		/* points to end of history buffer */
14542660SmarkmEXTERN int Hist_num;		/* what point up the history we are at now. */
14642660SmarkmEXTERN Char WhichBuf[INBUFSIZE];	/* buffer for which command */
14742660SmarkmEXTERN Char *LastWhich;		/* points to end of which buffer */
14842660SmarkmEXTERN Char *CursWhich;		/* points to the cursor point in which buf */
14942660SmarkmEXTERN int HistWhich;		/* Hist_num is saved in this */
15042660SmarkmEXTERN char Expand;		/* true if we are expanding a line */
15142660Smarkmextern Char HistLit;		/* true if history lines are shown literal */
15221495SjmacdEXTERN Char CurrentHistLit;	/* Literal status of current show history line */
15321495Sjmacd
15421495Sjmacd/*
15521495Sjmacd * These are truly extern
15621495Sjmacd */
15721495Sjmacdextern int MacroLvl;
15821495Sjmacd
15921495SjmacdEXTERN Char *KeyMacro[MAXMACROLEVELS];
16021495Sjmacd
16121495SjmacdEXTERN Char **Display;		/* display buffer seed vector */
16221495SjmacdEXTERN int CursorV,		/* real cursor vertical (line) */
16321495Sjmacd        CursorH,		/* real cursor horisontal (column) */
16421495Sjmacd        TermV,			/* number of real screen lines
16521495Sjmacd				 * (sizeof(DisplayBuf) / width */
16621495Sjmacd        TermH;			/* screen width */
16793139SruEXTERN Char **Vdisplay;		/* new buffer */
16893139Sru
16993139Sru/* Variables that describe terminal ability */
17093139SruEXTERN int T_Lines, T_Cols;	/* Rows and Cols of the terminal */
17193139SruEXTERN Char T_CanIns;		/* true if I can insert characters */
17221495SjmacdEXTERN Char T_CanDel;		/* dito for delete characters */
17321495SjmacdEXTERN Char T_Tabs;		/* true if tty interface is passing tabs */
17442660SmarkmEXTERN Char T_Margin;
17521495Sjmacd#define MARGIN_AUTO  1		/* term has auto margins */
17621495Sjmacd#define MARGIN_MAGIC 2		/* concept glitch */
17721495SjmacdEXTERN speed_t T_Speed;		/* Tty input Baud rate */
17821495SjmacdEXTERN Char T_CanCEOL;		/* true if we can clear to end of line */
17921495SjmacdEXTERN Char T_CanUP;		/* true if this term can do reverse linefeen */
18021495SjmacdEXTERN Char T_HasMeta;		/* true if we have a meta key */
18142660Smarkm
18242660Smarkm/* note the extra characters in the Strchr() call in this macro */
18321495Sjmacd#define isword(c)	(Isalpha(c)||Isdigit(c)||Strchr(word_chars,c))
18442660Smarkm#define min(x,y)	(((x)<(y))?(x):(y))
18542660Smarkm#define max(x,y)	(((x)>(y))?(x):(y))
18642660Smarkm
18742660Smarkm/*
18821495Sjmacd * Terminal dependend data structures
18921495Sjmacd */
19021495Sjmacdtypedef struct {
19156160Sru#ifdef WINNT_NATIVE
19242660Smarkm    int dummy;
19321495Sjmacd#else /* !WINNT_NATIVE */
19421495Sjmacd# if defined(POSIX) || defined(TERMIO)
19521495Sjmacd#  ifdef POSIX
19621495Sjmacd    struct termios d_t;
19721495Sjmacd#  else
19821495Sjmacd    struct termio d_t;
19921495Sjmacd#  endif /* POSIX */
20042660Smarkm# else /* SGTTY */
20142660Smarkm#  ifdef TIOCGETP
20221495Sjmacd    struct sgttyb d_t;
20342660Smarkm#  endif /* TIOCGETP */
20421495Sjmacd#  ifdef TIOCGETC
20542660Smarkm    struct tchars d_tc;
20642660Smarkm#  endif /* TIOCGETC */
20742660Smarkm#  ifdef TIOCGPAGE
20842660Smarkm    struct ttypagestat d_pc;
20942660Smarkm#  endif /* TIOCGPAGE */
21042660Smarkm#  ifdef TIOCLGET
21142660Smarkm    int d_lb;
21242660Smarkm#  endif /* TIOCLGET */
21342660Smarkm# endif /* POSIX || TERMIO */
21442660Smarkm# ifdef TIOCGLTC
21542660Smarkm    struct ltchars d_ltc;
21621495Sjmacd# endif /* TIOCGLTC */
21742660Smarkm#endif /* WINNT_NATIVE */
21842660Smarkm} ttydata_t;
21942660Smarkm
22021495Sjmacd#define MODE_INSERT	0
22142660Smarkm#define MODE_REPLACE	1
22242660Smarkm#define MODE_REPLACE_1	2
22342660Smarkm
22442660Smarkm#define EX_IO	0	/* while we are executing	*/
22542660Smarkm#define ED_IO	1	/* while we are editing		*/
22642660Smarkm#define TS_IO	2	/* new mode from terminal	*/
22742660Smarkm#define QU_IO	2	/* used only for quoted chars	*/
22842660Smarkm#define NN_IO	3	/* The number of entries	*/
22942660Smarkm
23042660Smarkm#if defined(POSIX) || defined(TERMIO)
23142660Smarkm# define M_INPUT	0
23242660Smarkm# define M_OUTPUT	1
23342660Smarkm# define M_CONTROL	2
23421495Sjmacd# define M_LINED	3
23542660Smarkm# define M_CHAR		4
23621495Sjmacd# define M_NN		5
23742660Smarkm#else /* GSTTY */
23842660Smarkm# define M_CONTROL	0
23942660Smarkm# define M_LOCAL	1
24042660Smarkm# define M_CHAR		2
24121495Sjmacd# define M_NN		3
24242660Smarkm#endif /* TERMIO */
24342660Smarkmtypedef struct {
24442660Smarkm    char *t_name;
24542660Smarkm    int  t_setmask;
24642660Smarkm    int  t_clrmask;
24742660Smarkm} ttyperm_t[NN_IO][M_NN];
24821495Sjmacd
24921495Sjmacdextern ttyperm_t ttylist;
25021495Sjmacd#include "ed.decls.h"
25121495Sjmacd
25221495Sjmacd#endif /* _h_ed */
25356160Sru