Attempt to complete a partial pathname.
Given a partial pathname, fill in as much of the rest of the path as is unique.
56{
57 const char *p = NULL;
58 DIR *dir = NULL;
59 struct dirent *de = NULL;
60 int init = 0;
61 size_t len;
62 struct Buffer *dirpart = NULL;
63 struct Buffer *exp_dirpart = NULL;
64 struct Buffer *filepart = NULL;
66 struct Buffer *imap_path = NULL;
67 int rc;
68
70
73
76
78
80 if ((ch == '=') || (ch == '+') || (ch == '!'))
81 {
82 if (ch == '!')
84 else
86
88 }
89 else
90 {
92 }
93
95 {
98 return rc;
99 }
100
102
107
109 if ((ch == '=') || (ch == '+') || (ch == '!'))
110 {
112 if (ch == '!')
114 else
117 if (p)
118 {
124 }
125 else
126 {
128 }
130 }
131 else
132 {
134 if (p)
135 {
137 {
142 }
143 else
144 {
150 }
151 }
152 else
153 {
154
157 }
158 }
159
160 if (!dir)
161 {
163 strerror(errno), errno);
164 goto cleanup;
165 }
166
167
168
170 if (len == 0)
171 {
172 while ((de = readdir(dir)))
173 {
175 {
177 init++;
178 break;
179 }
180 }
181 }
182
183 while ((de = readdir(dir)))
184 {
186 {
187 if (init)
188 {
189 char *cp = filepart->
data;
190
191 for (int i = 0; (*cp != '\0') && (de->d_name[i] != '\0'); i++, cp++)
192 {
193 if (*cp != de->d_name[i])
194 break;
195 }
196 *cp = '\0';
198 }
199 else
200 {
201 struct stat st = { 0 };
202
204
205
207 {
209 }
210 else
211 {
214 }
216 if ((stat(
buf_string(tmp), &st) != -1) && (st.st_mode & S_IFDIR))
218 init = 1;
219 }
220 }
221 }
222 closedir(dir);
223
225 {
227 }
228 else
229 {
233 {
235 }
237 }
238
239cleanup:
244
245 return init ? 0 : -1;
246}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
size_t buf_concatn_path(struct Buffer *buf, const char *dir, size_t dirlen, const char *fname, size_t fnamelen)
Join a directory name and a filename.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
size_t buf_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
@ MUTT_OPENDIR_NONE
Plain opendir()
bool OptNews
(pseudo) used to change reader mode
#define mutt_debug(LEVEL,...)
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
int imap_complete(struct Buffer *buf, const char *path)
Try to complete an IMAP folder path.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
@ MUTT_IMAP
'IMAP' Mailbox type
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
int nntp_complete(struct Buffer *buf)
Auto-complete NNTP newsgroups.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
String manipulation buffer.