Print this page
12212 typos in some section 3tecla man pages
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man3tecla/cpl_complete_word.3tecla
+++ new/usr/src/man/man3tecla/cpl_complete_word.3tecla
1 1 '\" te
2 2 .\" Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd. All Rights Reserved.
3 3 .\" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
4 4 .\" "Software"), to deal in the Software without restriction, including
5 5 .\" without limitation the rights to use, copy, modify, merge, publish,
6 6 .\" distribute, and/or sell copies of the Software, and to permit persons
7 7 .\" to whom the Software is furnished to do so, provided that the above
8 8 .\" copyright notice(s) and this permission notice appear in all copies of
9 9 .\" the Software and that both the above copyright notice(s) and this
10 10 .\" permission notice appear in supporting documentation.
11 11 .\"
12 12 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 13 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 14 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
15 15 .\" OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
16 16 .\" HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 .\" INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
18 18 .\" FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
19 19 .\" NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
20 20 .\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 21 .\"
22 22 .\" Except as contained in this notice, the name of a copyright holder
23 23 .\" shall not be used in advertising or otherwise to promote the sale, use
24 24 .\" or other dealings in this Software without prior written authorization
25 25 .\" of the copyright holder.
26 26 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
27 -.TH CPL_COMPLETE_WORD 3TECLA "Jun 1, 2004"
27 +.TH CPL_COMPLETE_WORD 3TECLA "January 18, 2020"
28 28 .SH NAME
29 29 cpl_complete_word, cfc_file_start, cfc_literal_escapes, cfc_set_check_fn,
30 30 cpl_add_completion, cpl_file_completions, cpl_last_error, cpl_list_completions,
31 31 cpl_recall_matches, cpl_record_error, del_CplFileConf, cpl_check_exe,
32 32 del_WordCompletion, new_CplFileConf, new_WordCompletion \- look up possible
33 33 completions for a word
34 34 .SH SYNOPSIS
35 -.LP
36 35 .nf
37 36 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-ltecla\fR [ \fIlibrary\fR\&.\|.\|. ]
38 37 #include <stdio.h>
39 38 #include <libtecla.h>
40 39
41 40 \fBWordCompletion *\fR\fBnew_WordCompletion\fR(\fBvoid\fR);
42 41 .fi
43 42
44 43 .LP
45 44 .nf
46 45 \fBWordCompletion *\fR\fBdel_WordCompletion\fR(\fBWordCompletion *\fR\fIcpl\fR);
47 46 .fi
48 47
49 48 .LP
50 49 .nf
51 50 \fBCPL_MATCH_FN\fR(\fBcpl_file_completions\fR);
52 51 .fi
53 52
54 53 .LP
55 54 .nf
56 55 \fBCplFileConf *\fR\fBnew_CplFileConf\fR(\fBvoid\fR);
57 56 .fi
58 57
59 58 .LP
60 59 .nf
61 60 \fBvoid\fR \fBcfc_file_start\fR(\fB(CplFileConf *\fR\fIcfc\fR, \fBint\fR \fIstart_index\fR);
62 61 .fi
63 62
64 63 .LP
65 64 .nf
66 65 \fBvoid\fR \fBcfc_literal_escapes\fR(\fBCplFileConf *\fR\fIcfc\fR, \fBint\fR \fIliteral\fR);
67 66 .fi
68 67
69 68 .LP
70 69 .nf
71 70 \fBvoid\fR \fBcfc_set_check_fn\fR(\fBCplFileConf *\fR\fIcfc\fR, \fBCplCheckFn *\fR\fIchk_fn\fR,
72 71 \fBvoid *\fR\fIchk_data\fR);
73 72 .fi
74 73
75 74 .LP
76 75 .nf
77 76 \fBCPL_CHECK_FN\fR(\fBcpl_check_exe\fR);
78 77 .fi
79 78
80 79 .LP
81 80 .nf
82 81 \fBCplFileConf *\fR\fBdel_CplFileConf\fR(\fBCplFileConf *\fR\fIcfc\fR);
83 82 .fi
84 83
85 84 .LP
86 85 .nf
87 86 \fBCplMatches *\fR\fBcpl_complete_word\fR(\fBWordCompletion *\fR\fIcpl\fR, \fBconst char *\fR\fIline\fR,
88 87 \fBint\fR \fIword_end\fR, \fBvoid *\fR\fIdata\fR, \fBCplMatchFn *\fR\fImatch_fn\fR);
89 88 .fi
90 89
91 90 .LP
92 91 .nf
93 92 \fBCplMatches *\fR\fBcpl_recall_matches\fR(\fBWordCompletion *\fR\fIcpl\fR);
94 93 .fi
95 94
96 95 .LP
97 96 .nf
98 97 \fBint\fR \fBcpl_list_completions\fR(\fBCplMatches *\fR\fIresult\fR, \fBFILE *\fR\fIfp\fR, \fBint\fR \fIterm_width\fR);
99 98 .fi
100 99
101 100 .LP
102 101 .nf
103 102 \fBint\fR \fBcpl_add_completion\fR(\fBWordCompletion *\fR\fIcpl\fR, \fBconst char *\fR\fIline\fR,
104 103 \fBint\fR \fIword_start\fR, \fBint\fR \fIword_end\fR, \fBconst char *\fR\fIsuffix\fR,
105 104 \fBconst char *\fR\fItype_suffix\fR, \fBconst char *\fR\fIcont_suffix\fR);
106 105 .fi
107 106
108 107 .LP
↓ open down ↓ |
63 lines elided |
↑ open up ↑ |
109 108 .nf
110 109 \fBvoid\fR \fBcpl_record_error\fR(\fBWordCompletion *\fR\fIcpl\fR, \fBconst char *\fR\fIerrmsg\fR);
111 110 .fi
112 111
113 112 .LP
114 113 .nf
115 114 \fBconst char *\fR\fBcpl_last_error\fR(\fBWordCompletion *\fR\fIcpl\fR);
116 115 .fi
117 116
118 117 .SH DESCRIPTION
119 -.sp
120 -.LP
121 118 The \fBcpl_complete_word()\fR function is part of the \fBlibtecla\fR(3LIB)
122 119 library. It is usually called behind the scenes by \fBgl_get_line\fR(3TECLA),
123 120 but can also be called separately.
124 121 .sp
125 122 .LP
126 123 Given an input line containing an incomplete word to be completed, it calls a
127 124 user-provided callback function (or the provided file-completion callback
128 125 function) to look up all possible completion suffixes for that word. The
129 126 callback function is expected to look backward in the line, starting from the
130 127 specified cursor position, to find the start of the word to be completed, then
131 128 to look up all possible completions of that word and record them, one at a
132 129 time, by calling \fBcpl_add_completion()\fR.
133 130 .sp
134 131 .LP
135 132 The \fBnew_WordCompletion()\fR function creates the resources used by the
136 133 \fBcpl_complete_word()\fR function. In particular, it maintains the memory that
137 134 is used to return the results of calling \fBcpl_complete_word()\fR.
138 135 .sp
139 136 .LP
140 137 The \fBdel_WordCompletion()\fR function deletes the resources that were
141 138 returned by a previous call to \fBnew_WordCompletion()\fR. It always returns
142 139 \fINULL\fR (that is, a deleted object). It takes no action if the \fIcpl\fR
143 140 argument is \fINULL\fR.
144 141 .sp
145 142 .LP
146 143 The callback functions that look up possible completions should be defined with
147 144 the \fBCPL_MATCH_FN()\fR macro, which is defined in <\fBlibtecla.h\fR>.
148 145 Functions of this type are called by \fBcpl_complete_word()\fR, and all of the
149 146 arguments of the callback are those that were passed to said function. In
150 147 particular, the \fIline\fR argument contains the input line containing the word
151 148 to be completed, and \fIword_end\fR is the index of the character that follows
152 149 the last character of the incomplete word within this string. The callback is
153 150 expected to look backwards from \fIword_end\fR for the start of the incomplete
154 151 word. What constitutes the start of a word clearly depends on the application,
155 152 so it makes sense for the callback to take on this responsibility. For example,
156 153 the builtin filename completion function looks backwards until it encounters an
157 154 unescaped space or the start of the line. Having found the start of the word,
158 155 the callback should then lookup all possible completions of this word, and
159 156 record each completion with separate calls to \fBcpl_add_completion()\fR. If
160 157 the callback needs access to an application-specific symbol table, it can pass
161 158 it and any other data that it needs using the \fIdata\fR argument. This removes
162 159 any need for global variables.
163 160 .sp
164 161 .LP
165 162 The callback function should return 0 if no errors occur. On failure it should
166 163 return 1 and register a terse description of the error by calling
167 164 \fBcpl_record_error()\fR.
168 165 .sp
169 166 .LP
170 167 The last error message recorded by calling \fBcpl_record_error()\fR can
171 168 subsequently be queried by calling \fBcpl_last_error()\fR.
172 169 .sp
173 170 .LP
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
174 171 The \fBcpl_add_completion()\fR function is called zero or more times by the
175 172 completion callback function to record each possible completion in the
176 173 specified \fBWordCompletion\fR object. These completions are subsequently
177 174 returned by \fBcpl_complete_word()\fR. The \fIcpl\fR, \fIline\fR, and
178 175 \fIword_end\fR arguments should be those that were passed to the callback
179 176 function. The \fIword_start\fR argument should be the index within the input
180 177 line string of the start of the word that is being completed. This should equal
181 178 \fIword_end\fR if a zero-length string is being completed. The \fIsuffix\fR
182 179 argument is the string that would have to be appended to the incomplete word to
183 180 complete it. If this needs any quoting (for example, the addition of
184 -backslashes before special charaters) to be valid within the displayed input
181 +backslashes before special characters) to be valid within the displayed input
185 182 line, this should be included. A copy of the suffix string is allocated
186 183 internally, so there is no need to maintain your copy of the string after
187 184 \fBcpl_add_completion()\fR returns.
188 185 .sp
189 186 .LP
190 187 In the array of possible completions that the \fBcpl_complete_word()\fR
191 188 function returns, the suffix recorded by \fBcpl_add_completion()\fR is listed
192 -along with the concatentation of this suffix with the word that lies between
189 +along with the concatenation of this suffix with the word that lies between
193 190 \fIword_start\fR and \fIword_end\fR in the input line.
194 191 .sp
195 192 .LP
196 193 The \fItype_suffix\fR argument specifies an optional string to be appended to
197 194 the completion if it is displayed as part of a list of completions by
198 -\fIcpl_list_completions\fR. The intention is that this indicate to the user the
195 +\fIcpl_list_completions\fR. The intention is that this indicates to the user the
199 196 type of each completion. For example, the file completion function places a
200 197 directory separator after completions that are directories, to indicate their
201 -nature to the user. Similary, if the completion were a function, you could
198 +nature to the user. Similarly, if the completion were a function, you could
202 199 indicate this to the user by setting \fItype_suffix\fR to "()". Note that the
203 200 \fItype_suffix\fR string is not copied, so if the argument is not a literal
204 201 string between speech marks, be sure that the string remains valid for at least
205 202 as long as the results of \fBcpl_complete_word()\fR are needed.
206 203 .sp
207 204 .LP
208 205 The \fIcont_suffix\fR argument is a continuation suffix to append to the
209 206 completed word in the input line if this is the only completion. This is
210 207 something that is not part of the completion itself, but that gives the user an
211 208 indication about how they might continue to extend the token. For example, the
212 209 file-completion callback function adds a directory separator if the completed
213 210 word is a directory. If the completed word were a function name, you could
214 211 similarly aid the user by arranging for an open parenthesis to be appended.
215 212 .sp
216 213 .LP
217 -The \fBcpl_complete_word()\fR is normally called behind the scenes by
214 +The \fBcpl_complete_word()\fR function is normally called behind the scenes by
218 215 \fBgl_get_line\fR(3TECLA), but can also be called separately if you separately
219 216 allocate a \fBWordCompletion\fR object. It performs word completion, as
220 217 described at the beginning of this section. Its first argument is a resource
221 218 object previously returned by \fBnew_WordCompletion()\fR. The \fIline\fR
222 219 argument is the input line string, containing the word to be completed. The
223 220 \fIword_end\fR argument contains the index of the character in the input line,
224 221 that just follows the last character of the word to be completed. When called
225 222 by \fBgl_get_line()\fR, this is the character over which the user pressed TAB.
226 223 The \fImatch_fn\fR argument is the function pointer of the callback function
227 224 which will lookup possible completions of the word, as described above, and the
228 225 \fIdata\fR argument provides a way for the application to pass arbitrary data
229 226 to the callback function.
230 227 .sp
231 228 .LP
232 229 If no errors occur, the \fBcpl_complete_word()\fR function returns a pointer to
233 230 a \fBCplMatches\fR container, as defined below. This container is allocated as
234 231 part of the \fIcpl\fR object that was passed to \fBcpl_complete_word()\fR, and
235 232 will thus change on each call which uses the same \fIcpl\fR argument.
236 233 .sp
237 234 .in +2
238 235 .nf
239 236 typedef struct {
240 237 char *completion; /* A matching completion */
241 238 /* string */
242 239 char *suffix; /* The part of the */
243 240 /* completion string which */
244 241 /* would have to be */
245 242 /* appended to complete the */
246 243 /* original word. */
247 244 const char *type_suffix; /* A suffix to be added when */
248 245 /* listing completions, to */
249 246 /* indicate the type of the */
250 247 /* completion. */
251 248 } CplMatch;
252 249
253 250 typedef struct {
254 251 char *suffix; /* The common initial part */
255 252 /* of all of the completion */
256 253 /* suffixes. */
257 254 const char *cont_suffix; /* Optional continuation */
258 255 /* string to be appended to */
259 256 /* the sole completion when */
260 257 /* nmatch==1. */
261 258 CplMatch *matches; /* The array of possible */
262 259 /* completion strings, */
263 260 /* sorted into lexical */
264 261 /* order. */
265 262 int nmatch; /* The number of elements in */
266 263 /* the above matches[] */
267 264 /* array. */
268 265 } CplMatches;
269 266 .fi
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
270 267 .in -2
271 268
272 269 .sp
273 270 .LP
274 271 If an error occurs during completion, \fBcpl_complete_word()\fR returns
275 272 \fINULL\fR. A description of the error can be acquired by calling the
276 273 \fBcpl_last_error()\fR function.
277 274 .sp
278 275 .LP
279 276 The \fBcpl_last_error()\fR function returns a terse description of the error
280 -which occurred on the last call to \fBcpl_com plete_word()\fR or
277 +which occurred on the last call to \fBcpl_complete_word()\fR or
281 278 \fBcpl_add_completion()\fR.
282 279 .sp
283 280 .LP
284 281 As a convenience, the return value of the last call to
285 282 \fBcpl_complete_word()\fR can be recalled at a later time by calling
286 283 \fBcpl_recall_matches()\fR. If \fBcpl_complete_word()\fR returned \fINULL\fR,
287 284 so will \fBcpl_recall_matches()\fR.
288 285 .sp
289 286 .LP
290 287 When the \fBcpl_complete_word()\fR function returns multiple possible
291 288 completions, the \fBcpl_list_completions()\fR function can be called upon to
292 289 list them, suitably arranged across the available width of the terminal. It
293 290 arranges for the displayed columns of completions to all have the same width,
294 291 set by the longest completion. It also appends the \fItype_suffix\fR strings
295 292 that were recorded with each completion, thus indicating their types to the
296 293 user.
297 294 .SS "Builtin Filename completion Callback"
298 -.sp
299 -.LP
300 -By default the \fBgl_get_line()\fR function, passes the
295 +By default the \fBgl_get_line()\fR function passes the
301 296 \fBCPL_MATCH_FN\fR(\fBcps_file_completions\fR) completion callback function to
302 297 \fBcpl_complete_word()\fR. This function can also be used separately, either by
303 298 sending it to \fBcpl_complete_word()\fR, or by calling it directly from your
304 299 own completion callback function.
305 300 .sp
306 301 .in +2
307 302 .nf
308 303 #define CPL_MATCH_FN(fn) int (fn)(WordCompletion *cpl, \e
309 304 void *data, const char *line, \e
310 305 int word_end)
311 306
312 307 typedef CPL_MATCH_FN(CplMatchFn);
313 308
314 309 CPL_MATCH_FN(cpl_file_completions);
315 310 .fi
316 311 .in -2
317 312
318 313 .sp
319 314 .LP
320 315 Certain aspects of the behavior of this callback can be changed via its
321 316 \fIdata\fR argument. If you are happy with its default behavior you can pass
322 317 \fINULL\fR in this argument. Otherwise it should be a pointer to a
323 318 \fBCplFileConf\fR object, previously allocated by calling
324 319 \fBnew_CplFileConf()\fR.
325 320 .sp
326 321 .LP
327 322 \fBCplFileConf\fR objects encapsulate the configuration parameters of
328 323 \fBcpl_file_completions()\fR. These parameters, which start out with default
329 324 values, can be changed by calling the accessor functions described below.
330 325 .sp
331 326 .LP
332 327 By default, the \fBcpl_file_completions()\fR callback function searches
333 328 backwards for the start of the filename being completed, looking for the first
334 329 unescaped space or the start of the input line. If you wish to specify a
335 330 different location, call \fBcfc_file_start()\fR with the index at which the
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
336 331 filename starts in the input line. Passing \fIstart_index\fR=-1 reenables the
337 332 default behavior.
338 333 .sp
339 334 .LP
340 335 By default, when \fBcpl_file_completions()\fR looks at a filename in the input
341 336 line, each lone backslash in the input line is interpreted as being a special
342 337 character which removes any special significance of the character which follows
343 338 it, such as a space which should be taken as part of the filename rather than
344 339 delimiting the start of the filename. These backslashes are thus ignored while
345 340 looking for completions, and subsequently added before spaces, tabs and literal
346 -back slashes in the list of completions. To have unescaped back slashes treated
341 +backslashes in the list of completions. To have unescaped backslashes treated
347 342 as normal characters, call \fBcfc_literal_escapes()\fR with a non-zero value in
348 343 its \fIliteral\fR argument.
349 344 .sp
350 345 .LP
351 346 By default, \fBcpl_file_completions()\fR reports all files whose names start
352 347 with the prefix that is being completed. If you only want a selected subset of
353 348 these files to be reported in the list of completions, you can arrange this by
354 349 providing a callback function which takes the full pathname of a file, and
355 350 returns 0 if the file should be ignored, or 1 if the file should be included in
356 351 the list of completions. To register such a function for use by
357 352 \fBcpl_file_completions()\fR, call \fBcfc_set_check_fn()\fR, and pass it a
358 353 pointer to the function, together with a pointer to any data that you would
359 354 like passed to this callback whenever it is called. Your callback can make its
360 355 decisions based on any property of the file, such as the filename itself,
361 356 whether the file is readable, writable or executable, or even based on what the
362 357 file contains.
363 358 .sp
364 359 .in +2
365 360 .nf
366 361 #define CPL_CHECK_FN(fn) int (fn)(void *data, \e
367 362 const char *pathname)
368 363
369 364 typedef CPL_CHECK_FN(CplCheckFn);
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
370 365
371 366 void cfc_set_check_fn(CplFileConf *cfc, CplCheckFn *chk_fn, \e
372 367 void *chk_data);
373 368 .fi
374 369 .in -2
375 370
376 371 .sp
377 372 .LP
378 373 The \fBcpl_check_exe()\fR function is a provided callback of the above type,
379 374 for use with \fBcpl_file_completions()\fR. It returns non-zero if the filename
380 -that it is given represents a normal file that the user has execute permission
381 -to. You could use this to have \fBcpl_file_completions()\fR only list
375 +that it is given represents a normal file that the user has permission to
376 +execute. You could use this to have \fBcpl_file_completions()\fR only list
382 377 completions of executable files.
383 378 .sp
384 379 .LP
385 380 When you have finished with a \fBCplFileConf\fR variable, you can pass it to
386 381 the \fBdel_CplFileConf()\fR destructor function to reclaim its memory.
387 382 .SS "Thread Safety"
388 -.sp
389 -.LP
390 383 It is safe to use the facilities of this module in multiple threads, provided
391 384 that each thread uses a separately allocated \fBWordCompletion\fR object. In
392 385 other words, if two threads want to do word completion, they should each call
393 386 \fBnew_WordCompletion()\fR to allocate their own completion objects.
394 387 .SH ATTRIBUTES
395 -.sp
396 -.LP
397 388 See \fBattributes\fR(5) for descriptions of the following attributes:
398 389 .sp
399 390
400 391 .sp
401 392 .TS
402 393 box;
403 394 c | c
404 395 l | l .
405 396 ATTRIBUTE TYPE ATTRIBUTE VALUE
406 397 _
407 398 Interface Stability Evolving
408 399 _
409 400 MT-Level MT-Safe
410 401 .TE
411 402
412 403 .SH SEE ALSO
413 -.sp
414 -.LP
415 404 \fBef_expand_file\fR(3TECLA), \fBgl_get_line\fR(3TECLA), \fBlibtecla\fR(3LIB),
416 405 \fBpca_lookup_file\fR(3TECLA), \fBattributes\fR(5)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX