xref: /illumos-gate/usr/src/lib/libtecla/common/cplfile.h (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
1 #ifndef cplfile_h
2 #define cplfile_h
3 
4 /*
5  * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
6  *
7  * All rights reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, and/or sell copies of the Software, and to permit persons
14  * to whom the Software is furnished to do so, provided that the above
15  * copyright notice(s) and this permission notice appear in all copies of
16  * the Software and that both the above copyright notice(s) and this
17  * permission notice appear in supporting documentation.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28  *
29  * Except as contained in this notice, the name of a copyright holder
30  * shall not be used in advertising or otherwise to promote the sale, use
31  * or other dealings in this Software without prior written authorization
32  * of the copyright holder.
33  */
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 typedef struct CompleteFile CompleteFile;
38 
39 /*
40  * Create a file-completion resource object.
41  */
42 CompleteFile *_new_CompleteFile(void);
43 /*
44  * Delete a file-completion resource object.
45  */
46 CompleteFile *_del_CompleteFile(CompleteFile *cf);
47 
48 /*.......................................................................
49  * Complete the string between path[0] and path[len-1] as a pathname,
50  * leaving the last component uncompleted if it is potentially ambiguous,
51  * and returning an array of possible completions. Note that the returned
52  * container belongs to the 'cf' object and its contents will change on
53  * subsequent calls to this function.
54  *
55  * Input:
56  *  cpl   WordCompletion *  The object in which to record the completions.
57  *  cf      CompleteFile *  The filename-completion resource object.
58  *  line      const char *  The string containing the incomplete filename.
59  *  word_start       int    The index of the first character in line[]
60  *                          of the incomplete filename.
61  *  word_end         int    The index of the character in line[] that
62  *                          follows the last character of the incomplete
63  *                          filename.
64  *  escaped          int    If true, backslashes in path[] are
65  *                          interpreted as escaping the characters
66  *                          that follow them, and any spaces, tabs,
67  *                          backslashes, or wildcard characters in the
68  *                          returned suffixes will be similarly be escaped.
69  *                          If false, backslashes will be interpreted as
70  *                          literal parts of the file name, and no
71  *                          backslashes will be added to the returned
72  *                          suffixes.
73  *  check_fn  CplCheckFn *  If not zero, this argument specifies a
74  *                          function to call to ask whether a given
75  *                          file should be included in the list
76  *                          of completions.
77  *  check_data      void *  Anonymous data to be passed to check_fn().
78  * Output:
79  *  return           int    0 - OK.
80  *                          1 - Error. A description of the error can be
81  *                                     acquired by calling cf_last_error(cf).
82  */
83 int _cf_complete_file(WordCompletion *cpl, CompleteFile *cf,
84 		     const char *line, int word_start, int word_end,
85 		     int escaped, CplCheckFn *check_fn, void *check_data);
86 
87 /*.......................................................................
88  * Return a description of the error that occurred on the last call to
89  * cf_complete_file().
90  *
91  * Input:
92  *  cf    CompleteFile *  The path-completion resource object.
93  * Output:
94  *  return        char *  The description of the last error.
95  */
96 const char *_cf_last_error(CompleteFile *cf);
97 
98 #endif
99