Commit | Line | Data |
---|---|---|
5bdf8622 DJ |
1 | /* history.h -- the names of functions that you can call in history. */ |
2 | /* Copyright (C) 1989-2003 Free Software Foundation, Inc. | |
d60d9f65 SS |
3 | |
4 | This file contains the GNU History Library (the Library), a set of | |
5 | routines for managing the text of previously typed lines. | |
6 | ||
7 | The Library is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
1b17e766 | 9 | the Free Software Foundation; either version 2, or (at your option) |
d60d9f65 SS |
10 | any later version. |
11 | ||
12 | The Library is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | General Public License for more details. | |
16 | ||
17 | The GNU General Public License is often shipped with GNU software, and | |
18 | is generally kept in a file called COPYING or LICENSE. If you do not | |
19 | have a copy of the license, write to the Free Software Foundation, | |
1b17e766 | 20 | 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ |
d60d9f65 SS |
21 | |
22 | #ifndef _HISTORY_H_ | |
23 | #define _HISTORY_H_ | |
24 | ||
c862e87b JM |
25 | #ifdef __cplusplus |
26 | extern "C" { | |
27 | #endif | |
28 | ||
5bdf8622 DJ |
29 | #include <time.h> /* XXX - for history timestamp code */ |
30 | ||
c862e87b JM |
31 | #if defined READLINE_LIBRARY |
32 | # include "rlstdc.h" | |
9255ee31 | 33 | # include "rltypedefs.h" |
c862e87b JM |
34 | #else |
35 | # include <readline/rlstdc.h> | |
9255ee31 | 36 | # include <readline/rltypedefs.h> |
d60d9f65 SS |
37 | #endif |
38 | ||
c862e87b JM |
39 | #ifdef __STDC__ |
40 | typedef void *histdata_t; | |
41 | #else | |
42 | typedef char *histdata_t; | |
43 | #endif | |
44 | ||
d60d9f65 SS |
45 | /* The structure used to store a history entry. */ |
46 | typedef struct _hist_entry { | |
47 | char *line; | |
5bdf8622 | 48 | char *timestamp; /* char * rather than time_t for read/write */ |
c862e87b | 49 | histdata_t data; |
d60d9f65 SS |
50 | } HIST_ENTRY; |
51 | ||
5bdf8622 DJ |
52 | /* Size of the history-library-managed space in history entry HS. */ |
53 | #define HISTENT_BYTES(hs) (strlen ((hs)->line) + strlen ((hs)->timestamp)) | |
54 | ||
d60d9f65 SS |
55 | /* A structure used to pass the current state of the history stuff around. */ |
56 | typedef struct _hist_state { | |
57 | HIST_ENTRY **entries; /* Pointer to the entries themselves. */ | |
58 | int offset; /* The location pointer within this array. */ | |
59 | int length; /* Number of elements within this array. */ | |
60 | int size; /* Number of slots allocated to this array. */ | |
61 | int flags; | |
62 | } HISTORY_STATE; | |
63 | ||
64 | /* Flag values for the `flags' member of HISTORY_STATE. */ | |
65 | #define HS_STIFLED 0x01 | |
66 | ||
67 | /* Initialization and state management. */ | |
68 | ||
69 | /* Begin a session in which the history functions might be used. This | |
70 | just initializes the interactive variables. */ | |
9255ee31 | 71 | extern void using_history PARAMS((void)); |
d60d9f65 SS |
72 | |
73 | /* Return the current HISTORY_STATE of the history. */ | |
9255ee31 | 74 | extern HISTORY_STATE *history_get_history_state PARAMS((void)); |
d60d9f65 SS |
75 | |
76 | /* Set the state of the current history array to STATE. */ | |
9255ee31 | 77 | extern void history_set_history_state PARAMS((HISTORY_STATE *)); |
d60d9f65 SS |
78 | |
79 | /* Manage the history list. */ | |
80 | ||
81 | /* Place STRING at the end of the history list. | |
82 | The associated data field (if any) is set to NULL. */ | |
9255ee31 | 83 | extern void add_history PARAMS((const char *)); |
d60d9f65 | 84 | |
5bdf8622 DJ |
85 | /* Change the timestamp associated with the most recent history entry to |
86 | STRING. */ | |
87 | extern void add_history_time PARAMS((const char *)); | |
88 | ||
d60d9f65 SS |
89 | /* A reasonably useless function, only here for completeness. WHICH |
90 | is the magic number that tells us which element to delete. The | |
91 | elements are numbered from 0. */ | |
9255ee31 | 92 | extern HIST_ENTRY *remove_history PARAMS((int)); |
d60d9f65 | 93 | |
5bdf8622 DJ |
94 | /* Free the history entry H and return any application-specific data |
95 | associated with it. */ | |
96 | extern histdata_t free_history_entry PARAMS((HIST_ENTRY *)); | |
97 | ||
d60d9f65 SS |
98 | /* Make the history entry at WHICH have LINE and DATA. This returns |
99 | the old entry so you can dispose of the data. In the case of an | |
100 | invalid WHICH, a NULL pointer is returned. */ | |
9255ee31 | 101 | extern HIST_ENTRY *replace_history_entry PARAMS((int, const char *, histdata_t)); |
d60d9f65 SS |
102 | |
103 | /* Clear the history list and start over. */ | |
9255ee31 | 104 | extern void clear_history PARAMS((void)); |
d60d9f65 SS |
105 | |
106 | /* Stifle the history list, remembering only MAX number of entries. */ | |
9255ee31 | 107 | extern void stifle_history PARAMS((int)); |
d60d9f65 SS |
108 | |
109 | /* Stop stifling the history. This returns the previous amount the | |
110 | history was stifled by. The value is positive if the history was | |
111 | stifled, negative if it wasn't. */ | |
9255ee31 | 112 | extern int unstifle_history PARAMS((void)); |
d60d9f65 SS |
113 | |
114 | /* Return 1 if the history is stifled, 0 if it is not. */ | |
9255ee31 | 115 | extern int history_is_stifled PARAMS((void)); |
d60d9f65 SS |
116 | |
117 | /* Information about the history list. */ | |
118 | ||
119 | /* Return a NULL terminated array of HIST_ENTRY which is the current input | |
120 | history. Element 0 of this list is the beginning of time. If there | |
121 | is no history, return NULL. */ | |
9255ee31 | 122 | extern HIST_ENTRY **history_list PARAMS((void)); |
d60d9f65 SS |
123 | |
124 | /* Returns the number which says what history element we are now | |
125 | looking at. */ | |
9255ee31 | 126 | extern int where_history PARAMS((void)); |
d60d9f65 SS |
127 | |
128 | /* Return the history entry at the current position, as determined by | |
129 | history_offset. If there is no entry there, return a NULL pointer. */ | |
9255ee31 | 130 | extern HIST_ENTRY *current_history PARAMS((void)); |
d60d9f65 SS |
131 | |
132 | /* Return the history entry which is logically at OFFSET in the history | |
133 | array. OFFSET is relative to history_base. */ | |
9255ee31 | 134 | extern HIST_ENTRY *history_get PARAMS((int)); |
d60d9f65 | 135 | |
5bdf8622 DJ |
136 | /* Return the timestamp associated with the HIST_ENTRY * passed as an |
137 | argument */ | |
138 | extern time_t history_get_time PARAMS((HIST_ENTRY *)); | |
139 | ||
d60d9f65 SS |
140 | /* Return the number of bytes that the primary history entries are using. |
141 | This just adds up the lengths of the_history->lines. */ | |
9255ee31 | 142 | extern int history_total_bytes PARAMS((void)); |
d60d9f65 SS |
143 | |
144 | /* Moving around the history list. */ | |
145 | ||
146 | /* Set the position in the history list to POS. */ | |
9255ee31 | 147 | extern int history_set_pos PARAMS((int)); |
d60d9f65 SS |
148 | |
149 | /* Back up history_offset to the previous history entry, and return | |
150 | a pointer to that entry. If there is no previous entry, return | |
151 | a NULL pointer. */ | |
9255ee31 | 152 | extern HIST_ENTRY *previous_history PARAMS((void)); |
d60d9f65 SS |
153 | |
154 | /* Move history_offset forward to the next item in the input_history, | |
155 | and return the a pointer to that entry. If there is no next entry, | |
156 | return a NULL pointer. */ | |
9255ee31 | 157 | extern HIST_ENTRY *next_history PARAMS((void)); |
d60d9f65 SS |
158 | |
159 | /* Searching the history list. */ | |
160 | ||
161 | /* Search the history for STRING, starting at history_offset. | |
162 | If DIRECTION < 0, then the search is through previous entries, | |
163 | else through subsequent. If the string is found, then | |
164 | current_history () is the history entry, and the value of this function | |
165 | is the offset in the line of that history entry that the string was | |
166 | found in. Otherwise, nothing is changed, and a -1 is returned. */ | |
9255ee31 | 167 | extern int history_search PARAMS((const char *, int)); |
d60d9f65 SS |
168 | |
169 | /* Search the history for STRING, starting at history_offset. | |
c862e87b JM |
170 | The search is anchored: matching lines must begin with string. |
171 | DIRECTION is as in history_search(). */ | |
9255ee31 | 172 | extern int history_search_prefix PARAMS((const char *, int)); |
d60d9f65 SS |
173 | |
174 | /* Search for STRING in the history list, starting at POS, an | |
175 | absolute index into the list. DIR, if negative, says to search | |
176 | backwards from POS, else forwards. | |
177 | Returns the absolute index of the history element where STRING | |
178 | was found, or -1 otherwise. */ | |
9255ee31 | 179 | extern int history_search_pos PARAMS((const char *, int, int)); |
d60d9f65 SS |
180 | |
181 | /* Managing the history file. */ | |
182 | ||
183 | /* Add the contents of FILENAME to the history list, a line at a time. | |
184 | If FILENAME is NULL, then read from ~/.history. Returns 0 if | |
185 | successful, or errno if not. */ | |
9255ee31 | 186 | extern int read_history PARAMS((const char *)); |
d60d9f65 SS |
187 | |
188 | /* Read a range of lines from FILENAME, adding them to the history list. | |
189 | Start reading at the FROM'th line and end at the TO'th. If FROM | |
190 | is zero, start at the beginning. If TO is less than FROM, read | |
191 | until the end of the file. If FILENAME is NULL, then read from | |
192 | ~/.history. Returns 0 if successful, or errno if not. */ | |
9255ee31 | 193 | extern int read_history_range PARAMS((const char *, int, int)); |
d60d9f65 SS |
194 | |
195 | /* Write the current history to FILENAME. If FILENAME is NULL, | |
196 | then write the history list to ~/.history. Values returned | |
197 | are as in read_history (). */ | |
9255ee31 | 198 | extern int write_history PARAMS((const char *)); |
d60d9f65 SS |
199 | |
200 | /* Append NELEMENT entries to FILENAME. The entries appended are from | |
201 | the end of the list minus NELEMENTs up to the end of the list. */ | |
9255ee31 | 202 | extern int append_history PARAMS((int, const char *)); |
d60d9f65 SS |
203 | |
204 | /* Truncate the history file, leaving only the last NLINES lines. */ | |
9255ee31 | 205 | extern int history_truncate_file PARAMS((const char *, int)); |
d60d9f65 SS |
206 | |
207 | /* History expansion. */ | |
208 | ||
209 | /* Expand the string STRING, placing the result into OUTPUT, a pointer | |
210 | to a string. Returns: | |
211 | ||
212 | 0) If no expansions took place (or, if the only change in | |
213 | the text was the de-slashifying of the history expansion | |
214 | character) | |
215 | 1) If expansions did take place | |
216 | -1) If there was an error in expansion. | |
217 | 2) If the returned line should just be printed. | |
218 | ||
219 | If an error ocurred in expansion, then OUTPUT contains a descriptive | |
220 | error message. */ | |
9255ee31 | 221 | extern int history_expand PARAMS((char *, char **)); |
d60d9f65 SS |
222 | |
223 | /* Extract a string segment consisting of the FIRST through LAST | |
224 | arguments present in STRING. Arguments are broken up as in | |
225 | the shell. */ | |
9255ee31 | 226 | extern char *history_arg_extract PARAMS((int, int, const char *)); |
d60d9f65 SS |
227 | |
228 | /* Return the text of the history event beginning at the current | |
c862e87b JM |
229 | offset into STRING. Pass STRING with *INDEX equal to the |
230 | history_expansion_char that begins this specification. | |
231 | DELIMITING_QUOTE is a character that is allowed to end the string | |
232 | specification for what to search for in addition to the normal | |
233 | characters `:', ` ', `\t', `\n', and sometimes `?'. */ | |
9255ee31 | 234 | extern char *get_history_event PARAMS((const char *, int *, int)); |
d60d9f65 SS |
235 | |
236 | /* Return an array of tokens, much as the shell might. The tokens are | |
237 | parsed out of STRING. */ | |
9255ee31 | 238 | extern char **history_tokenize PARAMS((const char *)); |
d60d9f65 SS |
239 | |
240 | /* Exported history variables. */ | |
241 | extern int history_base; | |
242 | extern int history_length; | |
9255ee31 | 243 | extern int history_max_entries; |
d60d9f65 SS |
244 | extern char history_expansion_char; |
245 | extern char history_subst_char; | |
9255ee31 | 246 | extern char *history_word_delimiters; |
d60d9f65 SS |
247 | extern char history_comment_char; |
248 | extern char *history_no_expand_chars; | |
249 | extern char *history_search_delimiter_chars; | |
250 | extern int history_quotes_inhibit_expansion; | |
251 | ||
5bdf8622 DJ |
252 | extern int history_write_timestamps; |
253 | ||
9255ee31 EZ |
254 | /* Backwards compatibility */ |
255 | extern int max_input_history; | |
256 | ||
d60d9f65 SS |
257 | /* If set, this function is called to decide whether or not a particular |
258 | history expansion should be treated as a special case for the calling | |
259 | application and not expanded. */ | |
9255ee31 | 260 | extern rl_linebuf_func_t *history_inhibit_expansion_function; |
d60d9f65 | 261 | |
c862e87b JM |
262 | #ifdef __cplusplus |
263 | } | |
264 | #endif | |
265 | ||
d60d9f65 | 266 | #endif /* !_HISTORY_H_ */ |