comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/readline/history.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
comparison
equal deleted inserted replaced
67:0e9998148a16 69:33d812a61356
1 /* history.h -- the names of functions that you can call in history. */
2
3 /* Copyright (C) 1989-2022 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 /* Let's not step on anyone else's define for now, since we don't use this yet. */
46 #ifndef HS_HISTORY_VERSION
47 # define HS_HISTORY_VERSION 0x0802 /* History 8.2 */
48 #endif
49
50 /* The structure used to store a history entry. */
51 typedef struct _hist_entry {
52 char *line;
53 char *timestamp; /* char * rather than time_t for read/write */
54 histdata_t data;
55 } HIST_ENTRY;
56
57 /* Size of the history-library-managed space in history entry HS. */
58 #define HISTENT_BYTES(hs) (strlen ((hs)->line) + strlen ((hs)->timestamp))
59
60 /* A structure used to pass the current state of the history stuff around. */
61 typedef struct _hist_state {
62 HIST_ENTRY **entries; /* Pointer to the entries themselves. */
63 int offset; /* The location pointer within this array. */
64 int length; /* Number of elements within this array. */
65 int size; /* Number of slots allocated to this array. */
66 int flags;
67 } HISTORY_STATE;
68
69 /* Flag values for the `flags' member of HISTORY_STATE. */
70 #define HS_STIFLED 0x01
71
72 /* Initialization and state management. */
73
74 /* Begin a session in which the history functions might be used. This
75 just initializes the interactive variables. */
76 extern void using_history (void);
77
78 /* Return the current HISTORY_STATE of the history. */
79 extern HISTORY_STATE *history_get_history_state (void);
80
81 /* Set the state of the current history array to STATE. */
82 extern void history_set_history_state (HISTORY_STATE *);
83
84 /* Manage the history list. */
85
86 /* Place STRING at the end of the history list.
87 The associated data field (if any) is set to NULL. */
88 extern void add_history (const char *);
89
90 /* Change the timestamp associated with the most recent history entry to
91 STRING. */
92 extern void add_history_time (const char *);
93
94 /* Remove an entry from the history list. WHICH is the magic number that
95 tells us which element to delete. The elements are numbered from 0. */
96 extern HIST_ENTRY *remove_history (int);
97
98 /* Remove a set of entries from the history list: FIRST to LAST, inclusive */
99 extern HIST_ENTRY **remove_history_range (int, int);
100
101 /* Allocate a history entry consisting of STRING and TIMESTAMP and return
102 a pointer to it. */
103 extern HIST_ENTRY *alloc_history_entry (char *, char *);
104
105 /* Copy the history entry H, but not the (opaque) data pointer */
106 extern HIST_ENTRY *copy_history_entry (HIST_ENTRY *);
107
108 /* Free the history entry H and return any application-specific data
109 associated with it. */
110 extern histdata_t free_history_entry (HIST_ENTRY *);
111
112 /* Make the history entry at WHICH have LINE and DATA. This returns
113 the old entry so you can dispose of the data. In the case of an
114 invalid WHICH, a NULL pointer is returned. */
115 extern HIST_ENTRY *replace_history_entry (int, const char *, histdata_t);
116
117 /* Clear the history list and start over. */
118 extern void clear_history (void);
119
120 /* Stifle the history list, remembering only MAX number of entries. */
121 extern void stifle_history (int);
122
123 /* Stop stifling the history. This returns the previous amount the
124 history was stifled by. The value is positive if the history was
125 stifled, negative if it wasn't. */
126 extern int unstifle_history (void);
127
128 /* Return 1 if the history is stifled, 0 if it is not. */
129 extern int history_is_stifled (void);
130
131 /* Information about the history list. */
132
133 /* Return a NULL terminated array of HIST_ENTRY which is the current input
134 history. Element 0 of this list is the beginning of time. If there
135 is no history, return NULL. */
136 extern HIST_ENTRY **history_list (void);
137
138 /* Returns the number which says what history element we are now
139 looking at. */
140 extern int where_history (void);
141
142 /* Return the history entry at the current position, as determined by
143 history_offset. If there is no entry there, return a NULL pointer. */
144 extern HIST_ENTRY *current_history (void);
145
146 /* Return the history entry which is logically at OFFSET in the history
147 array. OFFSET is relative to history_base. */
148 extern HIST_ENTRY *history_get (int);
149
150 /* Return the timestamp associated with the HIST_ENTRY * passed as an
151 argument */
152 extern time_t history_get_time (HIST_ENTRY *);
153
154 /* Return the number of bytes that the primary history entries are using.
155 This just adds up the lengths of the_history->lines. */
156 extern int history_total_bytes (void);
157
158 /* Moving around the history list. */
159
160 /* Set the position in the history list to POS. */
161 extern int history_set_pos (int);
162
163 /* Back up history_offset to the previous history entry, and return
164 a pointer to that entry. If there is no previous entry, return
165 a NULL pointer. */
166 extern HIST_ENTRY *previous_history (void);
167
168 /* Move history_offset forward to the next item in the input_history,
169 and return the a pointer to that entry. If there is no next entry,
170 return a NULL pointer. */
171 extern HIST_ENTRY *next_history (void);
172
173 /* Searching the history list. */
174
175 /* Search the history for STRING, starting at history_offset.
176 If DIRECTION < 0, then the search is through previous entries,
177 else through subsequent. If the string is found, then
178 current_history () is the history entry, and the value of this function
179 is the offset in the line of that history entry that the string was
180 found in. Otherwise, nothing is changed, and a -1 is returned. */
181 extern int history_search (const char *, int);
182
183 /* Search the history for STRING, starting at history_offset.
184 The search is anchored: matching lines must begin with string.
185 DIRECTION is as in history_search(). */
186 extern int history_search_prefix (const char *, int);
187
188 /* Search for STRING in the history list, starting at POS, an
189 absolute index into the list. DIR, if negative, says to search
190 backwards from POS, else forwards.
191 Returns the absolute index of the history element where STRING
192 was found, or -1 otherwise. */
193 extern int history_search_pos (const char *, int, int);
194
195 /* Managing the history file. */
196
197 /* Add the contents of FILENAME to the history list, a line at a time.
198 If FILENAME is NULL, then read from ~/.history. Returns 0 if
199 successful, or errno if not. */
200 extern int read_history (const char *);
201
202 /* Read a range of lines from FILENAME, adding them to the history list.
203 Start reading at the FROM'th line and end at the TO'th. If FROM
204 is zero, start at the beginning. If TO is less than FROM, read
205 until the end of the file. If FILENAME is NULL, then read from
206 ~/.history. Returns 0 if successful, or errno if not. */
207 extern int read_history_range (const char *, int, int);
208
209 /* Write the current history to FILENAME. If FILENAME is NULL,
210 then write the history list to ~/.history. Values returned
211 are as in read_history (). */
212 extern int write_history (const char *);
213
214 /* Append NELEMENT entries to FILENAME. The entries appended are from
215 the end of the list minus NELEMENTs up to the end of the list. */
216 extern int append_history (int, const char *);
217
218 /* Truncate the history file, leaving only the last NLINES lines. */
219 extern int history_truncate_file (const char *, int);
220
221 /* History expansion. */
222
223 /* Expand the string STRING, placing the result into OUTPUT, a pointer
224 to a string. Returns:
225
226 0) If no expansions took place (or, if the only change in
227 the text was the de-slashifying of the history expansion
228 character)
229 1) If expansions did take place
230 -1) If there was an error in expansion.
231 2) If the returned line should just be printed.
232
233 If an error occurred in expansion, then OUTPUT contains a descriptive
234 error message. */
235 extern int history_expand (char *, char **);
236
237 /* Extract a string segment consisting of the FIRST through LAST
238 arguments present in STRING. Arguments are broken up as in
239 the shell. */
240 extern char *history_arg_extract (int, int, const char *);
241
242 /* Return the text of the history event beginning at the current
243 offset into STRING. Pass STRING with *INDEX equal to the
244 history_expansion_char that begins this specification.
245 DELIMITING_QUOTE is a character that is allowed to end the string
246 specification for what to search for in addition to the normal
247 characters `:', ` ', `\t', `\n', and sometimes `?'. */
248 extern char *get_history_event (const char *, int *, int);
249
250 /* Return an array of tokens, much as the shell might. The tokens are
251 parsed out of STRING. */
252 extern char **history_tokenize (const char *);
253
254 /* Exported history variables. */
255 extern int history_base;
256 extern int history_length;
257 extern int history_max_entries;
258 extern int history_offset;
259
260 extern int history_lines_read_from_file;
261 extern int history_lines_written_to_file;
262
263 extern char history_expansion_char;
264 extern char history_subst_char;
265 extern char *history_word_delimiters;
266 extern char history_comment_char;
267 extern char *history_no_expand_chars;
268 extern char *history_search_delimiter_chars;
269
270 extern int history_quotes_inhibit_expansion;
271 extern int history_quoting_state;
272
273 extern int history_write_timestamps;
274
275 /* These two are undocumented; the second is reserved for future use */
276 extern int history_multiline_entries;
277 extern int history_file_version;
278
279 /* Backwards compatibility */
280 extern int max_input_history;
281
282 /* If set, this function is called to decide whether or not a particular
283 history expansion should be treated as a special case for the calling
284 application and not expanded. */
285 extern rl_linebuf_func_t *history_inhibit_expansion_function;
286
287 #ifdef __cplusplus
288 }
289 #endif
290
291 #endif /* !_HISTORY_H_ */