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