|
||||
File indexing completed on 2025-01-18 10:10:07
0001 /* history.h -- the names of functions that you can call in history. */ 0002 0003 /* Copyright (C) 1989-2022 Free Software Foundation, Inc. 0004 0005 This file contains the GNU History Library (History), a set of 0006 routines for managing the text of previously typed lines. 0007 0008 History is free software: you can redistribute it and/or modify 0009 it under the terms of the GNU General Public License as published by 0010 the Free Software Foundation, either version 3 of the License, or 0011 (at your option) any later version. 0012 0013 History is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 GNU General Public License for more details. 0017 0018 You should have received a copy of the GNU General Public License 0019 along with History. If not, see <http://www.gnu.org/licenses/>. 0020 */ 0021 0022 #ifndef _HISTORY_H_ 0023 #define _HISTORY_H_ 0024 0025 #ifdef __cplusplus 0026 extern "C" { 0027 #endif 0028 0029 #include <time.h> /* XXX - for history timestamp code */ 0030 0031 #if defined READLINE_LIBRARY 0032 # include "rlstdc.h" 0033 # include "rltypedefs.h" 0034 #else 0035 # include <readline/rlstdc.h> 0036 # include <readline/rltypedefs.h> 0037 #endif 0038 0039 #ifdef __STDC__ 0040 typedef void *histdata_t; 0041 #else 0042 typedef char *histdata_t; 0043 #endif 0044 0045 /* Let's not step on anyone else's define for now, since we don't use this yet. */ 0046 #ifndef HS_HISTORY_VERSION 0047 # define HS_HISTORY_VERSION 0x0802 /* History 8.2 */ 0048 #endif 0049 0050 /* The structure used to store a history entry. */ 0051 typedef struct _hist_entry { 0052 char *line; 0053 char *timestamp; /* char * rather than time_t for read/write */ 0054 histdata_t data; 0055 } HIST_ENTRY; 0056 0057 /* Size of the history-library-managed space in history entry HS. */ 0058 #define HISTENT_BYTES(hs) (strlen ((hs)->line) + strlen ((hs)->timestamp)) 0059 0060 /* A structure used to pass the current state of the history stuff around. */ 0061 typedef struct _hist_state { 0062 HIST_ENTRY **entries; /* Pointer to the entries themselves. */ 0063 int offset; /* The location pointer within this array. */ 0064 int length; /* Number of elements within this array. */ 0065 int size; /* Number of slots allocated to this array. */ 0066 int flags; 0067 } HISTORY_STATE; 0068 0069 /* Flag values for the `flags' member of HISTORY_STATE. */ 0070 #define HS_STIFLED 0x01 0071 0072 /* Initialization and state management. */ 0073 0074 /* Begin a session in which the history functions might be used. This 0075 just initializes the interactive variables. */ 0076 extern void using_history (void); 0077 0078 /* Return the current HISTORY_STATE of the history. */ 0079 extern HISTORY_STATE *history_get_history_state (void); 0080 0081 /* Set the state of the current history array to STATE. */ 0082 extern void history_set_history_state (HISTORY_STATE *); 0083 0084 /* Manage the history list. */ 0085 0086 /* Place STRING at the end of the history list. 0087 The associated data field (if any) is set to NULL. */ 0088 extern void add_history (const char *); 0089 0090 /* Change the timestamp associated with the most recent history entry to 0091 STRING. */ 0092 extern void add_history_time (const char *); 0093 0094 /* Remove an entry from the history list. WHICH is the magic number that 0095 tells us which element to delete. The elements are numbered from 0. */ 0096 extern HIST_ENTRY *remove_history (int); 0097 0098 /* Remove a set of entries from the history list: FIRST to LAST, inclusive */ 0099 extern HIST_ENTRY **remove_history_range (int, int); 0100 0101 /* Allocate a history entry consisting of STRING and TIMESTAMP and return 0102 a pointer to it. */ 0103 extern HIST_ENTRY *alloc_history_entry (char *, char *); 0104 0105 /* Copy the history entry H, but not the (opaque) data pointer */ 0106 extern HIST_ENTRY *copy_history_entry (HIST_ENTRY *); 0107 0108 /* Free the history entry H and return any application-specific data 0109 associated with it. */ 0110 extern histdata_t free_history_entry (HIST_ENTRY *); 0111 0112 /* Make the history entry at WHICH have LINE and DATA. This returns 0113 the old entry so you can dispose of the data. In the case of an 0114 invalid WHICH, a NULL pointer is returned. */ 0115 extern HIST_ENTRY *replace_history_entry (int, const char *, histdata_t); 0116 0117 /* Clear the history list and start over. */ 0118 extern void clear_history (void); 0119 0120 /* Stifle the history list, remembering only MAX number of entries. */ 0121 extern void stifle_history (int); 0122 0123 /* Stop stifling the history. This returns the previous amount the 0124 history was stifled by. The value is positive if the history was 0125 stifled, negative if it wasn't. */ 0126 extern int unstifle_history (void); 0127 0128 /* Return 1 if the history is stifled, 0 if it is not. */ 0129 extern int history_is_stifled (void); 0130 0131 /* Information about the history list. */ 0132 0133 /* Return a NULL terminated array of HIST_ENTRY which is the current input 0134 history. Element 0 of this list is the beginning of time. If there 0135 is no history, return NULL. */ 0136 extern HIST_ENTRY **history_list (void); 0137 0138 /* Returns the number which says what history element we are now 0139 looking at. */ 0140 extern int where_history (void); 0141 0142 /* Return the history entry at the current position, as determined by 0143 history_offset. If there is no entry there, return a NULL pointer. */ 0144 extern HIST_ENTRY *current_history (void); 0145 0146 /* Return the history entry which is logically at OFFSET in the history 0147 array. OFFSET is relative to history_base. */ 0148 extern HIST_ENTRY *history_get (int); 0149 0150 /* Return the timestamp associated with the HIST_ENTRY * passed as an 0151 argument */ 0152 extern time_t history_get_time (HIST_ENTRY *); 0153 0154 /* Return the number of bytes that the primary history entries are using. 0155 This just adds up the lengths of the_history->lines. */ 0156 extern int history_total_bytes (void); 0157 0158 /* Moving around the history list. */ 0159 0160 /* Set the position in the history list to POS. */ 0161 extern int history_set_pos (int); 0162 0163 /* Back up history_offset to the previous history entry, and return 0164 a pointer to that entry. If there is no previous entry, return 0165 a NULL pointer. */ 0166 extern HIST_ENTRY *previous_history (void); 0167 0168 /* Move history_offset forward to the next item in the input_history, 0169 and return the a pointer to that entry. If there is no next entry, 0170 return a NULL pointer. */ 0171 extern HIST_ENTRY *next_history (void); 0172 0173 /* Searching the history list. */ 0174 0175 /* Search the history for STRING, starting at history_offset. 0176 If DIRECTION < 0, then the search is through previous entries, 0177 else through subsequent. If the string is found, then 0178 current_history () is the history entry, and the value of this function 0179 is the offset in the line of that history entry that the string was 0180 found in. Otherwise, nothing is changed, and a -1 is returned. */ 0181 extern int history_search (const char *, int); 0182 0183 /* Search the history for STRING, starting at history_offset. 0184 The search is anchored: matching lines must begin with string. 0185 DIRECTION is as in history_search(). */ 0186 extern int history_search_prefix (const char *, int); 0187 0188 /* Search for STRING in the history list, starting at POS, an 0189 absolute index into the list. DIR, if negative, says to search 0190 backwards from POS, else forwards. 0191 Returns the absolute index of the history element where STRING 0192 was found, or -1 otherwise. */ 0193 extern int history_search_pos (const char *, int, int); 0194 0195 /* Managing the history file. */ 0196 0197 /* Add the contents of FILENAME to the history list, a line at a time. 0198 If FILENAME is NULL, then read from ~/.history. Returns 0 if 0199 successful, or errno if not. */ 0200 extern int read_history (const char *); 0201 0202 /* Read a range of lines from FILENAME, adding them to the history list. 0203 Start reading at the FROM'th line and end at the TO'th. If FROM 0204 is zero, start at the beginning. If TO is less than FROM, read 0205 until the end of the file. If FILENAME is NULL, then read from 0206 ~/.history. Returns 0 if successful, or errno if not. */ 0207 extern int read_history_range (const char *, int, int); 0208 0209 /* Write the current history to FILENAME. If FILENAME is NULL, 0210 then write the history list to ~/.history. Values returned 0211 are as in read_history (). */ 0212 extern int write_history (const char *); 0213 0214 /* Append NELEMENT entries to FILENAME. The entries appended are from 0215 the end of the list minus NELEMENTs up to the end of the list. */ 0216 extern int append_history (int, const char *); 0217 0218 /* Truncate the history file, leaving only the last NLINES lines. */ 0219 extern int history_truncate_file (const char *, int); 0220 0221 /* History expansion. */ 0222 0223 /* Expand the string STRING, placing the result into OUTPUT, a pointer 0224 to a string. Returns: 0225 0226 0) If no expansions took place (or, if the only change in 0227 the text was the de-slashifying of the history expansion 0228 character) 0229 1) If expansions did take place 0230 -1) If there was an error in expansion. 0231 2) If the returned line should just be printed. 0232 0233 If an error occurred in expansion, then OUTPUT contains a descriptive 0234 error message. */ 0235 extern int history_expand (char *, char **); 0236 0237 /* Extract a string segment consisting of the FIRST through LAST 0238 arguments present in STRING. Arguments are broken up as in 0239 the shell. */ 0240 extern char *history_arg_extract (int, int, const char *); 0241 0242 /* Return the text of the history event beginning at the current 0243 offset into STRING. Pass STRING with *INDEX equal to the 0244 history_expansion_char that begins this specification. 0245 DELIMITING_QUOTE is a character that is allowed to end the string 0246 specification for what to search for in addition to the normal 0247 characters `:', ` ', `\t', `\n', and sometimes `?'. */ 0248 extern char *get_history_event (const char *, int *, int); 0249 0250 /* Return an array of tokens, much as the shell might. The tokens are 0251 parsed out of STRING. */ 0252 extern char **history_tokenize (const char *); 0253 0254 /* Exported history variables. */ 0255 extern int history_base; 0256 extern int history_length; 0257 extern int history_max_entries; 0258 extern int history_offset; 0259 0260 extern int history_lines_read_from_file; 0261 extern int history_lines_written_to_file; 0262 0263 extern char history_expansion_char; 0264 extern char history_subst_char; 0265 extern char *history_word_delimiters; 0266 extern char history_comment_char; 0267 extern char *history_no_expand_chars; 0268 extern char *history_search_delimiter_chars; 0269 0270 extern int history_quotes_inhibit_expansion; 0271 extern int history_quoting_state; 0272 0273 extern int history_write_timestamps; 0274 0275 /* These two are undocumented; the second is reserved for future use */ 0276 extern int history_multiline_entries; 0277 extern int history_file_version; 0278 0279 /* Backwards compatibility */ 0280 extern int max_input_history; 0281 0282 /* If set, this function is called to decide whether or not a particular 0283 history expansion should be treated as a special case for the calling 0284 application and not expanded. */ 0285 extern rl_linebuf_func_t *history_inhibit_expansion_function; 0286 0287 #ifdef __cplusplus 0288 } 0289 #endif 0290 0291 #endif /* !_HISTORY_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |