Attempt to complete a partial pathname.
Given a partial pathname, fill in as much of the rest of the path as is unique.
58{
59 const char *p = NULL;
60 DIR *dir = NULL;
61 struct dirent *de = NULL;
62 int init = 0;
63 size_t len;
64 struct Buffer *dirpart = NULL;
65 struct Buffer *exp_dirpart = NULL;
66 struct Buffer *filepart = NULL;
68 struct Buffer *imap_path = NULL;
69 int rc;
70
72
75
78
80
82 if ((ch == '=') || (ch == '+') || (ch == '!'))
83 {
84 if (ch == '!')
86 else
88
90 }
91 else
92 {
94 }
95
97 {
100 return rc;
101 }
102
104
109
111 if ((ch == '=') || (ch == '+') || (ch == '!'))
112 {
114 if (ch == '!')
116 else
119 if (p)
120 {
126 }
127 else
128 {
130 }
132 }
133 else
134 {
136 if (p)
137 {
139 {
144 }
145 else
146 {
152 }
153 }
154 else
155 {
156
159 }
160 }
161
162 if (!dir)
163 {
165 strerror(errno), errno);
166 goto cleanup;
167 }
168
169
170
172 if (len == 0)
173 {
174 while ((de = readdir(dir)))
175 {
177 {
179 init++;
180 break;
181 }
182 }
183 }
184
185 while ((de = readdir(dir)))
186 {
188 {
189 if (init)
190 {
191 char *cp = filepart->
data;
192
193 for (int i = 0; (*cp != '\0') && (de->d_name[i] != '\0'); i++, cp++)
194 {
195 if (*cp != de->d_name[i])
196 break;
197 }
198 *cp = '\0';
200 }
201 else
202 {
203 struct stat st = { 0 };
204
206
207
209 {
211 }
212 else
213 {
216 }
218 if ((stat(
buf_string(tmp), &st) != -1) && (st.st_mode & S_IFDIR))
220 init = 1;
221 }
222 }
223 }
224 closedir(dir);
225
227 {
229 }
230 else
231 {
235 {
237 }
239 }
240
241cleanup:
246
247 return init ? 0 : -1;
248}
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?
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
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_strcpy(struct Buffer *buf, const char *s)
Copy a string into 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.
@ MUTT_IMAP
'IMAP' Mailbox type
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.
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.
char * data
Pointer to data.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.