ed.h revision 145479
1145479Smp/* $Header: /src/pub/tcsh/ed.h,v 3.44 2005/03/05 03:20:15 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 TABSIZE		8	/* usually 8 spaces/tab */
4159243Sobrien#define MAXMACROLEVELS	10	/* max number of nested kbd macros */
4259243Sobrien
4369408Sache#ifndef WINNT_NATIVE
4459243Sobrien# define NT_NUM_KEYS	256
4569408Sache#endif /* WINNT_NATIVE */
4659243Sobrien
4759243Sobrien/****************************************************************************/
4859243Sobrien/* stuff for the different states returned by the character editor routines */
4959243Sobrien/****************************************************************************/
5059243Sobrien
5159243Sobrien#define CCRETVAL	char	/* size needed for the different char editor */
5259243Sobrien /* return values */
5359243Sobrien
5459243Sobrien#define KEYCMD   unsigned char	/* size needed to index into CcFuncTbl */
5559243Sobrien /* Must be unsigned 		       */
5659243Sobrien
57145479Smptypedef CCRETVAL(*PFCmd) __P((Char));	/* pointer to function returning CCRETVAL */
5859243Sobrien
5959243Sobrienstruct KeyFuncs {		/* for the "bind" shell command */
60145479Smp    const char *name;		/* function name for bind command */
6159243Sobrien    int     func;		/* function numeric value */
62145479Smp    const char *desc;		/* description of function */
6359243Sobrien};
6459243Sobrien
6559243Sobrienextern PFCmd CcFuncTbl[];	/* table of available commands */
6659243Sobrienextern KEYCMD CcKeyMap[];	/* keymap table, each index into above tbl */
6759243Sobrienextern KEYCMD CcAltMap[];	/* Alt keymap table */
6859243Sobrienextern KEYCMD CcEmacsMap[];	/* keymap table for Emacs default bindings */
6959243Sobrienextern KEYCMD CcViCmdMap[];	/* for Vi command mode defaults */
7059243Sobrienextern struct KeyFuncs FuncNames[];	/* string names vs. CcFuncTbl indices */
7159243Sobrien
7259243Sobrienextern KEYCMD NumFuns;		/* number of KEYCMDs in above table */
7359243Sobrien
7459243Sobrien#define	CC_ERROR		100	/* there should NOT be 100 different... */
7559243Sobrien#define CC_FATAL		101	/* fatal error: inconsistant, must
7659243Sobrien					 * reset */
7759243Sobrien#define	CC_NORM			0
7859243Sobrien#define	CC_NEWLINE		1
7959243Sobrien#define	CC_EOF			2
8059243Sobrien#define	CC_COMPLETE		3
8159243Sobrien#define	CC_LIST_CHOICES		4
8259243Sobrien#define	CC_LIST_GLOB		5
8359243Sobrien#define CC_EXPAND_GLOB		6
8459243Sobrien#define	CC_HELPME		9
8559243Sobrien#define CC_CORRECT		10
8659243Sobrien#define CC_WHICH		11
8759243Sobrien#define CC_ARGHACK		12
8859243Sobrien#define CC_CORRECT_L		13
8959243Sobrien#define CC_REFRESH		14
9059243Sobrien#define CC_EXPAND_VARS		15
9159243Sobrien#define CC_NORMALIZE_PATH	16
9259243Sobrien#define CC_LIST_ALL		17
9359243Sobrien#define CC_COMPLETE_ALL		18
9459243Sobrien#define CC_COMPLETE_FWD		19
9559243Sobrien#define CC_COMPLETE_BACK	20
9659243Sobrien#define CC_NORMALIZE_COMMAND	21
9759243Sobrien
9859243Sobrientypedef struct {
9959243Sobrien    Char *buf;
10059243Sobrien    int   len;
10159243Sobrien} CStr;
10259243Sobrien
10359243Sobrientypedef union Xmapval {		/* value passed to the Xkey routines */
10459243Sobrien    KEYCMD cmd;
10559243Sobrien    CStr str;
10659243Sobrien} XmapVal;
10759243Sobrien
10859243Sobrien#define XK_NOD	-1		/* Internal tree node */
10959243Sobrien#define XK_CMD	 0		/* X-key was an editor command */
11059243Sobrien#define XK_STR	 1		/* X-key was a string macro */
11159243Sobrien#define XK_EXE	 2		/* X-key was a unix command */
11259243Sobrien
11359243Sobrien/****************************/
11459243Sobrien/* Editor state and buffers */
11559243Sobrien/****************************/
11659243Sobrien
11759243SobrienEXTERN KEYCMD *CurrentKeyMap;	/* current command key map */
11859243SobrienEXTERN int inputmode;		/* insert, replace, replace1 mode */
11959243SobrienEXTERN Char GettingInput;	/* true if getting an input line (mostly) */
12059243SobrienEXTERN Char NeedsRedraw;	/* for editor and twenex error messages */
12159243SobrienEXTERN Char InputBuf[INBUFSIZE];	/* the real input data */
12259243SobrienEXTERN Char *LastChar, *Cursor;	/* point to the next open space */
12359243SobrienEXTERN Char *InputLim;		/* limit of size of InputBuf */
12459243SobrienEXTERN Char MetaNext;		/* flags for ^V and ^[ functions */
12559243SobrienEXTERN Char AltKeyMap;		/* Using alternative command map (for vi mode) */
12659243SobrienEXTERN Char VImode;		/* true if running in vi mode (PWP 6-27-88) */
12759243SobrienEXTERN Char *Mark;		/* the emacs "mark" (dot is Cursor) */
12859243SobrienEXTERN Char DoingArg;		/* true if we have an argument */
12959243SobrienEXTERN int Argument;		/* "universal" argument value */
13059243SobrienEXTERN KEYCMD LastCmd;		/* previous command executed */
13183098SmpEXTERN CStr *KillRing;		/* kill ring */
13283098SmpEXTERN int KillRingMax;		/* max length of kill ring */
13383098SmpEXTERN int KillRingLen;		/* current length of kill ring */
13483098SmpEXTERN int KillPos;		/* points to next kill */
13583098SmpEXTERN int YankPos;		/* points to next yank */
13659243Sobrien
13759243SobrienEXTERN Char UndoBuf[INBUFSIZE];
13859243SobrienEXTERN Char *UndoPtr;
13959243SobrienEXTERN int  UndoSize;
14059243SobrienEXTERN int  UndoAction;
14159243Sobrien
14259243SobrienEXTERN Char HistBuf[INBUFSIZE];	/* history buffer */
14359243SobrienEXTERN Char *LastHist;		/* points to end of history buffer */
14459243SobrienEXTERN int Hist_num;		/* what point up the history we are at now. */
14559243SobrienEXTERN Char WhichBuf[INBUFSIZE];	/* buffer for which command */
14659243SobrienEXTERN Char *LastWhich;		/* points to end of which buffer */
14759243SobrienEXTERN Char *CursWhich;		/* points to the cursor point in which buf */
14859243SobrienEXTERN int HistWhich;		/* Hist_num is saved in this */
14959243SobrienEXTERN char Expand;		/* true if we are expanding a line */
15059243Sobrienextern Char HistLit;		/* true if history lines are shown literal */
15159243SobrienEXTERN Char CurrentHistLit;	/* Literal status of current show history line */
152145479Smpextern int Tty_raw_mode;
15359243Sobrien
15459243Sobrien/*
15559243Sobrien * These are truly extern
15659243Sobrien */
15759243Sobrienextern int MacroLvl;
158145479Smpextern Char *litptr;	 /* Entries start at offsets divisible by LIT_FACTOR */
159145479Smp#define LIT_FACTOR 4
160145479Smpextern int didsetty;
16159243Sobrien
16259243SobrienEXTERN Char *KeyMacro[MAXMACROLEVELS];
16359243Sobrien
164145479Smp/* CHAR_DBWIDTH in Display and Vdisplay means the non-first column of a character
165145479Smp   that is wider than one "regular" position. The cursor should never point
166145479Smp   in the middle of a multiple-column character. */
16759243SobrienEXTERN Char **Display;		/* display buffer seed vector */
16859243SobrienEXTERN int CursorV,		/* real cursor vertical (line) */
16959243Sobrien        CursorH,		/* real cursor horisontal (column) */
17059243Sobrien        TermV,			/* number of real screen lines
17159243Sobrien				 * (sizeof(DisplayBuf) / width */
17259243Sobrien        TermH;			/* screen width */
173145479SmpEXTERN Char **Vdisplay;	/* new buffer */
17459243Sobrien
17559243Sobrien/* Variables that describe terminal ability */
17659243SobrienEXTERN int T_Lines, T_Cols;	/* Rows and Cols of the terminal */
17759243SobrienEXTERN Char T_CanIns;		/* true if I can insert characters */
17859243SobrienEXTERN Char T_CanDel;		/* dito for delete characters */
17959243SobrienEXTERN Char T_Tabs;		/* true if tty interface is passing tabs */
18059243SobrienEXTERN Char T_Margin;
18159243Sobrien#define MARGIN_AUTO  1		/* term has auto margins */
18259243Sobrien#define MARGIN_MAGIC 2		/* concept glitch */
18359243SobrienEXTERN speed_t T_Speed;		/* Tty input Baud rate */
18459243SobrienEXTERN Char T_CanCEOL;		/* true if we can clear to end of line */
18559243SobrienEXTERN Char T_CanUP;		/* true if this term can do reverse linefeen */
18659243SobrienEXTERN Char T_HasMeta;		/* true if we have a meta key */
18759243Sobrien
18859243Sobrien/* note the extra characters in the Strchr() call in this macro */
18959243Sobrien#define isword(c)	(Isalpha(c)||Isdigit(c)||Strchr(word_chars,c))
19059243Sobrien#define min(x,y)	(((x)<(y))?(x):(y))
19159243Sobrien#define max(x,y)	(((x)>(y))?(x):(y))
19259243Sobrien
19359243Sobrien#define MODE_INSERT	0
19459243Sobrien#define MODE_REPLACE	1
19559243Sobrien#define MODE_REPLACE_1	2
19659243Sobrien
19759243Sobrien#define EX_IO	0	/* while we are executing	*/
19859243Sobrien#define ED_IO	1	/* while we are editing		*/
19959243Sobrien#define TS_IO	2	/* new mode from terminal	*/
20059243Sobrien#define QU_IO	2	/* used only for quoted chars	*/
20159243Sobrien#define NN_IO	3	/* The number of entries	*/
20259243Sobrien
20359243Sobrien#if defined(POSIX) || defined(TERMIO)
20459243Sobrien# define M_INPUT	0
20559243Sobrien# define M_OUTPUT	1
20659243Sobrien# define M_CONTROL	2
20759243Sobrien# define M_LINED	3
20859243Sobrien# define M_CHAR		4
20959243Sobrien# define M_NN		5
21059243Sobrien#else /* GSTTY */
21159243Sobrien# define M_CONTROL	0
21259243Sobrien# define M_LOCAL	1
21359243Sobrien# define M_CHAR		2
21459243Sobrien# define M_NN		3
21559243Sobrien#endif /* TERMIO */
21659243Sobrientypedef struct {
217145479Smp    const char *t_name;
218145479Smp    unsigned int  t_setmask;
219145479Smp    unsigned int  t_clrmask;
22059243Sobrien} ttyperm_t[NN_IO][M_NN];
22159243Sobrien
22259243Sobrienextern ttyperm_t ttylist;
223100616Smp#include "ed.term.h"
22459243Sobrien#include "ed.decls.h"
22559243Sobrien
226145479Smp#ifndef POSIX
227145479Smp/*
228145479Smp * We don't prototype these, cause some systems have them wrong!
229145479Smp */
230145479Smpextern int   tgetent	__P(());
231145479Smpextern char *tgetstr	__P(());
232145479Smpextern int   tgetflag	__P(());
233145479Smpextern int   tgetnum	__P(());
234145479Smpextern char *tgoto	__P(());
235145479Smp# define PUTPURE putpure
236145479Smp# define PUTRAW putraw
237145479Smp#else
238145479Smpextern int   tgetent	__P((char *, const char *));
239145479Smpextern char *tgetstr	__P((const char *, char **));
240145479Smpextern int   tgetflag	__P((const char *));
241145479Smpextern int   tgetnum	__P((const char *));
242145479Smpextern char *tgoto	__P((const char *, int, int));
243145479Smpextern void  tputs	__P((const char *, int, void (*)(int)));
244145479Smp# define PUTPURE ((void (*)__P((int))) putpure)
245145479Smp# define PUTRAW ((void (*)__P((int))) putraw)
246145479Smp#endif
247145479Smp
24859243Sobrien#endif /* _h_ed */
249