17ec8775117afd5fedfeae43f57db9cc73898dc2
[platform/upstream/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 /* The structure used to store a history entry. */
26 typedef struct _hist_entry {
27   char *line;
28   char *data;
29 } HIST_ENTRY;
30
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. */
37   int flags;
38 } HISTORY_STATE;
39
40 /* Flag values for the `flags' member of HISTORY_STATE. */
41 #define HS_STIFLED      0x01
42
43 /* Initialization and state management. */
44
45 /* Begin a session in which the history functions might be used.  This
46    just initializes the interactive variables. */
47 extern void using_history ();
48
49 /* Return the current HISTORY_STATE of the history. */
50 extern HISTORY_STATE *history_get_history_state ();
51
52 /* Set the state of the current history array to STATE. */
53 extern void history_set_history_state ();
54
55 /* Manage the history list. */
56
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 ();
60
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 ();
65
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 ();
70
71 /* Clear the history list and start over. */
72 extern void clear_history ();
73
74 /* Stifle the history list, remembering only MAX number of entries. */
75 extern void stifle_history ();
76
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 ();
81
82 /* Return 1 if the history is stifled, 0 if it is not. */
83 extern int history_is_stifled ();
84
85 /* Information about the history list. */
86
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 ();
91
92 /* Returns the number which says what history element we are now
93    looking at.  */
94 extern int where_history ();
95   
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 ();
99
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 ();
103
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 ();
107
108 /* Moving around the history list. */
109
110 /* Set the position in the history list to POS. */
111 int history_set_pos ();
112
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
115    a NULL pointer. */
116 extern HIST_ENTRY *previous_history ();
117
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 ();
122
123 /* Searching the history list. */
124
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 ();
132
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 ();
136
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 ();
143
144 /* Managing the history file. */
145
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 ();
150
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 ();
157
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 ();
162
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 ();
166
167 /* Truncate the history file, leaving only the last NLINES lines. */
168 extern int history_truncate_file ();
169
170 /* History expansion. */
171
172 /* Expand the string STRING, placing the result into OUTPUT, a pointer
173    to a string.  Returns:
174
175    0) If no expansions took place (or, if the only change in
176       the text was the de-slashifying of the history expansion
177       character)
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.
181
182   If an error ocurred in expansion, then OUTPUT contains a descriptive
183   error message. */
184 extern int history_expand ();
185
186 /* Extract a string segment consisting of the FIRST through LAST
187    arguments present in STRING.  Arguments are broken up as in
188    the shell. */
189 extern char *history_arg_extract ();
190
191 /* Return the text of the history event beginning at the current
192    offset into STRING. */
193 extern char *get_history_event ();
194
195 /* Return an array of tokens, much as the shell might.  The tokens are
196    parsed out of STRING. */
197 extern char **history_tokenize ();
198
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;
209
210 #endif /* !_HISTORY_H_ */