1999-04-16 09:34:55 +08:00
|
|
|
/* History.h -- the names of functions that you can call in history. */
|
|
|
|
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file contains the GNU History Library (the Library), a set of
|
|
|
|
routines for managing the text of previously typed lines.
|
|
|
|
|
|
|
|
The Library is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-10 01:20:00 +08:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
1999-04-16 09:34:55 +08:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
The Library is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
The GNU General Public License is often shipped with GNU software, and
|
|
|
|
is generally kept in a file called COPYING or LICENSE. If you do not
|
|
|
|
have a copy of the license, write to the Free Software Foundation,
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-10 01:20:00 +08:00
|
|
|
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
#ifndef _HISTORY_H_
|
|
|
|
#define _HISTORY_H_
|
|
|
|
|
1999-08-03 07:48:02 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined READLINE_LIBRARY
|
|
|
|
# include "rlstdc.h"
|
|
|
|
#else
|
|
|
|
# include <readline/rlstdc.h>
|
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:34:55 +08:00
|
|
|
#if !defined (_FUNCTION_DEF)
|
|
|
|
# define _FUNCTION_DEF
|
|
|
|
typedef int Function ();
|
|
|
|
typedef void VFunction ();
|
|
|
|
typedef char *CPFunction ();
|
|
|
|
typedef char **CPPFunction ();
|
|
|
|
#endif
|
|
|
|
|
1999-08-03 07:48:02 +08:00
|
|
|
#ifdef __STDC__
|
|
|
|
typedef void *histdata_t;
|
|
|
|
#else
|
|
|
|
typedef char *histdata_t;
|
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:34:55 +08:00
|
|
|
/* The structure used to store a history entry. */
|
|
|
|
typedef struct _hist_entry {
|
|
|
|
char *line;
|
1999-08-03 07:48:02 +08:00
|
|
|
histdata_t data;
|
1999-04-16 09:34:55 +08:00
|
|
|
} HIST_ENTRY;
|
|
|
|
|
|
|
|
/* A structure used to pass the current state of the history stuff around. */
|
|
|
|
typedef struct _hist_state {
|
|
|
|
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
|
|
|
|
int offset; /* The location pointer within this array. */
|
|
|
|
int length; /* Number of elements within this array. */
|
|
|
|
int size; /* Number of slots allocated to this array. */
|
|
|
|
int flags;
|
|
|
|
} HISTORY_STATE;
|
|
|
|
|
|
|
|
/* Flag values for the `flags' member of HISTORY_STATE. */
|
|
|
|
#define HS_STIFLED 0x01
|
|
|
|
|
|
|
|
/* Initialization and state management. */
|
|
|
|
|
|
|
|
/* Begin a session in which the history functions might be used. This
|
|
|
|
just initializes the interactive variables. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern void using_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return the current HISTORY_STATE of the history. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HISTORY_STATE *history_get_history_state __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Set the state of the current history array to STATE. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern void history_set_history_state __P((HISTORY_STATE *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Manage the history list. */
|
|
|
|
|
|
|
|
/* Place STRING at the end of the history list.
|
|
|
|
The associated data field (if any) is set to NULL. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern void add_history __P((char *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* A reasonably useless function, only here for completeness. WHICH
|
|
|
|
is the magic number that tells us which element to delete. The
|
|
|
|
elements are numbered from 0. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HIST_ENTRY *remove_history __P((int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Make the history entry at WHICH have LINE and DATA. This returns
|
|
|
|
the old entry so you can dispose of the data. In the case of an
|
|
|
|
invalid WHICH, a NULL pointer is returned. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HIST_ENTRY *replace_history_entry __P((int, char *, histdata_t));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Clear the history list and start over. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern void clear_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Stifle the history list, remembering only MAX number of entries. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern void stifle_history __P((int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Stop stifling the history. This returns the previous amount the
|
|
|
|
history was stifled by. The value is positive if the history was
|
|
|
|
stifled, negative if it wasn't. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int unstifle_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return 1 if the history is stifled, 0 if it is not. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int history_is_stifled __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Information about the history list. */
|
|
|
|
|
|
|
|
/* Return a NULL terminated array of HIST_ENTRY which is the current input
|
|
|
|
history. Element 0 of this list is the beginning of time. If there
|
|
|
|
is no history, return NULL. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HIST_ENTRY **history_list __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Returns the number which says what history element we are now
|
|
|
|
looking at. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int where_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return the history entry at the current position, as determined by
|
|
|
|
history_offset. If there is no entry there, return a NULL pointer. */
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-10 01:20:00 +08:00
|
|
|
extern HIST_ENTRY *current_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return the history entry which is logically at OFFSET in the history
|
|
|
|
array. OFFSET is relative to history_base. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HIST_ENTRY *history_get __P((int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return the number of bytes that the primary history entries are using.
|
|
|
|
This just adds up the lengths of the_history->lines. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int history_total_bytes __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Moving around the history list. */
|
|
|
|
|
|
|
|
/* Set the position in the history list to POS. */
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-10 01:20:00 +08:00
|
|
|
extern int history_set_pos __P((int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Back up history_offset to the previous history entry, and return
|
|
|
|
a pointer to that entry. If there is no previous entry, return
|
|
|
|
a NULL pointer. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HIST_ENTRY *previous_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Move history_offset forward to the next item in the input_history,
|
|
|
|
and return the a pointer to that entry. If there is no next entry,
|
|
|
|
return a NULL pointer. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern HIST_ENTRY *next_history __P((void));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Searching the history list. */
|
|
|
|
|
|
|
|
/* Search the history for STRING, starting at history_offset.
|
|
|
|
If DIRECTION < 0, then the search is through previous entries,
|
|
|
|
else through subsequent. If the string is found, then
|
|
|
|
current_history () is the history entry, and the value of this function
|
|
|
|
is the offset in the line of that history entry that the string was
|
|
|
|
found in. Otherwise, nothing is changed, and a -1 is returned. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int history_search __P((char *, int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Search the history for STRING, starting at history_offset.
|
1999-08-03 07:48:02 +08:00
|
|
|
The search is anchored: matching lines must begin with string.
|
|
|
|
DIRECTION is as in history_search(). */
|
|
|
|
extern int history_search_prefix __P((char *, int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Search for STRING in the history list, starting at POS, an
|
|
|
|
absolute index into the list. DIR, if negative, says to search
|
|
|
|
backwards from POS, else forwards.
|
|
|
|
Returns the absolute index of the history element where STRING
|
|
|
|
was found, or -1 otherwise. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int history_search_pos __P((char *, int, int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Managing the history file. */
|
|
|
|
|
|
|
|
/* Add the contents of FILENAME to the history list, a line at a time.
|
|
|
|
If FILENAME is NULL, then read from ~/.history. Returns 0 if
|
|
|
|
successful, or errno if not. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int read_history __P((char *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Read a range of lines from FILENAME, adding them to the history list.
|
|
|
|
Start reading at the FROM'th line and end at the TO'th. If FROM
|
|
|
|
is zero, start at the beginning. If TO is less than FROM, read
|
|
|
|
until the end of the file. If FILENAME is NULL, then read from
|
|
|
|
~/.history. Returns 0 if successful, or errno if not. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int read_history_range __P((char *, int, int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Write the current history to FILENAME. If FILENAME is NULL,
|
|
|
|
then write the history list to ~/.history. Values returned
|
|
|
|
are as in read_history (). */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int write_history __P((char *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Append NELEMENT entries to FILENAME. The entries appended are from
|
|
|
|
the end of the list minus NELEMENTs up to the end of the list. */
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-10 01:20:00 +08:00
|
|
|
extern int append_history __P((int, char *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Truncate the history file, leaving only the last NLINES lines. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int history_truncate_file __P((char *, int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* History expansion. */
|
|
|
|
|
|
|
|
/* Expand the string STRING, placing the result into OUTPUT, a pointer
|
|
|
|
to a string. Returns:
|
|
|
|
|
|
|
|
0) If no expansions took place (or, if the only change in
|
|
|
|
the text was the de-slashifying of the history expansion
|
|
|
|
character)
|
|
|
|
1) If expansions did take place
|
|
|
|
-1) If there was an error in expansion.
|
|
|
|
2) If the returned line should just be printed.
|
|
|
|
|
|
|
|
If an error ocurred in expansion, then OUTPUT contains a descriptive
|
|
|
|
error message. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern int history_expand __P((char *, char **));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Extract a string segment consisting of the FIRST through LAST
|
|
|
|
arguments present in STRING. Arguments are broken up as in
|
|
|
|
the shell. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern char *history_arg_extract __P((int, int, char *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return the text of the history event beginning at the current
|
1999-08-03 07:48:02 +08:00
|
|
|
offset into STRING. Pass STRING with *INDEX equal to the
|
|
|
|
history_expansion_char that begins this specification.
|
|
|
|
DELIMITING_QUOTE is a character that is allowed to end the string
|
|
|
|
specification for what to search for in addition to the normal
|
|
|
|
characters `:', ` ', `\t', `\n', and sometimes `?'. */
|
|
|
|
extern char *get_history_event __P((char *, int *, int));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Return an array of tokens, much as the shell might. The tokens are
|
|
|
|
parsed out of STRING. */
|
1999-08-03 07:48:02 +08:00
|
|
|
extern char **history_tokenize __P((char *));
|
1999-04-16 09:34:55 +08:00
|
|
|
|
|
|
|
/* Exported history variables. */
|
|
|
|
extern int history_base;
|
|
|
|
extern int history_length;
|
|
|
|
extern int max_input_history;
|
|
|
|
extern char history_expansion_char;
|
|
|
|
extern char history_subst_char;
|
|
|
|
extern char history_comment_char;
|
|
|
|
extern char *history_no_expand_chars;
|
|
|
|
extern char *history_search_delimiter_chars;
|
|
|
|
extern int history_quotes_inhibit_expansion;
|
|
|
|
|
|
|
|
/* If set, this function is called to decide whether or not a particular
|
|
|
|
history expansion should be treated as a special case for the calling
|
|
|
|
application and not expanded. */
|
|
|
|
extern Function *history_inhibit_expansion_function;
|
|
|
|
|
1999-08-03 07:48:02 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:34:55 +08:00
|
|
|
#endif /* !_HISTORY_H_ */
|