📄 history.3
字号:
This section describes the calling sequence for the various functionsexported by the GNU History library..SS Initializing History and State ManagementThis section describes functions used to initialize and managethe state of the History library when you want to use the historyfunctions in your program..Fn1 void using_history voidBegin a session in which the history functions might be used. Thisinitializes the interactive variables..Fn1 "HISTORY_STATE *" history_get_history_state voidReturn a structure describing the current state of the input history..Fn1 void history_set_history_state "HISTORY_STATE *state"Set the state of the history list according to \fIstate\fP..SS History List ManagementThese functions manage individual entries on the history list, or setparameters managing the list itself..Fn1 void add_history "const char *string"Place \fIstring\fP at the end of the history list. The associated datafield (if any) is set to \fBNULL\fP..Fn1 "HIST_ENTRY *" remove_history "int which"Remove history entry at offset \fIwhich\fP from the history. Theremoved element is returned so you can free the line, data,and containing structure..Fn3 "HIST_ENTRY *" replace_history_entry "int which" "const char *line" "histdata_t data"Make the history entry at offset \fIwhich\fP have \fIline\fP and \fIdata\fP.This returns the old entry so you can dispose of the data. In the caseof an invalid \fIwhich\fP, a \fBNULL\fP pointer is returned..Fn1 void clear_history "void"Clear the history list by deleting all the entries..Fn1 void stifle_history "int max"Stifle the history list, remembering only the last \fImax\fP entries..Fn1 int unstifle_history "void"Stop stifling the history. This returns the previously-setmaximum number of history entries (as set by \fBstifle_history()\fP).history was stifled. The value is positive if the history wasstifled, negative if it wasn't..Fn1 int history_is_stifled "void"Returns non-zero if the history is stifled, zero if it is not..SS Information About the History ListThese functions return information about the entire history list orindividual list entries..Fn1 "HIST_ENTRY **" history_list "void"Return a \fBNULL\fP terminated array of \fIHIST_ENTRY *\fP which is thecurrent input history. Element 0 of this list is the beginning of time.If there is no history, return \fBNULL\fP..Fn1 int where_history "void"Returns the offset of the current history element..Fn1 "HIST_ENTRY *" current_history "void"Return the history entry at the current position, as determined by\fBwhere_history()\fP. If there is no entry there, return a \fBNULL\fPpointer..Fn1 "HIST_ENTRY *" history_get "int offset"Return the history entry at position \fIoffset\fP, starting from\fBhistory_base\fP.If there is no entry there, or if \fIoffset\fPis greater than the history length, return a \fBNULL\fP pointer..Fn1 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..SS Moving Around the History ListThese functions allow the current index into the history list to beset or changed..Fn1 int history_set_pos "int pos"Set the current history offset to \fIpos\fP, an absolute indexinto the list.Returns 1 on success, 0 if \fIpos\fP is less than zero or greaterthan the number of history entries..Fn1 "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 \fBNULL\fP pointer..Fn1 "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 \fBNULL\fP pointer..SS Searching the History ListThese 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 \fIanchored\fP,meaning that the string must match at the beginning of the history entry..Fn2 int history_search "const char *string" "int direction"Search the history for \fIstring\fP, starting at the current history offset.If \fIdirection\fP is less than 0, then the search is throughprevious entries, otherwise through subsequent entries.If \fIstring\fP is found, thenthe current history index is set to that history entry, and the valuereturned is the offset in the line of the entry where\fIstring\fP was found. Otherwise, nothing is changed, and a -1 isreturned..Fn2 int history_search_prefix "const char *string" "int direction"Search the history for \fIstring\fP, starting at the current historyoffset. The search is anchored: matching lines must begin with\fIstring\fP. If \fIdirection\fP is less than 0, then the search isthrough previous entries, otherwise through subsequent entries.If \fIstring\fP 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. .Fn3 int history_search_pos "const char *string" "int direction" "int pos"Search for \fIstring\fP in the history list, starting at \fIpos\fP, anabsolute index into the list. If \fIdirection\fP is negative, the searchproceeds backward from \fIpos\fP, otherwise forward. Returns the absoluteindex of the history element where \fIstring\fP was found, or -1 otherwise..SS Managing the History FileThe History library can read the history from and write it to a file.This section documents the functions for managing a history file..Fn1 int read_history "const char *filename"Add the contents of \fIfilename\fP to the history list, a line at a time.If \fIfilename\fP is \fBNULL\fP, then read from \fI~/.history\fP.Returns 0 if successful, or \fBerrno\fP if not..Fn3 int read_history_range "const char *filename" "int from" "int to"Read a range of lines from \fIfilename\fP, adding them to the history list.Start reading at line \fIfrom\fP and end at \fIto\fP.If \fIfrom\fP is zero, start at the beginning. If \fIto\fP is less than\fIfrom\fP, then read until the end of the file. If \fIfilename\fP is\fBNULL\fP, then read from \fI~/.history\fP. Returns 0 if successful,or \fBerrno\fP if not..Fn1 int write_history "const char *filename"Write the current history to \fIfilename\fP, overwriting \fIfilename\fPif necessary.If \fIfilename\fP is \fBNULL\fP, then write the history list to \fI~/.history\fP.Returns 0 on success, or \fBerrno\fP on a read or write error..Fn2 int append_history "int nelements" "const char *filename"Append the last \fInelements\fP of the history list to \fIfilename\fP.If \fIfilename\fP is \fBNULL\fP, then append to \fI~/.history\fP.Returns 0 on success, or \fBerrno\fP on a read or write error..Fn2 int history_truncate_file "const char *filename" "int nlines"Truncate the history file \fIfilename\fP, leaving only the last\fInlines\fP lines.If \fIfilename\fP is \fBNULL\fP, then \fI~/.history\fP is truncated.Returns 0 on success, or \fBerrno\fP on failure..SS History ExpansionThese functions implement history expansion..Fn2 int history_expand "char *string" "char **output"Expand \fIstring\fP, placing the result into \fIoutput\fP, a pointerto a string. Returns:.RS.PD 0.TP0If no expansions took place (or, if the only change inthe text was the removal of escape characters preceding the history expansioncharacter);.TP1if expansions did take place;.TP-1if there was an error in expansion;.TP2if the returned line should be displayed, but not executed,as with the \fB:p\fP modifier..PD.REIf an error ocurred in expansion, then \fIoutput\fP contains a descriptiveerror message..Fn3 "char *" get_history_event "const char *string" "int *cindex" "int qchar"Returns the text of the history event beginning at \fIstring\fP +\fI*cindex\fP. \fI*cindex\fP is modified to point to after the eventspecifier. At function entry, \fIcindex\fP points to the index into\fIstring\fP where the history event specification begins. \fIqchar\fPis a character that is allowed to end the event specification in additionto the ``normal'' terminating characters..Fn1 "char **" history_tokenize "const char *string"Return an array of tokens parsed out of \fIstring\fP, much as theshell might.The tokens are split on the characters in the\fBhistory_word_delimiters\fP variable,and shell quoting conventions are obeyed..Fn3 "char *" history_arg_extract "int first" "int last" "const char *string"Extract a string segment consisting of the \fIfirst\fP through \fIlast\fParguments present in \fIstring\fP. Arguments are split using\fBhistory_tokenize()\fP..SS History VariablesThis section describes the externally-visible variables exported bythe GNU History Library..Vb int history_baseThe logical offset of the first entry in the history list..Vb int history_lengthThe number of entries currently stored in the history list..Vb int history_max_entriesThe maximum number of history entries. This must be changed using\fBstifle_history()\fP..Vb char history_expansion_charThe character that introduces a history event. The default is \fB!\fP.Setting this to 0 inhibits history expansion..Vb char history_subst_charThe character that invokes word substitution if found at the start ofa line. The default is \fB^\fP..Vb char history_comment_charDuring 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..Vb "char *" history_word_delimitersThe characters that separate tokens for \fBhistory_tokenize()\fP.The default value is \fB"\ \et\en()<>;&|"\fP..Vb "char *" history_no_expand_charsThe list of characters which inhibit history expansion if found immediatelyfollowing \fBhistory_expansion_char\fP. The default is space, tab, newline,\fB\er\fP, and \fB=\fP..Vb "char *" history_search_delimiter_charsThe list of additional characters which can delimit a history searchstring, in addition to space, tab, \fI:\fP and \fI?\fP in the case ofa substring search. The default is empty..Vb int history_quotes_inhibit_expansionIf non-zero, single-quoted words are not scanned for the history expansioncharacter. The default value is 0..Vb "rl_linebuf_func_t *" history_inhibit_expansion_functionThis should be set to the address of a function that takes two arguments:a \fBchar *\fP (\fIstring\fP)and an \fBint\fP index into that string (\fIi\fP).It should return a non-zero value if the history expansion starting at\fIstring[i]\fP should not be performed; zero if the expansion shouldbe done.It is intended for use by applications like \fBbash\fP that use the historyexpansion character for additional purposes.By default, this variable is set to \fBNULL\fP..SH FILES.PD 0 .TP.FN ~/.historyDefault filename for reading and writing saved history.PD.SH "SEE ALSO".PD 0.TP\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey.TP\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey.TP\fIbash\fP(1).TP\fIreadline\fP(3).PD.SH AUTHORSBrian Fox, Free Software Foundation.brbfox@gnu.org.PPChet Ramey, Case Western Reserve University.brchet@ins.CWRU.Edu.SH BUG REPORTSIf you find a bug in the.B historylibrary, you should report it. But first, you shouldmake sure that it really is a bug, and that it appears in the latestversion of the.B historylibrary that you have..PPOnce you have determined that a bug actually exists, mail abug report to \fIbug\-readline\fP@\fIgnu.org\fP.If you have a fix, you are welcome to mail thatas well! Suggestions and `philosophical' bug reports may be mailedto \fPbug-readline\fP@\fIgnu.org\fP or posted to the Usenetnewsgroup.BR gnu.bash.bug ..PPComments and bug reports concerningthis manual page should be directed to.IR chet@ins.CWRU.Edu .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -