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