Attempt to complete a partial pathname.
Given a partial pathname, fill in as much of the rest of the path as is unique.
59{
60 const char *p = NULL;
61 DIR *dir = NULL;
62 struct dirent *de = NULL;
63 int init = 0;
64 size_t len;
65 struct Buffer *dirpart = NULL;
66 struct Buffer *exp_dirpart = NULL;
67 struct Buffer *filepart = NULL;
69 struct Buffer *imap_path = NULL;
70 int rc;
71
73
76
79
81
83 if ((ch == '=') || (ch == '+') || (ch == '!'))
84 {
85 if (ch == '!')
87 else
89
91 }
92 else
93 {
95 }
96
98 {
101 return rc;
102 }
103
105
110
112 if ((ch == '=') || (ch == '+') || (ch == '!'))
113 {
115 if (ch == '!')
117 else
120 if (p)
121 {
127 }
128 else
129 {
131 }
133 }
134 else
135 {
137 if (p)
138 {
140 {
145 }
146 else
147 {
153 }
154 }
155 else
156 {
157
160 }
161 }
162
163 if (!dir)
164 {
166 strerror(errno), errno);
167 goto cleanup;
168 }
169
170
171
173 if (len == 0)
174 {
175 while ((de = readdir(dir)))
176 {
178 {
180 init++;
181 break;
182 }
183 }
184 }
185
186 while ((de = readdir(dir)))
187 {
189 {
190 if (init)
191 {
192 char *cp = filepart->
data;
193
194 for (int i = 0; (*cp != '\0') && (de->d_name[i] != '\0'); i++, cp++)
195 {
196 if (*cp != de->d_name[i])
197 break;
198 }
199 *cp = '\0';
201 }
202 else
203 {
204 struct stat st = { 0 };
205
207
208
210 {
212 }
213 else
214 {
217 }
219 if ((stat(
buf_string(tmp), &st) != -1) && (st.st_mode & S_IFDIR))
221 init = 1;
222 }
223 }
224 }
225 closedir(dir);
226
228 {
230 }
231 else
232 {
236 {
238 }
240 }
241
242cleanup:
247
248 return init ? 0 : -1;
249}
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?
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 expand_path(struct Buffer *buf, bool regex)
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.