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