00001 // @(#)root/editline:$Id: histedit.h 30194 2009-09-16 12:19:46Z 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: histedit.fH,v 1.16 2000/09/04 22:06:30 lukem 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 * histedit.fH: Line editor and history interface. 00048 */ 00049 #ifndef _HISTEDIT_H_ 00050 #define _HISTEDIT_H_ 00051 00052 #include <sys/types.h> 00053 #include <stdio.h> 00054 00055 /* 00056 * ==== Editing ==== 00057 */ 00058 struct EditLine_t; 00059 00060 /* 00061 * For user-defined function interface 00062 */ 00063 struct LineInfo_t { 00064 const char* fBuffer; 00065 const char* fCursor; 00066 const char* fLastChar; 00067 }; 00068 00069 00070 /* 00071 * EditLine_t editor function return codes. 00072 * For user-defined function interface 00073 */ 00074 #define CC_NORM 0 00075 #define CC_NEWLINE 1 00076 #define CC_EOF 2 00077 #define CC_ARGHACK 3 00078 #define CC_REFRESH 4 00079 #define CC_CURSOR 5 00080 #define CC_ERROR 6 00081 #define CC_FATAL 7 00082 #define CC_REDISPLAY 8 00083 #define CC_REFRESH_BEEP 9 00084 00085 /* 00086 * Initialization, cleanup, and resetting 00087 */ 00088 00089 00090 EditLine_t* el_init(const char*, FILE*, FILE*, FILE*); 00091 void el_reset(EditLine_t*); 00092 void el_end(EditLine_t*); 00093 00094 00095 /* 00096 * Get a line, a character or push a string back in the input queue 00097 * 00098 * Note that el_gets() returns the trailing newline! 00099 */ 00100 const char* el_gets(EditLine_t*, int*); 00101 const char* el_gets_newline(EditLine_t*, int*); 00102 bool el_eof(EditLine_t*); 00103 int el_getc(EditLine_t*, char*); 00104 void el_push(EditLine_t*, const char*); 00105 00106 /* 00107 * Beep! 00108 */ 00109 void el_beep(EditLine_t*); 00110 00111 /* 00112 * High level function internals control 00113 * Parses argc, argv array and executes builtin editline commands 00114 */ 00115 int el_parse(EditLine_t*, int, const char**); 00116 00117 /* 00118 * Low level editline access functions 00119 */ 00120 int el_set(EditLine_t*, int, ...); 00121 int el_get(EditLine_t*, int, void*); 00122 00123 /* 00124 * el_set/el_get parameters 00125 */ 00126 #define EL_PROMPT 0 /* , ElPFunc_t); */ 00127 #define EL_TERMINAL 1 /* , const char *); */ 00128 #define EL_EDITOR 2 /* , const char *); */ 00129 #define EL_SIGNAL 3 /* , int); */ 00130 #define EL_BIND 4 /* , const char *, ..., NULL); */ 00131 #define EL_TELLTC 5 /* , const char *, ..., NULL); */ 00132 #define EL_SETTC 6 /* , const char *, ..., NULL); */ 00133 #define EL_ECHOTC 7 /* , const char *, ..., NULL); */ 00134 #define EL_SETTY 8 /* , const char *, ..., NULL); */ 00135 #define EL_ADDFN 9 /* , const char *, const char * */ 00136 /* , ElFunc_t); */ 00137 #define EL_HIST 10 /* , HistFun_t, const char *); */ 00138 #define EL_EDITMODE 11 /* , int); */ 00139 #define EL_RPROMPT 12 /* , ElPFunc_t); */ 00140 00141 /* 00142 * Source named file or $PWD/.editrc or $HOME/.editrc 00143 */ 00144 int el_source(EditLine_t*, const char*); 00145 00146 /* 00147 * Must be called when the terminal changes size; If EL_SIGNAL 00148 * is set this is done automatically otherwise it is the responsibility 00149 * of the application 00150 */ 00151 void el_resize(EditLine_t*); 00152 00153 00154 /* 00155 * User-defined function interface. 00156 */ 00157 const LineInfo_t* el_line(EditLine_t*); 00158 int el_insertstr(EditLine_t*, const char*); 00159 void el_deletestr(EditLine_t*, int); 00160 00161 /* 00162 * ==== HistoryFcns_t ==== 00163 */ 00164 00165 struct HistoryFcns_t; 00166 00167 struct HistEvent_t { 00168 int fNum; 00169 const char* fStr; 00170 }; 00171 00172 /* 00173 * HistoryFcns_t access functions. 00174 */ 00175 HistoryFcns_t* history_init(void); 00176 void history_end(HistoryFcns_t*); 00177 00178 int history(HistoryFcns_t*, HistEvent_t*, int, ...); 00179 00180 #define H_FUNC 0 /* , UTSL */ 00181 #define H_SETSIZE 1 /* , const int); */ 00182 #define H_GETSIZE 2 /* , void); */ 00183 #define H_FIRST 3 /* , void); */ 00184 #define H_LAST 4 /* , void); */ 00185 #define H_PREV 5 /* , void); */ 00186 #define H_NEXT 6 /* , void); */ 00187 #define H_CURR 8 /* , const int); */ 00188 #define H_SET 7 /* , void); */ 00189 #define H_ADD 9 /* , const char *); */ 00190 #define H_ENTER 10 /* , const char *); */ 00191 #define H_APPEND 11 /* , const char *); */ 00192 #define H_END 12 /* , void); */ 00193 #define H_NEXT_STR 13 /* , const char *); */ 00194 #define H_PREV_STR 14 /* , const char *); */ 00195 #define H_NEXT_EVENT 15 /* , const int); */ 00196 #define H_PREV_EVENT 16 /* , const int); */ 00197 #define H_LOAD 17 /* , const char *); */ 00198 #define H_SAVE 18 /* , const char *); */ 00199 #define H_CLEAR 19 /* , void); */ 00200 00201 #endif /* _HISTEDIT_H_ */