xorp

history.h

00001 #ifndef history_h
00002 #define history_h
00003 
00004 /*
00005  * Copyright (c) 2000, 2001 by Martin C. Shepherd.
00006  * 
00007  * All rights reserved.
00008  * 
00009  * Permission is hereby granted, free of charge, to any person obtaining a
00010  * copy of this software and associated documentation files (the
00011  * "Software"), to deal in the Software without restriction, including
00012  * without limitation the rights to use, copy, modify, merge, publish,
00013  * distribute, and/or sell copies of the Software, and to permit persons
00014  * to whom the Software is furnished to do so, provided that the above
00015  * copyright notice(s) and this permission notice appear in all copies of
00016  * the Software and that both the above copyright notice(s) and this
00017  * permission notice appear in supporting documentation.
00018  * 
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
00022  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00023  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
00024  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
00025  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00026  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00027  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00028  * 
00029  * Except as contained in this notice, the name of a copyright holder
00030  * shall not be used in advertising or otherwise to promote the sale, use
00031  * or other dealings in this Software without prior written authorization
00032  * of the copyright holder.
00033  */
00034 
00035 #include <stdio.h>  /* FILE * */
00036 
00037 /*-----------------------------------------------------------------------
00038  * This module is used to record and traverse historical lines of user input.
00039  */
00040 
00041 typedef struct GlHistory GlHistory;
00042 
00043 /*
00044  * Create a new history maintenance object.
00045  */
00046 GlHistory *_new_GlHistory(size_t buflen);
00047 
00048 /*
00049  * Delete a history maintenance object.
00050  */
00051 GlHistory *_del_GlHistory(GlHistory *glh);
00052 
00053 int _glh_add_history(GlHistory *glh, const char *line, int force);
00054 
00055 int _glh_search_prefix(GlHistory *glh, const char *line, int prefix_len);
00056 
00057 char *_glh_find_backwards(GlHistory *glh, char *line, size_t dim);
00058 char *_glh_find_forwards(GlHistory *glh, char *line, size_t dim);
00059 
00060 int _glh_cancel_search(GlHistory *glh);
00061 
00062 char *_glh_oldest_line(GlHistory *glh, char *line, size_t dim);
00063 char *_glh_current_line(GlHistory *glh, char *line, size_t dim);
00064 
00065 /*
00066  * Whenever a new line is added to the history buffer, it is given
00067  * a unique ID, recorded in an object of the following type.
00068  */
00069 typedef unsigned long GlhLineID;
00070 
00071 /*
00072  * Query the id of a history line offset by a given number of lines from
00073  * the one that is currently being recalled. If a recall session isn't
00074  * in progress, or the offset points outside the history list, 0 is
00075  * returned.
00076  */
00077 GlhLineID _glh_line_id(GlHistory *glh, int offset);
00078 
00079 /*
00080  * Recall a line by its history buffer ID. If the line is no longer
00081  * in the buffer, or the specified id is zero, NULL is returned.
00082  */
00083 char *_glh_recall_line(GlHistory *glh, GlhLineID id, char *line, size_t dim);
00084 
00085 /*
00086  * Write the contents of the history buffer to a given file. Note that
00087  * ~ and $ expansion are not performed on the filename.
00088  */
00089 int _glh_save_history(GlHistory *glh, const char *filename,
00090               const char *comment, int max_lines);
00091 
00092 /*
00093  * Restore the contents of the history buffer from a given file.
00094  * Note that ~ and $ expansion are not performed on the filename.
00095  */
00096 int _glh_load_history(GlHistory *glh, const char *filename, const char *comment,
00097               char *line, size_t dim);
00098 
00099 /*
00100  * Set and query the current history group.
00101  */
00102 int _glh_set_group(GlHistory *glh, unsigned group);
00103 int _glh_get_group(GlHistory *glh);
00104 
00105 /*
00106  * Display the contents of the history list to the specified stdio
00107  * output group.
00108  */
00109 int _glh_show_history(GlHistory *glh, FILE *fp, const char *fmt,
00110               int all_groups, int max_lines);
00111 
00112 /*
00113  * Change the size of the history buffer.
00114  */
00115 int _glh_resize_history(GlHistory *glh, size_t bufsize);
00116 
00117 /*
00118  * Set an upper limit to the number of lines that can be recorded in the
00119  * history list, or remove a previously specified limit.
00120  */
00121 void _glh_limit_history(GlHistory *glh, int max_lines);
00122 
00123 /*
00124  * Discard either all history, or the history associated with the current
00125  * history group.
00126  */
00127 void _glh_clear_history(GlHistory *glh, int all_groups);
00128 
00129 /*
00130  * Temporarily enable or disable the history facility.
00131  */
00132 void _glh_toggle_history(GlHistory *glh, int enable);
00133 
00134 /*
00135  * Lookup a history line by its sequential number of entry in the
00136  * history buffer.
00137  */
00138 int _glh_lookup_history(GlHistory *glh, GlhLineID id, const char **line,
00139             unsigned *group, time_t *timestamp);
00140 
00141 /*
00142  * Query the state of the history list.
00143  */
00144 void _glh_state_of_history(GlHistory *glh, int *enabled, unsigned *group,
00145                int *max_lines);
00146 
00147 /*
00148  * Get the range of lines in the history buffer.
00149  */
00150 void _glh_range_of_history(GlHistory *glh, unsigned long *oldest,
00151                unsigned long *newest, int *nlines);
00152 
00153 /*
00154  * Return the size of the history buffer and the amount of the
00155  * buffer that is currently in use.
00156  */
00157 void _glh_size_of_history(GlHistory *glh, size_t *buff_size, size_t *buff_used);
00158 
00159 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations