xref: /openbsd-src/gnu/lib/libreadline/doc/hstech.texinfo (revision af70c2df780099dcdde93deaba1af49686a47bbf)
11acd27e7Smillert@ignore
21acd27e7SmillertThis file documents the user interface to the GNU History library.
31acd27e7Smillert
4*af70c2dfSkettenisCopyright (C) 1988-2002 Free Software Foundation, Inc.
51acd27e7SmillertAuthored by Brian Fox and Chet Ramey.
61acd27e7Smillert
71acd27e7SmillertPermission is granted to make and distribute verbatim copies of this manual
81acd27e7Smillertprovided the copyright notice and this permission notice are preserved on
91acd27e7Smillertall copies.
101acd27e7Smillert
111acd27e7SmillertPermission is granted to process this file through Tex and print the
121acd27e7Smillertresults, provided the printed document carries copying permission notice
131acd27e7Smillertidentical to this one except for the removal of this paragraph (this
141acd27e7Smillertparagraph not being relevant to the printed manual).
151acd27e7Smillert
161acd27e7SmillertPermission is granted to copy and distribute modified versions of this
171acd27e7Smillertmanual under the conditions for verbatim copying, provided also that the
181acd27e7SmillertGNU Copyright statement is available to the distributee, and provided that
191acd27e7Smillertthe entire resulting derived work is distributed under the terms of a
201acd27e7Smillertpermission notice identical to this one.
211acd27e7Smillert
221acd27e7SmillertPermission is granted to copy and distribute translations of this manual
231acd27e7Smillertinto another language, under the above conditions for modified versions.
241acd27e7Smillert@end ignore
251acd27e7Smillert
261acd27e7Smillert@node Programming with GNU History
271acd27e7Smillert@chapter Programming with GNU History
281acd27e7Smillert
291acd27e7SmillertThis chapter describes how to interface programs that you write
30*af70c2dfSketteniswith the @sc{gnu} History Library.
311acd27e7SmillertIt should be considered a technical guide.
32*af70c2dfSkettenisFor information on the interactive use of @sc{gnu} History, @pxref{Using
331acd27e7SmillertHistory Interactively}.
341acd27e7Smillert
351acd27e7Smillert@menu
361acd27e7Smillert* Introduction to History::	What is the GNU History library for?
371acd27e7Smillert* History Storage::		How information is stored.
381acd27e7Smillert* History Functions::		Functions that you can use.
391acd27e7Smillert* History Variables::		Variables that control behaviour.
401acd27e7Smillert* History Programming Example::	Example of using the GNU History Library.
411acd27e7Smillert@end menu
421acd27e7Smillert
431acd27e7Smillert@node Introduction to History
441acd27e7Smillert@section Introduction to History
451acd27e7Smillert
46*af70c2dfSkettenisMany programs read input from the user a line at a time.  The @sc{gnu}
47*af70c2dfSkettenisHistory library is able to keep track of those lines, associate arbitrary
48*af70c2dfSkettenisdata with each line, and utilize information from previous lines in
49*af70c2dfSketteniscomposing new ones.
501acd27e7Smillert
511acd27e7SmillertThe programmer using the History library has available functions
521acd27e7Smillertfor remembering lines on a history list, associating arbitrary data
531acd27e7Smillertwith a line, removing lines from the list, searching through the list
541acd27e7Smillertfor a line containing an arbitrary text string, and referencing any line
551acd27e7Smillertin the list directly.  In addition, a history @dfn{expansion} function
561acd27e7Smillertis available which provides for a consistent user interface across
571acd27e7Smillertdifferent programs.
581acd27e7Smillert
591acd27e7SmillertThe user using programs written with the History library has the
601acd27e7Smillertbenefit of a consistent user interface with a set of well-known
611acd27e7Smillertcommands for manipulating the text of previous lines and using that text
621acd27e7Smillertin new commands.  The basic history manipulation commands are similar to
631acd27e7Smillertthe history substitution provided by @code{csh}.
641acd27e7Smillert
651acd27e7SmillertIf the programmer desires, he can use the Readline library, which
661acd27e7Smillertincludes some history manipulation by default, and has the added
671acd27e7Smillertadvantage of command line editing.
681acd27e7Smillert
691acd27e7SmillertBefore declaring any functions using any functionality the History
701acd27e7Smillertlibrary provides in other code, an application writer should include
711acd27e7Smillertthe file @code{<readline/history.h>} in any file that uses the
721acd27e7SmillertHistory library's features.  It supplies extern declarations for all
731acd27e7Smillertof the library's public functions and variables, and declares all of
741acd27e7Smillertthe public data structures.
751acd27e7Smillert
761acd27e7Smillert@node History Storage
771acd27e7Smillert@section History Storage
781acd27e7Smillert
791acd27e7SmillertThe history list is an array of history entries.  A history entry is
801acd27e7Smillertdeclared as follows:
811acd27e7Smillert
821acd27e7Smillert@example
83*af70c2dfSkettenistypedef void *histdata_t;
84*af70c2dfSkettenis
851acd27e7Smillerttypedef struct _hist_entry @{
861acd27e7Smillert  char *line;
87*af70c2dfSkettenis  histdata_t data;
881acd27e7Smillert@} HIST_ENTRY;
891acd27e7Smillert@end example
901acd27e7Smillert
911acd27e7SmillertThe history list itself might therefore be declared as
921acd27e7Smillert
931acd27e7Smillert@example
941acd27e7SmillertHIST_ENTRY **the_history_list;
951acd27e7Smillert@end example
961acd27e7Smillert
971acd27e7SmillertThe state of the History library is encapsulated into a single structure:
981acd27e7Smillert
991acd27e7Smillert@example
100*af70c2dfSkettenis/*
101*af70c2dfSkettenis * A structure used to pass around the current state of the history.
102*af70c2dfSkettenis */
1031acd27e7Smillerttypedef struct _hist_state @{
1041acd27e7Smillert  HIST_ENTRY **entries; /* Pointer to the entries themselves. */
1051acd27e7Smillert  int offset;           /* The location pointer within this array. */
1061acd27e7Smillert  int length;           /* Number of elements within this array. */
1071acd27e7Smillert  int size;             /* Number of slots allocated to this array. */
1081acd27e7Smillert  int flags;
1091acd27e7Smillert@} HISTORY_STATE;
1101acd27e7Smillert@end example
1111acd27e7Smillert
1121acd27e7SmillertIf the flags member includes @code{HS_STIFLED}, the history has been
1131acd27e7Smillertstifled.
1141acd27e7Smillert
1151acd27e7Smillert@node History Functions
1161acd27e7Smillert@section History Functions
1171acd27e7Smillert
1181acd27e7SmillertThis section describes the calling sequence for the various functions
119*af70c2dfSkettenisexported by the @sc{gnu} History library.
1201acd27e7Smillert
1211acd27e7Smillert@menu
1221acd27e7Smillert* Initializing History and State Management::	Functions to call when you
1231acd27e7Smillert						want to use history in a
1241acd27e7Smillert						program.
1251acd27e7Smillert* History List Management::		Functions used to manage the list
1261acd27e7Smillert					of history entries.
1271acd27e7Smillert* Information About the History List::	Functions returning information about
1281acd27e7Smillert					the history list.
1291acd27e7Smillert* Moving Around the History List::	Functions used to change the position
1301acd27e7Smillert					in the history list.
1311acd27e7Smillert* Searching the History List::		Functions to search the history list
1321acd27e7Smillert					for entries containing a string.
1331acd27e7Smillert* Managing the History File::		Functions that read and write a file
1341acd27e7Smillert					containing the history list.
1351acd27e7Smillert* History Expansion::			Functions to perform csh-like history
1361acd27e7Smillert					expansion.
1371acd27e7Smillert@end menu
1381acd27e7Smillert
1391acd27e7Smillert@node Initializing History and State Management
1401acd27e7Smillert@subsection Initializing History and State Management
1411acd27e7Smillert
1421acd27e7SmillertThis section describes functions used to initialize and manage
1431acd27e7Smillertthe state of the History library when you want to use the history
1441acd27e7Smillertfunctions in your program.
1451acd27e7Smillert
146*af70c2dfSkettenis@deftypefun void using_history (void)
1471acd27e7SmillertBegin a session in which the history functions might be used.  This
1481acd27e7Smillertinitializes the interactive variables.
1491acd27e7Smillert@end deftypefun
1501acd27e7Smillert
151*af70c2dfSkettenis@deftypefun {HISTORY_STATE *} history_get_history_state (void)
1521acd27e7SmillertReturn a structure describing the current state of the input history.
1531acd27e7Smillert@end deftypefun
1541acd27e7Smillert
1551acd27e7Smillert@deftypefun void history_set_history_state (HISTORY_STATE *state)
1561acd27e7SmillertSet the state of the history list according to @var{state}.
1571acd27e7Smillert@end deftypefun
1581acd27e7Smillert
1591acd27e7Smillert@node History List Management
1601acd27e7Smillert@subsection History List Management
1611acd27e7Smillert
1621acd27e7SmillertThese functions manage individual entries on the history list, or set
1631acd27e7Smillertparameters managing the list itself.
1641acd27e7Smillert
165*af70c2dfSkettenis@deftypefun void add_history (const char *string)
1661acd27e7SmillertPlace @var{string} at the end of the history list.  The associated data
1671acd27e7Smillertfield (if any) is set to @code{NULL}.
1681acd27e7Smillert@end deftypefun
1691acd27e7Smillert
1701acd27e7Smillert@deftypefun {HIST_ENTRY *} remove_history (int which)
1711acd27e7SmillertRemove history entry at offset @var{which} from the history.  The
1721acd27e7Smillertremoved element is returned so you can free the line, data,
1731acd27e7Smillertand containing structure.
1741acd27e7Smillert@end deftypefun
1751acd27e7Smillert
176*af70c2dfSkettenis@deftypefun {HIST_ENTRY *} replace_history_entry (int which, const char *line, histdata_t data)
1771acd27e7SmillertMake the history entry at offset @var{which} have @var{line} and @var{data}.
1781acd27e7SmillertThis returns the old entry so you can dispose of the data.  In the case
1791acd27e7Smillertof an invalid @var{which}, a @code{NULL} pointer is returned.
1801acd27e7Smillert@end deftypefun
1811acd27e7Smillert
182*af70c2dfSkettenis@deftypefun void clear_history (void)
1831acd27e7SmillertClear the history list by deleting all the entries.
1841acd27e7Smillert@end deftypefun
1851acd27e7Smillert
1861acd27e7Smillert@deftypefun void stifle_history (int max)
1871acd27e7SmillertStifle the history list, remembering only the last @var{max} entries.
1881acd27e7Smillert@end deftypefun
1891acd27e7Smillert
190*af70c2dfSkettenis@deftypefun int unstifle_history (void)
191*af70c2dfSkettenisStop stifling the history.  This returns the previously-set
192*af70c2dfSkettenismaximum number of history entries (as set by @code{stifle_history()}).
193*af70c2dfSkettenisThe value is positive if the history was
1941acd27e7Smillertstifled, negative if it wasn't.
1951acd27e7Smillert@end deftypefun
1961acd27e7Smillert
197*af70c2dfSkettenis@deftypefun int history_is_stifled (void)
1981acd27e7SmillertReturns non-zero if the history is stifled, zero if it is not.
1991acd27e7Smillert@end deftypefun
2001acd27e7Smillert
2011acd27e7Smillert@node Information About the History List
2021acd27e7Smillert@subsection Information About the History List
2031acd27e7Smillert
2041acd27e7SmillertThese functions return information about the entire history list or
2051acd27e7Smillertindividual list entries.
2061acd27e7Smillert
207*af70c2dfSkettenis@deftypefun {HIST_ENTRY **} history_list (void)
208*af70c2dfSkettenisReturn a @code{NULL} terminated array of @code{HIST_ENTRY *} which is the
2091acd27e7Smillertcurrent input history.  Element 0 of this list is the beginning of time.
2101acd27e7SmillertIf there is no history, return @code{NULL}.
2111acd27e7Smillert@end deftypefun
2121acd27e7Smillert
213*af70c2dfSkettenis@deftypefun int where_history (void)
2141acd27e7SmillertReturns the offset of the current history element.
2151acd27e7Smillert@end deftypefun
2161acd27e7Smillert
217*af70c2dfSkettenis@deftypefun {HIST_ENTRY *} current_history (void)
2181acd27e7SmillertReturn the history entry at the current position, as determined by
2191acd27e7Smillert@code{where_history()}.  If there is no entry there, return a @code{NULL}
2201acd27e7Smillertpointer.
2211acd27e7Smillert@end deftypefun
2221acd27e7Smillert
2231acd27e7Smillert@deftypefun {HIST_ENTRY *} history_get (int offset)
2241acd27e7SmillertReturn the history entry at position @var{offset}, starting from
225*af70c2dfSkettenis@code{history_base} (@pxref{History Variables}).
226*af70c2dfSkettenisIf there is no entry there, or if @var{offset}
2271acd27e7Smillertis greater than the history length, return a @code{NULL} pointer.
2281acd27e7Smillert@end deftypefun
2291acd27e7Smillert
230*af70c2dfSkettenis@deftypefun int history_total_bytes (void)
2311acd27e7SmillertReturn the number of bytes that the primary history entries are using.
2321acd27e7SmillertThis function returns the sum of the lengths of all the lines in the
2331acd27e7Smillerthistory.
2341acd27e7Smillert@end deftypefun
2351acd27e7Smillert
2361acd27e7Smillert@node Moving Around the History List
2371acd27e7Smillert@subsection Moving Around the History List
2381acd27e7Smillert
2391acd27e7SmillertThese functions allow the current index into the history list to be
2401acd27e7Smillertset or changed.
2411acd27e7Smillert
2421acd27e7Smillert@deftypefun int history_set_pos (int pos)
243*af70c2dfSkettenisSet the current history offset to @var{pos}, an absolute index
2441acd27e7Smillertinto the list.
245*af70c2dfSkettenisReturns 1 on success, 0 if @var{pos} is less than zero or greater
246*af70c2dfSkettenisthan the number of history entries.
2471acd27e7Smillert@end deftypefun
2481acd27e7Smillert
249*af70c2dfSkettenis@deftypefun {HIST_ENTRY *} previous_history (void)
2501acd27e7SmillertBack up the current history offset to the previous history entry, and
2511acd27e7Smillertreturn a pointer to that entry.  If there is no previous entry, return
2521acd27e7Smillerta @code{NULL} pointer.
2531acd27e7Smillert@end deftypefun
2541acd27e7Smillert
255*af70c2dfSkettenis@deftypefun {HIST_ENTRY *} next_history (void)
2561acd27e7SmillertMove the current history offset forward to the next history entry, and
2571acd27e7Smillertreturn the a pointer to that entry.  If there is no next entry, return
2581acd27e7Smillerta @code{NULL} pointer.
2591acd27e7Smillert@end deftypefun
2601acd27e7Smillert
2611acd27e7Smillert@node Searching the History List
2621acd27e7Smillert@subsection Searching the History List
2631acd27e7Smillert@cindex History Searching
2641acd27e7Smillert
2651acd27e7SmillertThese functions allow searching of the history list for entries containing
2661acd27e7Smillerta specific string.  Searching may be performed both forward and backward
2671acd27e7Smillertfrom the current history position.  The search may be @dfn{anchored},
2681acd27e7Smillertmeaning that the string must match at the beginning of the history entry.
2691acd27e7Smillert@cindex anchored search
2701acd27e7Smillert
271*af70c2dfSkettenis@deftypefun int history_search (const char *string, int direction)
272*af70c2dfSkettenisSearch the history for @var{string}, starting at the current history offset.
273*af70c2dfSkettenisIf @var{direction} is less than 0, then the search is through
274*af70c2dfSkettenisprevious entries, otherwise through subsequent entries.
275*af70c2dfSkettenisIf @var{string} is found, then
2761acd27e7Smillertthe current history index is set to that history entry, and the value
2771acd27e7Smillertreturned is the offset in the line of the entry where
2781acd27e7Smillert@var{string} was found.  Otherwise, nothing is changed, and a -1 is
2791acd27e7Smillertreturned.
2801acd27e7Smillert@end deftypefun
2811acd27e7Smillert
282*af70c2dfSkettenis@deftypefun int history_search_prefix (const char *string, int direction)
2831acd27e7SmillertSearch the history for @var{string}, starting at the current history
2841acd27e7Smillertoffset.  The search is anchored: matching lines must begin with
285*af70c2dfSkettenis@var{string}.  If @var{direction} is less than 0, then the search is
286*af70c2dfSkettenisthrough previous entries, otherwise through subsequent entries.
287*af70c2dfSkettenisIf @var{string} is found, then the
2881acd27e7Smillertcurrent history index is set to that entry, and the return value is 0.
2891acd27e7SmillertOtherwise, nothing is changed, and a -1 is returned.
2901acd27e7Smillert@end deftypefun
2911acd27e7Smillert
292*af70c2dfSkettenis@deftypefun int history_search_pos (const char *string, int direction, int pos)
2931acd27e7SmillertSearch for @var{string} in the history list, starting at @var{pos}, an
2941acd27e7Smillertabsolute index into the list.  If @var{direction} is negative, the search
2951acd27e7Smillertproceeds backward from @var{pos}, otherwise forward.  Returns the absolute
2961acd27e7Smillertindex of the history element where @var{string} was found, or -1 otherwise.
2971acd27e7Smillert@end deftypefun
2981acd27e7Smillert
2991acd27e7Smillert@node Managing the History File
3001acd27e7Smillert@subsection Managing the History File
3011acd27e7Smillert
3021acd27e7SmillertThe History library can read the history from and write it to a file.
3031acd27e7SmillertThis section documents the functions for managing a history file.
3041acd27e7Smillert
305*af70c2dfSkettenis@deftypefun int read_history (const char *filename)
306*af70c2dfSkettenisAdd the contents of @var{filename} to the history list, a line at a time.
307*af70c2dfSkettenisIf @var{filename} is @code{NULL}, then read from @file{~/.history}.
308*af70c2dfSkettenisReturns 0 if successful, or @code{errno} if not.
3091acd27e7Smillert@end deftypefun
3101acd27e7Smillert
311*af70c2dfSkettenis@deftypefun int read_history_range (const char *filename, int from, int to)
3121acd27e7SmillertRead a range of lines from @var{filename}, adding them to the history list.
313*af70c2dfSkettenisStart reading at line @var{from} and end at @var{to}.
314*af70c2dfSkettenisIf @var{from} is zero, start at the beginning.  If @var{to} is less than
3151acd27e7Smillert@var{from}, then read until the end of the file.  If @var{filename} is
3161acd27e7Smillert@code{NULL}, then read from @file{~/.history}.  Returns 0 if successful,
3171acd27e7Smillertor @code{errno} if not.
3181acd27e7Smillert@end deftypefun
3191acd27e7Smillert
320*af70c2dfSkettenis@deftypefun int write_history (const char *filename)
3211acd27e7SmillertWrite the current history to @var{filename}, overwriting @var{filename}
322*af70c2dfSkettenisif necessary.
323*af70c2dfSkettenisIf @var{filename} is @code{NULL}, then write the history list to
324*af70c2dfSkettenis@file{~/.history}.
325*af70c2dfSkettenisReturns 0 on success, or @code{errno} on a read or write error.
3261acd27e7Smillert@end deftypefun
3271acd27e7Smillert
328*af70c2dfSkettenis@deftypefun int append_history (int nelements, const char *filename)
3291acd27e7SmillertAppend the last @var{nelements} of the history list to @var{filename}.
330*af70c2dfSkettenisIf @var{filename} is @code{NULL}, then append to @file{~/.history}.
331*af70c2dfSkettenisReturns 0 on success, or @code{errno} on a read or write error.
3321acd27e7Smillert@end deftypefun
3331acd27e7Smillert
334*af70c2dfSkettenis@deftypefun int history_truncate_file (const char *filename, int nlines)
3351acd27e7SmillertTruncate the history file @var{filename}, leaving only the last
3361acd27e7Smillert@var{nlines} lines.
337*af70c2dfSkettenisIf @var{filename} is @code{NULL}, then @file{~/.history} is truncated.
338*af70c2dfSkettenisReturns 0 on success, or @code{errno} on failure.
3391acd27e7Smillert@end deftypefun
3401acd27e7Smillert
3411acd27e7Smillert@node History Expansion
3421acd27e7Smillert@subsection History Expansion
3431acd27e7Smillert
344*af70c2dfSkettenisThese functions implement history expansion.
3451acd27e7Smillert
3461acd27e7Smillert@deftypefun int history_expand (char *string, char **output)
3471acd27e7SmillertExpand @var{string}, placing the result into @var{output}, a pointer
3481acd27e7Smillertto a string (@pxref{History Interaction}).  Returns:
3491acd27e7Smillert@table @code
3501acd27e7Smillert@item 0
3511acd27e7SmillertIf no expansions took place (or, if the only change in
352*af70c2dfSkettenisthe text was the removal of escape characters preceding the history expansion
3531acd27e7Smillertcharacter);
3541acd27e7Smillert@item 1
3551acd27e7Smillertif expansions did take place;
3561acd27e7Smillert@item -1
3571acd27e7Smillertif there was an error in expansion;
3581acd27e7Smillert@item 2
3591acd27e7Smillertif the returned line should be displayed, but not executed,
3601acd27e7Smillertas with the @code{:p} modifier (@pxref{Modifiers}).
3611acd27e7Smillert@end table
3621acd27e7Smillert
3631acd27e7SmillertIf an error ocurred in expansion, then @var{output} contains a descriptive
3641acd27e7Smillerterror message.
3651acd27e7Smillert@end deftypefun
3661acd27e7Smillert
367*af70c2dfSkettenis@deftypefun {char *} get_history_event (const char *string, int *cindex, int qchar)
3681acd27e7SmillertReturns the text of the history event beginning at @var{string} +
3691acd27e7Smillert@var{*cindex}.  @var{*cindex} is modified to point to after the event
3701acd27e7Smillertspecifier.  At function entry, @var{cindex} points to the index into
3711acd27e7Smillert@var{string} where the history event specification begins.  @var{qchar}
3721acd27e7Smillertis a character that is allowed to end the event specification in addition
3731acd27e7Smillertto the ``normal'' terminating characters.
3741acd27e7Smillert@end deftypefun
3751acd27e7Smillert
376*af70c2dfSkettenis@deftypefun {char **} history_tokenize (const char *string)
3771acd27e7SmillertReturn an array of tokens parsed out of @var{string}, much as the
378*af70c2dfSkettenisshell might.  The tokens are split on the characters in the
379*af70c2dfSkettenis@var{history_word_delimiters} variable,
380*af70c2dfSkettenisand shell quoting conventions are obeyed.
381*af70c2dfSkettenis@end deftypefun
382*af70c2dfSkettenis
383*af70c2dfSkettenis@deftypefun {char *} history_arg_extract (int first, int last, const char *string)
384*af70c2dfSkettenisExtract a string segment consisting of the @var{first} through @var{last}
385*af70c2dfSkettenisarguments present in @var{string}.  Arguments are split using
386*af70c2dfSkettenis@code{history_tokenize}.
3871acd27e7Smillert@end deftypefun
3881acd27e7Smillert
3891acd27e7Smillert@node History Variables
3901acd27e7Smillert@section History Variables
3911acd27e7Smillert
392*af70c2dfSkettenisThis section describes the externally-visible variables exported by
393*af70c2dfSkettenisthe @sc{gnu} History Library.
3941acd27e7Smillert
3951acd27e7Smillert@deftypevar int history_base
3961acd27e7SmillertThe logical offset of the first entry in the history list.
3971acd27e7Smillert@end deftypevar
3981acd27e7Smillert
3991acd27e7Smillert@deftypevar int history_length
4001acd27e7SmillertThe number of entries currently stored in the history list.
4011acd27e7Smillert@end deftypevar
4021acd27e7Smillert
403*af70c2dfSkettenis@deftypevar int history_max_entries
4041acd27e7SmillertThe maximum number of history entries.  This must be changed using
4051acd27e7Smillert@code{stifle_history()}.
4061acd27e7Smillert@end deftypevar
4071acd27e7Smillert
4081acd27e7Smillert@deftypevar char history_expansion_char
409*af70c2dfSkettenisThe character that introduces a history event.  The default is @samp{!}.
410*af70c2dfSkettenisSetting this to 0 inhibits history expansion.
4111acd27e7Smillert@end deftypevar
4121acd27e7Smillert
4131acd27e7Smillert@deftypevar char history_subst_char
4141acd27e7SmillertThe character that invokes word substitution if found at the start of
4151acd27e7Smillerta line.  The default is @samp{^}.
4161acd27e7Smillert@end deftypevar
4171acd27e7Smillert
4181acd27e7Smillert@deftypevar char history_comment_char
4191acd27e7SmillertDuring tokenization, if this character is seen as the first character
4201acd27e7Smillertof a word, then it and all subsequent characters up to a newline are
4211acd27e7Smillertignored, suppressing history expansion for the remainder of the line.
4221acd27e7SmillertThis is disabled by default.
4231acd27e7Smillert@end deftypevar
4241acd27e7Smillert
425*af70c2dfSkettenis@deftypevar {char *} history_word_delimiters
426*af70c2dfSkettenisThe characters that separate tokens for @code{history_tokenize()}.
427*af70c2dfSkettenisThe default value is @code{" \t\n()<>;&|"}.
428*af70c2dfSkettenis@end deftypevar
429*af70c2dfSkettenis
4301acd27e7Smillert@deftypevar {char *} history_no_expand_chars
4311acd27e7SmillertThe list of characters which inhibit history expansion if found immediately
432*af70c2dfSkettenisfollowing @var{history_expansion_char}.  The default is space, tab, newline,
433*af70c2dfSketteniscarriage return, and @samp{=}.
4341acd27e7Smillert@end deftypevar
4351acd27e7Smillert
4361acd27e7Smillert@deftypevar {char *} history_search_delimiter_chars
4371acd27e7SmillertThe list of additional characters which can delimit a history search
438*af70c2dfSkettenisstring, in addition to space, TAB, @samp{:} and @samp{?} in the case of
4391acd27e7Smillerta substring search.  The default is empty.
4401acd27e7Smillert@end deftypevar
4411acd27e7Smillert
4421acd27e7Smillert@deftypevar int history_quotes_inhibit_expansion
4431acd27e7SmillertIf non-zero, single-quoted words are not scanned for the history expansion
4441acd27e7Smillertcharacter.  The default value is 0.
4451acd27e7Smillert@end deftypevar
4461acd27e7Smillert
447*af70c2dfSkettenis@deftypevar {rl_linebuf_func_t *} history_inhibit_expansion_function
4481acd27e7SmillertThis should be set to the address of a function that takes two arguments:
449*af70c2dfSkettenisa @code{char *} (@var{string})
450*af70c2dfSkettenisand an @code{int} index into that string (@var{i}).
4511acd27e7SmillertIt should return a non-zero value if the history expansion starting at
4522a9a9794Smiod@var{string}[@var{i}] should not be performed; zero if the expansion should
4531acd27e7Smillertbe done.
4541acd27e7SmillertIt is intended for use by applications like Bash that use the history
4551acd27e7Smillertexpansion character for additional purposes.
456*af70c2dfSkettenisBy default, this variable is set to @code{NULL}.
4571acd27e7Smillert@end deftypevar
4581acd27e7Smillert
4591acd27e7Smillert@node History Programming Example
4601acd27e7Smillert@section History Programming Example
4611acd27e7Smillert
462*af70c2dfSkettenisThe following program demonstrates simple use of the @sc{gnu} History Library.
4631acd27e7Smillert
4641acd27e7Smillert@smallexample
465*af70c2dfSkettenis#include <stdio.h>
466*af70c2dfSkettenis#include <readline/history.h>
467*af70c2dfSkettenis
468*af70c2dfSkettenismain (argc, argv)
469*af70c2dfSkettenis     int argc;
470*af70c2dfSkettenis     char **argv;
4711acd27e7Smillert@{
4721acd27e7Smillert  char line[1024], *t;
4731acd27e7Smillert  int len, done = 0;
4741acd27e7Smillert
4751acd27e7Smillert  line[0] = 0;
4761acd27e7Smillert
4771acd27e7Smillert  using_history ();
4781acd27e7Smillert  while (!done)
4791acd27e7Smillert    @{
4801acd27e7Smillert      printf ("history$ ");
4811acd27e7Smillert      fflush (stdout);
4821acd27e7Smillert      t = fgets (line, sizeof (line) - 1, stdin);
4831acd27e7Smillert      if (t && *t)
4841acd27e7Smillert        @{
4851acd27e7Smillert          len = strlen (t);
4861acd27e7Smillert          if (t[len - 1] == '\n')
4871acd27e7Smillert            t[len - 1] = '\0';
4881acd27e7Smillert        @}
4891acd27e7Smillert
4901acd27e7Smillert      if (!t)
4911acd27e7Smillert        strcpy (line, "quit");
4921acd27e7Smillert
4931acd27e7Smillert      if (line[0])
4941acd27e7Smillert        @{
4951acd27e7Smillert          char *expansion;
4961acd27e7Smillert          int result;
4971acd27e7Smillert
4981acd27e7Smillert          result = history_expand (line, &expansion);
4991acd27e7Smillert          if (result)
5001acd27e7Smillert            fprintf (stderr, "%s\n", expansion);
5011acd27e7Smillert
5021acd27e7Smillert          if (result < 0 || result == 2)
5031acd27e7Smillert            @{
5041acd27e7Smillert              free (expansion);
5051acd27e7Smillert              continue;
5061acd27e7Smillert            @}
5071acd27e7Smillert
5081acd27e7Smillert          add_history (expansion);
5091acd27e7Smillert          strncpy (line, expansion, sizeof (line) - 1);
5101acd27e7Smillert          free (expansion);
5111acd27e7Smillert        @}
5121acd27e7Smillert
5131acd27e7Smillert      if (strcmp (line, "quit") == 0)
5141acd27e7Smillert        done = 1;
5151acd27e7Smillert      else if (strcmp (line, "save") == 0)
5161acd27e7Smillert        write_history ("history_file");
5171acd27e7Smillert      else if (strcmp (line, "read") == 0)
5181acd27e7Smillert        read_history ("history_file");
5191acd27e7Smillert      else if (strcmp (line, "list") == 0)
5201acd27e7Smillert        @{
5211acd27e7Smillert          register HIST_ENTRY **the_list;
5221acd27e7Smillert          register int i;
5231acd27e7Smillert
5241acd27e7Smillert          the_list = history_list ();
5251acd27e7Smillert          if (the_list)
5261acd27e7Smillert            for (i = 0; the_list[i]; i++)
5271acd27e7Smillert              printf ("%d: %s\n", i + history_base, the_list[i]->line);
5281acd27e7Smillert        @}
5291acd27e7Smillert      else if (strncmp (line, "delete", 6) == 0)
5301acd27e7Smillert        @{
5311acd27e7Smillert          int which;
5321acd27e7Smillert          if ((sscanf (line + 6, "%d", &which)) == 1)
5331acd27e7Smillert            @{
5341acd27e7Smillert              HIST_ENTRY *entry = remove_history (which);
5351acd27e7Smillert              if (!entry)
5361acd27e7Smillert                fprintf (stderr, "No such entry %d\n", which);
5371acd27e7Smillert              else
5381acd27e7Smillert                @{
5391acd27e7Smillert                  free (entry->line);
5401acd27e7Smillert                  free (entry);
5411acd27e7Smillert                @}
5421acd27e7Smillert            @}
5431acd27e7Smillert          else
5441acd27e7Smillert            @{
5451acd27e7Smillert              fprintf (stderr, "non-numeric arg given to `delete'\n");
5461acd27e7Smillert            @}
5471acd27e7Smillert        @}
5481acd27e7Smillert    @}
5491acd27e7Smillert@}
5501acd27e7Smillert@end smallexample
551