/contrib/tcsh/ed.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 255 lines · 171 code · 30 blank · 54 comment · 1 complexity · 52e17d08a8470f08a8c37d10fb3822c7 MD5 · raw file

  1. /* $Header: /p/tcsh/cvsroot/tcsh/ed.h,v 3.50 2007/07/05 14:13:06 christos Exp $ */
  2. /*
  3. * ed.h: Editor declarations and globals
  4. */
  5. /*-
  6. * Copyright (c) 1980, 1991 The Regents of the University of California.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. */
  33. #ifndef _h_ed
  34. #define _h_ed
  35. #ifndef EXTERN
  36. # define EXTERN extern
  37. #endif
  38. #define MAXMACROLEVELS 10 /* max number of nested kbd macros */
  39. #ifndef WINNT_NATIVE
  40. # define NT_NUM_KEYS 256
  41. #endif /* WINNT_NATIVE */
  42. #ifdef __QNXNTO__
  43. #undef min
  44. #undef max
  45. #endif
  46. /****************************************************************************/
  47. /* stuff for the different states returned by the character editor routines */
  48. /****************************************************************************/
  49. #define CCRETVAL char /* size needed for the different char editor */
  50. /* return values */
  51. #define KEYCMD unsigned char /* size needed to index into CcFuncTbl */
  52. /* Must be unsigned */
  53. typedef CCRETVAL(*PFCmd) (Char); /* pointer to function returning CCRETVAL */
  54. struct KeyFuncs { /* for the "bind" shell command */
  55. const char *name; /* function name for bind command */
  56. int func; /* function numeric value */
  57. const char *desc; /* description of function */
  58. };
  59. extern PFCmd CcFuncTbl[]; /* table of available commands */
  60. extern KEYCMD CcKeyMap[]; /* keymap table, each index into above tbl */
  61. extern KEYCMD CcAltMap[]; /* Alt keymap table */
  62. extern KEYCMD CcEmacsMap[]; /* keymap table for Emacs default bindings */
  63. extern KEYCMD CcViCmdMap[]; /* for Vi command mode defaults */
  64. extern struct KeyFuncs FuncNames[]; /* string names vs. CcFuncTbl indices */
  65. extern KEYCMD NumFuns; /* number of KEYCMDs in above table */
  66. #define CC_ERROR 100 /* there should NOT be 100 different... */
  67. #define CC_FATAL 101 /* fatal error: inconsistant, must
  68. * reset */
  69. #define CC_NORM 0
  70. #define CC_NEWLINE 1
  71. #define CC_EOF 2
  72. #define CC_COMPLETE 3
  73. #define CC_LIST_CHOICES 4
  74. #define CC_LIST_GLOB 5
  75. #define CC_EXPAND_GLOB 6
  76. #define CC_HELPME 9
  77. #define CC_CORRECT 10
  78. #define CC_WHICH 11
  79. #define CC_ARGHACK 12
  80. #define CC_CORRECT_L 13
  81. #define CC_REFRESH 14
  82. #define CC_EXPAND_VARS 15
  83. #define CC_NORMALIZE_PATH 16
  84. #define CC_LIST_ALL 17
  85. #define CC_COMPLETE_ALL 18
  86. #define CC_COMPLETE_FWD 19
  87. #define CC_COMPLETE_BACK 20
  88. #define CC_NORMALIZE_COMMAND 21
  89. typedef struct {
  90. Char *buf;
  91. int len;
  92. } CStr;
  93. typedef union { /* value passed to the Xkey routines */
  94. KEYCMD cmd;
  95. CStr str;
  96. } XmapVal;
  97. #define XK_NOD -1 /* Internal tree node */
  98. #define XK_CMD 0 /* X-key was an editor command */
  99. #define XK_STR 1 /* X-key was a string macro */
  100. #define XK_EXE 2 /* X-key was a unix command */
  101. /****************************/
  102. /* Editor state and buffers */
  103. /****************************/
  104. EXTERN KEYCMD *CurrentKeyMap; /* current command key map */
  105. EXTERN int inputmode; /* insert, replace, replace1 mode */
  106. EXTERN Char GettingInput; /* true if getting an input line (mostly) */
  107. EXTERN Char NeedsRedraw; /* for editor and twenex error messages */
  108. EXTERN Char InputBuf[INBUFSIZE]; /* the real input data *//*FIXBUF*/
  109. EXTERN Char *LastChar, *Cursor; /* point to the next open space */
  110. EXTERN Char *InputLim; /* limit of size of InputBuf */
  111. EXTERN Char MetaNext; /* flags for ^V and ^[ functions */
  112. EXTERN Char AltKeyMap; /* Using alternative command map (for vi mode) */
  113. EXTERN Char VImode; /* true if running in vi mode (PWP 6-27-88) */
  114. EXTERN Char *Mark; /* the emacs "mark" (dot is Cursor) */
  115. EXTERN char MarkIsSet; /* true if the mark has been set explicitly */
  116. EXTERN Char DoingArg; /* true if we have an argument */
  117. EXTERN int Argument; /* "universal" argument value */
  118. EXTERN KEYCMD LastCmd; /* previous command executed */
  119. EXTERN CStr *KillRing; /* kill ring */
  120. EXTERN int KillRingMax; /* max length of kill ring */
  121. EXTERN int KillRingLen; /* current length of kill ring */
  122. EXTERN int KillPos; /* points to next kill */
  123. EXTERN int YankPos; /* points to next yank */
  124. EXTERN Char UndoBuf[INBUFSIZE];/*FIXBUF*/
  125. EXTERN Char *UndoPtr;
  126. EXTERN int UndoSize;
  127. EXTERN int UndoAction;
  128. EXTERN struct Strbuf HistBuf; /* = Strbuf_INIT; history buffer */
  129. EXTERN int Hist_num; /* what point up the history we are at now. */
  130. /* buffer for which command and others */
  131. EXTERN struct Strbuf SavedBuf; /* = Strbuf_INIT; */
  132. EXTERN size_t LastSaved; /* points to end of saved buffer */
  133. EXTERN size_t CursSaved; /* points to the cursor point in saved buf */
  134. EXTERN int HistSaved; /* Hist_num is saved in this */
  135. EXTERN char RestoreSaved; /* true if SavedBuf should be restored */
  136. EXTERN int IncMatchLen; /* current match length during incremental search */
  137. EXTERN char Expand; /* true if we are expanding a line */
  138. extern Char HistLit; /* true if history lines are shown literal */
  139. EXTERN Char CurrentHistLit; /* Literal status of current show history line */
  140. extern int Tty_raw_mode;
  141. /*
  142. * These are truly extern
  143. */
  144. extern int MacroLvl;
  145. extern Char *litptr; /* Entries start at offsets divisible by LIT_FACTOR */
  146. #define LIT_FACTOR 4
  147. extern int didsetty;
  148. EXTERN Char *KeyMacro[MAXMACROLEVELS];
  149. /* CHAR_DBWIDTH in Display and Vdisplay means the non-first column of a character
  150. that is wider than one "regular" position. The cursor should never point
  151. in the middle of a multiple-column character. */
  152. EXTERN Char **Display; /* display buffer seed vector */
  153. EXTERN int CursorV, /* real cursor vertical (line) */
  154. CursorH, /* real cursor horisontal (column) */
  155. TermV, /* number of real screen lines
  156. * (sizeof(DisplayBuf) / width */
  157. TermH; /* screen width */
  158. EXTERN Char **Vdisplay; /* new buffer */
  159. /* Variables that describe terminal ability */
  160. EXTERN int T_Lines, T_Cols; /* Rows and Cols of the terminal */
  161. EXTERN Char T_CanIns; /* true if I can insert characters */
  162. EXTERN Char T_CanDel; /* dito for delete characters */
  163. EXTERN char T_Tabs; /* true if tty interface is passing tabs */
  164. EXTERN char T_Margin;
  165. #define MARGIN_AUTO 1 /* term has auto margins */
  166. #define MARGIN_MAGIC 2 /* concept glitch */
  167. EXTERN speed_t T_Speed; /* Tty input Baud rate */
  168. EXTERN Char T_CanCEOL; /* true if we can clear to end of line */
  169. EXTERN Char T_CanUP; /* true if this term can do reverse linefeen */
  170. EXTERN char T_HasMeta; /* true if we have a meta key */
  171. /* note the extra characters in the Strchr() call in this macro */
  172. #define isword(c) (Isalpha(c)||Isdigit(c)||Strchr(word_chars,c))
  173. #define min(x,y) (((x)<(y))?(x):(y))
  174. #define max(x,y) (((x)>(y))?(x):(y))
  175. #define MODE_INSERT 0
  176. #define MODE_REPLACE 1
  177. #define MODE_REPLACE_1 2
  178. #define EX_IO 0 /* while we are executing */
  179. #define ED_IO 1 /* while we are editing */
  180. #define TS_IO 2 /* new mode from terminal */
  181. #define QU_IO 2 /* used only for quoted chars */
  182. #define NN_IO 3 /* The number of entries */
  183. #if defined(POSIX) || defined(TERMIO)
  184. # define M_INPUT 0
  185. # define M_OUTPUT 1
  186. # define M_CONTROL 2
  187. # define M_LINED 3
  188. # define M_CHAR 4
  189. # define M_NN 5
  190. #else /* GSTTY */
  191. # define M_CONTROL 0
  192. # define M_LOCAL 1
  193. # define M_CHAR 2
  194. # define M_NN 3
  195. #endif /* TERMIO */
  196. typedef struct {
  197. const char *t_name;
  198. unsigned int t_setmask;
  199. unsigned int t_clrmask;
  200. } ttyperm_t[NN_IO][M_NN];
  201. extern ttyperm_t ttylist;
  202. #include "ed.term.h"
  203. #include "ed.decls.h"
  204. #ifndef POSIX
  205. /*
  206. * We don't prototype these, cause some systems have them wrong!
  207. */
  208. extern int tgetent ();
  209. extern char *tgetstr ();
  210. extern int tgetflag ();
  211. extern int tgetnum ();
  212. extern char *tgoto ();
  213. # define PUTPURE putpure
  214. # define PUTRAW putraw
  215. #else
  216. extern int tgetent (char *, const char *);
  217. extern char *tgetstr (const char *, char **);
  218. extern int tgetflag (const char *);
  219. extern int tgetnum (const char *);
  220. extern char *tgoto (const char *, int, int);
  221. extern void tputs (const char *, int, void (*)(int));
  222. # define PUTPURE ((void (*)(int)) putpure)
  223. # define PUTRAW ((void (*)(int)) putraw)
  224. #endif
  225. #endif /* _h_ed */