SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG
DONATE


YUM REPOSITORY

 
 

MAN page from Trustix readline-4.2-1tr.i586.rpm

HISTORY

Section: C Library Functions (3)
Updated: 2001 Mar 6
Index 

NAME

history - GNU History Library 

COPYRIGHT

The GNU History Library is Copyright (C) 1989-2001 by the Free Software Foundation, Inc. 

DESCRIPTION

Many programs read input from the user a line at a time. The GNUHistory library is able to keep track of those lines, associate arbitrarydata with each line, and utilize information from previous lines incomposing new ones.

 

HISTORY EXPANSION

The history library supports a history expansion feature thatis identical to the history expansion inbash.This section describes what syntax features are available.

History expansions introduce words from the history list intothe input stream, making it easy to repeat commands, insert thearguments to a previous command into the current input line, orfix errors in previous commands quickly.

History expansion is usually performed immediately after a complete lineis read.It takes place in two parts.The first is to determine which line from the history listto use during substitution.The second is to select portions of that line for inclusion intothe current one.The line selected from the history is the event,and the portions of that line that are acted upon are words.Various modifiers are available to manipulate the selected words.The line is broken into words in the same fashion as bashdoes when reading input,so that several words that would otherwise be separated are considered one word when surrounded by quotes (see thedescription of history_tokenize() below).History expansions are introduced by the appearance of thehistory expansion character, which is ! by default.Only backslash (\) and single quotes can quotethe history expansion character. 

Event Designators

An event designator is a reference to a command line entry in thehistory list.

