00001 // @(#)root/editline:$Id: el.h 33560 2010-05-18 16:13:58Z axel $ 00002 // Author: Mary-Louise Gill, 2009 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 /* $NetBSD: el.fH,v 1.8 2001/01/06 14:44:50 jdolecek Exp $ */ 00013 00014 /*- 00015 * Copyright (c) 1992, 1993 00016 * The Regents of the University of California. All rights reserved. 00017 * 00018 * This code is derived from software contributed to Berkeley by 00019 * Christos Zoulas of Cornell University. 00020 * 00021 * Redistribution and use in source and binary forms, with or without 00022 * modification, are permitted provided that the following conditions 00023 * are met: 00024 * 1. Redistributions of source code must retain the above copyright 00025 * notice, this list of conditions and the following disclaimer. 00026 * 2. Redistributions in binary form must reproduce the above copyright 00027 * notice, this list of conditions and the following disclaimer in the 00028 * documentation and/or other materials provided with the distribution. 00029 * 3. Neither the name of the University nor the names of its contributors 00030 * may be used to endorse or promote products derived from this software 00031 * without specific prior written permission. 00032 * 00033 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00034 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00035 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00036 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00037 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00038 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00039 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00040 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00041 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00042 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00043 * SUCH DAMAGE. 00044 */ 00045 00046 /* 00047 * el.fH: Internal structures. 00048 */ 00049 #ifndef _h_el 00050 #define _h_el 00051 00052 /* 00053 * Local defaults 00054 */ 00055 #define KSHVI 00056 /* #define VIDEFAULT */ 00057 00058 #include <stdio.h> 00059 #include <sys/types.h> 00060 00061 #define EL_BUFSIZ 1024 /* Maximum line size */ 00062 00063 #define HANDLE_SIGNALS 1 << 0 00064 #define NO_TTY 1 << 1 00065 #define EDIT_DISABLED 1 << 2 00066 // #define DEBUG_READ 1 00067 00068 typedef int ElBool_t; /* True or not */ 00069 00070 typedef unsigned char ElAction_t; /* Index to command array */ 00071 00072 struct ElCoord_t { /* Position on the screen */ 00073 int fH; 00074 int fV; 00075 }; 00076 00077 struct ElColor_t { 00078 int fForeColor; /* The foreground text colour */ 00079 int fBackColor; /* The background colour */ 00080 ElColor_t(int f = -1, int b = -2): fForeColor(f), 00081 fBackColor(b) {} 00082 00083 ElColor_t& 00084 operator =(const ElColor_t& color) { 00085 (*this).fForeColor = color.fForeColor; 00086 (*this).fBackColor = color.fBackColor; 00087 return *this; 00088 } 00089 00090 00091 ElColor_t& 00092 operator =(int val) { 00093 fForeColor = val; 00094 fBackColor = val; 00095 return *this; 00096 } 00097 }; 00098 00099 00100 struct ElLine_t { 00101 char* fBuffer; /* Input line */ 00102 ElColor_t* fBufColor; /* Color info for each char in buffer */ 00103 char* fCursor; /* Cursor position */ 00104 char* fLastChar; /* Last character */ 00105 const char* fLimit; /* Max position */ 00106 }; 00107 00108 /* 00109 * Editor state 00110 */ 00111 struct ElState_t { 00112 int fInputMode; /* What mode are we in? */ 00113 int fDoingArg; /* Are we getting an argument? */ 00114 int fArgument; /* Numeric argument */ 00115 int fMetaNext; /* Is the next char a meta char */ 00116 ElAction_t fLastCmd; /* Previous command */ 00117 int fReplayHist; /* Previous command */ 00118 }; 00119 00120 /* 00121 * Until we come up with something better... 00122 */ 00123 #define el_malloc(a) malloc(a) 00124 #define el_realloc(a, b) realloc(a, b) 00125 #define el_free(a) free(a) 00126 00127 #include "compat.h" 00128 #include "sys.h" 00129 #include "tty.h" 00130 #include "prompt.h" 00131 #include "key.h" 00132 #include "term.h" 00133 #include "refresh.h" 00134 #include "chared.h" 00135 #include "common.h" 00136 #include "search.h" 00137 #include "hist.h" 00138 #include "map.h" 00139 #include "parse.h" 00140 #include "sig.h" 00141 #include "help.h" 00142 00143 struct EditLine_t { 00144 char* fProg; /* the program name */ 00145 FILE* fOutFile; /* Stdio stuff */ 00146 FILE* fErrFile; /* Stdio stuff */ 00147 FILE* fIn; /* Input file if !tty */ 00148 int fInFD; /* Input file descriptor */ 00149 int fFlags; /* Various flags. */ 00150 ElCoord_t fCursor; /* Cursor location */ 00151 char** fDisplay; /* Real screen image = what is there */ 00152 ElColor_t** fDispColor; /* Color for each char in fDisplay */ 00153 char** fVDisplay; /* Virtual screen image = what we see */ 00154 ElColor_t** fVDispColor; /* Color for each char in fVDisplay*/ 00155 ElLine_t fLine; /* The current line information */ 00156 ElState_t fState; /* Current editor state */ 00157 ElTerm_t fTerm; /* Terminal dependent stuff */ 00158 ElTTY_t fTTY; /* Tty dependent stuff */ 00159 ElRefresh_t fRefresh; /* Refresh stuff */ 00160 ElPrompt_t fPrompt; /* Prompt stuff */ 00161 ElPrompt_t fRPrompt; /* Prompt stuff */ 00162 ElCharEd_t fCharEd; /* Characted editor stuff */ 00163 ElMap_t fMap; /* Key mapping stuff */ 00164 ElKey_t fKey; /* Key binding stuff */ 00165 ElHistory_t fHistory; /* History_t stuff */ 00166 ElSearch_t fSearch; /* Search stuff */ 00167 ElSignal_t fSignal; /* Signal handling stuff */ 00168 }; 00169 00170 el_protected int el_editmode(EditLine_t*, int, const char**); 00171 00172 /** 00173 Added by stephan@s11n.net: returns the editline object associated 00174 with the readline compatibility interface, to allow clients to 00175 customize that object further. 00176 */ 00177 el_public EditLine_t* el_readline_el(); 00178 00179 00180 #ifdef DEBUG 00181 # define EL_ABORT(a) (void) (fprintf(el->fErrFile, "%s, %d: ", \ 00182 __FILE__, __LINE__), fprintf a, abort()) 00183 #else 00184 # define EL_ABORT(a) abort() 00185 #endif 00186 #endif /* _h_el */