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 typedef struct CompleteFile CompleteFile;
36 
37 /*
38  * Create a file-completion resource object.
39  */
40 CompleteFile *_new_CompleteFile(void);
41 /*
42  * Delete a file-completion resource object.
43  */
44 CompleteFile *_del_CompleteFile(CompleteFile *cf);
45 
46 /*.......................................................................
47  * Complete the string between path[0] and path[len-1] as a pathname,
48  * leaving the last component uncompleted if it is potentially ambiguous,
49  * and returning an array of possible completions. Note that the returned
50  * container belongs to the 'cf' object and its contents will change on
51  * subsequent calls to this function.
52  *
53  * Input:
54  *  cpl   WordCompletion *  The object in which to record the completions.
55  *  cf      CompleteFile *  The filename-completion resource object.
56  *  line      const char *  The string containing the incomplete filename.
57  *  word_start       int    The index of the first character in line[]
58  *                          of the incomplete filename.
59  *  word_end         int    The index of the character in line[] that
60  *                          follows the last character of the incomplete
61  *                          filename.
62  *  escaped          int    If true, backslashes in path[] are
63  *                          interpreted as escaping the characters
64  *                          that follow them, and any spaces, tabs,
65  *                          backslashes, or wildcard characters in the
66  *                          returned suffixes will be similarly be escaped.
67  *                          If false, backslashes will be interpreted as
68  *                          literal parts of the file name, and no
69  *                          backslashes will be added to the returned
70  *                          suffixes.
71  *  check_fn  CplCheckFn *  If not zero, this argument specifies a
72  *                          function to call to ask whether a given
73  *                          file should be included in the list
74  *                          of completions.
75  *  check_data      void *  Anonymous data to be passed to check_fn().
76  * Output:
77  *  return           int    0 - OK.
78  *                          1 - Error. A description of the error can be
79  *                                     acquired by calling cf_last_error(cf).
80  */
81 int _cf_complete_file(WordCompletion *cpl, CompleteFile *cf,
82 		     const char *line, int word_start, int word_end,
83 		     int escaped, CplCheckFn *check_fn, void *check_data);
84 
85 /*.......................................................................
86  * Return a description of the error that occurred on the last call to
87  * cf_complete_file().
88  *
89  * Input:
90  *  cf    CompleteFile *  The path-completion resource object.
91  * Output:
92  *  return        char *  The description of the last error.
93  */
94 const char *_cf_last_error(CompleteFile *cf);
95 
96 #endif
97