1312521Sngie/* History.h -- the names of functions that you can call in history. */
2312521Sngie/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
3312521Sngie
4312521Sngie   This file contains the GNU History Library (the Library), a set of
5312521Sngie   routines for managing the text of previously typed lines.
6312521Sngie
7312521Sngie   The Library is free software; you can redistribute it and/or modify
8312521Sngie   it under the terms of the GNU General Public License as published by
9312521Sngie   the Free Software Foundation; either version 2, or (at your option)
10312521Sngie   any later version.
11312521Sngie
12312521Sngie   The Library is distributed in the hope that it will be useful, but
13312521Sngie   WITHOUT ANY WARRANTY; without even the implied warranty of
14312521Sngie   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15312521Sngie   General Public License for more details.
16312521Sngie
17312521Sngie   The GNU General Public License is often shipped with GNU software, and
18312521Sngie   is generally kept in a file called COPYING or LICENSE.  If you do not
19312521Sngie   have a copy of the license, write to the Free Software Foundation,
20312521Sngie   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
21312521Sngie
22312521Sngie#ifndef _HISTORY_H_
23312521Sngie#define _HISTORY_H_
24312521Sngie
25312521Sngie#ifdef __cplusplus
26312521Sngieextern "C" {
27312521Sngie#endif
28312521Sngie
29312521Sngie#if defined READLINE_LIBRARY
30312521Sngie#  include "rlstdc.h"
31312521Sngie#  include "rltypedefs.h"
32312521Sngie#else
33312521Sngie#  include <readline/rlstdc.h>
34312521Sngie#  include <readline/rltypedefs.h>
35312521Sngie#endif
36312521Sngie
37312521Sngie#ifdef __STDC__
38312521Sngietypedef void *histdata_t;
39312521Sngie#else
40312521Sngietypedef char *histdata_t;
41338462Smarkj#endif
42312521Sngie
43312521Sngie/* The structure used to store a history entry. */
44312521Sngietypedef struct _hist_entry {
45312521Sngie  char *line;
46312521Sngie  histdata_t data;
47312521Sngie} HIST_ENTRY;
48312521Sngie
49312521Sngie/* A structure used to pass the current state of the history stuff around. */
50312521Sngietypedef struct _hist_state {
51312521Sngie  HIST_ENTRY **entries;		/* Pointer to the entries themselves. */
52312521Sngie  int offset;			/* The location pointer within this array. */
53312521Sngie  int length;			/* Number of elements within this array. */
54338462Smarkj  int size;			/* Number of slots allocated to this array. */
55312521Sngie  int flags;
56312521Sngie} HISTORY_STATE;
57338462Smarkj
58338462Smarkj/* Flag values for the `flags' member of HISTORY_STATE. */
59338462Smarkj#define HS_STIFLED	0x01
60338462Smarkj
61338462Smarkj/* Initialization and state management. */
62338462Smarkj
63338462Smarkj/* Begin a session in which the history functions might be used.  This
64338462Smarkj   just initializes the interactive variables. */
65338462Smarkjextern void using_history PARAMS((void));
66338462Smarkj
67338462Smarkj/* Return the current HISTORY_STATE of the history. */
68338462Smarkjextern HISTORY_STATE *history_get_history_state PARAMS((void));
69338462Smarkj
70338462Smarkj/* Set the state of the current history array to STATE. */
71338462Smarkjextern void history_set_history_state PARAMS((HISTORY_STATE *));
72362688S0mp
73362688S0mp/* Manage the history list. */
74362688S0mp
75362688S0mp/* Place STRING at the end of the history list.
76362688S0mp   The associated data field (if any) is set to NULL. */
77362688S0mpextern void add_history PARAMS((const char *));
78362688S0mp
79362688S0mp/* A reasonably useless function, only here for completeness.  WHICH
80362688S0mp   is the magic number that tells us which element to delete.  The
81362688S0mp   elements are numbered from 0. */
82362688S0mpextern HIST_ENTRY *remove_history PARAMS((int));
83362688S0mp
84362688S0mp/* Make the history entry at WHICH have LINE and DATA.  This returns
85362688S0mp   the old entry so you can dispose of the data.  In the case of an
86362688S0mp   invalid WHICH, a NULL pointer is returned. */
87362688S0mpextern HIST_ENTRY *replace_history_entry PARAMS((int, const char *, histdata_t));
88362688S0mp
89362688S0mp/* Clear the history list and start over. */
90312521Sngieextern void clear_history PARAMS((void));
91312521Sngie
92338462Smarkj/* Stifle the history list, remembering only MAX number of entries. */
93312521Sngieextern void stifle_history PARAMS((int));
94312521Sngie
95362688S0mp/* Stop stifling the history.  This returns the previous amount the
96312521Sngie   history was stifled by.  The value is positive if the history was
97   stifled, negative if it wasn't. */
98extern int unstifle_history PARAMS((void));
99
100/* Return 1 if the history is stifled, 0 if it is not. */
101extern int history_is_stifled PARAMS((void));
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. */
108extern HIST_ENTRY **history_list PARAMS((void));
109
110/* Returns the number which says what history element we are now
111   looking at.  */
112extern int where_history PARAMS((void));
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. */
116extern HIST_ENTRY *current_history PARAMS((void));
117
118/* Return the history entry which is logically at OFFSET in the history
119   array.  OFFSET is relative to history_base. */
120extern HIST_ENTRY *history_get PARAMS((int));
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. */
124extern int history_total_bytes PARAMS((void));
125
126/* Moving around the history list. */
127
128/* Set the position in the history list to POS. */
129extern int history_set_pos PARAMS((int));
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. */
134extern HIST_ENTRY *previous_history PARAMS((void));
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. */
139extern HIST_ENTRY *next_history PARAMS((void));
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. */
149extern int history_search PARAMS((const char *, int));
150
151/* Search the history for STRING, starting at history_offset.
152   The search is anchored: matching lines must begin with string.
153   DIRECTION is as in history_search(). */
154extern int history_search_prefix PARAMS((const char *, int));
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. */
161extern int history_search_pos PARAMS((const char *, int, int));
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. */
168extern int read_history PARAMS((const char *));
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. */
175extern int read_history_range PARAMS((const char *, int, int));
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 ().  */
180extern int write_history PARAMS((const char *));
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. */
184extern int append_history PARAMS((int, const char *));
185
186/* Truncate the history file, leaving only the last NLINES lines. */
187extern int history_truncate_file PARAMS((const char *, int));
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. */
203extern int history_expand PARAMS((char *, char **));
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. */
208extern char *history_arg_extract PARAMS((int, int, const char *));
209
210/* Return the text of the history event beginning at the current
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 `?'. */
216extern char *get_history_event PARAMS((const char *, int *, int));
217
218/* Return an array of tokens, much as the shell might.  The tokens are
219   parsed out of STRING. */
220extern char **history_tokenize PARAMS((const char *));
221
222/* Exported history variables. */
223extern int history_base;
224extern int history_length;
225extern int history_max_entries;
226extern char history_expansion_char;
227extern char history_subst_char;
228extern char *history_word_delimiters;
229extern char history_comment_char;
230extern char *history_no_expand_chars;
231extern char *history_search_delimiter_chars;
232extern int history_quotes_inhibit_expansion;
233
234/* Backwards compatibility */
235extern int max_input_history;
236
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. */
240extern rl_linebuf_func_t *history_inhibit_expansion_function;
241
242#ifdef __cplusplus
243}
244#endif
245
246#endif /* !_HISTORY_H_ */
247