⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hstech.texinfo

📁 linux下bash的源码
💻 TEXINFO
📖 第 1 页 / 共 2 页
字号:
@ignoreThis file documents the user interface to the GNU History library.Copyright (C) 1988, 1991 Free Software Foundation, Inc.Authored by Brian Fox and Chet Ramey.Permission is granted to make and distribute verbatim copies of this manualprovided the copyright notice and this permission notice are preserved onall copies.Permission is granted to process this file through Tex and print theresults, provided the printed document carries copying permission noticeidentical to this one except for the removal of this paragraph (thisparagraph not being relevant to the printed manual).Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also that theGNU Copyright statement is available to the distributee, and provided thatthe entire resulting derived work is distributed under the terms of apermission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions.@end ignore@node Programming with GNU History@chapter Programming with GNU HistoryThis chapter describes how to interface programs that you writewith the GNU History Library.It should be considered a technical guide.For information on the interactive use of GNU History, @pxref{UsingHistory Interactively}.@menu* Introduction to History::	What is the GNU History library for?* History Storage::		How information is stored.* History Functions::		Functions that you can use.* History Variables::		Variables that control behaviour.* History Programming Example::	Example of using the GNU History Library.@end menu@node Introduction to History@section Introduction to HistoryMany programs read input from the user a line at a time.  The GNU Historylibrary is able to keep track of those lines, associate arbitrary data witheach line, and utilize information from previous lines in composing newones.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 @dfn{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 are similar tothe history substitution provided by @code{csh}.If the programmer desires, he can use the Readline library, whichincludes some history manipulation by default, and has the addedadvantage of command line editing.@node History Storage@section History StorageThe history list is an array of history entries.  A history entry isdeclared as follows:@exampletypedef struct _hist_entry @{  char *line;  char *data;@} HIST_ENTRY;@end exampleThe history list itself might therefore be declared as@exampleHIST_ENTRY **the_history_list;@end exampleThe state of the History library is encapsulated into a single structure:@example/* 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;@end exampleIf the flags member includes @code{HS_STIFLED}, the history has beenstifled.@node History Functions@section History FunctionsThis section describes the calling sequence for the various functionspresent in GNU History.@menu* Initializing History and State Management::	Functions to call when you						want to use history in a						program.* History List Management::		Functions used to manage the list					of history entries.* Information About the History List::	Functions returning information about					the history list.* Moving Around the History List::	Functions used to change the position					in the history list.* Searching the History List::		Functions to search the history list					for entries containing a string.* Managing the History File::		Functions that read and write a file					containing the history list.* History Expansion::			Functions to perform csh-like history					expansion.@end menu@node Initializing History and State Management@subsection 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.@deftypefun void using_history ()Begin a session in which the history functions might be used.  Thisinitializes the interactive variables.@end deftypefun@deftypefun {HISTORY_STATE *} history_get_history_state ()Return a structure describing the current state of the input history.@end deftypefun@deftypefun void history_set_history_state (HISTORY_STATE *state)Set the state of the history list according to @var{state}.@end deftypefun@node History List Management@subsection History List ManagementThese functions manage individual entries on the history list, or setparameters managing the list itself.@deftypefun void add_history (char *string)Place @var{string} at the end of the history list.  The associated datafield (if any) is set to @code{NULL}.@end deftypefun@deftypefun {HIST_ENTRY *} remove_history (int which)Remove history entry at offset @var{which} from the history.  Theremoved element is returned so you can free the line, data,and containing structure.@end deftypefun@deftypefun {HIST_ENTRY *} replace_history_entry (int which, char *line, char *data)Make the history entry at offset @var{which} have @var{line} and @var{data}.This returns the old entry so you can dispose of the data.  In the caseof an invalid @var{which}, a @code{NULL} pointer is returned.@end deftypefun@deftypefun void stifle_history (int max)Stifle the history list, remembering only the last @var{max} entries.@end deftypefun@deftypefun int unstifle_history ()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.@end deftypefun@deftypefun int history_is_stifled ()Returns non-zero if the history is stifled, zero if it is not.@end deftypefun@node Information About the History List@subsection Information About the History ListThese functions return information about the entire history list orindividual list entries.@deftypefun {HIST_ENTRY **} history_list ()Return a @code{NULL} terminated array of @code{HIST_ENTRY} which is thecurrent input history.  Element 0 of this list is the beginning of time.If there is no history, return @code{NULL}.@end deftypefun@deftypefun int where_history ()Returns the offset of the current history element.@end deftypefun@deftypefun {HIST_ENTRY *} current_history ()Return the history entry at the current position, as determined by@code{where_history ()}.  If there is no entry there, return a @code{NULL}pointer.@end deftypefun@deftypefun {HIST_ENTRY *} history_get (int offset)Return the history entry at position @var{offset}, starting from@code{history_base}.  If there is no entry there, or if @var{offset}is greater than the history length, return a @code{NULL} pointer.@end deftypefun@deftypefun int history_total_bytes ()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.@end deftypefun@node Moving Around the History List@subsection Moving Around the History ListThese functions allow the current index into the history list to beset or changed.@deftypefun int history_set_pos (int pos)Set the position in the history list to @var{pos}, an absolute indexinto the list.@end deftypefun@deftypefun {HIST_ENTRY *} previous_history ()Back up the current history offset to the previous history entry, andreturn a pointer to that entry.  If there is no previous entry, returna @code{NULL} pointer.@end deftypefun@deftypefun {HIST_ENTRY *} next_history ()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 @code{NULL} pointer.@end deftypefun@node Searching the History List@subsection Searching the History List@cindex History Searching

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -