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

📄 hstech.texi

📁 在非GUI环境下
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
@ignoreThis file documents the user interface to the GNU History library.Copyright (C) 1988-2002 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 @sc{gnu} History Library.It should be considered a technical guide.For information on the interactive use of @sc{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 @sc{gnu}History library is able to keep track of those lines, associate arbitrarydata with each line, and utilize information from previous lines incomposing new ones. 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.Before declaring any functions using any functionality the Historylibrary provides in other code, an application writer should includethe file @code{<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.@node History Storage@section History StorageThe history list is an array of history entries.  A history entry isdeclared as follows:@exampletypedef void *histdata_t;typedef struct _hist_entry @{  char *line;  char *timestamp;  histdata_t 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 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;@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 functionsexported by the @sc{gnu} History library.@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 (void)Begin a session in which the history functions might be used.  Thisinitializes the interactive variables.@end deftypefun@deftypefun {HISTORY_STATE *} history_get_history_state (void)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 (const 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 void add_history_time (const char *string)Change the time stamp associated with the most recent history entry to@var{string}.@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 {histdata_t} free_history_entry (HIST_ENTRY *histent)Free the history entry @var{histent} and any history library privatedata associated with it.  Returns the application-specific dataso the caller can dispose of it.@end deftypefun@deftypefun {HIST_ENTRY *} replace_history_entry (int which, const char *line, histdata_t data)Make the history entry at offset @var{which} have @var{line} and @var{data}.This returns the old entry so the caller can dispose of anyapplication-specific data.  In the caseof an invalid @var{which}, a @code{NULL} pointer is returned.@end deftypefun@deftypefun void clear_history (void)Clear the history list by deleting all the entries.@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 (void)Stop stifling the history.  This returns the previously-setmaximum number of history entries (as set by @code{stifle_history()}).The value is positive if the history wasstifled, negative if it wasn't.@end deftypefun@deftypefun int history_is_stifled (void)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 (void)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 (void)Returns the offset of the current history element.@end deftypefun@deftypefun {HIST_ENTRY *} current_history (void)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} (@pxref{History Variables}).If there is no entry there, or if @var{offset}is greater than the history length, return a @code{NULL} pointer.@end deftypefun@deftypefun time_t history_get_time (HIST_ENTRY *entry)Return the time stamp associated with the history entry @var{entry}.@end deftypefun@deftypefun 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.@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 current history offset to @var{pos}, an absolute indexinto the list.Returns 1 on success, 0 if @var{pos} is less than zero or greaterthan the number of history entries.@end deftypefun@deftypefun {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 @code{NULL} pointer.@end deftypefun@deftypefun {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 @code{NULL} pointer.@end deftypefun@node Searching the History List@subsection Searching the History List@cindex History SearchingThese 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 @dfn{anchored},meaning that the string must match at the beginning of the history entry.@cindex anchored search

⌨️ 快捷键说明

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