1 #ifndef history_h 2 #define history_h 3 4 /* 5 * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd. 6 * 7 * All rights reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the 11 * "Software"), to deal in the Software without restriction, including 12 * without limitation the rights to use, copy, modify, merge, publish, 13 * distribute, and/or sell copies of the Software, and to permit persons 14 * to whom the Software is furnished to do so, provided that the above 15 * copyright notice(s) and this permission notice appear in all copies of 16 * the Software and that both the above copyright notice(s) and this 17 * permission notice appear in supporting documentation. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 22 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 24 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 25 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 26 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 27 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 28 * 29 * Except as contained in this notice, the name of a copyright holder 30 * shall not be used in advertising or otherwise to promote the sale, use 31 * or other dealings in this Software without prior written authorization 32 * of the copyright holder. 33 */ 34 35 #include <stdio.h> /* FILE * */ 36 37 /*----------------------------------------------------------------------- 38 * This module is used to record and traverse historical lines of user input. 39 */ 40 41 typedef struct GlHistory GlHistory; 42 43 /* 44 * Create a new history maintenance object. 45 */ 46 GlHistory *_new_GlHistory(size_t buflen); 47 48 /* 49 * Delete a history maintenance object. 50 */ 51 GlHistory *_del_GlHistory(GlHistory *glh); 52 53 int _glh_add_history(GlHistory *glh, const char *line, int force); 54 55 int _glh_search_prefix(GlHistory *glh, const char *line, int prefix_len); 56 57 char *_glh_find_backwards(GlHistory *glh, char *line, size_t dim); 58 char *_glh_find_forwards(GlHistory *glh, char *line, size_t dim); 59 60 int _glh_cancel_search(GlHistory *glh); 61 62 char *_glh_oldest_line(GlHistory *glh, char *line, size_t dim); 63 char *_glh_current_line(GlHistory *glh, char *line, size_t dim); 64 65 /* 66 * Whenever a new line is added to the history buffer, it is given 67 * a unique ID, recorded in an object of the following type. 68 */ 69 typedef unsigned long GlhLineID; 70 71 /* 72 * Query the id of a history line offset by a given number of lines from 73 * the one that is currently being recalled. If a recall session isn't 74 * in progress, or the offset points outside the history list, 0 is 75 * returned. 76 */ 77 GlhLineID _glh_line_id(GlHistory *glh, int offset); 78 79 /* 80 * Recall a line by its history buffer ID. If the line is no longer 81 * in the buffer, or the specified id is zero, NULL is returned. 82 */ 83 char *_glh_recall_line(GlHistory *glh, GlhLineID id, char *line, size_t dim); 84 85 /* 86 * Write the contents of the history buffer to a given file. Note that 87 * ~ and $ expansion are not performed on the filename. 88 */ 89 int _glh_save_history(GlHistory *glh, const char *filename, 90 const char *comment, int max_lines); 91 92 /* 93 * Restore the contents of the history buffer from a given file. 94 * Note that ~ and $ expansion are not performed on the filename. 95 */ 96 int _glh_load_history(GlHistory *glh, const char *filename, const char *comment, 97 char *line, size_t dim); 98 99 /* 100 * Set and query the current history group. 101 */ 102 int _glh_set_group(GlHistory *glh, unsigned group); 103 int _glh_get_group(GlHistory *glh); 104 105 /* 106 * Display the contents of the history list to the specified stdio 107 * output group. 108 */ 109 int _glh_show_history(GlHistory *glh, GlWriteFn *write_fn, void *data, 110 const char *fmt, int all_groups, int max_lines); 111 112 /* 113 * Change the size of the history buffer. 114 */ 115 int _glh_resize_history(GlHistory *glh, size_t bufsize); 116 117 /* 118 * Set an upper limit to the number of lines that can be recorded in the 119 * history list, or remove a previously specified limit. 120 */ 121 void _glh_limit_history(GlHistory *glh, int max_lines); 122 123 /* 124 * Discard either all history, or the history associated with the current 125 * history group. 126 */ 127 void _glh_clear_history(GlHistory *glh, int all_groups); 128 129 /* 130 * Temporarily enable or disable the history facility. 131 */ 132 void _glh_toggle_history(GlHistory *glh, int enable); 133 134 /* 135 * Lookup a history line by its sequential number of entry in the 136 * history buffer. 137 */ 138 int _glh_lookup_history(GlHistory *glh, GlhLineID id, const char **line, 139 unsigned *group, time_t *timestamp); 140 141 /* 142 * Query the state of the history list. 143 */ 144 void _glh_state_of_history(GlHistory *glh, int *enabled, unsigned *group, 145 int *max_lines); 146 147 /* 148 * Get the range of lines in the history buffer. 149 */ 150 void _glh_range_of_history(GlHistory *glh, unsigned long *oldest, 151 unsigned long *newest, int *nlines); 152 153 /* 154 * Return the size of the history buffer and the amount of the 155 * buffer that is currently in use. 156 */ 157 void _glh_size_of_history(GlHistory *glh, size_t *buff_size, size_t *buff_used); 158 159 /* 160 * Get information about the last error in this module. 161 */ 162 const char *_glh_last_error(GlHistory *glh); 163 164 /* 165 * Return non-zero if a history search session is currently in progress. 166 */ 167 int _glh_search_active(GlHistory *glh); 168 169 #endif 170