17d8fb588SMatthias Schmidt /*
27d8fb588SMatthias Schmidt * ed.h: Editor declarations and globals
37d8fb588SMatthias Schmidt */
47d8fb588SMatthias Schmidt /*-
57d8fb588SMatthias Schmidt * Copyright (c) 1980, 1991 The Regents of the University of California.
67d8fb588SMatthias Schmidt * All rights reserved.
77d8fb588SMatthias Schmidt *
87d8fb588SMatthias Schmidt * Redistribution and use in source and binary forms, with or without
97d8fb588SMatthias Schmidt * modification, are permitted provided that the following conditions
107d8fb588SMatthias Schmidt * are met:
117d8fb588SMatthias Schmidt * 1. Redistributions of source code must retain the above copyright
127d8fb588SMatthias Schmidt * notice, this list of conditions and the following disclaimer.
137d8fb588SMatthias Schmidt * 2. Redistributions in binary form must reproduce the above copyright
147d8fb588SMatthias Schmidt * notice, this list of conditions and the following disclaimer in the
157d8fb588SMatthias Schmidt * documentation and/or other materials provided with the distribution.
167d8fb588SMatthias Schmidt * 3. Neither the name of the University nor the names of its contributors
177d8fb588SMatthias Schmidt * may be used to endorse or promote products derived from this software
187d8fb588SMatthias Schmidt * without specific prior written permission.
197d8fb588SMatthias Schmidt *
207d8fb588SMatthias Schmidt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
217d8fb588SMatthias Schmidt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
227d8fb588SMatthias Schmidt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
237d8fb588SMatthias Schmidt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
247d8fb588SMatthias Schmidt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
257d8fb588SMatthias Schmidt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
267d8fb588SMatthias Schmidt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
277d8fb588SMatthias Schmidt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
287d8fb588SMatthias Schmidt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
297d8fb588SMatthias Schmidt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
307d8fb588SMatthias Schmidt * SUCH DAMAGE.
317d8fb588SMatthias Schmidt */
327d8fb588SMatthias Schmidt #ifndef _h_ed
337d8fb588SMatthias Schmidt #define _h_ed
347d8fb588SMatthias Schmidt
357d8fb588SMatthias Schmidt #ifndef EXTERN
367d8fb588SMatthias Schmidt # define EXTERN extern
377d8fb588SMatthias Schmidt #endif
387d8fb588SMatthias Schmidt
397d8fb588SMatthias Schmidt #define MAXMACROLEVELS 10 /* max number of nested kbd macros */
407d8fb588SMatthias Schmidt
417d8fb588SMatthias Schmidt #ifndef WINNT_NATIVE
427d8fb588SMatthias Schmidt # define NT_NUM_KEYS 256
437d8fb588SMatthias Schmidt #endif /* WINNT_NATIVE */
447d8fb588SMatthias Schmidt
4557e3f2b5SSimon 'corecode' Schubert #ifdef __QNXNTO__
4657e3f2b5SSimon 'corecode' Schubert #undef min
4757e3f2b5SSimon 'corecode' Schubert #undef max
4857e3f2b5SSimon 'corecode' Schubert #endif
4957e3f2b5SSimon 'corecode' Schubert
507d8fb588SMatthias Schmidt /****************************************************************************/
517d8fb588SMatthias Schmidt /* stuff for the different states returned by the character editor routines */
527d8fb588SMatthias Schmidt /****************************************************************************/
537d8fb588SMatthias Schmidt
547d8fb588SMatthias Schmidt #define CCRETVAL char /* size needed for the different char editor */
557d8fb588SMatthias Schmidt /* return values */
567d8fb588SMatthias Schmidt
577d8fb588SMatthias Schmidt #define KEYCMD unsigned char /* size needed to index into CcFuncTbl */
587d8fb588SMatthias Schmidt /* Must be unsigned */
597d8fb588SMatthias Schmidt
607d8fb588SMatthias Schmidt typedef CCRETVAL(*PFCmd) (Char); /* pointer to function returning CCRETVAL */
617d8fb588SMatthias Schmidt
627d8fb588SMatthias Schmidt struct KeyFuncs { /* for the "bind" shell command */
637d8fb588SMatthias Schmidt const char *name; /* function name for bind command */
647d8fb588SMatthias Schmidt int func; /* function numeric value */
657d8fb588SMatthias Schmidt const char *desc; /* description of function */
667d8fb588SMatthias Schmidt };
677d8fb588SMatthias Schmidt
687d8fb588SMatthias Schmidt extern PFCmd CcFuncTbl[]; /* table of available commands */
697d8fb588SMatthias Schmidt extern KEYCMD CcKeyMap[]; /* keymap table, each index into above tbl */
707d8fb588SMatthias Schmidt extern KEYCMD CcAltMap[]; /* Alt keymap table */
717d8fb588SMatthias Schmidt extern KEYCMD CcEmacsMap[]; /* keymap table for Emacs default bindings */
727d8fb588SMatthias Schmidt extern KEYCMD CcViCmdMap[]; /* for Vi command mode defaults */
737d8fb588SMatthias Schmidt extern struct KeyFuncs FuncNames[]; /* string names vs. CcFuncTbl indices */
747d8fb588SMatthias Schmidt
757d8fb588SMatthias Schmidt extern KEYCMD NumFuns; /* number of KEYCMDs in above table */
767d8fb588SMatthias Schmidt
777d8fb588SMatthias Schmidt #define CC_ERROR 100 /* there should NOT be 100 different... */
787d8fb588SMatthias Schmidt #define CC_FATAL 101 /* fatal error: inconsistant, must
797d8fb588SMatthias Schmidt * reset */
807d8fb588SMatthias Schmidt #define CC_NORM 0
817d8fb588SMatthias Schmidt #define CC_NEWLINE 1
827d8fb588SMatthias Schmidt #define CC_EOF 2
837d8fb588SMatthias Schmidt #define CC_COMPLETE 3
847d8fb588SMatthias Schmidt #define CC_LIST_CHOICES 4
857d8fb588SMatthias Schmidt #define CC_LIST_GLOB 5
867d8fb588SMatthias Schmidt #define CC_EXPAND_GLOB 6
877d8fb588SMatthias Schmidt #define CC_HELPME 9
887d8fb588SMatthias Schmidt #define CC_CORRECT 10
897d8fb588SMatthias Schmidt #define CC_WHICH 11
907d8fb588SMatthias Schmidt #define CC_ARGHACK 12
917d8fb588SMatthias Schmidt #define CC_CORRECT_L 13
927d8fb588SMatthias Schmidt #define CC_REFRESH 14
937d8fb588SMatthias Schmidt #define CC_EXPAND_VARS 15
947d8fb588SMatthias Schmidt #define CC_NORMALIZE_PATH 16
957d8fb588SMatthias Schmidt #define CC_LIST_ALL 17
967d8fb588SMatthias Schmidt #define CC_COMPLETE_ALL 18
977d8fb588SMatthias Schmidt #define CC_COMPLETE_FWD 19
987d8fb588SMatthias Schmidt #define CC_COMPLETE_BACK 20
997d8fb588SMatthias Schmidt #define CC_NORMALIZE_COMMAND 21
1007d8fb588SMatthias Schmidt
1017d8fb588SMatthias Schmidt typedef struct {
1027d8fb588SMatthias Schmidt Char *buf;
1037d8fb588SMatthias Schmidt int len;
1047d8fb588SMatthias Schmidt } CStr;
1057d8fb588SMatthias Schmidt
1067d8fb588SMatthias Schmidt typedef union { /* value passed to the Xkey routines */
1077d8fb588SMatthias Schmidt KEYCMD cmd;
1087d8fb588SMatthias Schmidt CStr str;
1097d8fb588SMatthias Schmidt } XmapVal;
1107d8fb588SMatthias Schmidt
1117d8fb588SMatthias Schmidt #define XK_NOD -1 /* Internal tree node */
1127d8fb588SMatthias Schmidt #define XK_CMD 0 /* X-key was an editor command */
1137d8fb588SMatthias Schmidt #define XK_STR 1 /* X-key was a string macro */
1147d8fb588SMatthias Schmidt #define XK_EXE 2 /* X-key was a unix command */
1157d8fb588SMatthias Schmidt
1167d8fb588SMatthias Schmidt /****************************/
1177d8fb588SMatthias Schmidt /* Editor state and buffers */
1187d8fb588SMatthias Schmidt /****************************/
1197d8fb588SMatthias Schmidt
1207d8fb588SMatthias Schmidt EXTERN KEYCMD *CurrentKeyMap; /* current command key map */
1217d8fb588SMatthias Schmidt EXTERN int inputmode; /* insert, replace, replace1 mode */
1227d8fb588SMatthias Schmidt EXTERN Char GettingInput; /* true if getting an input line (mostly) */
1237d8fb588SMatthias Schmidt EXTERN Char NeedsRedraw; /* for editor and twenex error messages */
1247d8fb588SMatthias Schmidt EXTERN Char InputBuf[INBUFSIZE]; /* the real input data *//*FIXBUF*/
1257d8fb588SMatthias Schmidt EXTERN Char *LastChar, *Cursor; /* point to the next open space */
1267d8fb588SMatthias Schmidt EXTERN Char *InputLim; /* limit of size of InputBuf */
1277d8fb588SMatthias Schmidt EXTERN Char MetaNext; /* flags for ^V and ^[ functions */
1287d8fb588SMatthias Schmidt EXTERN Char AltKeyMap; /* Using alternative command map (for vi mode) */
1297d8fb588SMatthias Schmidt EXTERN Char VImode; /* true if running in vi mode (PWP 6-27-88) */
1307d8fb588SMatthias Schmidt EXTERN Char *Mark; /* the emacs "mark" (dot is Cursor) */
1317d8fb588SMatthias Schmidt EXTERN char MarkIsSet; /* true if the mark has been set explicitly */
1327d8fb588SMatthias Schmidt EXTERN Char DoingArg; /* true if we have an argument */
1337d8fb588SMatthias Schmidt EXTERN int Argument; /* "universal" argument value */
1347d8fb588SMatthias Schmidt EXTERN KEYCMD LastCmd; /* previous command executed */
1357d8fb588SMatthias Schmidt EXTERN CStr *KillRing; /* kill ring */
1367d8fb588SMatthias Schmidt EXTERN int KillRingMax; /* max length of kill ring */
1377d8fb588SMatthias Schmidt EXTERN int KillRingLen; /* current length of kill ring */
1387d8fb588SMatthias Schmidt EXTERN int KillPos; /* points to next kill */
1397d8fb588SMatthias Schmidt EXTERN int YankPos; /* points to next yank */
1407d8fb588SMatthias Schmidt
1417d8fb588SMatthias Schmidt EXTERN Char UndoBuf[INBUFSIZE];/*FIXBUF*/
1427d8fb588SMatthias Schmidt EXTERN Char *UndoPtr;
1437d8fb588SMatthias Schmidt EXTERN int UndoSize;
1447d8fb588SMatthias Schmidt EXTERN int UndoAction;
1457d8fb588SMatthias Schmidt
1467d8fb588SMatthias Schmidt EXTERN struct Strbuf HistBuf; /* = Strbuf_INIT; history buffer */
1477d8fb588SMatthias Schmidt EXTERN int Hist_num; /* what point up the history we are at now. */
1487d8fb588SMatthias Schmidt /* buffer for which command and others */
1497d8fb588SMatthias Schmidt EXTERN struct Strbuf SavedBuf; /* = Strbuf_INIT; */
1507d8fb588SMatthias Schmidt EXTERN size_t LastSaved; /* points to end of saved buffer */
1517d8fb588SMatthias Schmidt EXTERN size_t CursSaved; /* points to the cursor point in saved buf */
1527d8fb588SMatthias Schmidt EXTERN int HistSaved; /* Hist_num is saved in this */
1537d8fb588SMatthias Schmidt EXTERN char RestoreSaved; /* true if SavedBuf should be restored */
1547d8fb588SMatthias Schmidt EXTERN int IncMatchLen; /* current match length during incremental search */
1557d8fb588SMatthias Schmidt EXTERN char Expand; /* true if we are expanding a line */
1567d8fb588SMatthias Schmidt extern Char HistLit; /* true if history lines are shown literal */
1577d8fb588SMatthias Schmidt EXTERN Char CurrentHistLit; /* Literal status of current show history line */
1587d8fb588SMatthias Schmidt extern int Tty_raw_mode;
1597d8fb588SMatthias Schmidt
1607d8fb588SMatthias Schmidt /*
1617d8fb588SMatthias Schmidt * These are truly extern
1627d8fb588SMatthias Schmidt */
1637d8fb588SMatthias Schmidt extern int MacroLvl;
1647d8fb588SMatthias Schmidt extern Char *litptr; /* Entries start at offsets divisible by LIT_FACTOR */
1657d8fb588SMatthias Schmidt #define LIT_FACTOR 4
1667d8fb588SMatthias Schmidt extern int didsetty;
1677d8fb588SMatthias Schmidt
1687d8fb588SMatthias Schmidt EXTERN Char *KeyMacro[MAXMACROLEVELS];
1697d8fb588SMatthias Schmidt
1707d8fb588SMatthias Schmidt /* CHAR_DBWIDTH in Display and Vdisplay means the non-first column of a character
1717d8fb588SMatthias Schmidt that is wider than one "regular" position. The cursor should never point
1727d8fb588SMatthias Schmidt in the middle of a multiple-column character. */
1737d8fb588SMatthias Schmidt EXTERN Char **Display; /* display buffer seed vector */
1747d8fb588SMatthias Schmidt EXTERN int CursorV, /* real cursor vertical (line) */
1757d8fb588SMatthias Schmidt CursorH, /* real cursor horisontal (column) */
1767d8fb588SMatthias Schmidt TermV, /* number of real screen lines
1777d8fb588SMatthias Schmidt * (sizeof(DisplayBuf) / width */
1787d8fb588SMatthias Schmidt TermH; /* screen width */
1797d8fb588SMatthias Schmidt EXTERN Char **Vdisplay; /* new buffer */
1807d8fb588SMatthias Schmidt
1817d8fb588SMatthias Schmidt /* Variables that describe terminal ability */
1827d8fb588SMatthias Schmidt EXTERN int T_Lines, T_Cols; /* Rows and Cols of the terminal */
1837d8fb588SMatthias Schmidt EXTERN Char T_CanIns; /* true if I can insert characters */
1847d8fb588SMatthias Schmidt EXTERN Char T_CanDel; /* dito for delete characters */
1857d8fb588SMatthias Schmidt EXTERN char T_Tabs; /* true if tty interface is passing tabs */
1867d8fb588SMatthias Schmidt EXTERN char T_Margin;
1877d8fb588SMatthias Schmidt #define MARGIN_AUTO 1 /* term has auto margins */
1887d8fb588SMatthias Schmidt #define MARGIN_MAGIC 2 /* concept glitch */
1897d8fb588SMatthias Schmidt EXTERN speed_t T_Speed; /* Tty input Baud rate */
1907d8fb588SMatthias Schmidt EXTERN Char T_CanCEOL; /* true if we can clear to end of line */
1917d8fb588SMatthias Schmidt EXTERN Char T_CanUP; /* true if this term can do reverse linefeen */
1927d8fb588SMatthias Schmidt EXTERN char T_HasMeta; /* true if we have a meta key */
1937d8fb588SMatthias Schmidt
1947d8fb588SMatthias Schmidt /* note the extra characters in the Strchr() call in this macro */
1957d8fb588SMatthias Schmidt #define isword(c) (Isalpha(c)||Isdigit(c)||Strchr(word_chars,c))
1967d8fb588SMatthias Schmidt #define min(x,y) (((x)<(y))?(x):(y))
1977d8fb588SMatthias Schmidt #define max(x,y) (((x)>(y))?(x):(y))
1987d8fb588SMatthias Schmidt
1997d8fb588SMatthias Schmidt #define MODE_INSERT 0
2007d8fb588SMatthias Schmidt #define MODE_REPLACE 1
2017d8fb588SMatthias Schmidt #define MODE_REPLACE_1 2
2027d8fb588SMatthias Schmidt
2037d8fb588SMatthias Schmidt #define EX_IO 0 /* while we are executing */
2047d8fb588SMatthias Schmidt #define ED_IO 1 /* while we are editing */
2057d8fb588SMatthias Schmidt #define TS_IO 2 /* new mode from terminal */
2067d8fb588SMatthias Schmidt #define QU_IO 2 /* used only for quoted chars */
2077d8fb588SMatthias Schmidt #define NN_IO 3 /* The number of entries */
2087d8fb588SMatthias Schmidt
2097d8fb588SMatthias Schmidt #if defined(POSIX) || defined(TERMIO)
2107d8fb588SMatthias Schmidt # define M_INPUT 0
2117d8fb588SMatthias Schmidt # define M_OUTPUT 1
2127d8fb588SMatthias Schmidt # define M_CONTROL 2
2137d8fb588SMatthias Schmidt # define M_LINED 3
2147d8fb588SMatthias Schmidt # define M_CHAR 4
2157d8fb588SMatthias Schmidt # define M_NN 5
2167d8fb588SMatthias Schmidt #else /* GSTTY */
2177d8fb588SMatthias Schmidt # define M_CONTROL 0
2187d8fb588SMatthias Schmidt # define M_LOCAL 1
2197d8fb588SMatthias Schmidt # define M_CHAR 2
2207d8fb588SMatthias Schmidt # define M_NN 3
2217d8fb588SMatthias Schmidt #endif /* TERMIO */
2227d8fb588SMatthias Schmidt typedef struct {
2237d8fb588SMatthias Schmidt const char *t_name;
2247d8fb588SMatthias Schmidt unsigned int t_setmask;
2257d8fb588SMatthias Schmidt unsigned int t_clrmask;
2267d8fb588SMatthias Schmidt } ttyperm_t[NN_IO][M_NN];
2277d8fb588SMatthias Schmidt
2287d8fb588SMatthias Schmidt extern ttyperm_t ttylist;
2297d8fb588SMatthias Schmidt #include "ed.term.h"
2307d8fb588SMatthias Schmidt #include "ed.decls.h"
2317d8fb588SMatthias Schmidt
2327d8fb588SMatthias Schmidt #ifndef POSIX
2337d8fb588SMatthias Schmidt /*
2347d8fb588SMatthias Schmidt * We don't prototype these, cause some systems have them wrong!
2357d8fb588SMatthias Schmidt */
2367d8fb588SMatthias Schmidt extern int tgetent ();
2377d8fb588SMatthias Schmidt extern char *tgetstr ();
2387d8fb588SMatthias Schmidt extern int tgetflag ();
2397d8fb588SMatthias Schmidt extern int tgetnum ();
2407d8fb588SMatthias Schmidt extern char *tgoto ();
2417d8fb588SMatthias Schmidt # define PUTPURE putpure
2427d8fb588SMatthias Schmidt # define PUTRAW putraw
2437d8fb588SMatthias Schmidt #else
2447d8fb588SMatthias Schmidt extern int tgetent (char *, const char *);
2457d8fb588SMatthias Schmidt extern char *tgetstr (const char *, char **);
2467d8fb588SMatthias Schmidt extern int tgetflag (const char *);
2477d8fb588SMatthias Schmidt extern int tgetnum (const char *);
2487d8fb588SMatthias Schmidt extern char *tgoto (const char *, int, int);
2497d8fb588SMatthias Schmidt extern void tputs (const char *, int, void (*)(int));
PUTPURE(int c)250*d6ab524cSAntonio Huete Jimenez static __inline void PUTPURE(int c) {
251*d6ab524cSAntonio Huete Jimenez (void)putpure(c);
252*d6ab524cSAntonio Huete Jimenez }
PUTRAW(int c)253*d6ab524cSAntonio Huete Jimenez static __inline void PUTRAW(int c) {
254*d6ab524cSAntonio Huete Jimenez (void)putraw(c);
255*d6ab524cSAntonio Huete Jimenez }
2567d8fb588SMatthias Schmidt #endif
2577d8fb588SMatthias Schmidt
2587d8fb588SMatthias Schmidt #endif /* _h_ed */
259