ed.h revision 69408
169408Sache/* $Header: /src/pub/tcsh/ed.h,v 3.30 2000/11/11 23:03:34 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
4769408Sache#ifndef WINNT_NATIVE
4859243Sobrien# define NT_NUM_KEYS	256
4969408Sache#endif /* WINNT_NATIVE */
5059243Sobrien
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
6159243Sobrientypedef CCRETVAL(*PFCmd) __P((int));	/* pointer to function returning CCRETVAL */
6259243Sobrien
6359243Sobrienstruct KeyFuncs {		/* for the "bind" shell command */
6459243Sobrien    char   *name;		/* function name for bind command */
6559243Sobrien    int     func;		/* function numeric value */
6659243Sobrien    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
10759243Sobrientypedef union Xmapval {		/* 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 */
12559243SobrienEXTERN Char InputBuf[INBUFSIZE];	/* the real input data */
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) */
13259243SobrienEXTERN Char DoingArg;		/* true if we have an argument */
13359243SobrienEXTERN int Argument;		/* "universal" argument value */
13459243SobrienEXTERN KEYCMD LastCmd;		/* previous command executed */
13559243SobrienEXTERN Char KillBuf[INBUFSIZE];	/* kill buffer */
13659243SobrienEXTERN Char *LastKill;		/* points to end of kill buffer */
13759243Sobrien
13859243SobrienEXTERN Char UndoBuf[INBUFSIZE];
13959243SobrienEXTERN Char *UndoPtr;
14059243SobrienEXTERN int  UndoSize;
14159243SobrienEXTERN int  UndoAction;
14259243Sobrien
14359243SobrienEXTERN Char HistBuf[INBUFSIZE];	/* history buffer */
14459243SobrienEXTERN Char *LastHist;		/* points to end of history buffer */
14559243SobrienEXTERN int Hist_num;		/* what point up the history we are at now. */
14659243SobrienEXTERN Char WhichBuf[INBUFSIZE];	/* buffer for which command */
14759243SobrienEXTERN Char *LastWhich;		/* points to end of which buffer */
14859243SobrienEXTERN Char *CursWhich;		/* points to the cursor point in which buf */
14959243SobrienEXTERN int HistWhich;		/* Hist_num is saved in this */
15059243SobrienEXTERN char Expand;		/* true if we are expanding a line */
15159243Sobrienextern Char HistLit;		/* true if history lines are shown literal */
15259243SobrienEXTERN Char CurrentHistLit;	/* Literal status of current show history line */
15359243Sobrien
15459243Sobrien/*
15559243Sobrien * These are truly extern
15659243Sobrien */
15759243Sobrienextern int MacroLvl;
15859243Sobrien
15959243SobrienEXTERN Char *KeyMacro[MAXMACROLEVELS];
16059243Sobrien
16159243SobrienEXTERN Char **Display;		/* display buffer seed vector */
16259243SobrienEXTERN int CursorV,		/* real cursor vertical (line) */
16359243Sobrien        CursorH,		/* real cursor horisontal (column) */
16459243Sobrien        TermV,			/* number of real screen lines
16559243Sobrien				 * (sizeof(DisplayBuf) / width */
16659243Sobrien        TermH;			/* screen width */
16759243SobrienEXTERN Char **Vdisplay;		/* new buffer */
16859243Sobrien
16959243Sobrien/* Variables that describe terminal ability */
17059243SobrienEXTERN int T_Lines, T_Cols;	/* Rows and Cols of the terminal */
17159243SobrienEXTERN Char T_CanIns;		/* true if I can insert characters */
17259243SobrienEXTERN Char T_CanDel;		/* dito for delete characters */
17359243SobrienEXTERN Char T_Tabs;		/* true if tty interface is passing tabs */
17459243SobrienEXTERN Char T_Margin;
17559243Sobrien#define MARGIN_AUTO  1		/* term has auto margins */
17659243Sobrien#define MARGIN_MAGIC 2		/* concept glitch */
17759243SobrienEXTERN speed_t T_Speed;		/* Tty input Baud rate */
17859243SobrienEXTERN Char T_CanCEOL;		/* true if we can clear to end of line */
17959243SobrienEXTERN Char T_CanUP;		/* true if this term can do reverse linefeen */
18059243SobrienEXTERN Char T_HasMeta;		/* true if we have a meta key */
18159243Sobrien
18259243Sobrien/* note the extra characters in the Strchr() call in this macro */
18359243Sobrien#define isword(c)	(Isalpha(c)||Isdigit(c)||Strchr(word_chars,c))
18459243Sobrien#define min(x,y)	(((x)<(y))?(x):(y))
18559243Sobrien#define max(x,y)	(((x)>(y))?(x):(y))
18659243Sobrien
18759243Sobrien/*
18859243Sobrien * Terminal dependend data structures
18959243Sobrien */
19059243Sobrientypedef struct {
19169408Sache#ifdef WINNT_NATIVE
19259243Sobrien    int dummy;
19369408Sache#else /* !WINNT_NATIVE */
19459243Sobrien# if defined(POSIX) || defined(TERMIO)
19559243Sobrien#  ifdef POSIX
19659243Sobrien    struct termios d_t;
19759243Sobrien#  else
19859243Sobrien    struct termio d_t;
19959243Sobrien#  endif /* POSIX */
20059243Sobrien# else /* SGTTY */
20159243Sobrien#  ifdef TIOCGETP
20259243Sobrien    struct sgttyb d_t;
20359243Sobrien#  endif /* TIOCGETP */
20459243Sobrien#  ifdef TIOCGETC
20559243Sobrien    struct tchars d_tc;
20659243Sobrien#  endif /* TIOCGETC */
20759243Sobrien#  ifdef TIOCGPAGE
20859243Sobrien    struct ttypagestat d_pc;
20959243Sobrien#  endif /* TIOCGPAGE */
21059243Sobrien#  ifdef TIOCLGET
21159243Sobrien    int d_lb;
21259243Sobrien#  endif /* TIOCLGET */
21359243Sobrien# endif /* POSIX || TERMIO */
21459243Sobrien# ifdef TIOCGLTC
21559243Sobrien    struct ltchars d_ltc;
21659243Sobrien# endif /* TIOCGLTC */
21769408Sache#endif /* WINNT_NATIVE */
21859243Sobrien} ttydata_t;
21959243Sobrien
22059243Sobrien#define MODE_INSERT	0
22159243Sobrien#define MODE_REPLACE	1
22259243Sobrien#define MODE_REPLACE_1	2
22359243Sobrien
22459243Sobrien#define EX_IO	0	/* while we are executing	*/
22559243Sobrien#define ED_IO	1	/* while we are editing		*/
22659243Sobrien#define TS_IO	2	/* new mode from terminal	*/
22759243Sobrien#define QU_IO	2	/* used only for quoted chars	*/
22859243Sobrien#define NN_IO	3	/* The number of entries	*/
22959243Sobrien
23059243Sobrien#if defined(POSIX) || defined(TERMIO)
23159243Sobrien# define M_INPUT	0
23259243Sobrien# define M_OUTPUT	1
23359243Sobrien# define M_CONTROL	2
23459243Sobrien# define M_LINED	3
23559243Sobrien# define M_CHAR		4
23659243Sobrien# define M_NN		5
23759243Sobrien#else /* GSTTY */
23859243Sobrien# define M_CONTROL	0
23959243Sobrien# define M_LOCAL	1
24059243Sobrien# define M_CHAR		2
24159243Sobrien# define M_NN		3
24259243Sobrien#endif /* TERMIO */
24359243Sobrientypedef struct {
24459243Sobrien    char *t_name;
24559243Sobrien    int  t_setmask;
24659243Sobrien    int  t_clrmask;
24759243Sobrien} ttyperm_t[NN_IO][M_NN];
24859243Sobrien
24959243Sobrienextern ttyperm_t ttylist;
25059243Sobrien#include "ed.decls.h"
25159243Sobrien
25259243Sobrien#endif /* _h_ed */
253