8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libtecla / common / history.h
blobfbc2ae2bdaff4bb7ac743108499bbc4f947b2846
1 #ifndef history_h
2 #define history_h
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.
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.
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.
35 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <stdio.h> /* FILE * */
39 /*-----------------------------------------------------------------------
40 * This module is used to record and traverse historical lines of user input.
43 typedef struct GlHistory GlHistory;
46 * Create a new history maintenance object.
48 GlHistory *_new_GlHistory(size_t buflen);
51 * Delete a history maintenance object.
53 GlHistory *_del_GlHistory(GlHistory *glh);
55 int _glh_add_history(GlHistory *glh, const char *line, int force);
57 int _glh_search_prefix(GlHistory *glh, const char *line, int prefix_len);
59 char *_glh_find_backwards(GlHistory *glh, char *line, size_t dim);
60 char *_glh_find_forwards(GlHistory *glh, char *line, size_t dim);
62 int _glh_cancel_search(GlHistory *glh);
64 char *_glh_oldest_line(GlHistory *glh, char *line, size_t dim);
65 char *_glh_current_line(GlHistory *glh, char *line, size_t dim);
68 * Whenever a new line is added to the history buffer, it is given
69 * a unique ID, recorded in an object of the following type.
71 typedef unsigned long GlhLineID;
74 * Query the id of a history line offset by a given number of lines from
75 * the one that is currently being recalled. If a recall session isn't
76 * in progress, or the offset points outside the history list, 0 is
77 * returned.
79 GlhLineID _glh_line_id(GlHistory *glh, int offset);
82 * Recall a line by its history buffer ID. If the line is no longer
83 * in the buffer, or the specified id is zero, NULL is returned.
85 char *_glh_recall_line(GlHistory *glh, GlhLineID id, char *line, size_t dim);
88 * Write the contents of the history buffer to a given file. Note that
89 * ~ and $ expansion are not performed on the filename.
91 int _glh_save_history(GlHistory *glh, const char *filename,
92 const char *comment, int max_lines);
95 * Restore the contents of the history buffer from a given file.
96 * Note that ~ and $ expansion are not performed on the filename.
98 int _glh_load_history(GlHistory *glh, const char *filename, const char *comment,
99 char *line, size_t dim);
102 * Set and query the current history group.
104 int _glh_set_group(GlHistory *glh, unsigned group);
105 int _glh_get_group(GlHistory *glh);
108 * Display the contents of the history list to the specified stdio
109 * output group.
111 int _glh_show_history(GlHistory *glh, GlWriteFn *write_fn, void *data,
112 const char *fmt, int all_groups, int max_lines);
115 * Change the size of the history buffer.
117 int _glh_resize_history(GlHistory *glh, size_t bufsize);
120 * Set an upper limit to the number of lines that can be recorded in the
121 * history list, or remove a previously specified limit.
123 void _glh_limit_history(GlHistory *glh, int max_lines);
126 * Discard either all history, or the history associated with the current
127 * history group.
129 void _glh_clear_history(GlHistory *glh, int all_groups);
132 * Temporarily enable or disable the history facility.
134 void _glh_toggle_history(GlHistory *glh, int enable);
137 * Lookup a history line by its sequential number of entry in the
138 * history buffer.
140 int _glh_lookup_history(GlHistory *glh, GlhLineID id, const char **line,
141 unsigned *group, time_t *timestamp);
144 * Query the state of the history list.
146 void _glh_state_of_history(GlHistory *glh, int *enabled, unsigned *group,
147 int *max_lines);
150 * Get the range of lines in the history buffer.
152 void _glh_range_of_history(GlHistory *glh, unsigned long *oldest,
153 unsigned long *newest, int *nlines);
156 * Return the size of the history buffer and the amount of the
157 * buffer that is currently in use.
159 void _glh_size_of_history(GlHistory *glh, size_t *buff_size, size_t *buff_used);
162 * Get information about the last error in this module.
164 const char *_glh_last_error(GlHistory *glh);
167 * Return non-zero if a history search session is currently in progress.
169 int _glh_search_active(GlHistory *glh);
171 #endif