!
Start a history substitution, except when followed by ablank,newline, = or (.
!n
Refer to command linen.
!-n
Refer to the current command line minusn.
!!
Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command starting with string.
!?string[?]
Refer to the most recent command containingstring.The trailing ? may be omitted ifstringis followed immediately by a newline.
^string1^string2^
Quick substitution. Repeat the last command, replacingstring1withstring2.Equivalent to``!!:s/string1/string2/''(see Modifiers below).
!#
The entire command line typed so far.
 

Word Designators

Word designators are used to select desired words from the event.A :separates the event specification from the word designator.It may be omitted if the word designator begins with a^,$,*,-,or%.Words are numbered from the beginning of the line,with the first word being denoted by 0 (zero).Words are inserted into the current line separated by single spaces.

0 (zero)
The zeroth word. For the shell, this is the commandword.
n
The nth word.
^
The first argument. That is, word 1.
$
The last argument.
%
The word matched by the most recent `?string?' search.
x-y
A range of words; `-y' abbreviates `0-y'.
*
All of the words but the zeroth. This is a synonymfor `1-$'. It is not an error to use*if there is just oneword in the event; the empty string is returned in that case.
x*
Abbreviates x-$.
x-
Abbreviates x-$ like x*, but omits the last word.

If a word designator is supplied without an event specification, theprevious command is used as the event. 

Modifiers

After the optional word designator, there may appear a sequence ofone or more of the following modifiers, each preceded by a `:'.

h
Remove a trailing file name component, leaving only the head.
t
Remove all leading file name components, leaving the tail.
r
Remove a trailing suffix of the form .xxx, leaving thebasename.
e
Remove all but the trailing suffix.
p
Print the new command but do not execute it.
q
Quote the substituted words, escaping further substitutions.
x
Quote the substituted words as withq,but break into words atblanksand newlines.
s/old/new/
Substitutenewfor the first occurrence ofoldin the event line. Any delimiter can be used in place of /. Thefinal delimiter is optional if it is the last character of theevent line. The delimiter may be quoted inoldandnewwith a single backslash. If & appears innew,it is replaced byold.A single backslash will quote the &. Ifoldis null, it is set to the lastoldsubstituted, or, if no previous history substitutions took place,the laststringin a!?string[?]search.
&
Repeat the previous substitution.
g
Cause changes to be applied over the entire event line. This isused in conjunction with `:s' (e.g., `:gs/old/new/')or `:&'. If used with`:s', any delimiter can be usedin place of /, and the final delimiter is optionalif it is the last character of the event line.
 

PROGRAMMING WITH HISTORY FUNCTIONS

This section describes how to use the History library in other programs. 

Introduction to History

The programmer using the History library has available functionsfor remembering lines on a history list, associating arbitrary datawith a line, removing lines from the list, searching through the listfor a line containing an arbitrary text string, and referencing any linein the list directly. In addition, a history expansion functionis available which provides for a consistent user interface acrossdifferent programs.

The user using programs written with the History library has thebenefit of a consistent user interface with a set of well-knowncommands for manipulating the text of previous lines and using that textin new commands. The basic history manipulation commands areidentical tothe history substitution provided by bash.

If the programmer desires, he can use the Readline library, whichincludes some history manipulation by default, and has the addedadvantage of command line editing.

Before declaring any functions using any functionality the Historylibrary provides in other code, an application writer should includethe file<readline/history.h>in any file that uses theHistory library's features. It supplies extern declarations for allof the library's public functions and variables, and declares all ofthe public data structures.

 

History Storage

The history list is an array of history entries. A history entry isdeclared as follows:

typedef void * histdata_t;

typedef struct _hist_entry {  char *line;  histdata_t data;} HIST_ENTRY;

The history list itself might therefore be declared as

HIST_ENTRY ** the_history_list;

The state of the History library is encapsulated into a single structure:

/* * A structure used to pass around the current state of the history. */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;

If the flags member includes HS_STIFLED, the history has beenstifled. 

History Functions

This section describes the calling sequence for the various functionsexported by the GNU History library. 

Initializing History and State Management

This section describes functions used to initialize and managethe state of the History library when you want to use the historyfunctions in your program.

1 void (using_history, void, )
Begin a session in which the history functions might be used. Thisinitializes the interactive variables.

1 HISTORY_STATE * (history_get_history_state, void, )
Return a structure describing the current state of the input history.

1 void (history_set_history_state, HISTORY_STATE *state, )
Set the state of the history list according to state.

 

History List Management

These functions manage individual entries on the history list, or setparameters managing the list itself.

1 void (add_history, const char *string, )
Place string at the end of the history list. The associated datafield (if any) is set to NULL.

1 HIST_ENTRY * (remove_history, int which, )
Remove history entry at offset which from the history. Theremoved element is returned so you can free the line, data,and containing structure.

3 HIST_ENTRY * (replace_history_entry, int which, const char *line)
Make the history entry at offset which have line and data.This returns the old entry so you can dispose of the data. In the caseof an invalid which, a NULL pointer is returned.

1 void (clear_history, void, )
Clear the history list by deleting all the entries.

1 void (stifle_history, int max, )
Stifle the history list, remembering only the last max entries.

1 int (unstifle_history, void, )
Stop stifling the history. This returns the previous amount thehistory was stifled. The value is positive if the history wasstifled, negative if it wasn't.

1 int (history_is_stifled, void, )
Returns non-zero if the history is stifled, zero if it is not.

 

Information About the History List

These functions return information about the entire history list orindividual list entries.

1 HIST_ENTRY ** (history_list, void, )
Return a NULL terminated array of HIST_ENTRY * which is thecurrent input history. Element 0 of this list is the beginning of time.If there is no history, return NULL.

1 int (where_history, void, )
Returns the offset of the current history element.

1 HIST_ENTRY * (current_history, void, )
Return the history entry at the current position, as determined bywhere_history(). If there is no entry there, return a NULLpointer.

1 HIST_ENTRY * (history_get, int offset, )
Return the history entry at position offset, starting fromhistory_base.If there is no entry there, or if offsetis greater than the history length, return a NULL pointer.

1 int (history_total_bytes, void, )
Return the number of bytes that the primary history entries are using.This function returns the sum of the lengths of all the lines in thehistory.

 

Moving Around the History List

These functions allow the current index into the history list to beset or changed.

1 int (history_set_pos, int pos, )
Set the current history offset to pos, an absolute indexinto the list.Returns 1 on success, 0 if pos is less than zero or greaterthan the number of history entries.

1 HIST_ENTRY * (previous_history, void, )
Back up the current history offset to the previous history entry, andreturn a pointer to that entry. If there is no previous entry, returna NULL pointer.

1 HIST_ENTRY * (next_history, void, )
Move the current history offset forward to the next history entry, andreturn the a pointer to that entry. If there is no next entry, returna NULL pointer.

 

Searching the History List

These functions allow searching of the history list for entries containinga specific string. Searching may be performed both forward and backwardfrom the current history position. The search may be anchored,meaning that the string must match at the beginning of the history entry.

2 int (history_search, const char *string, int direction)
Search the history for string, starting at the current history offset.If direction is less than 0, then the search is throughprevious entries, otherwise through subsequent entries.If string is found, thenthe current history index is set to that history entry, and the valuereturned is the offset in the line of the entry wherestring was found. Otherwise, nothing is changed, and a -1 isreturned.

2 int (history_search_prefix, const char *string, int direction)
Search the history for string, starting at the current historyoffset. The search is anchored: matching lines must begin withstring. If direction is less than 0, then the search isthrough previous entries, otherwise through subsequent entries.If string is found, then thecurrent history index is set to that entry, and the return value is 0. Otherwise, nothing is changed, and a -1 is returned.

3 int (history_search_pos, const char *string, int direction)
Search for string in the history list, starting at pos, anabsolute index into the list. If direction is negative, the searchproceeds backward from pos, otherwise forward. Returns the absoluteindex of the history element where string was found, or -1 otherwise.

 

Managing the History File

The History library can read the history from and write it to a file.This section documents the functions for managing a history file.

1 int (read_history, const char *filename, )
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.

3 int (read_history_range, const char *filename, int from)
Read a range of lines from filename, adding them to the history list.Start reading at line from and end at to.If from is zero, start at the beginning. If to is less thanfrom, then read until the end of the file. If filename isNULL, then read from ~/.history. Returns 0 if successful,or errno if not.

1 int (write_history, const char *filename, )
Write the current history to filename, overwriting filenameif necessary.If filename is NULL, then write the history list to ~/.history.Returns 0 on success, or errno on a read or write error.

2 int (append_history, int nelements, const char *filename)
Append the last nelements of the history list to filename.If filename is NULL, then append to ~/.history.Returns 0 on success, or errno on a read or write error.

2 int (history_truncate_file, const char *filename, int nlines)
Truncate the history file filename, leaving only the lastnlines lines.If filename is NULL, then ~/.history is truncated.Returns 0 on success, or errno on failure.

 

History Expansion

These functions implement history expansion.

2 int (history_expand, char *string, char **output)
Expand string, placing the result into output, a pointerto a string. Returns:

0
If no expansions took place (or, if the only change inthe text was the removal of escape characters preceding the history expansioncharacter);
1
if expansions did take place;
-1
if there was an error in expansion;
2
if the returned line should be displayed, but not executed,as with the :p modifier.
If an error ocurred in expansion, then output contains a descriptiveerror message.

3 char * (get_history_event, const char *string, int *cindex)
Returns the text of the history event beginning at string +*cindex. *cindex is modified to point to after the eventspecifier. At function entry, cindex points to the index intostring where the history event specification begins. qcharis a character that is allowed to end the event specification in additionto the ``normal'' terminating characters.

1 char ** (history_tokenize, const char *string, )
Return an array of tokens parsed out of string, much as theshell might.The tokens are split on the characters in thehistory_word_delimiters variable,and shell quoting conventions are obeyed.

3 char * (history_arg_extract, int first, int last)
Extract a string segment consisting of the first through lastarguments present in string. Arguments are split usinghistory_tokenize().

 

History Variables

This section describes the externally-visible variables exported bythe GNU History Library.

int history_base
The logical offset of the first entry in the history list.

int history_length
The number of entries currently stored in the history list.

int history_max_entries
The maximum number of history entries. This must be changed usingstifle_history().

char history_expansion_char
The character that introduces a history event. The default is !.Setting this to 0 inhibits history expansion.

char history_subst_char
The character that invokes word substitution if found at the start ofa line. The default is ^.

char history_comment_char
During tokenization, if this character is seen as the first characterof a word, then it and all subsequent characters up to a newline areignored, suppressing history expansion for the remainder of the line.This is disabled by default.

char * history_word_delimiters
The characters that separate tokens for history_tokenize().The default value is " \t\n()<>;&|".

char * history_no_expand_chars
The list of characters which inhibit history expansion if found immediatelyfollowing history_expansion_char. The default is space, tab, newline,\r, and =.

char * history_search_delimiter_chars
The list of additional characters which can delimit a history searchstring, in addition to space, tab, : and ? in the case ofa substring search. The default is empty.

int history_quotes_inhibit_expansion
If non-zero, single-quoted words are not scanned for the history expansioncharacter. The default value is 0.

rl_linebuf_func_t * history_inhibit_expansion_function
This should be set to the address of a function that takes two arguments:a char * (string)and an int index into that string (i).It should return a non-zero value if the history expansion starting atstring[i] should not be performed; zero if the expansion shouldbe done.It is intended for use by applications like bash that use the historyexpansion character for additional purposes.By default, this variable is set to NULL. 

FILES

~/.history
Default filename for reading and writing saved history
 

SEE ALSO

The Gnu Readline Library, Brian Fox and Chet Ramey
The Gnu History Library, Brian Fox and Chet Ramey
bash(1)
readline(3)
 

AUTHORS

Brian Fox, Free Software Foundation
bfoxAATTgnu.org

Chet Ramey, Case Western Reserve University
chetAATTins.CWRU.Edu 

BUG REPORTS

If you find a bug in thehistorylibrary, you should report it. But first, you shouldmake sure that it really is a bug, and that it appears in the latestversion of thehistorylibrary that you have.

Once you have determined that a bug actually exists, mail abug report to bug-readline@gnu.org.If you have a fix, you are welcome to mail thatas well! Suggestions and `philosophical' bug reports may be mailedto bug-readline@gnu.org or posted to the Usenetnewsgroupgnu.bash.bug.

Comments and bug reports concerningthis manual page should be directed tochetAATTins.CWRU.Edu.


 

Index

NAME
COPYRIGHT
DESCRIPTION
HISTORY EXPANSION
Event Designators
Word Designators
Modifiers
PROGRAMMING WITH HISTORY FUNCTIONS
Introduction to History
History Storage
History Functions
Initializing History and State Management
History List Management
Information About the History List
Moving Around the History List
Searching the History List
Managing the History File
History Expansion
History Variables
FILES
SEE ALSO
AUTHORS
BUG REPORTS

This document was created byman2html,using the manual pages.