1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A#ifndef SEARCHSIZE
1N/A/*
1N/A * edit.h - common data structure for vi and emacs edit options
1N/A *
1N/A * David Korn
1N/A * AT&T Labs
1N/A *
1N/A */
1N/A
1N/A#define SEARCHSIZE 80
1N/A
1N/A#include "FEATURE/options"
1N/A#include "FEATURE/locale"
1N/A#if !SHOPT_VSH && !SHOPT_ESH
1N/A# define ed_winsize() (SEARCHSIZE)
1N/A#else
1N/A
1N/A#if !KSHELL
1N/A# include <setjmp.h>
1N/A# include <sig.h>
1N/A# include <ctype.h>
1N/A#endif /* KSHELL */
1N/A
1N/A#include "FEATURE/setjmp"
1N/A#include "terminal.h"
1N/A
1N/A#define STRIP 0377
1N/A#define LOOKAHEAD 80
1N/A
1N/A#if SHOPT_MULTIBYTE
1N/A# ifndef ESS_MAXCHAR
1N/A# include "national.h"
1N/A# endif /* ESS_MAXCHAR */
1N/A typedef wchar_t genchar;
1N/A# define CHARSIZE (sizeof(wchar_t)<=2?3:sizeof(wchar_t))
1N/A#else
1N/A typedef char genchar;
1N/A# define CHARSIZE 1
1N/A#endif /* SHOPT_MULTIBYTE */
1N/A
1N/A#define TABSIZE 8
1N/A#define PRSIZE 160
1N/A#define MAXLINE 1024 /* longest edit line permitted */
1N/A
1N/Atypedef struct _edit_pos
1N/A{
1N/A unsigned short line;
1N/A unsigned short col;
1N/A} Edpos_t;
1N/A
1N/A#if SHOPT_EDPREDICT
1N/Atypedef struct Histmatch
1N/A{
1N/A struct Histmatch *next;
1N/A int index;
1N/A short len;
1N/A short count;
1N/A char data[1];
1N/A} Histmatch_t;
1N/A#endif /* SHOPT_EDPREDICT */
1N/A
1N/A
1N/A
1N/Atypedef struct edit
1N/A{
1N/A sigjmp_buf e_env;
1N/A int e_intr;
1N/A int e_kill;
1N/A int e_erase;
1N/A int e_werase;
1N/A int e_eof;
1N/A int e_lnext;
1N/A int e_fchar;
1N/A int e_plen; /* length of prompt string */
1N/A char e_crlf; /* zero if cannot return to beginning of line */
1N/A char e_nocrnl; /* don't put a new-line with ^L */
1N/A int e_llimit; /* line length limit */
1N/A int e_hline; /* current history line number */
1N/A int e_hloff; /* line number offset for command */
1N/A int e_hismin; /* minimum history line number */
1N/A int e_hismax; /* maximum history line number */
1N/A int e_raw; /* set when in raw mode or alt mode */
1N/A int e_cur; /* current line position */
1N/A int e_eol; /* end-of-line position */
1N/A int e_pcur; /* current physical line position */
1N/A int e_peol; /* end of physical line position */
1N/A int e_mode; /* edit mode */
1N/A int e_lookahead; /* index in look-ahead buffer */
1N/A int e_repeat;
1N/A int e_saved;
1N/A int e_fcol; /* first column */
1N/A int e_ucol; /* column for undo */
1N/A int e_wsize; /* width of display window */
1N/A char *e_outbase; /* pointer to start of output buffer */
1N/A char *e_outptr; /* pointer to position in output buffer */
1N/A char *e_outlast; /* pointer to end of output buffer */
1N/A genchar *e_inbuf; /* pointer to input buffer */
1N/A char *e_prompt; /* pointer to buffer containing the prompt */
1N/A genchar *e_ubuf; /* pointer to the undo buffer */
1N/A genchar *e_killbuf; /* pointer to delete buffer */
1N/A char e_search[SEARCHSIZE]; /* search string */
1N/A genchar *e_Ubuf; /* temporary workspace buffer */
1N/A genchar *e_physbuf; /* temporary workspace buffer */
1N/A int e_lbuf[LOOKAHEAD];/* pointer to look-ahead buffer */
1N/A int e_fd; /* file descriptor */
1N/A int e_ttyspeed; /* line speed, also indicates tty parms are valid */
1N/A int e_tabcount;
1N/A#ifdef _hdr_utime
1N/A ino_t e_tty_ino;
1N/A dev_t e_tty_dev;
1N/A char *e_tty;
1N/A#endif
1N/A#if SHOPT_OLDTERMIO
1N/A char e_echoctl;
1N/A char e_tcgeta;
1N/A struct termio e_ott;
1N/A#endif
1N/A#if SHOPT_MULTIBYTE
1N/A int e_curchar;
1N/A int e_cursize;
1N/A#endif
1N/A int *e_globals; /* global variables */
1N/A genchar *e_window; /* display window image */
1N/A char e_inmacro; /* processing macro expansion */
1N/A#if KSHELL
1N/A char e_vi_insert[2]; /* for sh_keytrap */
1N/A int32_t e_col; /* for sh_keytrap */
1N/A#else
1N/A char e_prbuff[PRSIZE]; /* prompt buffer */
1N/A#endif /* KSHELL */
1N/A struct termios e_ttyparm; /* initial tty parameters */
1N/A struct termios e_nttyparm; /* raw tty parameters */
1N/A struct termios e_savetty; /* saved terminal state */
1N/A int e_savefd; /* file descriptor for saved terminal state */
1N/A char e_macro[4]; /* macro buffer */
1N/A void *e_vi; /* vi specific data */
1N/A void *e_emacs; /* emacs specific data */
1N/A Shell_t *sh; /* interpreter pointer */
1N/A char *e_stkptr; /* saved stack pointer */
1N/A int e_stkoff; /* saved stack offset */
1N/A char **e_clist; /* completion list after <ESC>= */
1N/A int e_nlist; /* number of elements on completion list */
1N/A int e_multiline; /* allow multiple lines for editing */
1N/A int e_winsz; /* columns in window */
1N/A Edpos_t e_curpos; /* cursor line and column */
1N/A Namval_t *e_default; /* variable containing default value */
1N/A Namval_t *e_term; /* TERM variable */
1N/A char e_termname[80]; /* terminal name */
1N/A#if SHOPT_EDPREDICT
1N/A Histmatch_t **hlist;
1N/A Histmatch_t *hfirst;
1N/A unsigned short nhlist;
1N/A unsigned short hoff;
1N/A unsigned short hmax;
1N/A char *hpat;
1N/A char *hstak;
1N/A#endif /* SHOPT_EDPREDICT */
1N/A} Edit_t;
1N/A
1N/A#undef MAXWINDOW
1N/A#define MAXWINDOW 300 /* maximum width window */
1N/A#define FAST 2
1N/A#define SLOW 1
1N/A#define ESC cntl('[')
1N/A#define UEOF -2 /* user eof char synonym */
1N/A#define UINTR -3 /* user intr char synonym */
1N/A#define UERASE -4 /* user erase char synonym */
1N/A#define UKILL -5 /* user kill char synonym */
1N/A#define UWERASE -6 /* user word erase char synonym */
1N/A#define ULNEXT -7 /* user next literal char synonym */
1N/A
1N/A#if ( 'a' == 97) /* ASCII? */
1N/A# define cntl(x) (x&037)
1N/A#else
1N/A# define cntl(c) (c=='D'?55:(c=='E'?45:(c=='F'?46:(c=='G'?'\a':(c=='H'?'\b': \
1N/A (c=='I'?'\t':(c=='J'?'\n':(c=='T'?60:(c=='U'?61:(c=='V'?50: \
1N/A (c=='W'?38:(c=='Z'?63:(c=='['?39:(c==']'?29: \
1N/A (c<'J'?c+1-'A':(c+10-'J'))))))))))))))))
1N/A#endif
1N/A
1N/A#if !KSHELL
1N/A# define STRIP 0377
1N/A# define GMACS 1
1N/A# define EMACS 2
1N/A# define VIRAW 4
1N/A# define EDITVI 8
1N/A# define NOHIST 16
1N/A# define EDITMASK 15
1N/A# define is_option(m) (opt_flag&(m))
1N/A extern char opt_flag;
1N/A# ifdef SYSCALL
1N/A# define read(fd,buff,n) syscall(3,fd,buff,n)
1N/A# else
1N/A# define read(fd,buff,n) rEAd(fd,buff,n)
1N/A# endif /* SYSCALL */
1N/A#endif /* KSHELL */
1N/A
1N/Aextern void ed_crlf(Edit_t*);
1N/Aextern void ed_putchar(Edit_t*, int);
1N/Aextern void ed_ringbell(void);
1N/Aextern void ed_setup(Edit_t*,int, int);
1N/Aextern void ed_flush(Edit_t*);
1N/Aextern int ed_getchar(Edit_t*,int);
1N/Aextern int ed_virt_to_phys(Edit_t*,genchar*,genchar*,int,int,int);
1N/Aextern int ed_window(void);
1N/Aextern void ed_ungetchar(Edit_t*,int);
1N/Aextern int ed_viread(void*, int, char*, int, int);
1N/Aextern int ed_read(void*, int, char*, int, int);
1N/Aextern int ed_emacsread(void*, int, char*, int, int);
1N/Aextern Edpos_t ed_curpos(Edit_t*, genchar*, int, int, Edpos_t);
1N/Aextern int ed_setcursor(Edit_t*, genchar*, int, int, int);
1N/A#if KSHELL
1N/A extern int ed_macro(Edit_t*,int);
1N/A extern int ed_expand(Edit_t*, char[],int*,int*,int,int);
1N/A extern int ed_fulledit(Edit_t*);
1N/A extern void *ed_open(Shell_t*);
1N/A#endif /* KSHELL */
1N/A# if SHOPT_MULTIBYTE
1N/A extern int ed_internal(const char*, genchar*);
1N/A extern int ed_external(const genchar*, char*);
1N/A extern void ed_gencpy(genchar*,const genchar*);
1N/A extern void ed_genncpy(genchar*,const genchar*,int);
1N/A extern int ed_genlen(const genchar*);
1N/A extern int ed_setwidth(const char*);
1N/A# endif /* SHOPT_MULTIBYTE */
1N/A#if SHOPT_EDPREDICT
1N/A extern int ed_histgen(Edit_t*, const char*);
1N/A extern void ed_histlist(Edit_t*, int);
1N/A#endif /* SHOPT_EDPREDICT */
1N/A
1N/Aextern const char e_runvi[];
1N/A#if !KSHELL
1N/A extern const char e_version[];
1N/A#endif /* KSHELL */
1N/A
1N/A#if SHOPT_HISTEXPAND
1N/A
1N/A/* flags */
1N/A
1N/A#define HIST_EVENT 0x1 /* event designator seen */
1N/A#define HIST_QUESTION 0x2 /* question mark event designator */
1N/A#define HIST_HASH 0x4 /* hash event designator */
1N/A#define HIST_WORDDSGN 0x8 /* word designator seen */
1N/A#define HIST_QUICKSUBST 0x10 /* quick substition designator seen */
1N/A#define HIST_SUBSTITUTE 0x20 /* for substition loop */
1N/A#define HIST_NEWLINE 0x40 /* newline in squashed white space */
1N/A
1N/A/* modifier flags */
1N/A
1N/A#define HIST_PRINT 0x100 /* print new command */
1N/A#define HIST_QUOTE 0x200 /* quote resulting history line */
1N/A#define HIST_QUOTE_BR 0x400 /* quote every word on space break */
1N/A#define HIST_GLOBALSUBST 0x800 /* apply substition globally */
1N/A
1N/A#define HIST_ERROR 0x1000 /* an error ocurred */
1N/A
1N/A/* flags to be returned */
1N/A
1N/A#define HIST_FLAG_RETURN_MASK (HIST_EVENT|HIST_PRINT|HIST_ERROR)
1N/A
1N/Aextern int hist_expand(const char *, char **);
1N/A#endif
1N/A
1N/A#endif
1N/A#endif