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