1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1982-2011 AT&T Intellectual Property * 5* and is licensed under the * 6* Common Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.opensource.org/licenses/cpl1.0.txt * 11* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12* * 13* Information and Software Systems Research * 14* AT&T Research * 15* Florham Park NJ * 16* * 17* David Korn <dgk@research.att.com> * 18* * 19***********************************************************************/ 20#pragma prototyped 21#ifndef SEARCHSIZE 22/* 23 * edit.h - common data structure for vi and emacs edit options 24 * 25 * David Korn 26 * AT&T Labs 27 * 28 */ 29 30#define SEARCHSIZE 80 31 32#include "FEATURE/options" 33#include "FEATURE/locale" 34#if !SHOPT_VSH && !SHOPT_ESH 35# define ed_winsize() (SEARCHSIZE) 36#else 37 38#if !KSHELL 39# include <setjmp.h> 40# include <sig.h> 41# include <ctype.h> 42#endif /* KSHELL */ 43 44#include "FEATURE/setjmp" 45#include "terminal.h" 46 47#define STRIP 0377 48#define LOOKAHEAD 80 49 50#if SHOPT_MULTIBYTE 51# ifndef ESS_MAXCHAR 52# include "national.h" 53# endif /* ESS_MAXCHAR */ 54 typedef wchar_t genchar; 55# define CHARSIZE (sizeof(wchar_t)<=2?3:sizeof(wchar_t)) 56#else 57 typedef char genchar; 58# define CHARSIZE 1 59#endif /* SHOPT_MULTIBYTE */ 60 61#define TABSIZE 8 62#define PRSIZE 160 63#define MAXLINE 1024 /* longest edit line permitted */ 64 65typedef struct _edit_pos 66{ 67 unsigned short line; 68 unsigned short col; 69} Edpos_t; 70 71#if SHOPT_EDPREDICT 72typedef struct Histmatch 73{ 74 struct Histmatch *next; 75 int index; 76 short len; 77 short count; 78 char data[1]; 79} Histmatch_t; 80#endif /* SHOPT_EDPREDICT */ 81 82 83 84typedef struct edit 85{ 86 sigjmp_buf e_env; 87 int e_intr; 88 int e_kill; 89 int e_erase; 90 int e_werase; 91 int e_eof; 92 int e_lnext; 93 int e_fchar; 94 int e_plen; /* length of prompt string */ 95 char e_crlf; /* zero if cannot return to beginning of line */ 96 char e_nocrnl; /* don't put a new-line with ^L */ 97 int e_llimit; /* line length limit */ 98 int e_hline; /* current history line number */ 99 int e_hloff; /* line number offset for command */ 100 int e_hismin; /* minimum history line number */ 101 int e_hismax; /* maximum history line number */ 102 int e_raw; /* set when in raw mode or alt mode */ 103 int e_cur; /* current line position */ 104 int e_eol; /* end-of-line position */ 105 int e_pcur; /* current physical line position */ 106 int e_peol; /* end of physical line position */ 107 int e_mode; /* edit mode */ 108 int e_lookahead; /* index in look-ahead buffer */ 109 int e_repeat; 110 int e_saved; 111 int e_fcol; /* first column */ 112 int e_ucol; /* column for undo */ 113 int e_wsize; /* width of display window */ 114 char *e_outbase; /* pointer to start of output buffer */ 115 char *e_outptr; /* pointer to position in output buffer */ 116 char *e_outlast; /* pointer to end of output buffer */ 117 genchar *e_inbuf; /* pointer to input buffer */ 118 char *e_prompt; /* pointer to buffer containing the prompt */ 119 genchar *e_ubuf; /* pointer to the undo buffer */ 120 genchar *e_killbuf; /* pointer to delete buffer */ 121 char e_search[SEARCHSIZE]; /* search string */ 122 genchar *e_Ubuf; /* temporary workspace buffer */ 123 genchar *e_physbuf; /* temporary workspace buffer */ 124 int e_lbuf[LOOKAHEAD];/* pointer to look-ahead buffer */ 125 int e_fd; /* file descriptor */ 126 int e_ttyspeed; /* line speed, also indicates tty parms are valid */ 127 int e_tabcount; 128#ifdef _hdr_utime 129 ino_t e_tty_ino; 130 dev_t e_tty_dev; 131 char *e_tty; 132#endif 133#if SHOPT_OLDTERMIO 134 char e_echoctl; 135 char e_tcgeta; 136 struct termio e_ott; 137#endif 138#if SHOPT_MULTIBYTE 139 int e_curchar; 140 int e_cursize; 141#endif 142 int *e_globals; /* global variables */ 143 genchar *e_window; /* display window image */ 144 char e_inmacro; /* processing macro expansion */ 145#if KSHELL 146 char e_vi_insert[2]; /* for sh_keytrap */ 147 int32_t e_col; /* for sh_keytrap */ 148#else 149 char e_prbuff[PRSIZE]; /* prompt buffer */ 150#endif /* KSHELL */ 151 struct termios e_ttyparm; /* initial tty parameters */ 152 struct termios e_nttyparm; /* raw tty parameters */ 153 struct termios e_savetty; /* saved terminal state */ 154 int e_savefd; /* file descriptor for saved terminal state */ 155 char e_macro[4]; /* macro buffer */ 156 void *e_vi; /* vi specific data */ 157 void *e_emacs; /* emacs specific data */ 158 Shell_t *sh; /* interpreter pointer */ 159 char *e_stkptr; /* saved stack pointer */ 160 int e_stkoff; /* saved stack offset */ 161 char **e_clist; /* completion list after <ESC>= */ 162 int e_nlist; /* number of elements on completion list */ 163 int e_multiline; /* allow multiple lines for editing */ 164 int e_winsz; /* columns in window */ 165 Edpos_t e_curpos; /* cursor line and column */ 166 Namval_t *e_default; /* variable containing default value */ 167 Namval_t *e_term; /* TERM variable */ 168 char e_termname[80]; /* terminal name */ 169#if SHOPT_EDPREDICT 170 Histmatch_t **hlist; 171 Histmatch_t *hfirst; 172 unsigned short nhlist; 173 unsigned short hoff; 174 unsigned short hmax; 175 char *hpat; 176 char *hstak; 177#endif /* SHOPT_EDPREDICT */ 178} Edit_t; 179 180#undef MAXWINDOW 181#define MAXWINDOW 300 /* maximum width window */ 182#define FAST 2 183#define SLOW 1 184#define ESC cntl('[') 185#define UEOF -2 /* user eof char synonym */ 186#define UINTR -3 /* user intr char synonym */ 187#define UERASE -4 /* user erase char synonym */ 188#define UKILL -5 /* user kill char synonym */ 189#define UWERASE -6 /* user word erase char synonym */ 190#define ULNEXT -7 /* user next literal char synonym */ 191 192#if ( 'a' == 97) /* ASCII? */ 193# define cntl(x) (x&037) 194#else 195# define cntl(c) (c=='D'?55:(c=='E'?45:(c=='F'?46:(c=='G'?'\a':(c=='H'?'\b': \ 196 (c=='I'?'\t':(c=='J'?'\n':(c=='T'?60:(c=='U'?61:(c=='V'?50: \ 197 (c=='W'?38:(c=='Z'?63:(c=='['?39:(c==']'?29: \ 198 (c<'J'?c+1-'A':(c+10-'J')))))))))))))))) 199#endif 200 201#if !KSHELL 202# define STRIP 0377 203# define GMACS 1 204# define EMACS 2 205# define VIRAW 4 206# define EDITVI 8 207# define NOHIST 16 208# define EDITMASK 15 209# define is_option(m) (opt_flag&(m)) 210 extern char opt_flag; 211# ifdef SYSCALL 212# define read(fd,buff,n) syscall(3,fd,buff,n) 213# else 214# define read(fd,buff,n) rEAd(fd,buff,n) 215# endif /* SYSCALL */ 216#endif /* KSHELL */ 217 218extern void ed_crlf(Edit_t*); 219extern void ed_putchar(Edit_t*, int); 220extern void ed_ringbell(void); 221extern void ed_setup(Edit_t*,int, int); 222extern void ed_flush(Edit_t*); 223extern int ed_getchar(Edit_t*,int); 224extern int ed_virt_to_phys(Edit_t*,genchar*,genchar*,int,int,int); 225extern int ed_window(void); 226extern void ed_ungetchar(Edit_t*,int); 227extern int ed_viread(void*, int, char*, int, int); 228extern int ed_read(void*, int, char*, int, int); 229extern int ed_emacsread(void*, int, char*, int, int); 230extern Edpos_t ed_curpos(Edit_t*, genchar*, int, int, Edpos_t); 231extern int ed_setcursor(Edit_t*, genchar*, int, int, int); 232#if KSHELL 233 extern int ed_macro(Edit_t*,int); 234 extern int ed_expand(Edit_t*, char[],int*,int*,int,int); 235 extern int ed_fulledit(Edit_t*); 236 extern void *ed_open(Shell_t*); 237#endif /* KSHELL */ 238# if SHOPT_MULTIBYTE 239 extern int ed_internal(const char*, genchar*); 240 extern int ed_external(const genchar*, char*); 241 extern void ed_gencpy(genchar*,const genchar*); 242 extern void ed_genncpy(genchar*,const genchar*,int); 243 extern int ed_genlen(const genchar*); 244 extern int ed_setwidth(const char*); 245# endif /* SHOPT_MULTIBYTE */ 246#if SHOPT_EDPREDICT 247 extern int ed_histgen(Edit_t*, const char*); 248 extern void ed_histlist(Edit_t*, int); 249#endif /* SHOPT_EDPREDICT */ 250 251extern const char e_runvi[]; 252#if !KSHELL 253 extern const char e_version[]; 254#endif /* KSHELL */ 255 256#if SHOPT_HISTEXPAND 257 258/* flags */ 259 260#define HIST_EVENT 0x1 /* event designator seen */ 261#define HIST_QUESTION 0x2 /* question mark event designator */ 262#define HIST_HASH 0x4 /* hash event designator */ 263#define HIST_WORDDSGN 0x8 /* word designator seen */ 264#define HIST_QUICKSUBST 0x10 /* quick substition designator seen */ 265#define HIST_SUBSTITUTE 0x20 /* for substition loop */ 266#define HIST_NEWLINE 0x40 /* newline in squashed white space */ 267 268/* modifier flags */ 269 270#define HIST_PRINT 0x100 /* print new command */ 271#define HIST_QUOTE 0x200 /* quote resulting history line */ 272#define HIST_QUOTE_BR 0x400 /* quote every word on space break */ 273#define HIST_GLOBALSUBST 0x800 /* apply substition globally */ 274 275#define HIST_ERROR 0x1000 /* an error ocurred */ 276 277/* flags to be returned */ 278 279#define HIST_FLAG_RETURN_MASK (HIST_EVENT|HIST_PRINT|HIST_ERROR) 280 281extern int hist_expand(const char *, char **); 282#endif 283 284#endif 285#endif 286