00001 /* history.h -- the names of functions that you can call in history. */ 00002 /* Copyright (C) 1989-2003 Free Software Foundation, Inc. 00003 00004 This file contains the GNU History Library (the Library), a set of 00005 routines for managing the text of previously typed lines. 00006 00007 The Library is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2, or (at your option) 00010 any later version. 00011 00012 The Library is distributed in the hope that it will be useful, but 00013 WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 The GNU General Public License is often shipped with GNU software, and 00018 is generally kept in a file called COPYING or LICENSE. If you do not 00019 have a copy of the license, write to the Free Software Foundation, 00020 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 00021 00022 #ifndef _HISTORY_H_ 00023 #define _HISTORY_H_ 00024 00025 #ifdef __cplusplus 00026 extern "C" { 00027 #endif 00028 00029 #include <time.h> /* XXX - for history timestamp code */ 00030 00031 #if defined READLINE_LIBRARY 00032 # include "rlstdc.h" 00033 # include "rltypedefs.h" 00034 #else 00035 # include <readline/rlstdc.h> 00036 # include <readline/rltypedefs.h> 00037 #endif 00038 00039 #ifdef __STDC__ 00040 typedef void *histdata_t; 00041 #else 00042 typedef char *histdata_t; 00043 #endif 00044 00045 /* The structure used to store a history entry. */ 00046 typedef struct _hist_entry { 00047 char *line; 00048 char *timestamp; /* char * rather than time_t for read/write */ 00049 histdata_t data; 00050 } HIST_ENTRY; 00051 00052 /* Size of the history-library-managed space in history entry HS. */ 00053 #define HISTENT_BYTES(hs) (strlen ((hs)->line) + strlen ((hs)->timestamp)) 00054 00055 /* A structure used to pass the current state of the history stuff around. */ 00056 typedef struct _hist_state { 00057 HIST_ENTRY **entries; /* Pointer to the entries themselves. */ 00058 int offset; /* The location pointer within this array. */ 00059 int length; /* Number of elements within this array. */ 00060 int size; /* Number of slots allocated to this array. */ 00061 int flags; 00062 } HISTORY_STATE; 00063 00064 /* Flag values for the `flags' member of HISTORY_STATE. */ 00065 #define HS_STIFLED 0x01 00066 00067 /* Initialization and state management. */ 00068 00069 /* Begin a session in which the history functions might be used. This 00070 just initializes the interactive variables. */ 00071 extern void using_history PARAMS((void)); 00072 00073 /* Return the current HISTORY_STATE of the history. */ 00074 extern HISTORY_STATE *history_get_history_state PARAMS((void)); 00075 00076 /* Set the state of the current history array to STATE. */ 00077 extern void history_set_history_state PARAMS((HISTORY_STATE *)); 00078 00079 /* Manage the history list. */ 00080 00081 /* Place STRING at the end of the history list. 00082 The associated data field (if any) is set to NULL. */ 00083 extern void add_history PARAMS((const char *)); 00084 00085 /* Change the timestamp associated with the most recent history entry to 00086 STRING. */ 00087 extern void add_history_time PARAMS((const char *)); 00088 00089 /* A reasonably useless function, only here for completeness. WHICH 00090 is the magic number that tells us which element to delete. The 00091 elements are numbered from 0. */ 00092 extern HIST_ENTRY *remove_history PARAMS((int)); 00093 00094 /* Free the history entry H and return any application-specific data 00095 associated with it. */ 00096 extern histdata_t free_history_entry PARAMS((HIST_ENTRY *)); 00097 00098 /* Make the history entry at WHICH have LINE and DATA. This returns 00099 the old entry so you can dispose of the data. In the case of an 00100 invalid WHICH, a NULL pointer is returned. */ 00101 extern HIST_ENTRY *replace_history_entry PARAMS((int, const char *, histdata_t)); 00102 00103 /* Clear the history list and start over. */ 00104 extern void clear_history PARAMS((void)); 00105 00106 /* Stifle the history list, remembering only MAX number of entries. */ 00107 extern void stifle_history PARAMS((int)); 00108 00109 /* Stop stifling the history. This returns the previous amount the 00110 history was stifled by. The value is positive if the history was 00111 stifled, negative if it wasn't. */ 00112 extern int unstifle_history PARAMS((void)); 00113 00114 /* Return 1 if the history is stifled, 0 if it is not. */ 00115 extern int history_is_stifled PARAMS((void)); 00116 00117 /* Information about the history list. */ 00118 00119 /* Return a NULL terminated array of HIST_ENTRY which is the current input 00120 history. Element 0 of this list is the beginning of time. If there 00121 is no history, return NULL. */ 00122 extern HIST_ENTRY **history_list PARAMS((void)); 00123 00124 /* Returns the number which says what history element we are now 00125 looking at. */ 00126 extern int where_history PARAMS((void)); 00127 00128 /* Return the history entry at the current position, as determined by 00129 history_offset. If there is no entry there, return a NULL pointer. */ 00130 extern HIST_ENTRY *current_history PARAMS((void)); 00131 00132 /* Return the history entry which is logically at OFFSET in the history 00133 array. OFFSET is relative to history_base. */ 00134 extern HIST_ENTRY *history_get PARAMS((int)); 00135 00136 /* Return the timestamp associated with the HIST_ENTRY * passed as an 00137 argument */ 00138 extern time_t history_get_time PARAMS((HIST_ENTRY *)); 00139 00140 /* Return the number of bytes that the primary history entries are using. 00141 This just adds up the lengths of the_history->lines. */ 00142 extern int history_total_bytes PARAMS((void)); 00143 00144 /* Moving around the history list. */ 00145 00146 /* Set the position in the history list to POS. */ 00147 extern int history_set_pos PARAMS((int)); 00148 00149 /* Back up history_offset to the previous history entry, and return 00150 a pointer to that entry. If there is no previous entry, return 00151 a NULL pointer. */ 00152 extern HIST_ENTRY *previous_history PARAMS((void)); 00153 00154 /* Move history_offset forward to the next item in the input_history, 00155 and return the a pointer to that entry. If there is no next entry, 00156 return a NULL pointer. */ 00157 extern HIST_ENTRY *next_history PARAMS((void)); 00158 00159 /* Searching the history list. */ 00160 00161 /* Search the history for STRING, starting at history_offset. 00162 If DIRECTION < 0, then the search is through previous entries, 00163 else through subsequent. If the string is found, then 00164 current_history () is the history entry, and the value of this function 00165 is the offset in the line of that history entry that the string was 00166 found in. Otherwise, nothing is changed, and a -1 is returned. */ 00167 extern int history_search PARAMS((const char *, int)); 00168 00169 /* Search the history for STRING, starting at history_offset. 00170 The search is anchored: matching lines must begin with string. 00171 DIRECTION is as in history_search(). */ 00172 extern int history_search_prefix PARAMS((const char *, int)); 00173 00174 /* Search for STRING in the history list, starting at POS, an 00175 absolute index into the list. DIR, if negative, says to search 00176 backwards from POS, else forwards. 00177 Returns the absolute index of the history element where STRING 00178 was found, or -1 otherwise. */ 00179 extern int history_search_pos PARAMS((const char *, int, int)); 00180 00181 /* Managing the history file. */ 00182 00183 /* Add the contents of FILENAME to the history list, a line at a time. 00184 If FILENAME is NULL, then read from ~/.history. Returns 0 if 00185 successful, or errno if not. */ 00186 extern int read_history PARAMS((const char *)); 00187 00188 /* Read a range of lines from FILENAME, adding them to the history list. 00189 Start reading at the FROM'th line and end at the TO'th. If FROM 00190 is zero, start at the beginning. If TO is less than FROM, read 00191 until the end of the file. If FILENAME is NULL, then read from 00192 ~/.history. Returns 0 if successful, or errno if not. */ 00193 extern int read_history_range PARAMS((const char *, int, int)); 00194 00195 /* Write the current history to FILENAME. If FILENAME is NULL, 00196 then write the history list to ~/.history. Values returned 00197 are as in read_history (). */ 00198 extern int write_history PARAMS((const char *)); 00199 00200 /* Append NELEMENT entries to FILENAME. The entries appended are from 00201 the end of the list minus NELEMENTs up to the end of the list. */ 00202 extern int append_history PARAMS((int, const char *)); 00203 00204 /* Truncate the history file, leaving only the last NLINES lines. */ 00205 extern int history_truncate_file PARAMS((const char *, int)); 00206 00207 /* History expansion. */ 00208 00209 /* Expand the string STRING, placing the result into OUTPUT, a pointer 00210 to a string. Returns: 00211 00212 0) If no expansions took place (or, if the only change in 00213 the text was the de-slashifying of the history expansion 00214 character) 00215 1) If expansions did take place 00216 -1) If there was an error in expansion. 00217 2) If the returned line should just be printed. 00218 00219 If an error ocurred in expansion, then OUTPUT contains a descriptive 00220 error message. */ 00221 extern int history_expand PARAMS((char *, char **)); 00222 00223 /* Extract a string segment consisting of the FIRST through LAST 00224 arguments present in STRING. Arguments are broken up as in 00225 the shell. */ 00226 extern char *history_arg_extract PARAMS((int, int, const char *)); 00227 00228 /* Return the text of the history event beginning at the current 00229 offset into STRING. Pass STRING with *INDEX equal to the 00230 history_expansion_char that begins this specification. 00231 DELIMITING_QUOTE is a character that is allowed to end the string 00232 specification for what to search for in addition to the normal 00233 characters `:', ` ', `\t', `\n', and sometimes `?'. */ 00234 extern char *get_history_event PARAMS((const char *, int *, int)); 00235 00236 /* Return an array of tokens, much as the shell might. The tokens are 00237 parsed out of STRING. */ 00238 extern char **history_tokenize PARAMS((const char *)); 00239 00240 /* Exported history variables. */ 00241 extern int history_base; 00242 extern int history_length; 00243 extern int history_max_entries; 00244 extern char history_expansion_char; 00245 extern char history_subst_char; 00246 extern char *history_word_delimiters; 00247 extern char history_comment_char; 00248 extern char *history_no_expand_chars; 00249 extern char *history_search_delimiter_chars; 00250 extern int history_quotes_inhibit_expansion; 00251 00252 extern int history_write_timestamps; 00253 00254 /* Backwards compatibility */ 00255 extern int max_input_history; 00256 00257 /* If set, this function is called to decide whether or not a particular 00258 history expansion should be treated as a special case for the calling 00259 application and not expanded. */ 00260 extern rl_linebuf_func_t *history_inhibit_expansion_function; 00261 00262 #ifdef __cplusplus 00263 } 00264 #endif 00265 00266 #endif /* !_HISTORY_H_ */