1 /* History.h -- the names of functions that you can call in history. */
2 /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
4 This file contains the GNU History Library (the Library), a set of
5 routines for managing the text of previously typed lines.
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 2, or (at your option)
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.
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 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
29 #if defined READLINE_LIBRARY
32 # include <readline/rlstdc.h>
35 #if !defined (_FUNCTION_DEF)
36 # define _FUNCTION_DEF
37 typedef int Function ();
38 typedef void VFunction ();
39 typedef char *CPFunction ();
40 typedef char **CPPFunction ();
44 typedef void *histdata_t
;
46 typedef char *histdata_t
;
49 /* The structure used to store a history entry. */
50 typedef struct _hist_entry
{
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. */
64 /* Flag values for the `flags' member of HISTORY_STATE. */
65 #define HS_STIFLED 0x01
67 /* Initialization and state management. */
69 /* Begin a session in which the history functions might be used. This
70 just initializes the interactive variables. */
71 extern void using_history
__P((void));
73 /* Return the current HISTORY_STATE of the history. */
74 extern HISTORY_STATE
*history_get_history_state
__P((void));
76 /* Set the state of the current history array to STATE. */
77 extern void history_set_history_state
__P((HISTORY_STATE
*));
79 /* Manage the history list. */
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
__P((char *));
85 /* A reasonably useless function, only here for completeness. WHICH
86 is the magic number that tells us which element to delete. The
87 elements are numbered from 0. */
88 extern HIST_ENTRY
*remove_history
__P((int));
90 /* Make the history entry at WHICH have LINE and DATA. This returns
91 the old entry so you can dispose of the data. In the case of an
92 invalid WHICH, a NULL pointer is returned. */
93 extern HIST_ENTRY
*replace_history_entry
__P((int, char *, histdata_t
));
95 /* Clear the history list and start over. */
96 extern void clear_history
__P((void));
98 /* Stifle the history list, remembering only MAX number of entries. */
99 extern void stifle_history
__P((int));
101 /* Stop stifling the history. This returns the previous amount the
102 history was stifled by. The value is positive if the history was
103 stifled, negative if it wasn't. */
104 extern int unstifle_history
__P((void));
106 /* Return 1 if the history is stifled, 0 if it is not. */
107 extern int history_is_stifled
__P((void));
109 /* Information about the history list. */
111 /* Return a NULL terminated array of HIST_ENTRY which is the current input
112 history. Element 0 of this list is the beginning of time. If there
113 is no history, return NULL. */
114 extern HIST_ENTRY
**history_list
__P((void));
116 /* Returns the number which says what history element we are now
118 extern int where_history
__P((void));
120 /* Return the history entry at the current position, as determined by
121 history_offset. If there is no entry there, return a NULL pointer. */
122 extern HIST_ENTRY
*current_history
__P((void));
124 /* Return the history entry which is logically at OFFSET in the history
125 array. OFFSET is relative to history_base. */
126 extern HIST_ENTRY
*history_get
__P((int));
128 /* Return the number of bytes that the primary history entries are using.
129 This just adds up the lengths of the_history->lines. */
130 extern int history_total_bytes
__P((void));
132 /* Moving around the history list. */
134 /* Set the position in the history list to POS. */
135 extern int history_set_pos
__P((int));
137 /* Back up history_offset to the previous history entry, and return
138 a pointer to that entry. If there is no previous entry, return
140 extern HIST_ENTRY
*previous_history
__P((void));
142 /* Move history_offset forward to the next item in the input_history,
143 and return the a pointer to that entry. If there is no next entry,
144 return a NULL pointer. */
145 extern HIST_ENTRY
*next_history
__P((void));
147 /* Searching the history list. */
149 /* Search the history for STRING, starting at history_offset.
150 If DIRECTION < 0, then the search is through previous entries,
151 else through subsequent. If the string is found, then
152 current_history () is the history entry, and the value of this function
153 is the offset in the line of that history entry that the string was
154 found in. Otherwise, nothing is changed, and a -1 is returned. */
155 extern int history_search
__P((char *, int));
157 /* Search the history for STRING, starting at history_offset.
158 The search is anchored: matching lines must begin with string.
159 DIRECTION is as in history_search(). */
160 extern int history_search_prefix
__P((char *, int));
162 /* Search for STRING in the history list, starting at POS, an
163 absolute index into the list. DIR, if negative, says to search
164 backwards from POS, else forwards.
165 Returns the absolute index of the history element where STRING
166 was found, or -1 otherwise. */
167 extern int history_search_pos
__P((char *, int, int));
169 /* Managing the history file. */
171 /* Add the contents of FILENAME to the history list, a line at a time.
172 If FILENAME is NULL, then read from ~/.history. Returns 0 if
173 successful, or errno if not. */
174 extern int read_history
__P((char *));
176 /* Read a range of lines from FILENAME, adding them to the history list.
177 Start reading at the FROM'th line and end at the TO'th. If FROM
178 is zero, start at the beginning. If TO is less than FROM, read
179 until the end of the file. If FILENAME is NULL, then read from
180 ~/.history. Returns 0 if successful, or errno if not. */
181 extern int read_history_range
__P((char *, int, int));
183 /* Write the current history to FILENAME. If FILENAME is NULL,
184 then write the history list to ~/.history. Values returned
185 are as in read_history (). */
186 extern int write_history
__P((char *));
188 /* Append NELEMENT entries to FILENAME. The entries appended are from
189 the end of the list minus NELEMENTs up to the end of the list. */
190 extern int append_history
__P((int, char *));
192 /* Truncate the history file, leaving only the last NLINES lines. */
193 extern int history_truncate_file
__P((char *, int));
195 /* History expansion. */
197 /* Expand the string STRING, placing the result into OUTPUT, a pointer
198 to a string. Returns:
200 0) If no expansions took place (or, if the only change in
201 the text was the de-slashifying of the history expansion
203 1) If expansions did take place
204 -1) If there was an error in expansion.
205 2) If the returned line should just be printed.
207 If an error ocurred in expansion, then OUTPUT contains a descriptive
209 extern int history_expand
__P((char *, char **));
211 /* Extract a string segment consisting of the FIRST through LAST
212 arguments present in STRING. Arguments are broken up as in
214 extern char *history_arg_extract
__P((int, int, char *));
216 /* Return the text of the history event beginning at the current
217 offset into STRING. Pass STRING with *INDEX equal to the
218 history_expansion_char that begins this specification.
219 DELIMITING_QUOTE is a character that is allowed to end the string
220 specification for what to search for in addition to the normal
221 characters `:', ` ', `\t', `\n', and sometimes `?'. */
222 extern char *get_history_event
__P((char *, int *, int));
224 /* Return an array of tokens, much as the shell might. The tokens are
225 parsed out of STRING. */
226 extern char **history_tokenize
__P((char *));
228 /* Exported history variables. */
229 extern int history_base
;
230 extern int history_length
;
231 extern int max_input_history
;
232 extern char history_expansion_char
;
233 extern char history_subst_char
;
234 extern char history_comment_char
;
235 extern char *history_no_expand_chars
;
236 extern char *history_search_delimiter_chars
;
237 extern int history_quotes_inhibit_expansion
;
239 /* If set, this function is called to decide whether or not a particular
240 history expansion should be treated as a special case for the calling
241 application and not expanded. */
242 extern Function
*history_inhibit_expansion_function
;
248 #endif /* !_HISTORY_H_ */