| 1 |
/* History.h -- the names of functions that you can call in history. */ |
| 2 |
|
| 3 |
/* The structure used to store a history entry. */ |
| 4 |
typedef struct { |
| 5 |
char *line; |
| 6 |
char *data; |
| 7 |
} HIST_ENTRY; |
| 8 |
|
| 9 |
/* A structure used to pass the current state of the history stuff around. */ |
| 10 |
typedef struct _hist_entry { |
| 11 |
HIST_ENTRY **entries; /* Pointer to the entries themselves. */ |
| 12 |
int offset; /* The location pointer within this array. */ |
| 13 |
int length; /* Number of elements within this array. */ |
| 14 |
int size; /* Number of slots allocated to this array. */ |
| 15 |
} HISTORY_STATE; |
| 16 |
|
| 17 |
/* For convenience only. You set this when interpreting history commands. |
| 18 |
It is the logical offset of the first history element. */ |
| 19 |
extern int history_base; |
| 20 |
|
| 21 |
/* Begin a session in which the history functions might be used. This |
| 22 |
just initializes the interactive variables. */ |
| 23 |
extern void using_history (); |
| 24 |
|
| 25 |
/* Return the current HISTORY_STATE of the history. */ |
| 26 |
extern HISTORY_STATE *history_get_history_state (); |
| 27 |
|
| 28 |
/* Set the state of the current history array to STATE. */ |
| 29 |
extern void history_set_history_state (); |
| 30 |
|
| 31 |
/* Place STRING at the end of the history list. |
| 32 |
The associated data field (if any) is set to NULL. */ |
| 33 |
extern void add_history (); |
| 34 |
|
| 35 |
/* Returns the number which says what history element we are now |
| 36 |
looking at. */ |
| 37 |
extern int where_history (); |
| 38 |
|
| 39 |
/* Set the position in the history list to POS. */ |
| 40 |
int history_set_pos (); |
| 41 |
|
| 42 |
/* Search for STRING in the history list, starting at POS, an |
| 43 |
absolute index into the list. DIR, if negative, says to search |
| 44 |
backwards from POS, else forwards. |
| 45 |
Returns the absolute index of the history element where STRING |
| 46 |
was found, or -1 otherwise. */ |
| 47 |
extern int history_search_pos (); |
| 48 |
|
| 49 |
/* A reasonably useless function, only here for completeness. WHICH |
| 50 |
is the magic number that tells us which element to delete. The |
| 51 |
elements are numbered from 0. */ |
| 52 |
extern HIST_ENTRY *remove_history (); |
| 53 |
|
| 54 |
/* Stifle the history list, remembering only MAX number of entries. */ |
| 55 |
extern void stifle_history (); |
| 56 |
|
| 57 |
/* Stop stifling the history. This returns the previous amount the |
| 58 |
history was stifled by. The value is positive if the history was |
| 59 |
stifled, negative if it wasn't. */ |
| 60 |
extern int unstifle_history (); |
| 61 |
|
| 62 |
/* Add the contents of FILENAME to the history list, a line at a time. |
| 63 |
If FILENAME is NULL, then read from ~/.history. Returns 0 if |
| 64 |
successful, or errno if not. */ |
| 65 |
extern int read_history (); |
| 66 |
|
| 67 |
/* Read a range of lines from FILENAME, adding them to the history list. |
| 68 |
Start reading at the FROM'th line and end at the TO'th. If FROM |
| 69 |
is zero, start at the beginning. If TO is less than FROM, read |
| 70 |
until the end of the file. If FILENAME is NULL, then read from |
| 71 |
~/.history. Returns 0 if successful, or errno if not. */ |
| 72 |
extern int read_history_range (); |
| 73 |
|
| 74 |
/* Append the current history to FILENAME. If FILENAME is NULL, |
| 75 |
then append the history list to ~/.history. Values returned |
| 76 |
are as in read_history (). */ |
| 77 |
extern int write_history (); |
| 78 |
|
| 79 |
/* Append NELEMENT entries to FILENAME. The entries appended are from |
| 80 |
the end of the list minus NELEMENTs up to the end of the list. */ |
| 81 |
int append_history (); |
| 82 |
|
| 83 |
/* Make the history entry at WHICH have LINE and DATA. This returns |
| 84 |
the old entry so you can dispose of the data. In the case of an |
| 85 |
invalid WHICH, a NULL pointer is returned. */ |
| 86 |
extern HIST_ENTRY *replace_history_entry (); |
| 87 |
|
| 88 |
/* Return the history entry at the current position, as determined by |
| 89 |
history_offset. If there is no entry there, return a NULL pointer. */ |
| 90 |
HIST_ENTRY *current_history (); |
| 91 |
|
| 92 |
/* Back up history_offset to the previous history entry, and return |
| 93 |
a pointer to that entry. If there is no previous entry, return |
| 94 |
a NULL pointer. */ |
| 95 |
extern HIST_ENTRY *previous_history (); |
| 96 |
|
| 97 |
/* Move history_offset forward to the next item in the input_history, |
| 98 |
and return the a pointer to that entry. If there is no next entry, |
| 99 |
return a NULL pointer. */ |
| 100 |
extern HIST_ENTRY *next_history (); |
| 101 |
|
| 102 |
/* Return a NULL terminated array of HIST_ENTRY which is the current input |
| 103 |
history. Element 0 of this list is the beginning of time. If there |
| 104 |
is no history, return NULL. */ |
| 105 |
extern HIST_ENTRY **history_list (); |
| 106 |
|
| 107 |
/* Return the history entry which is logically at OFFSET in the history |
| 108 |
array. OFFSET is relative to history_base. */ |
| 109 |
extern HIST_ENTRY *history_get (); |
| 110 |
|
| 111 |
/* Search the history for STRING, starting at history_offset. |
| 112 |
If DIRECTION < 0, then the search is through previous entries, |
| 113 |
else through subsequent. If the string is found, then |
| 114 |
current_history () is the history entry, and the value of this function |
| 115 |
is the offset in the line of that history entry that the string was |
| 116 |
found in. Otherwise, nothing is changed, and a -1 is returned. */ |
| 117 |
extern int history_search (); |
| 118 |
|
| 119 |
/* Expand the string STRING, placing the result into OUTPUT, a pointer |
| 120 |
to a string. Returns: |
| 121 |
|
| 122 |
0) If no expansions took place (or, if the only change in |
| 123 |
the text was the de-slashifying of the history expansion |
| 124 |
character) |
| 125 |
1) If expansions did take place |
| 126 |
-1) If there was an error in expansion. |
| 127 |
|
| 128 |
If an error ocurred in expansion, then OUTPUT contains a descriptive |
| 129 |
error message. */ |
| 130 |
extern int history_expand (); |
| 131 |
|
| 132 |
/* Return an array of tokens, much as the shell might. The tokens are |
| 133 |
parsed out of STRING. */ |
| 134 |
extern char **history_tokenize (); |
| 135 |
|
| 136 |
/* Extract a string segment consisting of the FIRST through LAST |
| 137 |
arguments present in STRING. Arguments are broken up as in |
| 138 |
the shell. */ |
| 139 |
extern char *history_arg_extract (); |
| 140 |
|
| 141 |
/* Return the number of bytes that the primary history entries are using. |
| 142 |
This just adds up the lengths of the_history->lines. */ |
| 143 |
extern int history_total_bytes (); |
| 144 |
|
| 145 |
/* Exported history variables. */ |
| 146 |
extern int history_stifled; |
| 147 |
extern int history_length; |
| 148 |
extern int max_input_history; |
| 149 |
extern char history_expansion_char; |
| 150 |
extern char history_subst_char; |
| 151 |
extern char history_comment_char; |
| 152 |
extern char *history_no_expand_chars; |
| 153 |
extern int history_base; |