xref: /titanic_50/usr/src/lib/libtecla/libtecla.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate #ifndef libtecla_h
2*7c478bd9Sstevel@tonic-gate #define libtecla_h
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate /*
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * All rights reserved.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * Permission is hereby granted, free of charge, to any person obtaining a
10*7c478bd9Sstevel@tonic-gate  * copy of this software and associated documentation files (the
11*7c478bd9Sstevel@tonic-gate  * "Software"), to deal in the Software without restriction, including
12*7c478bd9Sstevel@tonic-gate  * without limitation the rights to use, copy, modify, merge, publish,
13*7c478bd9Sstevel@tonic-gate  * distribute, and/or sell copies of the Software, and to permit persons
14*7c478bd9Sstevel@tonic-gate  * to whom the Software is furnished to do so, provided that the above
15*7c478bd9Sstevel@tonic-gate  * copyright notice(s) and this permission notice appear in all copies of
16*7c478bd9Sstevel@tonic-gate  * the Software and that both the above copyright notice(s) and this
17*7c478bd9Sstevel@tonic-gate  * permission notice appear in supporting documentation.
18*7c478bd9Sstevel@tonic-gate  *
19*7c478bd9Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20*7c478bd9Sstevel@tonic-gate  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21*7c478bd9Sstevel@tonic-gate  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22*7c478bd9Sstevel@tonic-gate  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23*7c478bd9Sstevel@tonic-gate  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24*7c478bd9Sstevel@tonic-gate  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25*7c478bd9Sstevel@tonic-gate  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26*7c478bd9Sstevel@tonic-gate  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27*7c478bd9Sstevel@tonic-gate  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28*7c478bd9Sstevel@tonic-gate  *
29*7c478bd9Sstevel@tonic-gate  * Except as contained in this notice, the name of a copyright holder
30*7c478bd9Sstevel@tonic-gate  * shall not be used in advertising or otherwise to promote the sale, use
31*7c478bd9Sstevel@tonic-gate  * or other dealings in this Software without prior written authorization
32*7c478bd9Sstevel@tonic-gate  * of the copyright holder.
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include <stdio.h>   /* FILE * */
42*7c478bd9Sstevel@tonic-gate #include <stdlib.h>  /* size_t */
43*7c478bd9Sstevel@tonic-gate #include <time.h>    /* time_t */
44*7c478bd9Sstevel@tonic-gate #include <signal.h>  /* struct sigaction */
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate  * The following are the three components of the libtecla version number.
48*7c478bd9Sstevel@tonic-gate  * Note that it is better to use the libtecla_version() function than these
49*7c478bd9Sstevel@tonic-gate  * macros since the macros only tell you which version of the library your
50*7c478bd9Sstevel@tonic-gate  * code was compiled against, whereas the libtecla_version() function
51*7c478bd9Sstevel@tonic-gate  * tells you which version of the shared tecla library your program is
52*7c478bd9Sstevel@tonic-gate  * actually linked to.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate #define TECLA_MAJOR_VER 1
55*7c478bd9Sstevel@tonic-gate #define TECLA_MINOR_VER 6
56*7c478bd9Sstevel@tonic-gate #define TECLA_MICRO_VER 0
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /*.......................................................................
59*7c478bd9Sstevel@tonic-gate  * Query the version number of the tecla library.
60*7c478bd9Sstevel@tonic-gate  *
61*7c478bd9Sstevel@tonic-gate  * Input:
62*7c478bd9Sstevel@tonic-gate  *  major    int *   The major version number of the library
63*7c478bd9Sstevel@tonic-gate  *                   will be assigned to *major. This number is
64*7c478bd9Sstevel@tonic-gate  *                   only incremented when a change to the library is
65*7c478bd9Sstevel@tonic-gate  *                   made that breaks binary (shared library) and/or
66*7c478bd9Sstevel@tonic-gate  *                   compilation backwards compatibility.
67*7c478bd9Sstevel@tonic-gate  *  minor    int *   The minor version number of the library
68*7c478bd9Sstevel@tonic-gate  *                   will be assigned to *minor. This number is
69*7c478bd9Sstevel@tonic-gate  *                   incremented whenever new functions are added to
70*7c478bd9Sstevel@tonic-gate  *                   the public API.
71*7c478bd9Sstevel@tonic-gate  *  micro    int *   The micro version number of the library will be
72*7c478bd9Sstevel@tonic-gate  *                   assigned to *micro. This number is incremented
73*7c478bd9Sstevel@tonic-gate  *                   whenever internal changes are made that don't
74*7c478bd9Sstevel@tonic-gate  *                   change the public API, such as bug fixes and
75*7c478bd9Sstevel@tonic-gate  *                   performance enhancements.
76*7c478bd9Sstevel@tonic-gate  */
77*7c478bd9Sstevel@tonic-gate void libtecla_version(int *major, int *minor, int *micro);
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate /*-----------------------------------------------------------------------
80*7c478bd9Sstevel@tonic-gate  * The getline module provides interactive command-line input, recall
81*7c478bd9Sstevel@tonic-gate  * and editing by users at terminals. See the gl_getline(3) man page for
82*7c478bd9Sstevel@tonic-gate  * more details.
83*7c478bd9Sstevel@tonic-gate  *-----------------------------------------------------------------------*/
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate  * Provide an opaque handle for the resource object that is defined in
87*7c478bd9Sstevel@tonic-gate  * getline.h.
88*7c478bd9Sstevel@tonic-gate  */
89*7c478bd9Sstevel@tonic-gate typedef struct GetLine GetLine;
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate /*
92*7c478bd9Sstevel@tonic-gate  * The following two functions are used to create and delete the
93*7c478bd9Sstevel@tonic-gate  * resource objects that are used by the gl_getline() function.
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate GetLine *new_GetLine(size_t linelen, size_t histlen);
96*7c478bd9Sstevel@tonic-gate GetLine *del_GetLine(GetLine *gl);
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /*
99*7c478bd9Sstevel@tonic-gate  * Read a line into an internal buffer of gl.
100*7c478bd9Sstevel@tonic-gate  */
101*7c478bd9Sstevel@tonic-gate char *gl_get_line(GetLine *gl, const char *prompt, const char *start_line,
102*7c478bd9Sstevel@tonic-gate 		  int start_pos);
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate /*.......................................................................
105*7c478bd9Sstevel@tonic-gate  * Prompt the user for a single-character reply.
106*7c478bd9Sstevel@tonic-gate  *
107*7c478bd9Sstevel@tonic-gate  * Input:
108*7c478bd9Sstevel@tonic-gate  *  gl       GetLine *  A resource object returned by new_GetLine().
109*7c478bd9Sstevel@tonic-gate  *  prompt      char *  The prompt to prefix the query with, or NULL
110*7c478bd9Sstevel@tonic-gate  *                      to reuse the previous prompt.
111*7c478bd9Sstevel@tonic-gate  *  defchar     char    The character to substitute if the
112*7c478bd9Sstevel@tonic-gate  *                      user simply hits return, or '\n' if you don't
113*7c478bd9Sstevel@tonic-gate  *                      need to substitute anything.
114*7c478bd9Sstevel@tonic-gate  * Output:
115*7c478bd9Sstevel@tonic-gate  *  return       int    The character that was read, or EOF if the read
116*7c478bd9Sstevel@tonic-gate  *                      had to be aborted (in which case you can call
117*7c478bd9Sstevel@tonic-gate  *                      gl_return_status() to find out why).
118*7c478bd9Sstevel@tonic-gate  */
119*7c478bd9Sstevel@tonic-gate int gl_query_char(GetLine *gl, const char *prompt, char defchar);
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /*.......................................................................
122*7c478bd9Sstevel@tonic-gate  * Read a single uninterpretted character from the user, without
123*7c478bd9Sstevel@tonic-gate  * displaying anything.
124*7c478bd9Sstevel@tonic-gate  *
125*7c478bd9Sstevel@tonic-gate  * Input:
126*7c478bd9Sstevel@tonic-gate  *  gl     GetLine *  A resource object previously returned by
127*7c478bd9Sstevel@tonic-gate  *                    new_GetLine().
128*7c478bd9Sstevel@tonic-gate  * Output:
129*7c478bd9Sstevel@tonic-gate  *  return     int    The character that was read, or EOF if the read
130*7c478bd9Sstevel@tonic-gate  *                    had to be aborted (in which case you can call
131*7c478bd9Sstevel@tonic-gate  *                    gl_return_status() to find out why).
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate int gl_read_char(GetLine *gl);
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate  * Configure the application specific and/or user-specific behavior of
137*7c478bd9Sstevel@tonic-gate  * gl_get_line().
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate int gl_configure_getline(GetLine *gl, const char *app_string,
140*7c478bd9Sstevel@tonic-gate 			 const char *app_file, const char *user_file);
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate /*
143*7c478bd9Sstevel@tonic-gate  * The following enumerators specify the origin of a key binding, and
144*7c478bd9Sstevel@tonic-gate  * are listed in order of decreasing priority, such that user-specified
145*7c478bd9Sstevel@tonic-gate  * key-bindings take precedence over application default bindings.
146*7c478bd9Sstevel@tonic-gate  */
147*7c478bd9Sstevel@tonic-gate typedef enum {
148*7c478bd9Sstevel@tonic-gate   GL_USER_KEY,  /* A key-binding specified by the user */
149*7c478bd9Sstevel@tonic-gate   GL_APP_KEY    /* A key-binding specified by the application */
150*7c478bd9Sstevel@tonic-gate } GlKeyOrigin;
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate /*
153*7c478bd9Sstevel@tonic-gate  * Bind a key sequence to a given action. If action==NULL, unbind the
154*7c478bd9Sstevel@tonic-gate  * key-sequence.
155*7c478bd9Sstevel@tonic-gate  */
156*7c478bd9Sstevel@tonic-gate int gl_bind_keyseq(GetLine *gl, GlKeyOrigin origin, const char *keyseq,
157*7c478bd9Sstevel@tonic-gate 		   const char *action);
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate /*-----------------------------------------------------------------------
160*7c478bd9Sstevel@tonic-gate  * The file-expansion module provides facilities for expanding ~user/ and
161*7c478bd9Sstevel@tonic-gate  * $envvar expressions, and for expanding glob-style wildcards.
162*7c478bd9Sstevel@tonic-gate  * See the ef_expand_file(3) man page for more details.
163*7c478bd9Sstevel@tonic-gate  *-----------------------------------------------------------------------*/
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  * ExpandFile objects contain the resources needed to expand pathnames.
167*7c478bd9Sstevel@tonic-gate  */
168*7c478bd9Sstevel@tonic-gate typedef struct ExpandFile ExpandFile;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * The following functions are used to create and delete the resource
172*7c478bd9Sstevel@tonic-gate  * objects that are used by the ef_expand_file() function.
173*7c478bd9Sstevel@tonic-gate  */
174*7c478bd9Sstevel@tonic-gate ExpandFile *new_ExpandFile(void);
175*7c478bd9Sstevel@tonic-gate ExpandFile *del_ExpandFile(ExpandFile *ef);
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate /*
178*7c478bd9Sstevel@tonic-gate  * A container of the following type is returned by ef_expand_file().
179*7c478bd9Sstevel@tonic-gate  */
180*7c478bd9Sstevel@tonic-gate typedef struct {
181*7c478bd9Sstevel@tonic-gate   int exists;       /* True if the files in files[] currently exist. */
182*7c478bd9Sstevel@tonic-gate                     /*  This only time that this may not be true is if */
183*7c478bd9Sstevel@tonic-gate                     /*  the input filename didn't contain any wildcards */
184*7c478bd9Sstevel@tonic-gate                     /*  and thus wasn't matched against existing files. */
185*7c478bd9Sstevel@tonic-gate                     /*  In this case the single entry in 'nfile' may not */
186*7c478bd9Sstevel@tonic-gate                     /*  refer to an existing file. */
187*7c478bd9Sstevel@tonic-gate   int nfile;        /* The number of files in files[] */
188*7c478bd9Sstevel@tonic-gate   char **files;     /* An array of 'nfile' filenames. */
189*7c478bd9Sstevel@tonic-gate } FileExpansion;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate /*
192*7c478bd9Sstevel@tonic-gate  * The ef_expand_file() function expands a specified pathname, converting
193*7c478bd9Sstevel@tonic-gate  * ~user/ and ~/ patterns at the start of the pathname to the
194*7c478bd9Sstevel@tonic-gate  * corresponding home directories, replacing $envvar with the value of
195*7c478bd9Sstevel@tonic-gate  * the corresponding environment variable, and then, if there are any
196*7c478bd9Sstevel@tonic-gate  * wildcards, matching these against existing filenames.
197*7c478bd9Sstevel@tonic-gate  *
198*7c478bd9Sstevel@tonic-gate  * If no errors occur, a container is returned containing the array of
199*7c478bd9Sstevel@tonic-gate  * files that resulted from the expansion. If there were no wildcards
200*7c478bd9Sstevel@tonic-gate  * in the input pathname, this will contain just the original pathname
201*7c478bd9Sstevel@tonic-gate  * after expansion of ~ and $ expressions. If there were any wildcards,
202*7c478bd9Sstevel@tonic-gate  * then the array will contain the files that matched them. Note that
203*7c478bd9Sstevel@tonic-gate  * if there were any wildcards but no existing files match them, this
204*7c478bd9Sstevel@tonic-gate  * is counted as an error and NULL is returned.
205*7c478bd9Sstevel@tonic-gate  *
206*7c478bd9Sstevel@tonic-gate  * The supported wildcards and their meanings are:
207*7c478bd9Sstevel@tonic-gate  *  *        -  Match any sequence of zero or more characters.
208*7c478bd9Sstevel@tonic-gate  *  ?        -  Match any single character.
209*7c478bd9Sstevel@tonic-gate  *  [chars]  -  Match any single character that appears in 'chars'.
210*7c478bd9Sstevel@tonic-gate  *              If 'chars' contains an expression of the form a-b,
211*7c478bd9Sstevel@tonic-gate  *              then any character between a and b, including a and b,
212*7c478bd9Sstevel@tonic-gate  *              matches. The '-' character looses its special meaning
213*7c478bd9Sstevel@tonic-gate  *              as a range specifier when it appears at the start
214*7c478bd9Sstevel@tonic-gate  *              of the sequence of characters.
215*7c478bd9Sstevel@tonic-gate  *  [^chars] -  The same as [chars] except that it matches any single
216*7c478bd9Sstevel@tonic-gate  *              character that doesn't appear in 'chars'.
217*7c478bd9Sstevel@tonic-gate  *
218*7c478bd9Sstevel@tonic-gate  * Wildcard expressions are applied to individual filename components.
219*7c478bd9Sstevel@tonic-gate  * They don't match across directory separators. A '.' character at
220*7c478bd9Sstevel@tonic-gate  * the beginning of a filename component must also be matched
221*7c478bd9Sstevel@tonic-gate  * explicitly by a '.' character in the input pathname, since these
222*7c478bd9Sstevel@tonic-gate  * are UNIX's hidden files.
223*7c478bd9Sstevel@tonic-gate  *
224*7c478bd9Sstevel@tonic-gate  * Input:
225*7c478bd9Sstevel@tonic-gate  *  fe         ExpandFile *  The pathname expansion resource object.
226*7c478bd9Sstevel@tonic-gate  *  path       const char *  The path name to be expanded.
227*7c478bd9Sstevel@tonic-gate  *  pathlen           int    The length of the suffix of path[] that
228*7c478bd9Sstevel@tonic-gate  *                           constitutes the filename to be expanded,
229*7c478bd9Sstevel@tonic-gate  *                           or -1 to specify that the whole of the
230*7c478bd9Sstevel@tonic-gate  *                           path string should be used.
231*7c478bd9Sstevel@tonic-gate  * Output:
232*7c478bd9Sstevel@tonic-gate  *  return  FileExpansion *  A pointer to a results container within the
233*7c478bd9Sstevel@tonic-gate  *                           given ExpandFile object. This contains an
234*7c478bd9Sstevel@tonic-gate  *                           array of the pathnames that resulted from
235*7c478bd9Sstevel@tonic-gate  *                           expanding ~ and $ expressions and from
236*7c478bd9Sstevel@tonic-gate  *                           matching any wildcards, sorted into lexical
237*7c478bd9Sstevel@tonic-gate  *                           order.
238*7c478bd9Sstevel@tonic-gate  *
239*7c478bd9Sstevel@tonic-gate  *                           This container and its contents will be
240*7c478bd9Sstevel@tonic-gate  *                           recycled on subsequent calls, so if you need
241*7c478bd9Sstevel@tonic-gate  *                           to keep the results of two successive runs,
242*7c478bd9Sstevel@tonic-gate  *                           you will either have to allocate a private
243*7c478bd9Sstevel@tonic-gate  *                           copy of the array, or use two ExpandFile
244*7c478bd9Sstevel@tonic-gate  *                           objects.
245*7c478bd9Sstevel@tonic-gate  *
246*7c478bd9Sstevel@tonic-gate  *                           On error, NULL is returned. A description
247*7c478bd9Sstevel@tonic-gate  *                           of the error can be acquired by calling the
248*7c478bd9Sstevel@tonic-gate  *                           ef_last_error() function.
249*7c478bd9Sstevel@tonic-gate  */
250*7c478bd9Sstevel@tonic-gate FileExpansion *ef_expand_file(ExpandFile *ef, const char *path, int pathlen);
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate /*.......................................................................
253*7c478bd9Sstevel@tonic-gate  * Print out an array of matching files.
254*7c478bd9Sstevel@tonic-gate  *
255*7c478bd9Sstevel@tonic-gate  * Input:
256*7c478bd9Sstevel@tonic-gate  *  result  FileExpansion *   The container of the sorted array of
257*7c478bd9Sstevel@tonic-gate  *                            expansions.
258*7c478bd9Sstevel@tonic-gate  *  fp               FILE *   The output stream to write to.
259*7c478bd9Sstevel@tonic-gate  *  term_width        int     The width of the terminal.
260*7c478bd9Sstevel@tonic-gate  * Output:
261*7c478bd9Sstevel@tonic-gate  *  return            int     0 - OK.
262*7c478bd9Sstevel@tonic-gate  *                            1 - Error.
263*7c478bd9Sstevel@tonic-gate  */
264*7c478bd9Sstevel@tonic-gate int ef_list_expansions(FileExpansion *result, FILE *fp, int term_width);
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate  * The ef_last_error() function returns a description of the last error
268*7c478bd9Sstevel@tonic-gate  * that occurred in a call ef_expand_file(). Note that this message is
269*7c478bd9Sstevel@tonic-gate  * contained in an array which is allocated as part of *ef, and its
270*7c478bd9Sstevel@tonic-gate  * contents thus potentially change on every call to ef_expand_file().
271*7c478bd9Sstevel@tonic-gate  */
272*7c478bd9Sstevel@tonic-gate const char *ef_last_error(ExpandFile *ef);
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate /*-----------------------------------------------------------------------
275*7c478bd9Sstevel@tonic-gate  * The WordCompletion module is used for completing incomplete words, such
276*7c478bd9Sstevel@tonic-gate  * as filenames. Programs can use functions within this module to register
277*7c478bd9Sstevel@tonic-gate  * their own customized completion functions.
278*7c478bd9Sstevel@tonic-gate  *-----------------------------------------------------------------------*/
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate /*
281*7c478bd9Sstevel@tonic-gate  * Ambiguous completion matches are recorded in objects of the
282*7c478bd9Sstevel@tonic-gate  * following type.
283*7c478bd9Sstevel@tonic-gate  */
284*7c478bd9Sstevel@tonic-gate typedef struct WordCompletion WordCompletion;
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate /*
287*7c478bd9Sstevel@tonic-gate  * Create a new completion object.
288*7c478bd9Sstevel@tonic-gate  */
289*7c478bd9Sstevel@tonic-gate WordCompletion *new_WordCompletion(void);
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate /*
292*7c478bd9Sstevel@tonic-gate  * Delete a redundant completion object.
293*7c478bd9Sstevel@tonic-gate  */
294*7c478bd9Sstevel@tonic-gate WordCompletion *del_WordCompletion(WordCompletion *cpl);
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate /*.......................................................................
297*7c478bd9Sstevel@tonic-gate  * Callback functions declared and prototyped using the following macro
298*7c478bd9Sstevel@tonic-gate  * are called upon to return an array of possible completion suffixes
299*7c478bd9Sstevel@tonic-gate  * for the token that precedes a specified location in the given
300*7c478bd9Sstevel@tonic-gate  * input line. It is up to this function to figure out where the token
301*7c478bd9Sstevel@tonic-gate  * starts, and to call cpl_add_completion() to register each possible
302*7c478bd9Sstevel@tonic-gate  * completion before returning.
303*7c478bd9Sstevel@tonic-gate  *
304*7c478bd9Sstevel@tonic-gate  * Input:
305*7c478bd9Sstevel@tonic-gate  *  cpl  WordCompletion *  An opaque pointer to the object that will
306*7c478bd9Sstevel@tonic-gate  *                         contain the matches. This should be filled
307*7c478bd9Sstevel@tonic-gate  *                         via zero or more calls to cpl_add_completion().
308*7c478bd9Sstevel@tonic-gate  *  data           void *  The anonymous 'data' argument that was
309*7c478bd9Sstevel@tonic-gate  *                         passed to cpl_complete_word() or
310*7c478bd9Sstevel@tonic-gate  *                         gl_customize_completion()).
311*7c478bd9Sstevel@tonic-gate  *  line     const char *  The current input line.
312*7c478bd9Sstevel@tonic-gate  *  word_end        int    The index of the character in line[] which
313*7c478bd9Sstevel@tonic-gate  *                         follows the end of the token that is being
314*7c478bd9Sstevel@tonic-gate  *                         completed.
315*7c478bd9Sstevel@tonic-gate  * Output
316*7c478bd9Sstevel@tonic-gate  *  return          int    0 - OK.
317*7c478bd9Sstevel@tonic-gate  *                         1 - Error.
318*7c478bd9Sstevel@tonic-gate  */
319*7c478bd9Sstevel@tonic-gate #define CPL_MATCH_FN(fn) int (fn)(WordCompletion *cpl, void *data, \
320*7c478bd9Sstevel@tonic-gate                                   const char *line, int word_end)
321*7c478bd9Sstevel@tonic-gate typedef CPL_MATCH_FN(CplMatchFn);
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate /*.......................................................................
324*7c478bd9Sstevel@tonic-gate  * Optional callback functions declared and prototyped using the
325*7c478bd9Sstevel@tonic-gate  * following macro are called upon to return non-zero if a given
326*7c478bd9Sstevel@tonic-gate  * file, specified by its pathname, is to be included in a list of
327*7c478bd9Sstevel@tonic-gate  * completions.
328*7c478bd9Sstevel@tonic-gate  *
329*7c478bd9Sstevel@tonic-gate  * Input:
330*7c478bd9Sstevel@tonic-gate  *  data            void *  The application specified pointer which
331*7c478bd9Sstevel@tonic-gate  *                          was specified when this callback function
332*7c478bd9Sstevel@tonic-gate  *                          was registered. This can be used to have
333*7c478bd9Sstevel@tonic-gate  *                          anything you like passed to your callback.
334*7c478bd9Sstevel@tonic-gate  *  pathname  const char *  The pathname of the file to be checked to
335*7c478bd9Sstevel@tonic-gate  *                          see if it should be included in the list
336*7c478bd9Sstevel@tonic-gate  *                          of completions.
337*7c478bd9Sstevel@tonic-gate  * Output
338*7c478bd9Sstevel@tonic-gate  *  return           int    0 - Ignore this file.
339*7c478bd9Sstevel@tonic-gate  *                          1 - Do include this file in the list
340*7c478bd9Sstevel@tonic-gate  *                              of completions.
341*7c478bd9Sstevel@tonic-gate  */
342*7c478bd9Sstevel@tonic-gate #define CPL_CHECK_FN(fn) int (fn)(void *data, const char *pathname)
343*7c478bd9Sstevel@tonic-gate typedef CPL_CHECK_FN(CplCheckFn);
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate /*
346*7c478bd9Sstevel@tonic-gate  * You can use the following CplCheckFn callback function to only
347*7c478bd9Sstevel@tonic-gate  * have executables included in a list of completions.
348*7c478bd9Sstevel@tonic-gate  */
349*7c478bd9Sstevel@tonic-gate CPL_CHECK_FN(cpl_check_exe);
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate /*
352*7c478bd9Sstevel@tonic-gate  * cpl_file_completions() is the builtin filename completion callback
353*7c478bd9Sstevel@tonic-gate  * function. This can also be called by your own custom CPL_MATCH_FN()
354*7c478bd9Sstevel@tonic-gate  * callback functions. To do this pass on all of the arguments of your
355*7c478bd9Sstevel@tonic-gate  * custom callback function to cpl_file_completions(), with the exception
356*7c478bd9Sstevel@tonic-gate  * of the (void *data) argument. The data argument should either be passed
357*7c478bd9Sstevel@tonic-gate  * NULL to request the default behaviour of the file-completion function,
358*7c478bd9Sstevel@tonic-gate  * or be passed a pointer to a CplFileConf structure (see below). In the
359*7c478bd9Sstevel@tonic-gate  * latter case the contents of the structure modify the behavior of the
360*7c478bd9Sstevel@tonic-gate  * file-completer.
361*7c478bd9Sstevel@tonic-gate  */
362*7c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cpl_file_completions);
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate /*
365*7c478bd9Sstevel@tonic-gate  * Objects of the following type can be used to change the default
366*7c478bd9Sstevel@tonic-gate  * behavior of the cpl_file_completions() callback function.
367*7c478bd9Sstevel@tonic-gate  */
368*7c478bd9Sstevel@tonic-gate typedef struct CplFileConf CplFileConf;
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate /*
371*7c478bd9Sstevel@tonic-gate  * If you want to change the behavior of the cpl_file_completions()
372*7c478bd9Sstevel@tonic-gate  * callback function, call the following function to allocate a
373*7c478bd9Sstevel@tonic-gate  * configuration object, then call one or more of the subsequent
374*7c478bd9Sstevel@tonic-gate  * functions to change any of the default configuration parameters
375*7c478bd9Sstevel@tonic-gate  * that you don't want. This function returns NULL when there is
376*7c478bd9Sstevel@tonic-gate  * insufficient memory.
377*7c478bd9Sstevel@tonic-gate  */
378*7c478bd9Sstevel@tonic-gate CplFileConf *new_CplFileConf(void);
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate /*
381*7c478bd9Sstevel@tonic-gate  * If backslashes in the prefix being passed to cpl_file_completions()
382*7c478bd9Sstevel@tonic-gate  * should be treated as literal characters, call the following function
383*7c478bd9Sstevel@tonic-gate  * with literal=1. Otherwise the default is to treat them as escape
384*7c478bd9Sstevel@tonic-gate  * characters which remove the special meanings of spaces etc..
385*7c478bd9Sstevel@tonic-gate  */
386*7c478bd9Sstevel@tonic-gate void cfc_literal_escapes(CplFileConf *cfc, int literal);
387*7c478bd9Sstevel@tonic-gate 
388*7c478bd9Sstevel@tonic-gate /*
389*7c478bd9Sstevel@tonic-gate  * Before calling cpl_file_completions(), call this function if you
390*7c478bd9Sstevel@tonic-gate  * know the index at which the filename prefix starts in the input line.
391*7c478bd9Sstevel@tonic-gate  * Otherwise by default, or if you specify start_index to be -1, the
392*7c478bd9Sstevel@tonic-gate  * filename is taken to start after the first unescaped space preceding
393*7c478bd9Sstevel@tonic-gate  * the cursor, or the start of the line, which ever comes first.
394*7c478bd9Sstevel@tonic-gate  */
395*7c478bd9Sstevel@tonic-gate void cfc_file_start(CplFileConf *cfc, int start_index);
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate /*
398*7c478bd9Sstevel@tonic-gate  * If you only want certain types of files to be included in the
399*7c478bd9Sstevel@tonic-gate  * list of completions, use the following function to specify a
400*7c478bd9Sstevel@tonic-gate  * callback function which will be called to ask whether a given file
401*7c478bd9Sstevel@tonic-gate  * should be included. The chk_data argument is will be passed to the
402*7c478bd9Sstevel@tonic-gate  * callback function whenever it is called and can be anything you want.
403*7c478bd9Sstevel@tonic-gate  */
404*7c478bd9Sstevel@tonic-gate void cfc_set_check_fn(CplFileConf *cfc, CplCheckFn *chk_fn, void *chk_data);
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate /*
407*7c478bd9Sstevel@tonic-gate  * The following function deletes a CplFileConf objects previously
408*7c478bd9Sstevel@tonic-gate  * returned by new_CplFileConf(). It always returns NULL.
409*7c478bd9Sstevel@tonic-gate  */
410*7c478bd9Sstevel@tonic-gate CplFileConf *del_CplFileConf(CplFileConf *cfc);
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate /*
413*7c478bd9Sstevel@tonic-gate  * The following configuration structure is deprecated. Do not change
414*7c478bd9Sstevel@tonic-gate  * its contents, since this will break any programs that still use it,
415*7c478bd9Sstevel@tonic-gate  * and don't use it in new programs. Instead use opaque CplFileConf
416*7c478bd9Sstevel@tonic-gate  * objects as described above. cpl_file_completions() figures out
417*7c478bd9Sstevel@tonic-gate  * what type of structure you pass it, by virtue of a magic int code
418*7c478bd9Sstevel@tonic-gate  * placed at the start of CplFileConf object by new_CplFileConf().
419*7c478bd9Sstevel@tonic-gate  */
420*7c478bd9Sstevel@tonic-gate typedef struct {
421*7c478bd9Sstevel@tonic-gate   int escaped;     /* Opposite to the argument of cfc_literal_escapes() */
422*7c478bd9Sstevel@tonic-gate   int file_start;  /* Equivalent to the argument of cfc_file_start() */
423*7c478bd9Sstevel@tonic-gate } CplFileArgs;
424*7c478bd9Sstevel@tonic-gate /*
425*7c478bd9Sstevel@tonic-gate  * This initializes the deprecated CplFileArgs structures.
426*7c478bd9Sstevel@tonic-gate  */
427*7c478bd9Sstevel@tonic-gate void cpl_init_FileArgs(CplFileArgs *cfa);
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate /*.......................................................................
430*7c478bd9Sstevel@tonic-gate  * When an error occurs while performing a completion, custom completion
431*7c478bd9Sstevel@tonic-gate  * callback functions should register a terse description of the error
432*7c478bd9Sstevel@tonic-gate  * by calling cpl_record_error(). This message will then be returned on
433*7c478bd9Sstevel@tonic-gate  * the next call to cpl_last_error() and used by getline to display an
434*7c478bd9Sstevel@tonic-gate  * error message to the user.
435*7c478bd9Sstevel@tonic-gate  *
436*7c478bd9Sstevel@tonic-gate  * Input:
437*7c478bd9Sstevel@tonic-gate  *  cpl  WordCompletion *  The string-completion resource object that was
438*7c478bd9Sstevel@tonic-gate  *                         originally passed to the callback.
439*7c478bd9Sstevel@tonic-gate  *  errmsg   const char *  The description of the error.
440*7c478bd9Sstevel@tonic-gate  */
441*7c478bd9Sstevel@tonic-gate void cpl_record_error(WordCompletion *cpl, const char *errmsg);
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate /*.......................................................................
444*7c478bd9Sstevel@tonic-gate  * This function can be used to replace the builtin filename-completion
445*7c478bd9Sstevel@tonic-gate  * function with one of the user's choice. The user's completion function
446*7c478bd9Sstevel@tonic-gate  * has the option of calling the builtin filename-completion function
447*7c478bd9Sstevel@tonic-gate  * if it believes that the token that it has been presented with is a
448*7c478bd9Sstevel@tonic-gate  * filename (see cpl_file_completions() above).
449*7c478bd9Sstevel@tonic-gate  *
450*7c478bd9Sstevel@tonic-gate  * Input:
451*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
452*7c478bd9Sstevel@tonic-gate  *                           module.
453*7c478bd9Sstevel@tonic-gate  *  data             void *  This is passed to match_fn() whenever it is
454*7c478bd9Sstevel@tonic-gate  *                           called. It could, for example, point to a
455*7c478bd9Sstevel@tonic-gate  *                           symbol table that match_fn() would look up
456*7c478bd9Sstevel@tonic-gate  *                           matches in.
457*7c478bd9Sstevel@tonic-gate  *  match_fn   CplMatchFn *  The function that will identify the prefix
458*7c478bd9Sstevel@tonic-gate  *                           to be completed from the input line, and
459*7c478bd9Sstevel@tonic-gate  *                           report matching symbols.
460*7c478bd9Sstevel@tonic-gate  * Output:
461*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
462*7c478bd9Sstevel@tonic-gate  *                           1 - Error.
463*7c478bd9Sstevel@tonic-gate  */
464*7c478bd9Sstevel@tonic-gate int gl_customize_completion(GetLine *gl, void *data, CplMatchFn *match_fn);
465*7c478bd9Sstevel@tonic-gate 
466*7c478bd9Sstevel@tonic-gate /*.......................................................................
467*7c478bd9Sstevel@tonic-gate  * This function allows you to install alternate completion action
468*7c478bd9Sstevel@tonic-gate  * functions or completion listing functions, or to change the
469*7c478bd9Sstevel@tonic-gate  * completion function of an existing action of the same type. This
470*7c478bd9Sstevel@tonic-gate  * should preferably be called before the first call to gl_get_line()
471*7c478bd9Sstevel@tonic-gate  * so that the name of the action becomes defined before the user's
472*7c478bd9Sstevel@tonic-gate  * configuration file is read.
473*7c478bd9Sstevel@tonic-gate  *
474*7c478bd9Sstevel@tonic-gate  * Input:
475*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
476*7c478bd9Sstevel@tonic-gate  *                           module.
477*7c478bd9Sstevel@tonic-gate  *  data             void *  This is passed to match_fn() whenever it is
478*7c478bd9Sstevel@tonic-gate  *                           called. It could, for example, point to a
479*7c478bd9Sstevel@tonic-gate  *                           symbol table that match_fn() would look up
480*7c478bd9Sstevel@tonic-gate  *                           matches in.
481*7c478bd9Sstevel@tonic-gate  *  match_fn   CplMatchFn *  The function that will identify the prefix
482*7c478bd9Sstevel@tonic-gate  *                           to be completed from the input line, and
483*7c478bd9Sstevel@tonic-gate  *                           report matching symbols.
484*7c478bd9Sstevel@tonic-gate  *  list_only         int    If non-zero, install an action that only lists
485*7c478bd9Sstevel@tonic-gate  *                           possible completions, rather than attempting
486*7c478bd9Sstevel@tonic-gate  *                           to perform the completion.
487*7c478bd9Sstevel@tonic-gate  *  name       const char *  The name with which users can refer to the
488*7c478bd9Sstevel@tonic-gate  *                           binding in tecla configuration files.
489*7c478bd9Sstevel@tonic-gate  *  keyseq     const char *  The key sequence with which to invoke
490*7c478bd9Sstevel@tonic-gate  *                           the binding. This should be specified in the
491*7c478bd9Sstevel@tonic-gate  *                           same manner as key-sequences in tecla
492*7c478bd9Sstevel@tonic-gate  *                           configuration files (eg. "M-^I").
493*7c478bd9Sstevel@tonic-gate  * Output:
494*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
495*7c478bd9Sstevel@tonic-gate  *                           1 - Error.
496*7c478bd9Sstevel@tonic-gate  */
497*7c478bd9Sstevel@tonic-gate int gl_completion_action(GetLine *gl, void *data, CplMatchFn *match_fn,
498*7c478bd9Sstevel@tonic-gate 			 int list_only, const char *name, const char *keyseq);
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate /*.......................................................................
501*7c478bd9Sstevel@tonic-gate  * Change the terminal (or stream) that getline interacts with.
502*7c478bd9Sstevel@tonic-gate  *
503*7c478bd9Sstevel@tonic-gate  * Input:
504*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
505*7c478bd9Sstevel@tonic-gate  *                           module.
506*7c478bd9Sstevel@tonic-gate  *  input_fp         FILE *  The stdio stream to read from.
507*7c478bd9Sstevel@tonic-gate  *  output_fp        FILE *  The stdio stream to write to.
508*7c478bd9Sstevel@tonic-gate  *  term       const char *  The terminal type. This can be NULL if
509*7c478bd9Sstevel@tonic-gate  *                           either or both of input_fp and output_fp don't
510*7c478bd9Sstevel@tonic-gate  *                           refer to a terminal. Otherwise it should refer
511*7c478bd9Sstevel@tonic-gate  *                           to an entry in the terminal information database.
512*7c478bd9Sstevel@tonic-gate  * Output:
513*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
514*7c478bd9Sstevel@tonic-gate  *                           1 - Error.
515*7c478bd9Sstevel@tonic-gate  */
516*7c478bd9Sstevel@tonic-gate int gl_change_terminal(GetLine *gl, FILE *input_fp, FILE *output_fp,
517*7c478bd9Sstevel@tonic-gate 		       const char *term);
518*7c478bd9Sstevel@tonic-gate 
519*7c478bd9Sstevel@tonic-gate /*.......................................................................
520*7c478bd9Sstevel@tonic-gate  * The following functions can be used to save and restore the contents
521*7c478bd9Sstevel@tonic-gate  * of the history buffer.
522*7c478bd9Sstevel@tonic-gate  *
523*7c478bd9Sstevel@tonic-gate  * Input:
524*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
525*7c478bd9Sstevel@tonic-gate  *                           module.
526*7c478bd9Sstevel@tonic-gate  *  filename   const char *  The name of the new file to write to.
527*7c478bd9Sstevel@tonic-gate  *  comment    const char *  Extra information such as timestamps will
528*7c478bd9Sstevel@tonic-gate  *                           be recorded on a line started with this
529*7c478bd9Sstevel@tonic-gate  *                           string, the idea being that the file can
530*7c478bd9Sstevel@tonic-gate  *                           double as a command file. Specify "" if
531*7c478bd9Sstevel@tonic-gate  *                           you don't care. Be sure to specify the
532*7c478bd9Sstevel@tonic-gate  *                           same string to both functions.
533*7c478bd9Sstevel@tonic-gate  *  max_lines         int    The maximum number of lines to save, or -1
534*7c478bd9Sstevel@tonic-gate  *                           to save all of the lines in the history
535*7c478bd9Sstevel@tonic-gate  *                           list.
536*7c478bd9Sstevel@tonic-gate  * Output:
537*7c478bd9Sstevel@tonic-gate  *  return            int     0 - OK.
538*7c478bd9Sstevel@tonic-gate  *                            1 - Error.
539*7c478bd9Sstevel@tonic-gate  */
540*7c478bd9Sstevel@tonic-gate int gl_save_history(GetLine *gl, const char *filename, const char *comment,
541*7c478bd9Sstevel@tonic-gate 		    int max_lines);
542*7c478bd9Sstevel@tonic-gate int gl_load_history(GetLine *gl, const char *filename, const char *comment);
543*7c478bd9Sstevel@tonic-gate 
544*7c478bd9Sstevel@tonic-gate /*
545*7c478bd9Sstevel@tonic-gate  * Enumerate file-descriptor events that can be waited for.
546*7c478bd9Sstevel@tonic-gate  */
547*7c478bd9Sstevel@tonic-gate typedef enum {
548*7c478bd9Sstevel@tonic-gate   GLFD_READ,   /* Watch for data waiting to be read from a file descriptor */
549*7c478bd9Sstevel@tonic-gate   GLFD_WRITE,  /* Watch for ability to write to a file descriptor */
550*7c478bd9Sstevel@tonic-gate   GLFD_URGENT  /* Watch for urgent out-of-band data on the file descriptor */
551*7c478bd9Sstevel@tonic-gate } GlFdEvent;
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate /*
554*7c478bd9Sstevel@tonic-gate  * The following enumeration is used for the return status of file
555*7c478bd9Sstevel@tonic-gate  * descriptor event callbacks.
556*7c478bd9Sstevel@tonic-gate  */
557*7c478bd9Sstevel@tonic-gate typedef enum {
558*7c478bd9Sstevel@tonic-gate   GLFD_ABORT,    /* Cause gl_get_line() to abort with an error */
559*7c478bd9Sstevel@tonic-gate   GLFD_REFRESH,  /* Redraw the input line and continue waiting for input */
560*7c478bd9Sstevel@tonic-gate   GLFD_CONTINUE  /* Continue to wait for input, without redrawing the line */
561*7c478bd9Sstevel@tonic-gate } GlFdStatus;
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate /*.......................................................................
564*7c478bd9Sstevel@tonic-gate  * On systems that have the select() system call, while gl_get_line()
565*7c478bd9Sstevel@tonic-gate  * is waiting for terminal input, it can also be asked to listen for
566*7c478bd9Sstevel@tonic-gate  * activity on arbitrary file descriptors.  Callback functions of the
567*7c478bd9Sstevel@tonic-gate  * following type can be registered to be called when activity is
568*7c478bd9Sstevel@tonic-gate  * seen. If your callback needs to write to the terminal or use
569*7c478bd9Sstevel@tonic-gate  * signals, please see the gl_get_line(3) man page.
570*7c478bd9Sstevel@tonic-gate  *
571*7c478bd9Sstevel@tonic-gate  * Input:
572*7c478bd9Sstevel@tonic-gate  *  gl       GetLine *  The gl_get_line() resource object. You can use
573*7c478bd9Sstevel@tonic-gate  *                      this safely to call gl_watch_fd() or
574*7c478bd9Sstevel@tonic-gate  *                      gl_inactivity_timeout(). The effect of calling other
575*7c478bd9Sstevel@tonic-gate  *                      functions that take a gl argument is undefined,
576*7c478bd9Sstevel@tonic-gate  *                      and must be avoided.
577*7c478bd9Sstevel@tonic-gate  *  data        void *  A pointer to arbitrary callback data, as originally
578*7c478bd9Sstevel@tonic-gate  *                      registered with gl_watch_fd().
579*7c478bd9Sstevel@tonic-gate  *  fd           int    The file descriptor that has activity.
580*7c478bd9Sstevel@tonic-gate  *  event  GlFdEvent    The activity seen on the file descriptor. The
581*7c478bd9Sstevel@tonic-gate  *                      inclusion of this argument allows the same
582*7c478bd9Sstevel@tonic-gate  *                      callback to be registered for multiple events.
583*7c478bd9Sstevel@tonic-gate  * Output:
584*7c478bd9Sstevel@tonic-gate  *  return GlFdStatus   GLFD_ABORT    - Cause gl_get_line() to abort with
585*7c478bd9Sstevel@tonic-gate  *                                      an error (set errno if you need it).
586*7c478bd9Sstevel@tonic-gate  *                      GLFD_REFRESH  - Redraw the input line and continue
587*7c478bd9Sstevel@tonic-gate  *                                      waiting for input. Use this if you
588*7c478bd9Sstevel@tonic-gate  *                                      wrote something to the terminal.
589*7c478bd9Sstevel@tonic-gate  *                      GLFD_CONTINUE - Continue to wait for input, without
590*7c478bd9Sstevel@tonic-gate  *                                      redrawing the line.
591*7c478bd9Sstevel@tonic-gate  */
592*7c478bd9Sstevel@tonic-gate #define GL_FD_EVENT_FN(fn) GlFdStatus (fn)(GetLine *gl, void *data, int fd, \
593*7c478bd9Sstevel@tonic-gate 					   GlFdEvent event)
594*7c478bd9Sstevel@tonic-gate typedef GL_FD_EVENT_FN(GlFdEventFn);
595*7c478bd9Sstevel@tonic-gate 
596*7c478bd9Sstevel@tonic-gate /*.......................................................................
597*7c478bd9Sstevel@tonic-gate  * Where possible, register a function and associated data to be called
598*7c478bd9Sstevel@tonic-gate  * whenever a specified event is seen on a file descriptor.
599*7c478bd9Sstevel@tonic-gate  *
600*7c478bd9Sstevel@tonic-gate  * Input:
601*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
602*7c478bd9Sstevel@tonic-gate  *                           module.
603*7c478bd9Sstevel@tonic-gate  *  fd                int    The file descriptor to watch.
604*7c478bd9Sstevel@tonic-gate  *  event       GlFdEvent    The type of activity to watch for.
605*7c478bd9Sstevel@tonic-gate  *  callback  GlFdEventFn *  The function to call when the specified
606*7c478bd9Sstevel@tonic-gate  *                           event occurs. Setting this to 0 removes
607*7c478bd9Sstevel@tonic-gate  *                           any existing callback.
608*7c478bd9Sstevel@tonic-gate  *  data             void *  A pointer to arbitrary data to pass to the
609*7c478bd9Sstevel@tonic-gate  *                           callback function.
610*7c478bd9Sstevel@tonic-gate  * Output:
611*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
612*7c478bd9Sstevel@tonic-gate  *                           1 - Either gl==NULL, or this facility isn't
613*7c478bd9Sstevel@tonic-gate  *                               available on the the host system
614*7c478bd9Sstevel@tonic-gate  *                               (ie. select() isn't available). No
615*7c478bd9Sstevel@tonic-gate  *                               error message is generated in the latter
616*7c478bd9Sstevel@tonic-gate  *                               case.
617*7c478bd9Sstevel@tonic-gate  */
618*7c478bd9Sstevel@tonic-gate int gl_watch_fd(GetLine *gl, int fd, GlFdEvent event,
619*7c478bd9Sstevel@tonic-gate 		GlFdEventFn *callback, void *data);
620*7c478bd9Sstevel@tonic-gate 
621*7c478bd9Sstevel@tonic-gate /*
622*7c478bd9Sstevel@tonic-gate  * Enumerators from the following list are returned by activity
623*7c478bd9Sstevel@tonic-gate  * timeout callbacks registered by gl_inactivity_timeout(). They tell
624*7c478bd9Sstevel@tonic-gate  * gl_get_line() whether and how to procede.
625*7c478bd9Sstevel@tonic-gate  */
626*7c478bd9Sstevel@tonic-gate typedef enum {
627*7c478bd9Sstevel@tonic-gate   GLTO_ABORT,    /* Cause gl_get_line() to abort with an error */
628*7c478bd9Sstevel@tonic-gate   GLTO_REFRESH,  /* Redraw the input line and continue waiting for input */
629*7c478bd9Sstevel@tonic-gate   GLTO_CONTINUE  /* Continue to wait for input, without redrawing the line */
630*7c478bd9Sstevel@tonic-gate } GlAfterTimeout;
631*7c478bd9Sstevel@tonic-gate 
632*7c478bd9Sstevel@tonic-gate /*.......................................................................
633*7c478bd9Sstevel@tonic-gate  * On systems that have the select() system call, the application has
634*7c478bd9Sstevel@tonic-gate  * the option of providing a callback function of the following type,
635*7c478bd9Sstevel@tonic-gate  * which is called whenever no terminal input or other I/O activity is
636*7c478bd9Sstevel@tonic-gate  * seen for the timeout duration specified in the last call to
637*7c478bd9Sstevel@tonic-gate  * gl_inactivity_timeout().
638*7c478bd9Sstevel@tonic-gate  *
639*7c478bd9Sstevel@tonic-gate  * Input:
640*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The gl_get_line() resource object. You can use
641*7c478bd9Sstevel@tonic-gate  *                           this safely to call gl_watch_fd() or
642*7c478bd9Sstevel@tonic-gate  *                           gl_inactivity_timeout(). The effect of calling other
643*7c478bd9Sstevel@tonic-gate  *                           functions that take a gl argument is undefined,
644*7c478bd9Sstevel@tonic-gate  *                           and must be avoided.
645*7c478bd9Sstevel@tonic-gate  *  data             void *  A pointer to arbitrary callback data, as
646*7c478bd9Sstevel@tonic-gate  *                           originally registered with gl_inactivity_timeout().
647*7c478bd9Sstevel@tonic-gate  * Output:
648*7c478bd9Sstevel@tonic-gate  *  return GlAfterTimeout    GLTO_ABORT    - Cause gl_get_line() to
649*7c478bd9Sstevel@tonic-gate  *                                           abort with an error (set
650*7c478bd9Sstevel@tonic-gate  *                                           errno if you need it).
651*7c478bd9Sstevel@tonic-gate  *                           GLTO_REFRESH  - Redraw the input line and
652*7c478bd9Sstevel@tonic-gate  *                                           continue waiting for
653*7c478bd9Sstevel@tonic-gate  *                                           input. Use this if you
654*7c478bd9Sstevel@tonic-gate  *                                           wrote something to the
655*7c478bd9Sstevel@tonic-gate  *                                           terminal.
656*7c478bd9Sstevel@tonic-gate  *                           GLTO_CONTINUE - Continue to wait for
657*7c478bd9Sstevel@tonic-gate  *                                           input, without redrawing
658*7c478bd9Sstevel@tonic-gate  *                                           the line.
659*7c478bd9Sstevel@tonic-gate  */
660*7c478bd9Sstevel@tonic-gate #define GL_TIMEOUT_FN(fn) GlAfterTimeout (fn)(GetLine *gl, void *data)
661*7c478bd9Sstevel@tonic-gate typedef GL_TIMEOUT_FN(GlTimeoutFn);
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate /*.......................................................................
664*7c478bd9Sstevel@tonic-gate  * On systems with the select() system call, the gl_inactivity_timeout()
665*7c478bd9Sstevel@tonic-gate  * function provides the option of setting (or cancelling) an
666*7c478bd9Sstevel@tonic-gate  * inactivity timeout. Inactivity, in this case, refers both to
667*7c478bd9Sstevel@tonic-gate  * terminal input received from the user, and to I/O on any file
668*7c478bd9Sstevel@tonic-gate  * descriptors registered by calls to gl_watch_fd(). If at any time,
669*7c478bd9Sstevel@tonic-gate  * no activity is seen for the requested time period, the specified
670*7c478bd9Sstevel@tonic-gate  * timeout callback function is called. On returning, this callback
671*7c478bd9Sstevel@tonic-gate  * returns a code which tells gl_get_line() what to do next. Note that
672*7c478bd9Sstevel@tonic-gate  * each call to gl_inactivity_timeout() replaces any previously installed
673*7c478bd9Sstevel@tonic-gate  * timeout callback, and that specifying a callback of 0, turns off
674*7c478bd9Sstevel@tonic-gate  * inactivity timing.
675*7c478bd9Sstevel@tonic-gate  *
676*7c478bd9Sstevel@tonic-gate  * Beware that although the timeout argument includes a nano-second
677*7c478bd9Sstevel@tonic-gate  * component, few computer clocks presently have resolutions finer
678*7c478bd9Sstevel@tonic-gate  * than a few milliseconds, so asking for less than a few milliseconds
679*7c478bd9Sstevel@tonic-gate  * is equivalent to zero on a lot of systems.
680*7c478bd9Sstevel@tonic-gate  *
681*7c478bd9Sstevel@tonic-gate  * Input:
682*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
683*7c478bd9Sstevel@tonic-gate  *                           module.
684*7c478bd9Sstevel@tonic-gate  *  callback  GlTimeoutFn *  The function to call when the inactivity
685*7c478bd9Sstevel@tonic-gate  *                           timeout is exceeded. To turn off
686*7c478bd9Sstevel@tonic-gate  *                           inactivity timeouts altogether, send 0.
687*7c478bd9Sstevel@tonic-gate  *  data             void *  A pointer to arbitrary data to pass to the
688*7c478bd9Sstevel@tonic-gate  *                           callback function.
689*7c478bd9Sstevel@tonic-gate  *  sec     unsigned long    The number of whole seconds in the timeout.
690*7c478bd9Sstevel@tonic-gate  *  nsec    unsigned long    The fractional number of seconds in the
691*7c478bd9Sstevel@tonic-gate  *                           timeout, expressed in nano-seconds (see
692*7c478bd9Sstevel@tonic-gate  *                           the caveat above).
693*7c478bd9Sstevel@tonic-gate  * Output:
694*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
695*7c478bd9Sstevel@tonic-gate  *                           1 - Either gl==NULL, or this facility isn't
696*7c478bd9Sstevel@tonic-gate  *                               available on the the host system
697*7c478bd9Sstevel@tonic-gate  *                               (ie. select() isn't available). No
698*7c478bd9Sstevel@tonic-gate  *                               error message is generated in the latter
699*7c478bd9Sstevel@tonic-gate  *                               case.
700*7c478bd9Sstevel@tonic-gate  */
701*7c478bd9Sstevel@tonic-gate int gl_inactivity_timeout(GetLine *gl, GlTimeoutFn *timeout_fn, void *data,
702*7c478bd9Sstevel@tonic-gate 		   unsigned long sec, unsigned long nsec);
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate /*.......................................................................
705*7c478bd9Sstevel@tonic-gate  * Switch history streams. History streams represent separate history
706*7c478bd9Sstevel@tonic-gate  * lists recorded within a single history buffer. Different streams
707*7c478bd9Sstevel@tonic-gate  * are distinguished by integer identifiers chosen by the calling
708*7c478bd9Sstevel@tonic-gate  * appplicaton. Initially new_GetLine() sets the stream identifier to
709*7c478bd9Sstevel@tonic-gate  * 0. Whenever a new line is appended to the history list, the current
710*7c478bd9Sstevel@tonic-gate  * stream identifier is recorded with it, and history lookups only
711*7c478bd9Sstevel@tonic-gate  * consider lines marked with the current stream identifier.
712*7c478bd9Sstevel@tonic-gate  *
713*7c478bd9Sstevel@tonic-gate  * Input:
714*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The resource object of gl_get_line().
715*7c478bd9Sstevel@tonic-gate  *  id     unsigned    The new history stream identifier.
716*7c478bd9Sstevel@tonic-gate  * Output:
717*7c478bd9Sstevel@tonic-gate  *  return      int    0 - OK.
718*7c478bd9Sstevel@tonic-gate  *                     1 - Error.
719*7c478bd9Sstevel@tonic-gate  */
720*7c478bd9Sstevel@tonic-gate int gl_group_history(GetLine *gl, unsigned id);
721*7c478bd9Sstevel@tonic-gate 
722*7c478bd9Sstevel@tonic-gate /*.......................................................................
723*7c478bd9Sstevel@tonic-gate  * Display the contents of the history list.
724*7c478bd9Sstevel@tonic-gate  *
725*7c478bd9Sstevel@tonic-gate  * Input:
726*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The resource object of gl_get_line().
727*7c478bd9Sstevel@tonic-gate  *  fp         FILE *  The stdio output stream to write to.
728*7c478bd9Sstevel@tonic-gate  *  fmt  const char *  A format string. This containing characters to be
729*7c478bd9Sstevel@tonic-gate  *                     written verbatim, plus any of the following
730*7c478bd9Sstevel@tonic-gate  *                     format directives:
731*7c478bd9Sstevel@tonic-gate  *                       %D  -  The date, formatted like 2001-11-20
732*7c478bd9Sstevel@tonic-gate  *                       %T  -  The time of day, formatted like 23:59:59
733*7c478bd9Sstevel@tonic-gate  *                       %N  -  The sequential entry number of the
734*7c478bd9Sstevel@tonic-gate  *                              line in the history buffer.
735*7c478bd9Sstevel@tonic-gate  *                       %G  -  The number of the history group that
736*7c478bd9Sstevel@tonic-gate  *                              the line belongs to.
737*7c478bd9Sstevel@tonic-gate  *                       %%  -  A literal % character.
738*7c478bd9Sstevel@tonic-gate  *                       %H  -  The history line itself.
739*7c478bd9Sstevel@tonic-gate  *                     Note that a '\n' newline character is not
740*7c478bd9Sstevel@tonic-gate  *                     appended by default.
741*7c478bd9Sstevel@tonic-gate  *  all_groups  int    If true, display history lines from all
742*7c478bd9Sstevel@tonic-gate  *                     history groups. Otherwise only display
743*7c478bd9Sstevel@tonic-gate  *                     those of the current history group.
744*7c478bd9Sstevel@tonic-gate  *  max_lines   int    If max_lines is < 0, all available lines
745*7c478bd9Sstevel@tonic-gate  *                     are displayed. Otherwise only the most
746*7c478bd9Sstevel@tonic-gate  *                     recent max_lines lines will be displayed.
747*7c478bd9Sstevel@tonic-gate  * Output:
748*7c478bd9Sstevel@tonic-gate  *  return      int    0 - OK.
749*7c478bd9Sstevel@tonic-gate  *                     1 - Error.
750*7c478bd9Sstevel@tonic-gate  */
751*7c478bd9Sstevel@tonic-gate int gl_show_history(GetLine *gl, FILE *fp, const char *fmt, int all_groups,
752*7c478bd9Sstevel@tonic-gate 		    int max_lines);
753*7c478bd9Sstevel@tonic-gate 
754*7c478bd9Sstevel@tonic-gate /*.......................................................................
755*7c478bd9Sstevel@tonic-gate  * Resize or delete the history buffer.
756*7c478bd9Sstevel@tonic-gate  *
757*7c478bd9Sstevel@tonic-gate  * Input:
758*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The resource object of gl_get_line().
759*7c478bd9Sstevel@tonic-gate  *  bufsize  size_t    The number of bytes in the history buffer, or 0
760*7c478bd9Sstevel@tonic-gate  *                     to delete the buffer completely.
761*7c478bd9Sstevel@tonic-gate  * Output:
762*7c478bd9Sstevel@tonic-gate  *  return      int    0 - OK.
763*7c478bd9Sstevel@tonic-gate  *                     1 - Insufficient memory (the previous buffer
764*7c478bd9Sstevel@tonic-gate  *                         will have been retained). No error message
765*7c478bd9Sstevel@tonic-gate  *                         will be displayed.
766*7c478bd9Sstevel@tonic-gate  */
767*7c478bd9Sstevel@tonic-gate int gl_resize_history(GetLine *gl, size_t bufsize);
768*7c478bd9Sstevel@tonic-gate 
769*7c478bd9Sstevel@tonic-gate /*.......................................................................
770*7c478bd9Sstevel@tonic-gate  * Set an upper limit to the number of lines that can be recorded in the
771*7c478bd9Sstevel@tonic-gate  * history list, or remove a previously specified limit.
772*7c478bd9Sstevel@tonic-gate  *
773*7c478bd9Sstevel@tonic-gate  * Input:
774*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The resource object of gl_get_line().
775*7c478bd9Sstevel@tonic-gate  *  max_lines   int    The maximum number of lines to allow, or -1 to
776*7c478bd9Sstevel@tonic-gate  *                     cancel a previous limit and allow as many lines
777*7c478bd9Sstevel@tonic-gate  *                     as will fit in the current history buffer size.
778*7c478bd9Sstevel@tonic-gate  */
779*7c478bd9Sstevel@tonic-gate void gl_limit_history(GetLine *gl, int max_lines);
780*7c478bd9Sstevel@tonic-gate 
781*7c478bd9Sstevel@tonic-gate /*.......................................................................
782*7c478bd9Sstevel@tonic-gate  * Discard either all historical lines, or just those associated with the
783*7c478bd9Sstevel@tonic-gate  * current history group.
784*7c478bd9Sstevel@tonic-gate  *
785*7c478bd9Sstevel@tonic-gate  * Input:
786*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The resource object of gl_get_line().
787*7c478bd9Sstevel@tonic-gate  *  all_groups  int    If true, clear all of the history. If false,
788*7c478bd9Sstevel@tonic-gate  *                     clear only the stored lines associated with the
789*7c478bd9Sstevel@tonic-gate  *                     currently selected history group.
790*7c478bd9Sstevel@tonic-gate  */
791*7c478bd9Sstevel@tonic-gate void gl_clear_history(GetLine *gl, int all_groups);
792*7c478bd9Sstevel@tonic-gate 
793*7c478bd9Sstevel@tonic-gate /*.......................................................................
794*7c478bd9Sstevel@tonic-gate  * Temporarily enable or disable the gl_get_line() history mechanism.
795*7c478bd9Sstevel@tonic-gate  *
796*7c478bd9Sstevel@tonic-gate  * Input:
797*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The resource object of gl_get_line().
798*7c478bd9Sstevel@tonic-gate  *  enable      int    If true, turn on the history mechanism. If
799*7c478bd9Sstevel@tonic-gate  *                     false, disable it.
800*7c478bd9Sstevel@tonic-gate  */
801*7c478bd9Sstevel@tonic-gate void gl_toggle_history(GetLine *gl, int enable);
802*7c478bd9Sstevel@tonic-gate 
803*7c478bd9Sstevel@tonic-gate /*
804*7c478bd9Sstevel@tonic-gate  * Objects of the following type are returned by gl_terminal_size().
805*7c478bd9Sstevel@tonic-gate  */
806*7c478bd9Sstevel@tonic-gate typedef struct {
807*7c478bd9Sstevel@tonic-gate   int nline;        /* The terminal has nline lines */
808*7c478bd9Sstevel@tonic-gate   int ncolumn;      /* The terminal has ncolumn columns */
809*7c478bd9Sstevel@tonic-gate } GlTerminalSize;
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate /*.......................................................................
812*7c478bd9Sstevel@tonic-gate  * Update if necessary, and return the current size of the terminal.
813*7c478bd9Sstevel@tonic-gate  *
814*7c478bd9Sstevel@tonic-gate  * Input:
815*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of gl_get_line().
816*7c478bd9Sstevel@tonic-gate  *  def_ncolumn       int    If the number of columns in the terminal
817*7c478bd9Sstevel@tonic-gate  *                           can't be determined, substitute this number.
818*7c478bd9Sstevel@tonic-gate  *  def_nline         int    If the number of lines in the terminal can't
819*7c478bd9Sstevel@tonic-gate  *                           be determined, substitute this number.
820*7c478bd9Sstevel@tonic-gate  * Output:
821*7c478bd9Sstevel@tonic-gate  *  return GlTerminalSize    The current terminal size.
822*7c478bd9Sstevel@tonic-gate  */
823*7c478bd9Sstevel@tonic-gate GlTerminalSize gl_terminal_size(GetLine *gl, int def_ncolumn, int def_nline);
824*7c478bd9Sstevel@tonic-gate 
825*7c478bd9Sstevel@tonic-gate /*.......................................................................
826*7c478bd9Sstevel@tonic-gate  * Tell gl_get_line() the current terminal size. Note that this is only
827*7c478bd9Sstevel@tonic-gate  * necessary on systems where changes in terminal size aren't reported
828*7c478bd9Sstevel@tonic-gate  * via SIGWINCH.
829*7c478bd9Sstevel@tonic-gate  *
830*7c478bd9Sstevel@tonic-gate  * Input:
831*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of gl_get_line().
832*7c478bd9Sstevel@tonic-gate  *  ncolumn           int    The number of columns in the terminal.
833*7c478bd9Sstevel@tonic-gate  *  nline             int    The number of rows in the terminal.
834*7c478bd9Sstevel@tonic-gate  * Output:
835*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
836*7c478bd9Sstevel@tonic-gate  *                           1 - Error.
837*7c478bd9Sstevel@tonic-gate  */
838*7c478bd9Sstevel@tonic-gate int gl_set_term_size(GetLine *gl, int ncolumn, int nline);
839*7c478bd9Sstevel@tonic-gate 
840*7c478bd9Sstevel@tonic-gate /*
841*7c478bd9Sstevel@tonic-gate  * The gl_lookup_history() function returns information in an
842*7c478bd9Sstevel@tonic-gate  * argument of the following type.
843*7c478bd9Sstevel@tonic-gate  */
844*7c478bd9Sstevel@tonic-gate typedef struct {
845*7c478bd9Sstevel@tonic-gate   const char *line;    /* The requested history line */
846*7c478bd9Sstevel@tonic-gate   unsigned group;      /* The history group to which the */
847*7c478bd9Sstevel@tonic-gate                        /*  line belongs. */
848*7c478bd9Sstevel@tonic-gate   time_t timestamp;    /* The date and time at which the */
849*7c478bd9Sstevel@tonic-gate                        /*  line was originally entered. */
850*7c478bd9Sstevel@tonic-gate } GlHistoryLine;
851*7c478bd9Sstevel@tonic-gate 
852*7c478bd9Sstevel@tonic-gate /*.......................................................................
853*7c478bd9Sstevel@tonic-gate  * Lookup a history line by its sequential number of entry in the
854*7c478bd9Sstevel@tonic-gate  * history buffer.
855*7c478bd9Sstevel@tonic-gate  *
856*7c478bd9Sstevel@tonic-gate  * Input:
857*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of gl_get_line().
858*7c478bd9Sstevel@tonic-gate  *  id      unsigned long    The identification number of the line to
859*7c478bd9Sstevel@tonic-gate  *                           be returned, where 0 denotes the first line
860*7c478bd9Sstevel@tonic-gate  *                           that was entered in the history list, and
861*7c478bd9Sstevel@tonic-gate  *                           each subsequently added line has a number
862*7c478bd9Sstevel@tonic-gate  *                           one greater than the previous one. For
863*7c478bd9Sstevel@tonic-gate  *                           the range of lines currently in the list,
864*7c478bd9Sstevel@tonic-gate  *                           see the gl_range_of_history() function.
865*7c478bd9Sstevel@tonic-gate  * Input/Output:
866*7c478bd9Sstevel@tonic-gate  *  line    GlHistoryLine *  A pointer to the variable in which to
867*7c478bd9Sstevel@tonic-gate  *                           return the details of the line.
868*7c478bd9Sstevel@tonic-gate  * Output:
869*7c478bd9Sstevel@tonic-gate  *  return            int    0 - The line is no longer in the history
870*7c478bd9Sstevel@tonic-gate  *                               list, and *line has not been changed.
871*7c478bd9Sstevel@tonic-gate  *                           1 - The requested line can be found in
872*7c478bd9Sstevel@tonic-gate  *                               *line. Note that the string in
873*7c478bd9Sstevel@tonic-gate  *                               line->line is part of the history
874*7c478bd9Sstevel@tonic-gate  *                               buffer and will change, so a private
875*7c478bd9Sstevel@tonic-gate  *                               copy should be made if you wish to
876*7c478bd9Sstevel@tonic-gate  *                               use it after subsequent calls to any
877*7c478bd9Sstevel@tonic-gate  *                               functions that take gl as an argument.
878*7c478bd9Sstevel@tonic-gate  */
879*7c478bd9Sstevel@tonic-gate int gl_lookup_history(GetLine *gl, unsigned long id, GlHistoryLine *line);
880*7c478bd9Sstevel@tonic-gate 
881*7c478bd9Sstevel@tonic-gate /*
882*7c478bd9Sstevel@tonic-gate  * The gl_state_of_history() function returns information in an argument
883*7c478bd9Sstevel@tonic-gate  * of the following type.
884*7c478bd9Sstevel@tonic-gate  */
885*7c478bd9Sstevel@tonic-gate typedef struct {
886*7c478bd9Sstevel@tonic-gate   int enabled;     /* True if history is enabled */
887*7c478bd9Sstevel@tonic-gate   unsigned group;  /* The current history group */
888*7c478bd9Sstevel@tonic-gate   int max_lines;   /* The current upper limit on the number of lines */
889*7c478bd9Sstevel@tonic-gate                    /*  in the history list, or -1 if unlimited. */
890*7c478bd9Sstevel@tonic-gate } GlHistoryState;
891*7c478bd9Sstevel@tonic-gate 
892*7c478bd9Sstevel@tonic-gate /*.......................................................................
893*7c478bd9Sstevel@tonic-gate  * Query the state of the history list. Note that any of the input/output
894*7c478bd9Sstevel@tonic-gate  * pointers can be specified as NULL.
895*7c478bd9Sstevel@tonic-gate  *
896*7c478bd9Sstevel@tonic-gate  * Input:
897*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of gl_get_line().
898*7c478bd9Sstevel@tonic-gate  * Input/Output:
899*7c478bd9Sstevel@tonic-gate  *  state  GlHistoryState *  A pointer to the variable in which to record
900*7c478bd9Sstevel@tonic-gate  *                           the return values.
901*7c478bd9Sstevel@tonic-gate  */
902*7c478bd9Sstevel@tonic-gate void gl_state_of_history(GetLine *gl, GlHistoryState *state);
903*7c478bd9Sstevel@tonic-gate 
904*7c478bd9Sstevel@tonic-gate /*
905*7c478bd9Sstevel@tonic-gate  * The gl_range_of_history() function returns information in an argument
906*7c478bd9Sstevel@tonic-gate  * of the following type.
907*7c478bd9Sstevel@tonic-gate  */
908*7c478bd9Sstevel@tonic-gate typedef struct {
909*7c478bd9Sstevel@tonic-gate   unsigned long oldest;  /* The sequential entry number of the oldest */
910*7c478bd9Sstevel@tonic-gate                          /*  line in the history list. */
911*7c478bd9Sstevel@tonic-gate   unsigned long newest;  /* The sequential entry number of the newest */
912*7c478bd9Sstevel@tonic-gate                          /*  line in the history list. */
913*7c478bd9Sstevel@tonic-gate   int nlines;            /* The number of lines in the history list */
914*7c478bd9Sstevel@tonic-gate } GlHistoryRange;
915*7c478bd9Sstevel@tonic-gate 
916*7c478bd9Sstevel@tonic-gate /*.......................................................................
917*7c478bd9Sstevel@tonic-gate  * Query the number and range of lines in the history buffer.
918*7c478bd9Sstevel@tonic-gate  *
919*7c478bd9Sstevel@tonic-gate  * Input:
920*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of gl_get_line().
921*7c478bd9Sstevel@tonic-gate  *  range  GlHistoryRange *  A pointer to the variable in which to record
922*7c478bd9Sstevel@tonic-gate  *                           the return values. If range->nline=0, the
923*7c478bd9Sstevel@tonic-gate  *                           range of lines will be given as 0-0.
924*7c478bd9Sstevel@tonic-gate  */
925*7c478bd9Sstevel@tonic-gate void gl_range_of_history(GetLine *gl, GlHistoryRange *range);
926*7c478bd9Sstevel@tonic-gate 
927*7c478bd9Sstevel@tonic-gate /*
928*7c478bd9Sstevel@tonic-gate  * The gl_size_of_history() function returns information in an argument
929*7c478bd9Sstevel@tonic-gate  * of the following type.
930*7c478bd9Sstevel@tonic-gate  */
931*7c478bd9Sstevel@tonic-gate typedef struct {
932*7c478bd9Sstevel@tonic-gate   size_t size;      /* The size of the history buffer (bytes) */
933*7c478bd9Sstevel@tonic-gate   size_t used;      /* The number of bytes of the history buffer */
934*7c478bd9Sstevel@tonic-gate                     /*  that are currently occupied. */
935*7c478bd9Sstevel@tonic-gate } GlHistorySize;
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate /*.......................................................................
938*7c478bd9Sstevel@tonic-gate  * Return the size of the history buffer and the amount of the
939*7c478bd9Sstevel@tonic-gate  * buffer that is currently in use.
940*7c478bd9Sstevel@tonic-gate  *
941*7c478bd9Sstevel@tonic-gate  * Input:
942*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *  The resource object of gl_get_line().
943*7c478bd9Sstevel@tonic-gate  * Input/Output:
944*7c478bd9Sstevel@tonic-gate  *  GlHistorySize size *  A pointer to the variable in which to return
945*7c478bd9Sstevel@tonic-gate  *                        the results.
946*7c478bd9Sstevel@tonic-gate  */
947*7c478bd9Sstevel@tonic-gate void gl_size_of_history(GetLine *gl, GlHistorySize *size);
948*7c478bd9Sstevel@tonic-gate 
949*7c478bd9Sstevel@tonic-gate /*.......................................................................
950*7c478bd9Sstevel@tonic-gate  * Enable or disable the automatic addition of newly entered lines to the
951*7c478bd9Sstevel@tonic-gate  * history list.
952*7c478bd9Sstevel@tonic-gate  *
953*7c478bd9Sstevel@tonic-gate  * Input:
954*7c478bd9Sstevel@tonic-gate  *  gl          GetLine *   The resource object of gl_get_line().
955*7c478bd9Sstevel@tonic-gate  *  enable          int     If true, subsequently entered lines will
956*7c478bd9Sstevel@tonic-gate  *                          automatically be added to the history list
957*7c478bd9Sstevel@tonic-gate  *                          before they are returned to the caller of
958*7c478bd9Sstevel@tonic-gate  *                          gl_get_line(). If 0, the choice of how and
959*7c478bd9Sstevel@tonic-gate  *                          when to archive lines in the history list,
960*7c478bd9Sstevel@tonic-gate  *                          is left up to the calling application, which
961*7c478bd9Sstevel@tonic-gate  *                          can do so via calls to gl_append_history().
962*7c478bd9Sstevel@tonic-gate  * Output:
963*7c478bd9Sstevel@tonic-gate  *  return          int     0 - OK.
964*7c478bd9Sstevel@tonic-gate  *                          1 - Error.
965*7c478bd9Sstevel@tonic-gate  */
966*7c478bd9Sstevel@tonic-gate int gl_automatic_history(GetLine *gl, int enable);
967*7c478bd9Sstevel@tonic-gate 
968*7c478bd9Sstevel@tonic-gate /*.......................................................................
969*7c478bd9Sstevel@tonic-gate  * Append a specified line to the history list.
970*7c478bd9Sstevel@tonic-gate  *
971*7c478bd9Sstevel@tonic-gate  * Input:
972*7c478bd9Sstevel@tonic-gate  *  gl          GetLine *   The resource object of gl_get_line().
973*7c478bd9Sstevel@tonic-gate  *  line     const char *   The line to be added.
974*7c478bd9Sstevel@tonic-gate  * Output:
975*7c478bd9Sstevel@tonic-gate  *  return          int     0 - OK.
976*7c478bd9Sstevel@tonic-gate  *                          1 - Error.
977*7c478bd9Sstevel@tonic-gate  */
978*7c478bd9Sstevel@tonic-gate int gl_append_history(GetLine *gl, const char *line);
979*7c478bd9Sstevel@tonic-gate 
980*7c478bd9Sstevel@tonic-gate /*.......................................................................
981*7c478bd9Sstevel@tonic-gate  * Specify whether text that users type should be displayed or hidden.
982*7c478bd9Sstevel@tonic-gate  * In the latter case, only the prompt is displayed, and the final
983*7c478bd9Sstevel@tonic-gate  * input line is not archived in the history list.
984*7c478bd9Sstevel@tonic-gate  *
985*7c478bd9Sstevel@tonic-gate  * Input:
986*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *  The input-line history maintenance object.
987*7c478bd9Sstevel@tonic-gate  *  enable         int     0 - Disable echoing.
988*7c478bd9Sstevel@tonic-gate  *                         1 - Enable echoing.
989*7c478bd9Sstevel@tonic-gate  *                        -1 - Just query the mode without changing it.
990*7c478bd9Sstevel@tonic-gate  * Output:
991*7c478bd9Sstevel@tonic-gate  *  return         int    The echoing disposition that was in effect
992*7c478bd9Sstevel@tonic-gate  *                        before this function was called:
993*7c478bd9Sstevel@tonic-gate  *                         0 - Echoing was disabled.
994*7c478bd9Sstevel@tonic-gate  *                         1 - Echoing was enabled.
995*7c478bd9Sstevel@tonic-gate  */
996*7c478bd9Sstevel@tonic-gate int gl_echo_mode(GetLine *gl, int enable);
997*7c478bd9Sstevel@tonic-gate 
998*7c478bd9Sstevel@tonic-gate /*.......................................................................
999*7c478bd9Sstevel@tonic-gate  * This function can be called from gl_get_line() callbacks to have
1000*7c478bd9Sstevel@tonic-gate  * the prompt changed when they return. It has no effect if gl_get_line()
1001*7c478bd9Sstevel@tonic-gate  * is not currently being invoked.
1002*7c478bd9Sstevel@tonic-gate  *
1003*7c478bd9Sstevel@tonic-gate  * Input:
1004*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *  The resource object of gl_get_line().
1005*7c478bd9Sstevel@tonic-gate  *  prompt  const char *  The new prompt.
1006*7c478bd9Sstevel@tonic-gate  */
1007*7c478bd9Sstevel@tonic-gate void gl_replace_prompt(GetLine *gl, const char *prompt);
1008*7c478bd9Sstevel@tonic-gate 
1009*7c478bd9Sstevel@tonic-gate /*
1010*7c478bd9Sstevel@tonic-gate  * Enumerate the available prompt formatting styles.
1011*7c478bd9Sstevel@tonic-gate  */
1012*7c478bd9Sstevel@tonic-gate typedef enum {
1013*7c478bd9Sstevel@tonic-gate   GL_LITERAL_PROMPT,   /* Display the prompt string literally */
1014*7c478bd9Sstevel@tonic-gate   GL_FORMAT_PROMPT     /* The prompt string can contain any of the */
1015*7c478bd9Sstevel@tonic-gate                        /* following formatting directives: */
1016*7c478bd9Sstevel@tonic-gate                        /*   %B  -  Display subsequent characters */
1017*7c478bd9Sstevel@tonic-gate                        /*          with a bold font. */
1018*7c478bd9Sstevel@tonic-gate                        /*   %b  -  Stop displaying characters */
1019*7c478bd9Sstevel@tonic-gate                        /*          with the bold font. */
1020*7c478bd9Sstevel@tonic-gate                        /*   %U  -  Underline subsequent characters. */
1021*7c478bd9Sstevel@tonic-gate                        /*   %u  -  Stop underlining characters. */
1022*7c478bd9Sstevel@tonic-gate                        /*   %S  -  Highlight subsequent characters */
1023*7c478bd9Sstevel@tonic-gate                        /*          (also known as standout mode). */
1024*7c478bd9Sstevel@tonic-gate                        /*   %s  -  Stop highlighting characters */
1025*7c478bd9Sstevel@tonic-gate                        /*   %%  -  Display a single % character. */
1026*7c478bd9Sstevel@tonic-gate } GlPromptStyle;
1027*7c478bd9Sstevel@tonic-gate 
1028*7c478bd9Sstevel@tonic-gate /*.......................................................................
1029*7c478bd9Sstevel@tonic-gate  * Specify whether to heed text attribute directives within prompt
1030*7c478bd9Sstevel@tonic-gate  * strings.
1031*7c478bd9Sstevel@tonic-gate  *
1032*7c478bd9Sstevel@tonic-gate  * Input:
1033*7c478bd9Sstevel@tonic-gate  *  gl           GetLine *  The resource object of gl_get_line().
1034*7c478bd9Sstevel@tonic-gate  *  style  GlPromptStyle    The style of prompt (see the definition of
1035*7c478bd9Sstevel@tonic-gate  *                          GlPromptStyle in libtecla.h for details).
1036*7c478bd9Sstevel@tonic-gate  */
1037*7c478bd9Sstevel@tonic-gate void gl_prompt_style(GetLine *gl, GlPromptStyle style);
1038*7c478bd9Sstevel@tonic-gate 
1039*7c478bd9Sstevel@tonic-gate /*.......................................................................
1040*7c478bd9Sstevel@tonic-gate  * Remove a signal from the list of signals that gl_get_line() traps.
1041*7c478bd9Sstevel@tonic-gate  *
1042*7c478bd9Sstevel@tonic-gate  * Input:
1043*7c478bd9Sstevel@tonic-gate  *  gl           GetLine *  The resource object of gl_get_line().
1044*7c478bd9Sstevel@tonic-gate  *  signo            int    The number of the signal to be ignored.
1045*7c478bd9Sstevel@tonic-gate  * Output:
1046*7c478bd9Sstevel@tonic-gate  *  return           int    0 - OK.
1047*7c478bd9Sstevel@tonic-gate  *                          1 - Error.
1048*7c478bd9Sstevel@tonic-gate  */
1049*7c478bd9Sstevel@tonic-gate int gl_ignore_signal(GetLine *gl, int signo);
1050*7c478bd9Sstevel@tonic-gate 
1051*7c478bd9Sstevel@tonic-gate /*
1052*7c478bd9Sstevel@tonic-gate  * A bitwise union of the following enumerators is passed to
1053*7c478bd9Sstevel@tonic-gate  * gl_trap_signal() to specify the environment in which the
1054*7c478bd9Sstevel@tonic-gate  * application's signal handler is to be called.
1055*7c478bd9Sstevel@tonic-gate  */
1056*7c478bd9Sstevel@tonic-gate typedef enum {
1057*7c478bd9Sstevel@tonic-gate   GLS_RESTORE_SIG=1,  /* Restore the caller's signal environment */
1058*7c478bd9Sstevel@tonic-gate                       /* while handling the signal. */
1059*7c478bd9Sstevel@tonic-gate   GLS_RESTORE_TTY=2,  /* Restore the caller's terminal settings */
1060*7c478bd9Sstevel@tonic-gate                       /* while handling the signal. */
1061*7c478bd9Sstevel@tonic-gate   GLS_RESTORE_LINE=4, /* Move the cursor to the start of the next line */
1062*7c478bd9Sstevel@tonic-gate   GLS_REDRAW_LINE=8,  /* Redraw the input line when the signal handler */
1063*7c478bd9Sstevel@tonic-gate                       /*  returns. */
1064*7c478bd9Sstevel@tonic-gate   GLS_UNBLOCK_SIG=16, /* Normally a signal who's delivery is found to */
1065*7c478bd9Sstevel@tonic-gate                       /*  be blocked by the calling application is not */
1066*7c478bd9Sstevel@tonic-gate                       /*  trapped by gl_get_line(). Including this flag */
1067*7c478bd9Sstevel@tonic-gate                       /*  causes it to be temporarily unblocked and */
1068*7c478bd9Sstevel@tonic-gate                       /*  trapped while gl_get_line() is executing. */
1069*7c478bd9Sstevel@tonic-gate   GLS_DONT_FORWARD=32,/* Don't forward the signal to the signal handler */
1070*7c478bd9Sstevel@tonic-gate                       /*  of the calling program. */
1071*7c478bd9Sstevel@tonic-gate   GLS_RESTORE_ENV = GLS_RESTORE_SIG | GLS_RESTORE_TTY | GLS_REDRAW_LINE,
1072*7c478bd9Sstevel@tonic-gate   GLS_SUSPEND_INPUT = GLS_RESTORE_ENV | GLS_RESTORE_LINE
1073*7c478bd9Sstevel@tonic-gate } GlSignalFlags;
1074*7c478bd9Sstevel@tonic-gate 
1075*7c478bd9Sstevel@tonic-gate /*
1076*7c478bd9Sstevel@tonic-gate  * The following enumerators are passed to gl_trap_signal() to tell
1077*7c478bd9Sstevel@tonic-gate  * it what to do after the application's signal handler has been called.
1078*7c478bd9Sstevel@tonic-gate  */
1079*7c478bd9Sstevel@tonic-gate typedef enum {
1080*7c478bd9Sstevel@tonic-gate   GLS_RETURN,      /* Return the line as though the user had pressed the */
1081*7c478bd9Sstevel@tonic-gate                    /*  return key. */
1082*7c478bd9Sstevel@tonic-gate   GLS_ABORT,       /* Cause gl_get_line() to return NULL */
1083*7c478bd9Sstevel@tonic-gate   GLS_CONTINUE     /* After handling the signal, resume command line editing */
1084*7c478bd9Sstevel@tonic-gate } GlAfterSignal;
1085*7c478bd9Sstevel@tonic-gate 
1086*7c478bd9Sstevel@tonic-gate /*.......................................................................
1087*7c478bd9Sstevel@tonic-gate  * Tell gl_get_line() how to respond to a given signal. This can be used
1088*7c478bd9Sstevel@tonic-gate  * both to override the default responses to signals that gl_get_line()
1089*7c478bd9Sstevel@tonic-gate  * normally catches and to add new signals to the list that are to be
1090*7c478bd9Sstevel@tonic-gate  * caught.
1091*7c478bd9Sstevel@tonic-gate  *
1092*7c478bd9Sstevel@tonic-gate  * Input:
1093*7c478bd9Sstevel@tonic-gate  *  gl           GetLine *  The resource object of gl_get_line().
1094*7c478bd9Sstevel@tonic-gate  *  signo            int    The number of the signal to be caught.
1095*7c478bd9Sstevel@tonic-gate  *  flags       unsigned    A bitwise union of GlSignalFlags enumerators.
1096*7c478bd9Sstevel@tonic-gate  *  after  GlAfterSignal    What to do after the application's signal
1097*7c478bd9Sstevel@tonic-gate  *                          handler has been called.
1098*7c478bd9Sstevel@tonic-gate  *  errno_value      int    The value to set errno to.
1099*7c478bd9Sstevel@tonic-gate  * Output:
1100*7c478bd9Sstevel@tonic-gate  *  return           int    0 - OK.
1101*7c478bd9Sstevel@tonic-gate  *                          1 - Insufficient memory to record the
1102*7c478bd9Sstevel@tonic-gate  *                              new signal disposition.
1103*7c478bd9Sstevel@tonic-gate  */
1104*7c478bd9Sstevel@tonic-gate int gl_trap_signal(GetLine *gl, int signo, unsigned flags,
1105*7c478bd9Sstevel@tonic-gate 		   GlAfterSignal after, int errno_value);
1106*7c478bd9Sstevel@tonic-gate 
1107*7c478bd9Sstevel@tonic-gate /*.......................................................................
1108*7c478bd9Sstevel@tonic-gate  * By default, gl_get_line() doesn't trap signals that are blocked
1109*7c478bd9Sstevel@tonic-gate  * when it is called. This default can be changed either on a
1110*7c478bd9Sstevel@tonic-gate  * per-signal basis by calling gl_trap_signal(), or on a global basis
1111*7c478bd9Sstevel@tonic-gate  * by calling this function. What this function does is add the
1112*7c478bd9Sstevel@tonic-gate  * GLS_UNBLOCK_SIG flag to all signals that are currently configured
1113*7c478bd9Sstevel@tonic-gate  * to be trapped by gl_get_line(), such that when subsequent calls to
1114*7c478bd9Sstevel@tonic-gate  * gl_get_line() wait for I/O, these signals are temporarily
1115*7c478bd9Sstevel@tonic-gate  * unblocked. This behavior is useful in non-blocking server-I/O mode,
1116*7c478bd9Sstevel@tonic-gate  * where it is used to avoid race conditions related to handling these
1117*7c478bd9Sstevel@tonic-gate  * signals externally to gl_get_line(). See the demonstration code in
1118*7c478bd9Sstevel@tonic-gate  * demo3.c, or the gl_handle_signal() man page for further
1119*7c478bd9Sstevel@tonic-gate  * information.
1120*7c478bd9Sstevel@tonic-gate  *
1121*7c478bd9Sstevel@tonic-gate  * Input:
1122*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *   The resource object of gl_get_line().
1123*7c478bd9Sstevel@tonic-gate  */
1124*7c478bd9Sstevel@tonic-gate void gl_catch_blocked(GetLine *gl);
1125*7c478bd9Sstevel@tonic-gate 
1126*7c478bd9Sstevel@tonic-gate /*.......................................................................
1127*7c478bd9Sstevel@tonic-gate  * In server-I/O mode the terminal is left in raw mode between calls
1128*7c478bd9Sstevel@tonic-gate  * to gl_get_line(), so it is necessary for the application to install
1129*7c478bd9Sstevel@tonic-gate  * terminal restoring signal handlers for signals that could terminate
1130*7c478bd9Sstevel@tonic-gate  * or suspend the process, plus a terminal reconfiguration handler to
1131*7c478bd9Sstevel@tonic-gate  * be called when a process resumption signal is received, and finally
1132*7c478bd9Sstevel@tonic-gate  * a handler to be called when a terminal-resize signal is received.
1133*7c478bd9Sstevel@tonic-gate  *
1134*7c478bd9Sstevel@tonic-gate  * Since there are many signals that by default terminate or suspend
1135*7c478bd9Sstevel@tonic-gate  * processes, and different systems support different sub-sets of
1136*7c478bd9Sstevel@tonic-gate  * these signals, this function provides a convenient wrapper around
1137*7c478bd9Sstevel@tonic-gate  * sigaction() for assigning the specified handlers to all appropriate
1138*7c478bd9Sstevel@tonic-gate  * signals. It also arranges that when any one of these signals is
1139*7c478bd9Sstevel@tonic-gate  * being handled, all other catchable signals are blocked. This is
1140*7c478bd9Sstevel@tonic-gate  * necessary so that the specified signal handlers can safely call
1141*7c478bd9Sstevel@tonic-gate  * gl_raw_io(), gl_normal_io() and gl_update_size() without reentrancy
1142*7c478bd9Sstevel@tonic-gate  * issues.
1143*7c478bd9Sstevel@tonic-gate  *
1144*7c478bd9Sstevel@tonic-gate  * Input:
1145*7c478bd9Sstevel@tonic-gate  *  term_handler  void (*)(int)  The signal handler to invoke when
1146*7c478bd9Sstevel@tonic-gate  *                               a process terminating signal is
1147*7c478bd9Sstevel@tonic-gate  *                               received.
1148*7c478bd9Sstevel@tonic-gate  *  susp_handler  void (*)(int)  The signal handler to invoke when
1149*7c478bd9Sstevel@tonic-gate  *                               a process suspending signal is
1150*7c478bd9Sstevel@tonic-gate  *                               received.
1151*7c478bd9Sstevel@tonic-gate  *  cont_handler  void (*)(int)  The signal handler to invoke when
1152*7c478bd9Sstevel@tonic-gate  *                               a process resumption signal is
1153*7c478bd9Sstevel@tonic-gate  *                               received (ie. SIGCONT).
1154*7c478bd9Sstevel@tonic-gate  *  size_handler  void (*)(int)  The signal handler to invoke when
1155*7c478bd9Sstevel@tonic-gate  *                               a terminal-resize signal (ie. SIGWINCH)
1156*7c478bd9Sstevel@tonic-gate  *                               is received.
1157*7c478bd9Sstevel@tonic-gate  * Output:
1158*7c478bd9Sstevel@tonic-gate  *  return                  int  0 - OK.
1159*7c478bd9Sstevel@tonic-gate  *                               1 - Error.
1160*7c478bd9Sstevel@tonic-gate  */
1161*7c478bd9Sstevel@tonic-gate int gl_tty_signals(void (*term_handler)(int), void (*susp_handler)(int),
1162*7c478bd9Sstevel@tonic-gate 		   void (*cont_handler)(int), void (*size_handler)(int));
1163*7c478bd9Sstevel@tonic-gate 
1164*7c478bd9Sstevel@tonic-gate /*.......................................................................
1165*7c478bd9Sstevel@tonic-gate  * Return the last signal that was caught by the most recent call to
1166*7c478bd9Sstevel@tonic-gate  * gl_get_line(), or -1 if no signals were caught. This is useful if
1167*7c478bd9Sstevel@tonic-gate  * gl_get_line() returns errno=EINTR and you need to find out what signal
1168*7c478bd9Sstevel@tonic-gate  * caused it to abort.
1169*7c478bd9Sstevel@tonic-gate  *
1170*7c478bd9Sstevel@tonic-gate  * Input:
1171*7c478bd9Sstevel@tonic-gate  *  gl           GetLine *  The resource object of gl_get_line().
1172*7c478bd9Sstevel@tonic-gate  * Output:
1173*7c478bd9Sstevel@tonic-gate  *  return           int    The last signal caught by the most recent
1174*7c478bd9Sstevel@tonic-gate  *                          call to gl_get_line(), or -1 if no signals
1175*7c478bd9Sstevel@tonic-gate  *                          were caught.
1176*7c478bd9Sstevel@tonic-gate  */
1177*7c478bd9Sstevel@tonic-gate int gl_last_signal(GetLine *gl);
1178*7c478bd9Sstevel@tonic-gate 
1179*7c478bd9Sstevel@tonic-gate /*.......................................................................
1180*7c478bd9Sstevel@tonic-gate  * Return the signal mask used by gl_get_line(). This is the set of
1181*7c478bd9Sstevel@tonic-gate  * signals that gl_get_line() is currently configured to trap.
1182*7c478bd9Sstevel@tonic-gate  *
1183*7c478bd9Sstevel@tonic-gate  * Input:
1184*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *  The resource object of gl_get_line().
1185*7c478bd9Sstevel@tonic-gate  * Input/Output:
1186*7c478bd9Sstevel@tonic-gate  *  set       sigset_t *  The set of signals will be returned in *set,
1187*7c478bd9Sstevel@tonic-gate  *                        in the form of a signal process mask, as
1188*7c478bd9Sstevel@tonic-gate  *                        used by sigaction(), sigprocmask(),
1189*7c478bd9Sstevel@tonic-gate  *                        sigpending(), sigsuspend(), sigsetjmp() and
1190*7c478bd9Sstevel@tonic-gate  *                        other standard POSIX signal-aware
1191*7c478bd9Sstevel@tonic-gate  *                        functions.
1192*7c478bd9Sstevel@tonic-gate  * Output:
1193*7c478bd9Sstevel@tonic-gate  *  return         int    0 - OK.
1194*7c478bd9Sstevel@tonic-gate  *                        1 - Error (examine errno for reason).
1195*7c478bd9Sstevel@tonic-gate  */
1196*7c478bd9Sstevel@tonic-gate int gl_list_signals(GetLine *gl, sigset_t *set);
1197*7c478bd9Sstevel@tonic-gate 
1198*7c478bd9Sstevel@tonic-gate /*.......................................................................
1199*7c478bd9Sstevel@tonic-gate  * Respond to signals who's default effects have important
1200*7c478bd9Sstevel@tonic-gate  * consequences to gl_get_line(). This is intended for use in
1201*7c478bd9Sstevel@tonic-gate  * non-blocking server mode, where the external event loop is
1202*7c478bd9Sstevel@tonic-gate  * responsible for catching signals. Signals that are handled include
1203*7c478bd9Sstevel@tonic-gate  * those that by default terminate or suspend the process, and the
1204*7c478bd9Sstevel@tonic-gate  * signal that indicates that the terminal size has changed. Note that
1205*7c478bd9Sstevel@tonic-gate  * this function is not signal safe and should thus not be called from
1206*7c478bd9Sstevel@tonic-gate  * a signal handler itself. See the gl_io_mode() man page for how it
1207*7c478bd9Sstevel@tonic-gate  * should be used.
1208*7c478bd9Sstevel@tonic-gate  *
1209*7c478bd9Sstevel@tonic-gate  * In the case of signals that by default terminate or suspend
1210*7c478bd9Sstevel@tonic-gate  * processes, command-line editing will be suspended, the terminal
1211*7c478bd9Sstevel@tonic-gate  * returned to a usable state, then the default disposition of the
1212*7c478bd9Sstevel@tonic-gate  * signal restored and the signal resent, in order to suspend or
1213*7c478bd9Sstevel@tonic-gate  * terminate the process.  If the process subsequently resumes,
1214*7c478bd9Sstevel@tonic-gate  * command-line editing is resumed.
1215*7c478bd9Sstevel@tonic-gate  *
1216*7c478bd9Sstevel@tonic-gate  * In the case of signals that indicate that the terminal has been
1217*7c478bd9Sstevel@tonic-gate  * resized, the new size will be queried, and any input line that is
1218*7c478bd9Sstevel@tonic-gate  * being edited will be redrawn to fit the new dimensions of the
1219*7c478bd9Sstevel@tonic-gate  * terminal.
1220*7c478bd9Sstevel@tonic-gate  *
1221*7c478bd9Sstevel@tonic-gate  * Input:
1222*7c478bd9Sstevel@tonic-gate  *  signo    int    The number of the signal to respond to.
1223*7c478bd9Sstevel@tonic-gate  *  gl   GetLine *  The first element of an array of 'ngl' GetLine
1224*7c478bd9Sstevel@tonic-gate  *                  objects.
1225*7c478bd9Sstevel@tonic-gate  *  ngl      int    The number of elements in the gl[] array. Normally
1226*7c478bd9Sstevel@tonic-gate  *                  this will be one.
1227*7c478bd9Sstevel@tonic-gate  */
1228*7c478bd9Sstevel@tonic-gate void gl_handle_signal(int signo, GetLine *gl, int ngl);
1229*7c478bd9Sstevel@tonic-gate 
1230*7c478bd9Sstevel@tonic-gate /*.......................................................................
1231*7c478bd9Sstevel@tonic-gate  * Return extra information (ie. in addition to that provided by errno)
1232*7c478bd9Sstevel@tonic-gate  * about the last error to occur in either gl_get_line() or its
1233*7c478bd9Sstevel@tonic-gate  * associated public functions.
1234*7c478bd9Sstevel@tonic-gate  *
1235*7c478bd9Sstevel@tonic-gate  * Input:
1236*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *  The resource object of gl_get_line().
1237*7c478bd9Sstevel@tonic-gate  * Input/Output:
1238*7c478bd9Sstevel@tonic-gate  *  buff          char *  An optional output buffer. Note that if the
1239*7c478bd9Sstevel@tonic-gate  *                        calling application calls any gl_*()
1240*7c478bd9Sstevel@tonic-gate  *                        functions from signal handlers, it should
1241*7c478bd9Sstevel@tonic-gate  *                        provide a buffer here, so that a copy of
1242*7c478bd9Sstevel@tonic-gate  *                        the latest error message can safely be made
1243*7c478bd9Sstevel@tonic-gate  *                        while signals are blocked.
1244*7c478bd9Sstevel@tonic-gate  *  n           size_t    The allocated size of buff[].
1245*7c478bd9Sstevel@tonic-gate  * Output:
1246*7c478bd9Sstevel@tonic-gate  *  return  const char *  A pointer to the error message. This will
1247*7c478bd9Sstevel@tonic-gate  *                        be the buff argument, unless buff==NULL, in
1248*7c478bd9Sstevel@tonic-gate  *                        which case it will be a pointer to an
1249*7c478bd9Sstevel@tonic-gate  *                        internal error buffer. In the latter case,
1250*7c478bd9Sstevel@tonic-gate  *                        note that the contents of the returned buffer
1251*7c478bd9Sstevel@tonic-gate  *                        will change on subsequent calls to any gl_*()
1252*7c478bd9Sstevel@tonic-gate  *                        functions.
1253*7c478bd9Sstevel@tonic-gate  */
1254*7c478bd9Sstevel@tonic-gate const char *gl_error_message(GetLine *gl, char *buff, size_t n);
1255*7c478bd9Sstevel@tonic-gate 
1256*7c478bd9Sstevel@tonic-gate /*.......................................................................
1257*7c478bd9Sstevel@tonic-gate  * Clear the terminal and leave the cursor at the home position.  In
1258*7c478bd9Sstevel@tonic-gate  * server I/O mode, arrange for the input line to be redrawn from scratch
1259*7c478bd9Sstevel@tonic-gate  * when gl_get_line() is next called.
1260*7c478bd9Sstevel@tonic-gate  *
1261*7c478bd9Sstevel@tonic-gate  * Input:
1262*7c478bd9Sstevel@tonic-gate  *  gl          GetLine *   The resource object of gl_get_line().
1263*7c478bd9Sstevel@tonic-gate  * Output:
1264*7c478bd9Sstevel@tonic-gate  *  return          int     0 - OK.
1265*7c478bd9Sstevel@tonic-gate  *                          1 - Error.
1266*7c478bd9Sstevel@tonic-gate  */
1267*7c478bd9Sstevel@tonic-gate int gl_erase_terminal(GetLine *gl);
1268*7c478bd9Sstevel@tonic-gate 
1269*7c478bd9Sstevel@tonic-gate /*.......................................................................
1270*7c478bd9Sstevel@tonic-gate  * Display a left-justified string over multiple terminal lines,
1271*7c478bd9Sstevel@tonic-gate  * taking account of the current width of the terminal. Optional
1272*7c478bd9Sstevel@tonic-gate  * indentation and an optional prefix string can be specified to be
1273*7c478bd9Sstevel@tonic-gate  * displayed at the start of each new terminal line used. Similarly,
1274*7c478bd9Sstevel@tonic-gate  * an optional suffix can be specified to be displayed at the end of
1275*7c478bd9Sstevel@tonic-gate  * each terminal line.  If needed, a single paragraph can be broken
1276*7c478bd9Sstevel@tonic-gate  * across multiple calls.  Note that literal newlines in the input
1277*7c478bd9Sstevel@tonic-gate  * string can be used to force a newline at any point and that you
1278*7c478bd9Sstevel@tonic-gate  * should use this feature to explicitly end all paragraphs, including
1279*7c478bd9Sstevel@tonic-gate  * at the end of the last string that you write. Note that when a new
1280*7c478bd9Sstevel@tonic-gate  * line is started between two words that are separated by spaces,
1281*7c478bd9Sstevel@tonic-gate  * those spaces are not output, whereas when a new line is started
1282*7c478bd9Sstevel@tonic-gate  * because a newline character was found in the string, only the
1283*7c478bd9Sstevel@tonic-gate  * spaces before the newline character are discarded.
1284*7c478bd9Sstevel@tonic-gate  *
1285*7c478bd9Sstevel@tonic-gate  * Input:
1286*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *  The resource object of gl_get_line().
1287*7c478bd9Sstevel@tonic-gate  *  indentation    int    The number of spaces of indentation to write
1288*7c478bd9Sstevel@tonic-gate  *                        at the beginning of each new terminal line.
1289*7c478bd9Sstevel@tonic-gate  *  prefix  const char *  An optional prefix string to write after the
1290*7c478bd9Sstevel@tonic-gate  *                        indentation margin at the start of each new
1291*7c478bd9Sstevel@tonic-gate  *                        terminal line. You can specify NULL if no
1292*7c478bd9Sstevel@tonic-gate  *                        prefix is required.
1293*7c478bd9Sstevel@tonic-gate  *  suffix  const char *  An optional suffix string to draw at the end
1294*7c478bd9Sstevel@tonic-gate  *                        of the terminal line. Spaces will be added
1295*7c478bd9Sstevel@tonic-gate  *                        where necessary to ensure that the suffix ends
1296*7c478bd9Sstevel@tonic-gate  *                        in the last column of the terminal line. If
1297*7c478bd9Sstevel@tonic-gate  *                        no suffix is desired, specify NULL.
1298*7c478bd9Sstevel@tonic-gate  *  fill_char      int    The padding character to use when indenting
1299*7c478bd9Sstevel@tonic-gate  *                        the line or padding up to the suffix.
1300*7c478bd9Sstevel@tonic-gate  *  def_width      int    If the terminal width isn't known, such as when
1301*7c478bd9Sstevel@tonic-gate  *                        writing to a pipe or redirecting to a file,
1302*7c478bd9Sstevel@tonic-gate  *                        this number specifies what width to assume.
1303*7c478bd9Sstevel@tonic-gate  *  start          int    The number of characters already written to
1304*7c478bd9Sstevel@tonic-gate  *                        the start of the current terminal line. This
1305*7c478bd9Sstevel@tonic-gate  *                        is primarily used to allow individual
1306*7c478bd9Sstevel@tonic-gate  *                        paragraphs to be written over multiple calls
1307*7c478bd9Sstevel@tonic-gate  *                        to this function, but can also be used to
1308*7c478bd9Sstevel@tonic-gate  *                        allow you to start the first line of a
1309*7c478bd9Sstevel@tonic-gate  *                        paragraph with a different prefix or
1310*7c478bd9Sstevel@tonic-gate  *                        indentation than those specified above.
1311*7c478bd9Sstevel@tonic-gate  *  string  const char *  The string to be written.
1312*7c478bd9Sstevel@tonic-gate  * Output:
1313*7c478bd9Sstevel@tonic-gate  *  return         int    On error -1 is returned. Otherwise the
1314*7c478bd9Sstevel@tonic-gate  *                        return value is the terminal column index at
1315*7c478bd9Sstevel@tonic-gate  *                        which the cursor was left after writing the
1316*7c478bd9Sstevel@tonic-gate  *                        final word in the string. Successful return
1317*7c478bd9Sstevel@tonic-gate  *                        values can thus be passed verbatim to the
1318*7c478bd9Sstevel@tonic-gate  *                        'start' arguments of subsequent calls to
1319*7c478bd9Sstevel@tonic-gate  *                        gl_display_text() to allow the printing of a
1320*7c478bd9Sstevel@tonic-gate  *                        paragraph to be broken across multiple calls
1321*7c478bd9Sstevel@tonic-gate  *                        to gl_display_text().
1322*7c478bd9Sstevel@tonic-gate  */
1323*7c478bd9Sstevel@tonic-gate int gl_display_text(GetLine *gl, int indentation, const char *prefix,
1324*7c478bd9Sstevel@tonic-gate 		    const char *suffix, int fill_char, int def_width,
1325*7c478bd9Sstevel@tonic-gate 		    int start, const char *string);
1326*7c478bd9Sstevel@tonic-gate 
1327*7c478bd9Sstevel@tonic-gate 
1328*7c478bd9Sstevel@tonic-gate /*
1329*7c478bd9Sstevel@tonic-gate  * Enumerate the I/O modes supported by gl_get_line().
1330*7c478bd9Sstevel@tonic-gate  */
1331*7c478bd9Sstevel@tonic-gate typedef enum {
1332*7c478bd9Sstevel@tonic-gate   GL_NORMAL_MODE,    /* Normal line-at-a-time mode using gl_get_line()'s */
1333*7c478bd9Sstevel@tonic-gate                      /*  internal event loop. */
1334*7c478bd9Sstevel@tonic-gate   GL_SERVER_MODE     /* Non-blocking server mode, driven by an external */
1335*7c478bd9Sstevel@tonic-gate                      /*  event loop. */
1336*7c478bd9Sstevel@tonic-gate } GlIOMode;
1337*7c478bd9Sstevel@tonic-gate 
1338*7c478bd9Sstevel@tonic-gate /*.......................................................................
1339*7c478bd9Sstevel@tonic-gate  * Select the I/O mode to be used by gl_get_line().
1340*7c478bd9Sstevel@tonic-gate  *
1341*7c478bd9Sstevel@tonic-gate  * Input:
1342*7c478bd9Sstevel@tonic-gate  *  gl         GetLine *         The resource object of gl_get_line().
1343*7c478bd9Sstevel@tonic-gate  *  mode      GlIOMode           The I/O mode to establish. Note that
1344*7c478bd9Sstevel@tonic-gate  *                               when server mode, the terminal is placed
1345*7c478bd9Sstevel@tonic-gate  *                               in raw mode, as though gl_raw_io() had
1346*7c478bd9Sstevel@tonic-gate  *                               been called.
1347*7c478bd9Sstevel@tonic-gate  * Output:
1348*7c478bd9Sstevel@tonic-gate  *  return                  int  0 - OK.
1349*7c478bd9Sstevel@tonic-gate  *                               1 - Error.
1350*7c478bd9Sstevel@tonic-gate  */
1351*7c478bd9Sstevel@tonic-gate int gl_io_mode(GetLine *gl, GlIOMode mode);
1352*7c478bd9Sstevel@tonic-gate 
1353*7c478bd9Sstevel@tonic-gate /*.......................................................................
1354*7c478bd9Sstevel@tonic-gate  * In server mode, this function configures the terminal for non-blocking
1355*7c478bd9Sstevel@tonic-gate  * raw terminal I/O. In normal I/O mode it does nothing.
1356*7c478bd9Sstevel@tonic-gate  *
1357*7c478bd9Sstevel@tonic-gate  * Callers of this function must be careful to trap all signals that
1358*7c478bd9Sstevel@tonic-gate  * terminate or suspend the program, and call gl_normal_io()
1359*7c478bd9Sstevel@tonic-gate  * from the corresponding signal handlers in order to restore the
1360*7c478bd9Sstevel@tonic-gate  * terminal to its original settings before the program is terminated
1361*7c478bd9Sstevel@tonic-gate  * or suspended. They should also trap the SIGCONT signal to detect
1362*7c478bd9Sstevel@tonic-gate  * when the program resumes, and ensure that its signal handler
1363*7c478bd9Sstevel@tonic-gate  * call gl_raw_io() to redisplay the line and resume editing.
1364*7c478bd9Sstevel@tonic-gate  *
1365*7c478bd9Sstevel@tonic-gate  * Input:
1366*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The line editor resource object.
1367*7c478bd9Sstevel@tonic-gate  * Output:
1368*7c478bd9Sstevel@tonic-gate  *  return      int    0 - OK.
1369*7c478bd9Sstevel@tonic-gate  *                     1 - Error.
1370*7c478bd9Sstevel@tonic-gate  */
1371*7c478bd9Sstevel@tonic-gate int gl_raw_io(GetLine *gl);
1372*7c478bd9Sstevel@tonic-gate 
1373*7c478bd9Sstevel@tonic-gate /*.......................................................................
1374*7c478bd9Sstevel@tonic-gate  * Restore the terminal to the state that it had when gl_raw_io() was
1375*7c478bd9Sstevel@tonic-gate  * last called. After calling gl_raw_io(), this function must be called
1376*7c478bd9Sstevel@tonic-gate  * before terminating or suspending the program, and before attempting
1377*7c478bd9Sstevel@tonic-gate  * other uses of the terminal from within the program. See gl_raw_io()
1378*7c478bd9Sstevel@tonic-gate  * for more details.
1379*7c478bd9Sstevel@tonic-gate  *
1380*7c478bd9Sstevel@tonic-gate  * Input:
1381*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The line editor resource object.
1382*7c478bd9Sstevel@tonic-gate  * Output:
1383*7c478bd9Sstevel@tonic-gate  *  return      int    0 - OK.
1384*7c478bd9Sstevel@tonic-gate  *                     1 - Error.
1385*7c478bd9Sstevel@tonic-gate  */
1386*7c478bd9Sstevel@tonic-gate int gl_normal_io(GetLine *gl);
1387*7c478bd9Sstevel@tonic-gate 
1388*7c478bd9Sstevel@tonic-gate /*.......................................................................
1389*7c478bd9Sstevel@tonic-gate  * When in non-blocking server mode, this function can be used to abandon
1390*7c478bd9Sstevel@tonic-gate  * the current incompletely entered input line, and prepare to start
1391*7c478bd9Sstevel@tonic-gate  * editing a new line on the next call to gl_get_line().
1392*7c478bd9Sstevel@tonic-gate  *
1393*7c478bd9Sstevel@tonic-gate  * Input:
1394*7c478bd9Sstevel@tonic-gate  *  gl      GetLine *  The line editor resource object.
1395*7c478bd9Sstevel@tonic-gate  * Output:
1396*7c478bd9Sstevel@tonic-gate  *  return      int    0 - OK.
1397*7c478bd9Sstevel@tonic-gate  *                     1 - Error.
1398*7c478bd9Sstevel@tonic-gate  */
1399*7c478bd9Sstevel@tonic-gate void gl_abandon_line(GetLine *gl);
1400*7c478bd9Sstevel@tonic-gate 
1401*7c478bd9Sstevel@tonic-gate /*
1402*7c478bd9Sstevel@tonic-gate  * Enumerators of the following type are used to report why
1403*7c478bd9Sstevel@tonic-gate  * gl_get_line() returned. This is most useful in non-blocking
1404*7c478bd9Sstevel@tonic-gate  * server mode, since in that mode a NULL return value can mean
1405*7c478bd9Sstevel@tonic-gate  * either that an error occurred, or that I/O blocked.
1406*7c478bd9Sstevel@tonic-gate  */
1407*7c478bd9Sstevel@tonic-gate typedef enum {
1408*7c478bd9Sstevel@tonic-gate   GLR_NEWLINE,  /* A new input line was returned */
1409*7c478bd9Sstevel@tonic-gate   GLR_BLOCKED,  /* The terminal was in non-blocking mode, and input */
1410*7c478bd9Sstevel@tonic-gate                 /* or output would have blocked. */
1411*7c478bd9Sstevel@tonic-gate   GLR_SIGNAL,   /* A signal caused gl_get_line() to return. */
1412*7c478bd9Sstevel@tonic-gate   GLR_TIMEOUT,  /* An application timeout callback returned GLTO_ABORT */
1413*7c478bd9Sstevel@tonic-gate   GLR_FDABORT,  /* An application I/O callack returned GLFD_ABORT */
1414*7c478bd9Sstevel@tonic-gate   GLR_EOF,      /* End of file reached */
1415*7c478bd9Sstevel@tonic-gate   GLR_ERROR     /* An unexpected error caused gl_get_line() to abort */
1416*7c478bd9Sstevel@tonic-gate } GlReturnStatus;
1417*7c478bd9Sstevel@tonic-gate 
1418*7c478bd9Sstevel@tonic-gate /*.......................................................................
1419*7c478bd9Sstevel@tonic-gate  * Ask gl_get_line() what caused it to return.
1420*7c478bd9Sstevel@tonic-gate  *
1421*7c478bd9Sstevel@tonic-gate  * Input:
1422*7c478bd9Sstevel@tonic-gate  *  gl             GetLine *  The line editor resource object.
1423*7c478bd9Sstevel@tonic-gate  * Output:
1424*7c478bd9Sstevel@tonic-gate  *  return  GlReturnStatus    The return status of the last call to
1425*7c478bd9Sstevel@tonic-gate  *                            gl_get_line().
1426*7c478bd9Sstevel@tonic-gate  */
1427*7c478bd9Sstevel@tonic-gate GlReturnStatus gl_return_status(GetLine *gl);
1428*7c478bd9Sstevel@tonic-gate 
1429*7c478bd9Sstevel@tonic-gate /*
1430*7c478bd9Sstevel@tonic-gate  * Enumerate the types of I/O that gl_get_line() can be waiting for
1431*7c478bd9Sstevel@tonic-gate  * in non-blocking sedrver I/O mode.
1432*7c478bd9Sstevel@tonic-gate  */
1433*7c478bd9Sstevel@tonic-gate typedef enum {
1434*7c478bd9Sstevel@tonic-gate   GLP_READ,   /* gl_get_line() is waiting to write to the terminal */
1435*7c478bd9Sstevel@tonic-gate   GLP_WRITE   /* gl_get_line() is waiting to read from the terminal */
1436*7c478bd9Sstevel@tonic-gate } GlPendingIO;
1437*7c478bd9Sstevel@tonic-gate 
1438*7c478bd9Sstevel@tonic-gate /*.......................................................................
1439*7c478bd9Sstevel@tonic-gate  * In non-blocking server-I/O mode, this function should be called
1440*7c478bd9Sstevel@tonic-gate  * from the application's external event loop to see what type of
1441*7c478bd9Sstevel@tonic-gate  * terminal I/O is being waited for by gl_get_line(), and thus what
1442*7c478bd9Sstevel@tonic-gate  * direction of I/O to wait for with select() or poll().
1443*7c478bd9Sstevel@tonic-gate  *
1444*7c478bd9Sstevel@tonic-gate  * Input:
1445*7c478bd9Sstevel@tonic-gate  *  gl          GetLine *  The resource object of gl_get_line().
1446*7c478bd9Sstevel@tonic-gate  * Output:
1447*7c478bd9Sstevel@tonic-gate  *  return  GlPendingIO    The type of pending I/O being waited for.
1448*7c478bd9Sstevel@tonic-gate  */
1449*7c478bd9Sstevel@tonic-gate GlPendingIO gl_pending_io(GetLine *gl);
1450*7c478bd9Sstevel@tonic-gate 
1451*7c478bd9Sstevel@tonic-gate /*
1452*7c478bd9Sstevel@tonic-gate  * The following enumerators are returned by externally defined action
1453*7c478bd9Sstevel@tonic-gate  * functions to tell gl_get_line() how to procede after the action
1454*7c478bd9Sstevel@tonic-gate  * function returns.
1455*7c478bd9Sstevel@tonic-gate  */
1456*7c478bd9Sstevel@tonic-gate typedef enum {
1457*7c478bd9Sstevel@tonic-gate   GLA_ABORT,     /* Cause gl_get_line() to return NULL */
1458*7c478bd9Sstevel@tonic-gate   GLA_RETURN,    /* Return the line as though the user had pressed the */
1459*7c478bd9Sstevel@tonic-gate                  /*  return key. */
1460*7c478bd9Sstevel@tonic-gate   GLA_CONTINUE   /* Resume command-line editing */
1461*7c478bd9Sstevel@tonic-gate } GlAfterAction;
1462*7c478bd9Sstevel@tonic-gate 
1463*7c478bd9Sstevel@tonic-gate /*.......................................................................
1464*7c478bd9Sstevel@tonic-gate  * Functions of the following form implement external
1465*7c478bd9Sstevel@tonic-gate  * application-specific action functions, which can then be bound to
1466*7c478bd9Sstevel@tonic-gate  * sequences of terminal keys.
1467*7c478bd9Sstevel@tonic-gate  *
1468*7c478bd9Sstevel@tonic-gate  * Input:
1469*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The line editor resource object.
1470*7c478bd9Sstevel@tonic-gate  *  data             void *  The anonymous 'data' argument that was
1471*7c478bd9Sstevel@tonic-gate  *                           passed to gl_external_action() when the
1472*7c478bd9Sstevel@tonic-gate  *                           callback function was registered.
1473*7c478bd9Sstevel@tonic-gate  *  count             int    A positive repeat count specified by the user,
1474*7c478bd9Sstevel@tonic-gate  *                           or 1 if not specified. Action functions should
1475*7c478bd9Sstevel@tonic-gate  *                           ignore this if repeating the action multiple
1476*7c478bd9Sstevel@tonic-gate  *                           times isn't appropriate. Alternatively they
1477*7c478bd9Sstevel@tonic-gate  *                           can interpret it as a general numeric
1478*7c478bd9Sstevel@tonic-gate  *                           argument.
1479*7c478bd9Sstevel@tonic-gate  *  curpos         size_t    The position of the cursor within the input
1480*7c478bd9Sstevel@tonic-gate  *                           line, expressed as the index of the
1481*7c478bd9Sstevel@tonic-gate  *                           corresponding character within the line[]
1482*7c478bd9Sstevel@tonic-gate  *                           array.
1483*7c478bd9Sstevel@tonic-gate  *  line       const char *  A read-only copy of the current input line.
1484*7c478bd9Sstevel@tonic-gate  * Output
1485*7c478bd9Sstevel@tonic-gate  *  return  GlAfterAction    What should gl_get_line() do when the action
1486*7c478bd9Sstevel@tonic-gate  *                           function returns?
1487*7c478bd9Sstevel@tonic-gate  *                            GLA_ABORT    - Cause gl_get_line() to
1488*7c478bd9Sstevel@tonic-gate  *                                           abort with an error (set
1489*7c478bd9Sstevel@tonic-gate  *                                           errno if you need it).
1490*7c478bd9Sstevel@tonic-gate  *                            GLA_RETURN   - Return the input line as
1491*7c478bd9Sstevel@tonic-gate  *                                           though the user had typed
1492*7c478bd9Sstevel@tonic-gate  *                                           the return key.
1493*7c478bd9Sstevel@tonic-gate  *                            GLA_CONTINUE - Resume waiting for keyboard
1494*7c478bd9Sstevel@tonic-gate  *                                           input.
1495*7c478bd9Sstevel@tonic-gate  */
1496*7c478bd9Sstevel@tonic-gate #define GL_ACTION_FN(fn) GlAfterAction (fn)(GetLine *gl, void *data, \
1497*7c478bd9Sstevel@tonic-gate 	      int count, size_t curpos, const char *line)
1498*7c478bd9Sstevel@tonic-gate 
1499*7c478bd9Sstevel@tonic-gate typedef GL_ACTION_FN(GlActionFn);
1500*7c478bd9Sstevel@tonic-gate 
1501*7c478bd9Sstevel@tonic-gate /*.......................................................................
1502*7c478bd9Sstevel@tonic-gate  * Register an application-provided function as an action function.
1503*7c478bd9Sstevel@tonic-gate  * This should preferably be called before the first call to gl_get_line()
1504*7c478bd9Sstevel@tonic-gate  * so that the name of the action becomes defined before the user's
1505*7c478bd9Sstevel@tonic-gate  * configuration file is read.
1506*7c478bd9Sstevel@tonic-gate  *
1507*7c478bd9Sstevel@tonic-gate  * Input:
1508*7c478bd9Sstevel@tonic-gate  *  gl            GetLine *  The resource object of the command-line input
1509*7c478bd9Sstevel@tonic-gate  *                           module.
1510*7c478bd9Sstevel@tonic-gate  *  data             void *  Arbitrary application-specific callback
1511*7c478bd9Sstevel@tonic-gate  *                           data to be passed to the callback
1512*7c478bd9Sstevel@tonic-gate  *                           function, fn().
1513*7c478bd9Sstevel@tonic-gate  *  fn         GlActionFn *  The application-specific function that
1514*7c478bd9Sstevel@tonic-gate  *                           implements the action. This will be invoked
1515*7c478bd9Sstevel@tonic-gate  *                           whenever the user presses any
1516*7c478bd9Sstevel@tonic-gate  *                           key-sequence which is bound to this action.
1517*7c478bd9Sstevel@tonic-gate  *  name       const char *  The name with which users can refer to the
1518*7c478bd9Sstevel@tonic-gate  *                           binding in tecla configuration files.
1519*7c478bd9Sstevel@tonic-gate  *  keyseq     const char *  The key sequence with which to invoke
1520*7c478bd9Sstevel@tonic-gate  *                           the binding. This should be specified in the
1521*7c478bd9Sstevel@tonic-gate  *                           same manner as key-sequences in tecla
1522*7c478bd9Sstevel@tonic-gate  *                           configuration files (eg. "M-^I").
1523*7c478bd9Sstevel@tonic-gate  * Output:
1524*7c478bd9Sstevel@tonic-gate  *  return            int    0 - OK.
1525*7c478bd9Sstevel@tonic-gate  *                           1 - Error.
1526*7c478bd9Sstevel@tonic-gate  */
1527*7c478bd9Sstevel@tonic-gate int gl_register_action(GetLine *gl, void *data, GlActionFn *fn,
1528*7c478bd9Sstevel@tonic-gate                        const char *name, const char *keyseq);
1529*7c478bd9Sstevel@tonic-gate 
1530*7c478bd9Sstevel@tonic-gate /*.......................................................................
1531*7c478bd9Sstevel@tonic-gate  * This function is designed to be called by CPL_MATCH_FN() callback
1532*7c478bd9Sstevel@tonic-gate  * functions. It adds one possible completion of the token that is being
1533*7c478bd9Sstevel@tonic-gate  * completed to an array of completions. If the completion needs any
1534*7c478bd9Sstevel@tonic-gate  * special quoting to be valid when displayed in the input line, this
1535*7c478bd9Sstevel@tonic-gate  * quoting must be included in the string.
1536*7c478bd9Sstevel@tonic-gate  *
1537*7c478bd9Sstevel@tonic-gate  * Input:
1538*7c478bd9Sstevel@tonic-gate  *  cpl      WordCompletion *  The argument of the same name that was passed
1539*7c478bd9Sstevel@tonic-gate  *                             to the calling CPL_MATCH_FN() callback function.
1540*7c478bd9Sstevel@tonic-gate  *  line         const char *  The input line, as received by the callback
1541*7c478bd9Sstevel@tonic-gate  *                             function.
1542*7c478bd9Sstevel@tonic-gate  *  word_start          int    The index within line[] of the start of the
1543*7c478bd9Sstevel@tonic-gate  *                             word that is being completed. If an empty
1544*7c478bd9Sstevel@tonic-gate  *                             string is being completed, set this to be
1545*7c478bd9Sstevel@tonic-gate  *                             the same as word_end.
1546*7c478bd9Sstevel@tonic-gate  *  word_end            int    The index within line[] of the character which
1547*7c478bd9Sstevel@tonic-gate  *                             follows the incomplete word, as received by the
1548*7c478bd9Sstevel@tonic-gate  *                             callback function.
1549*7c478bd9Sstevel@tonic-gate  *  suffix       const char *  The appropriately quoted string that could
1550*7c478bd9Sstevel@tonic-gate  *                             be appended to the incomplete token to complete
1551*7c478bd9Sstevel@tonic-gate  *                             it. A copy of this string will be allocated
1552*7c478bd9Sstevel@tonic-gate  *                             internally.
1553*7c478bd9Sstevel@tonic-gate  *  type_suffix  const char *  When listing multiple completions, gl_get_line()
1554*7c478bd9Sstevel@tonic-gate  *                             appends this string to the completion to indicate
1555*7c478bd9Sstevel@tonic-gate  *                             its type to the user. If not pertinent pass "".
1556*7c478bd9Sstevel@tonic-gate  *                             Otherwise pass a literal or static string.
1557*7c478bd9Sstevel@tonic-gate  *  cont_suffix  const char *  If this turns out to be the only completion,
1558*7c478bd9Sstevel@tonic-gate  *                             gl_get_line() will append this string as
1559*7c478bd9Sstevel@tonic-gate  *                             a continuation. For example, the builtin
1560*7c478bd9Sstevel@tonic-gate  *                             file-completion callback registers a directory
1561*7c478bd9Sstevel@tonic-gate  *                             separator here for directory matches, and a
1562*7c478bd9Sstevel@tonic-gate  *                             space otherwise. If the match were a function
1563*7c478bd9Sstevel@tonic-gate  *                             name you might want to append an open
1564*7c478bd9Sstevel@tonic-gate  *                             parenthesis, etc.. If not relevant pass "".
1565*7c478bd9Sstevel@tonic-gate  *                             Otherwise pass a literal or static string.
1566*7c478bd9Sstevel@tonic-gate  * Output:
1567*7c478bd9Sstevel@tonic-gate  *  return              int    0 - OK.
1568*7c478bd9Sstevel@tonic-gate  *                             1 - Error.
1569*7c478bd9Sstevel@tonic-gate  */
1570*7c478bd9Sstevel@tonic-gate int cpl_add_completion(WordCompletion *cpl, const char *line,
1571*7c478bd9Sstevel@tonic-gate 		       int word_start, int word_end, const char *suffix,
1572*7c478bd9Sstevel@tonic-gate 		       const char *type_suffix, const char *cont_suffix);
1573*7c478bd9Sstevel@tonic-gate 
1574*7c478bd9Sstevel@tonic-gate /*
1575*7c478bd9Sstevel@tonic-gate  * Each possible completion string is recorded in an array element of
1576*7c478bd9Sstevel@tonic-gate  * the following type.
1577*7c478bd9Sstevel@tonic-gate  */
1578*7c478bd9Sstevel@tonic-gate typedef struct {
1579*7c478bd9Sstevel@tonic-gate   char *completion;        /* The matching completion string */
1580*7c478bd9Sstevel@tonic-gate   char *suffix;            /* The pointer into completion[] at which the */
1581*7c478bd9Sstevel@tonic-gate                            /*  string was extended. */
1582*7c478bd9Sstevel@tonic-gate   const char *type_suffix; /* A suffix to be added when listing completions */
1583*7c478bd9Sstevel@tonic-gate                            /*  to indicate the type of the completion. */
1584*7c478bd9Sstevel@tonic-gate } CplMatch;
1585*7c478bd9Sstevel@tonic-gate 
1586*7c478bd9Sstevel@tonic-gate /*
1587*7c478bd9Sstevel@tonic-gate  * Completions are returned in a container of the following form.
1588*7c478bd9Sstevel@tonic-gate  */
1589*7c478bd9Sstevel@tonic-gate typedef struct {
1590*7c478bd9Sstevel@tonic-gate   char *suffix;            /* The common initial part of all of the */
1591*7c478bd9Sstevel@tonic-gate                            /*  completion suffixes. */
1592*7c478bd9Sstevel@tonic-gate   const char *cont_suffix; /* Optional continuation string to be appended to */
1593*7c478bd9Sstevel@tonic-gate                            /*  the sole completion when nmatch==1. */
1594*7c478bd9Sstevel@tonic-gate   CplMatch *matches;       /* The array of possible completion strings, */
1595*7c478bd9Sstevel@tonic-gate                            /*  sorted into lexical order. */
1596*7c478bd9Sstevel@tonic-gate   int nmatch;              /* The number of elements in matches[] */
1597*7c478bd9Sstevel@tonic-gate } CplMatches;
1598*7c478bd9Sstevel@tonic-gate 
1599*7c478bd9Sstevel@tonic-gate /*.......................................................................
1600*7c478bd9Sstevel@tonic-gate  * Given an input line and the point at which completion is to be
1601*7c478bd9Sstevel@tonic-gate  * attempted, return an array of possible completions.
1602*7c478bd9Sstevel@tonic-gate  *
1603*7c478bd9Sstevel@tonic-gate  * Input:
1604*7c478bd9Sstevel@tonic-gate  *  cpl    WordCompletion *  The word-completion resource object.
1605*7c478bd9Sstevel@tonic-gate  *  line       const char *  The current input line.
1606*7c478bd9Sstevel@tonic-gate  *  word_end          int    The index of the character in line[] which
1607*7c478bd9Sstevel@tonic-gate  *                           follows the end of the token that is being
1608*7c478bd9Sstevel@tonic-gate  *                           completed.
1609*7c478bd9Sstevel@tonic-gate  *  data             void *  Anonymous 'data' to be passed to match_fn().
1610*7c478bd9Sstevel@tonic-gate  *  match_fn   CplMatchFn *  The function that will identify the prefix
1611*7c478bd9Sstevel@tonic-gate  *                           to be completed from the input line, and
1612*7c478bd9Sstevel@tonic-gate  *                           record completion suffixes.
1613*7c478bd9Sstevel@tonic-gate  * Output:
1614*7c478bd9Sstevel@tonic-gate  *  return     CplMatches *  The container of the array of possible
1615*7c478bd9Sstevel@tonic-gate  *                           completions. The returned pointer refers
1616*7c478bd9Sstevel@tonic-gate  *                           to a container owned by the parent Completion
1617*7c478bd9Sstevel@tonic-gate  *                           object, and its contents thus potentially
1618*7c478bd9Sstevel@tonic-gate  *                           change on every call to cpl_complete_word().
1619*7c478bd9Sstevel@tonic-gate  */
1620*7c478bd9Sstevel@tonic-gate CplMatches *cpl_complete_word(WordCompletion *cpl, const char *line,
1621*7c478bd9Sstevel@tonic-gate 			      int word_end, void *data,
1622*7c478bd9Sstevel@tonic-gate 			      CplMatchFn *match_fn);
1623*7c478bd9Sstevel@tonic-gate 
1624*7c478bd9Sstevel@tonic-gate /*.......................................................................
1625*7c478bd9Sstevel@tonic-gate  * Recall the return value of the last call to cpl_complete_word().
1626*7c478bd9Sstevel@tonic-gate  *
1627*7c478bd9Sstevel@tonic-gate  * Input:
1628*7c478bd9Sstevel@tonic-gate  *  cpl    WordCompletion *  The completion resource object.
1629*7c478bd9Sstevel@tonic-gate  * Output:
1630*7c478bd9Sstevel@tonic-gate  *  return     CplMatches *  The container of the array of possible
1631*7c478bd9Sstevel@tonic-gate  *                           completions, as returned by the last call to
1632*7c478bd9Sstevel@tonic-gate  *                           cpl_complete_word(). The returned pointer refers
1633*7c478bd9Sstevel@tonic-gate  *                           to a container owned by the parent WordCompletion
1634*7c478bd9Sstevel@tonic-gate  *                           object, and its contents thus potentially
1635*7c478bd9Sstevel@tonic-gate  *                           change on every call to cpl_complete_word().
1636*7c478bd9Sstevel@tonic-gate  *                           On error, either in the execution of this
1637*7c478bd9Sstevel@tonic-gate  *                           function, or in the last call to
1638*7c478bd9Sstevel@tonic-gate  *                           cpl_complete_word(), NULL is returned, and a
1639*7c478bd9Sstevel@tonic-gate  *                           description of the error can be acquired by
1640*7c478bd9Sstevel@tonic-gate  *                           calling cpl_last_error(cpl).
1641*7c478bd9Sstevel@tonic-gate  */
1642*7c478bd9Sstevel@tonic-gate CplMatches *cpl_recall_matches(WordCompletion *cpl);
1643*7c478bd9Sstevel@tonic-gate 
1644*7c478bd9Sstevel@tonic-gate /*.......................................................................
1645*7c478bd9Sstevel@tonic-gate  * Print out an array of matching completions.
1646*7c478bd9Sstevel@tonic-gate  *
1647*7c478bd9Sstevel@tonic-gate  * Input:
1648*7c478bd9Sstevel@tonic-gate  *  result  CplMatches *   The container of the sorted array of
1649*7c478bd9Sstevel@tonic-gate  *                         completions.
1650*7c478bd9Sstevel@tonic-gate  *  fp            FILE *   The output stream to write to.
1651*7c478bd9Sstevel@tonic-gate  *  term_width     int     The width of the terminal.
1652*7c478bd9Sstevel@tonic-gate  * Output:
1653*7c478bd9Sstevel@tonic-gate  *  return         int     0 - OK.
1654*7c478bd9Sstevel@tonic-gate  *                         1 - Error.
1655*7c478bd9Sstevel@tonic-gate  */
1656*7c478bd9Sstevel@tonic-gate int cpl_list_completions(CplMatches *result, FILE *fp, int term_width);
1657*7c478bd9Sstevel@tonic-gate 
1658*7c478bd9Sstevel@tonic-gate /*.......................................................................
1659*7c478bd9Sstevel@tonic-gate  * Return a description of the error that occurred on the last call to
1660*7c478bd9Sstevel@tonic-gate  * cpl_complete_word() or cpl_add_completion().
1661*7c478bd9Sstevel@tonic-gate  *
1662*7c478bd9Sstevel@tonic-gate  * Input:
1663*7c478bd9Sstevel@tonic-gate  *  cpl   WordCompletion *  The string-completion resource object.
1664*7c478bd9Sstevel@tonic-gate  * Output:
1665*7c478bd9Sstevel@tonic-gate  *  return    const char *  The description of the last error.
1666*7c478bd9Sstevel@tonic-gate  */
1667*7c478bd9Sstevel@tonic-gate const char *cpl_last_error(WordCompletion *cpl);
1668*7c478bd9Sstevel@tonic-gate 
1669*7c478bd9Sstevel@tonic-gate /*
1670*7c478bd9Sstevel@tonic-gate  * PathCache objects encapsulate the resources needed to record
1671*7c478bd9Sstevel@tonic-gate  * files of interest from comma-separated lists of directories.
1672*7c478bd9Sstevel@tonic-gate  */
1673*7c478bd9Sstevel@tonic-gate typedef struct PathCache PathCache;
1674*7c478bd9Sstevel@tonic-gate 
1675*7c478bd9Sstevel@tonic-gate /*.......................................................................
1676*7c478bd9Sstevel@tonic-gate  * Create an object who's function is to maintain a cache of filenames
1677*7c478bd9Sstevel@tonic-gate  * found within a list of directories, and provide quick lookup and
1678*7c478bd9Sstevel@tonic-gate  * completion of selected files in this cache.
1679*7c478bd9Sstevel@tonic-gate  *
1680*7c478bd9Sstevel@tonic-gate  * Output:
1681*7c478bd9Sstevel@tonic-gate  *  return     PathCache *  The new, initially empty cache, or NULL
1682*7c478bd9Sstevel@tonic-gate  *                          on error.
1683*7c478bd9Sstevel@tonic-gate  */
1684*7c478bd9Sstevel@tonic-gate PathCache *new_PathCache(void);
1685*7c478bd9Sstevel@tonic-gate 
1686*7c478bd9Sstevel@tonic-gate /*.......................................................................
1687*7c478bd9Sstevel@tonic-gate  * Delete a given cache of files, returning the resources that it
1688*7c478bd9Sstevel@tonic-gate  * was using to the system.
1689*7c478bd9Sstevel@tonic-gate  *
1690*7c478bd9Sstevel@tonic-gate  * Input:
1691*7c478bd9Sstevel@tonic-gate  *  pc      PathCache *  The cache to be deleted (can be NULL).
1692*7c478bd9Sstevel@tonic-gate  * Output:
1693*7c478bd9Sstevel@tonic-gate  *  return  PathCache *  The deleted object (ie. allways NULL).
1694*7c478bd9Sstevel@tonic-gate  */
1695*7c478bd9Sstevel@tonic-gate PathCache *del_PathCache(PathCache *pc);
1696*7c478bd9Sstevel@tonic-gate 
1697*7c478bd9Sstevel@tonic-gate /*.......................................................................
1698*7c478bd9Sstevel@tonic-gate  * Return a description of the last path-caching error that occurred.
1699*7c478bd9Sstevel@tonic-gate  *
1700*7c478bd9Sstevel@tonic-gate  * Input:
1701*7c478bd9Sstevel@tonic-gate  *  pc     PathCache *   The filename cache that suffered the error.
1702*7c478bd9Sstevel@tonic-gate  * Output:
1703*7c478bd9Sstevel@tonic-gate  *  return      char *   The description of the last error.
1704*7c478bd9Sstevel@tonic-gate  */
1705*7c478bd9Sstevel@tonic-gate const char *pca_last_error(PathCache *pc);
1706*7c478bd9Sstevel@tonic-gate 
1707*7c478bd9Sstevel@tonic-gate /*.......................................................................
1708*7c478bd9Sstevel@tonic-gate  * Build the list of files of interest contained in a given
1709*7c478bd9Sstevel@tonic-gate  * colon-separated list of directories.
1710*7c478bd9Sstevel@tonic-gate  *
1711*7c478bd9Sstevel@tonic-gate  * Input:
1712*7c478bd9Sstevel@tonic-gate  *  pc         PathCache *  The cache in which to store the names of
1713*7c478bd9Sstevel@tonic-gate  *                          the files that are found in the list of
1714*7c478bd9Sstevel@tonic-gate  *                          directories.
1715*7c478bd9Sstevel@tonic-gate  *  path      const char *  A colon-separated list of directory
1716*7c478bd9Sstevel@tonic-gate  *                          paths. Under UNIX, when searching for
1717*7c478bd9Sstevel@tonic-gate  *                          executables, this should be the return
1718*7c478bd9Sstevel@tonic-gate  *                          value of getenv("PATH").
1719*7c478bd9Sstevel@tonic-gate  * Output:
1720*7c478bd9Sstevel@tonic-gate  *  return           int    0 - OK.
1721*7c478bd9Sstevel@tonic-gate  *                          1 - An error occurred.
1722*7c478bd9Sstevel@tonic-gate  */
1723*7c478bd9Sstevel@tonic-gate int pca_scan_path(PathCache *pc, const char *path);
1724*7c478bd9Sstevel@tonic-gate 
1725*7c478bd9Sstevel@tonic-gate /*.......................................................................
1726*7c478bd9Sstevel@tonic-gate  * If you want subsequent calls to pca_lookup_file() and
1727*7c478bd9Sstevel@tonic-gate  * pca_path_completions() to only return the filenames of certain
1728*7c478bd9Sstevel@tonic-gate  * types of files, for example executables, or filenames ending in
1729*7c478bd9Sstevel@tonic-gate  * ".ps", call this function to register a file-selection callback
1730*7c478bd9Sstevel@tonic-gate  * function. This callback function takes the full pathname of a file,
1731*7c478bd9Sstevel@tonic-gate  * plus application-specific data, and returns 1 if the file is of
1732*7c478bd9Sstevel@tonic-gate  * interest, and zero otherwise.
1733*7c478bd9Sstevel@tonic-gate  *
1734*7c478bd9Sstevel@tonic-gate  * Input:
1735*7c478bd9Sstevel@tonic-gate  *  pc         PathCache *  The filename cache.
1736*7c478bd9Sstevel@tonic-gate  *  check_fn  CplCheckFn *  The function to call to see if the name of
1737*7c478bd9Sstevel@tonic-gate  *                          a given file should be included in the
1738*7c478bd9Sstevel@tonic-gate  *                          cache. This determines what type of files
1739*7c478bd9Sstevel@tonic-gate  *                          will reside in the cache. To revert to
1740*7c478bd9Sstevel@tonic-gate  *                          selecting all files, regardless of type,
1741*7c478bd9Sstevel@tonic-gate  *                          pass 0 here.
1742*7c478bd9Sstevel@tonic-gate  *  data            void *  You can pass a pointer to anything you
1743*7c478bd9Sstevel@tonic-gate  *                          like here, including NULL. It will be
1744*7c478bd9Sstevel@tonic-gate  *                          passed to your check_fn() callback
1745*7c478bd9Sstevel@tonic-gate  *                          function, for its private use.
1746*7c478bd9Sstevel@tonic-gate  */
1747*7c478bd9Sstevel@tonic-gate void pca_set_check_fn(PathCache *pc, CplCheckFn *check_fn, void *data);
1748*7c478bd9Sstevel@tonic-gate 
1749*7c478bd9Sstevel@tonic-gate /*.......................................................................
1750*7c478bd9Sstevel@tonic-gate  * Given the simple name of a file, search the cached list of files
1751*7c478bd9Sstevel@tonic-gate  * in the order in which they where found in the list of directories
1752*7c478bd9Sstevel@tonic-gate  * previously presented to pca_scan_path(), and return the pathname
1753*7c478bd9Sstevel@tonic-gate  * of the first file which has this name.
1754*7c478bd9Sstevel@tonic-gate  *
1755*7c478bd9Sstevel@tonic-gate  * Input:
1756*7c478bd9Sstevel@tonic-gate  *  pc     PathCache *  The cached list of files.
1757*7c478bd9Sstevel@tonic-gate  *  name  const char *  The name of the file to lookup.
1758*7c478bd9Sstevel@tonic-gate  *  name_len     int    The length of the filename substring at the
1759*7c478bd9Sstevel@tonic-gate  *                      beginning of name[], or -1 to assume that the
1760*7c478bd9Sstevel@tonic-gate  *                      filename occupies the whole of the string.
1761*7c478bd9Sstevel@tonic-gate  *  literal      int    If this argument is zero, lone backslashes
1762*7c478bd9Sstevel@tonic-gate  *                      in name[] are ignored during comparison
1763*7c478bd9Sstevel@tonic-gate  *                      with filenames in the cache, under the
1764*7c478bd9Sstevel@tonic-gate  *                      assumption that they were in the input line
1765*7c478bd9Sstevel@tonic-gate  *                      soley to escape the special significance of
1766*7c478bd9Sstevel@tonic-gate  *                      characters like spaces. To have them treated
1767*7c478bd9Sstevel@tonic-gate  *                      as normal characters, give this argument a
1768*7c478bd9Sstevel@tonic-gate  *                      non-zero value, such as 1.
1769*7c478bd9Sstevel@tonic-gate  * Output:
1770*7c478bd9Sstevel@tonic-gate  *  return      char *  The pathname of the first matching file,
1771*7c478bd9Sstevel@tonic-gate  *                      or NULL if not found. Note that the returned
1772*7c478bd9Sstevel@tonic-gate  *                      pointer points to memory owned by *pc, and
1773*7c478bd9Sstevel@tonic-gate  *                      will become invalid on the next call.
1774*7c478bd9Sstevel@tonic-gate  */
1775*7c478bd9Sstevel@tonic-gate char *pca_lookup_file(PathCache *pc, const char *name, int name_len,
1776*7c478bd9Sstevel@tonic-gate 		      int literal);
1777*7c478bd9Sstevel@tonic-gate 
1778*7c478bd9Sstevel@tonic-gate /*
1779*7c478bd9Sstevel@tonic-gate  * Objects of the following type can be used to change the default
1780*7c478bd9Sstevel@tonic-gate  * behavior of the pca_path_completions() callback function.
1781*7c478bd9Sstevel@tonic-gate  */
1782*7c478bd9Sstevel@tonic-gate typedef struct PcaPathConf PcaPathConf;
1783*7c478bd9Sstevel@tonic-gate 
1784*7c478bd9Sstevel@tonic-gate /*
1785*7c478bd9Sstevel@tonic-gate  * pca_path_completions() is a completion callback function for use directly
1786*7c478bd9Sstevel@tonic-gate  * with cpl_complete_word() or gl_customize_completions(), or indirectly
1787*7c478bd9Sstevel@tonic-gate  * from your own completion callback function. It requires that a PcaPathConf
1788*7c478bd9Sstevel@tonic-gate  * object be passed via its 'void *data' argument (see below).
1789*7c478bd9Sstevel@tonic-gate  */
1790*7c478bd9Sstevel@tonic-gate CPL_MATCH_FN(pca_path_completions);
1791*7c478bd9Sstevel@tonic-gate 
1792*7c478bd9Sstevel@tonic-gate /*.......................................................................
1793*7c478bd9Sstevel@tonic-gate  * Allocate and initialize a pca_path_completions() configuration object.
1794*7c478bd9Sstevel@tonic-gate  *
1795*7c478bd9Sstevel@tonic-gate  * Input:
1796*7c478bd9Sstevel@tonic-gate  *  pc         PathCache *  The filename cache in which to look for
1797*7c478bd9Sstevel@tonic-gate  *                          file name completions.
1798*7c478bd9Sstevel@tonic-gate  * Output:
1799*7c478bd9Sstevel@tonic-gate  *  return   PcaPathConf *  The new configuration structure, or NULL
1800*7c478bd9Sstevel@tonic-gate  *                          on error.
1801*7c478bd9Sstevel@tonic-gate  */
1802*7c478bd9Sstevel@tonic-gate PcaPathConf *new_PcaPathConf(PathCache *pc);
1803*7c478bd9Sstevel@tonic-gate 
1804*7c478bd9Sstevel@tonic-gate /*.......................................................................
1805*7c478bd9Sstevel@tonic-gate  * Deallocate memory, previously allocated by new_PcaPathConf().
1806*7c478bd9Sstevel@tonic-gate  *
1807*7c478bd9Sstevel@tonic-gate  * Input:
1808*7c478bd9Sstevel@tonic-gate  *  ppc     PcaPathConf *  Any pointer previously returned by
1809*7c478bd9Sstevel@tonic-gate  *                         new_PcaPathConf() [NULL is allowed].
1810*7c478bd9Sstevel@tonic-gate  * Output:
1811*7c478bd9Sstevel@tonic-gate  *  return  PcaPathConf *  The deleted structure (always NULL).
1812*7c478bd9Sstevel@tonic-gate  */
1813*7c478bd9Sstevel@tonic-gate PcaPathConf *del_PcaPathConf(PcaPathConf *ppc);
1814*7c478bd9Sstevel@tonic-gate 
1815*7c478bd9Sstevel@tonic-gate /*
1816*7c478bd9Sstevel@tonic-gate  * If backslashes in the prefix being passed to pca_path_completions()
1817*7c478bd9Sstevel@tonic-gate  * should be treated as literal characters, call the following function
1818*7c478bd9Sstevel@tonic-gate  * with literal=1. Otherwise the default is to treat them as escape
1819*7c478bd9Sstevel@tonic-gate  * characters which remove the special meanings of spaces etc..
1820*7c478bd9Sstevel@tonic-gate  */
1821*7c478bd9Sstevel@tonic-gate void ppc_literal_escapes(PcaPathConf *ppc, int literal);
1822*7c478bd9Sstevel@tonic-gate 
1823*7c478bd9Sstevel@tonic-gate /*
1824*7c478bd9Sstevel@tonic-gate  * Before calling pca_path_completions, call this function if you know
1825*7c478bd9Sstevel@tonic-gate  * the index at which the filename prefix starts in the input line.
1826*7c478bd9Sstevel@tonic-gate  * Otherwise by default, or if you specify start_index to be -1, the
1827*7c478bd9Sstevel@tonic-gate  * filename is taken to start after the first unescaped space preceding
1828*7c478bd9Sstevel@tonic-gate  * the cursor, or the start of the line, whichever comes first.
1829*7c478bd9Sstevel@tonic-gate  */
1830*7c478bd9Sstevel@tonic-gate void ppc_file_start(PcaPathConf *ppc, int start_index);
1831*7c478bd9Sstevel@tonic-gate 
1832*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1833*7c478bd9Sstevel@tonic-gate }
1834*7c478bd9Sstevel@tonic-gate #endif
1835*7c478bd9Sstevel@tonic-gate 
1836*7c478bd9Sstevel@tonic-gate #endif
1837