aboutsummaryrefslogtreecommitdiff
path: root/man/man3/complete.3
blob: b1478ddc5be733dbeeac679170fa9e6c399aaf3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
.TH COMPLETE 3
.SH NAME
complete \- file name completion
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.br
.B #include <complete.h>
.PP
.ft L
.nf
.ta \w'    'u +\w'    'u +\w'    'u +\w'    'u +\w'    'u
typedef struct Completion	Completion;
struct Completion{
	uchar advance;		/* whether forward progress has been made */
	uchar complete;	/* whether the completion now represents a file or directory */
	char *string;		/* the string to advance, suffixed " " or "/" for file or directory */
	int nmatch;		/* number of files that matched */
	int nfile;			/* number of files returned */
	char **filename;	/* their names */
};

.fi
.PP
.B
.ta \w'\fLchar* 'u

.PP
.B
Completion* complete(char *dir, char *s);
.PP
.B
void freecompletion(Completion *c);
.SH DESCRIPTION
The
.I complete
function implements file name completion.
Given a directory
.I dir
and a string
.IR s ,
it returns an analysis of the file names in that directory that begin with the string
.IR s .
The fields
.B nmatch
and
.B nfile
will be set to the number of files that match the prefix and
.B filename
will be filled in with their names.
If the file named is a directory, a slash character will be appended to it.
.PP
If no files match the string,
.B nmatch
will be zero, but
.I complete
will return the full set of files in the directory, with
.I nfile
set to their number.
.PP
The flag
.B advance
reports whether the string
.I s
can be extended without changing the set of files that match.  If true,
.B string
will be set to the extension; that is, the value of
.B string
may be appended to
.I s
by the caller to extend the embryonic file name unambiguously.
.PP
The flag
.B complete
reports whether the extended file name uniquely identifies a file.
If true,
.B string
will be suffixed with a blank, or a slash and a blank,
depending on whether the resulting file name identifies a plain file or a directory.
.PP
The
.I freecompletion
function frees a
.B Completion
structure and its contents.
.PP
In
.IR rio (1)
and
.IR acme (1),
file name completion is triggered by a control-F character or an Insert character.
.SH SOURCE
.B /usr/local/plan9/src/libcomplete
.SH SEE ALSO
.IR rio (1),
.IR acme (1)
.SH DIAGNOSTICS
The
.I complete
function returns a null pointer and sets
.I errstr
if the directory is unreadable or there is some other error.
.SH BUGS
The behavior of file name completion should be controlled by the plumber.