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