diff options
Diffstat (limited to 'complete.c')
-rw-r--r-- | complete.c | 135 |
1 files changed, 76 insertions, 59 deletions
@@ -44,13 +44,18 @@ int mutt_complete (char *s, size_t slen) struct dirent *de; int i ,init=0; size_t len; - char dirpart[_POSIX_PATH_MAX], exp_dirpart[_POSIX_PATH_MAX]; - char filepart[_POSIX_PATH_MAX]; + BUFFER *dirpart = NULL; + BUFFER *exp_dirpart = NULL; + BUFFER *filepart = NULL; + BUFFER *buf = NULL; + #ifdef USE_IMAP - char imap_path[LONG_STRING]; + BUFFER *imap_path = NULL; + int rc; dprint (2, (debugfile, "mutt_complete: completing %s\n", s)); + imap_path = mutt_buffer_pool_get (); /* we can use '/' as a delimiter, imap_complete rewrites it */ if (*s == '=' || *s == '+' || *s == '!') { @@ -59,38 +64,45 @@ int mutt_complete (char *s, size_t slen) else p = NONULL (Maildir); - mutt_concat_path (imap_path, p, s+1, sizeof (imap_path)); + mutt_buffer_concat_path (imap_path, p, s+1); } else - strfcpy (imap_path, s, sizeof(imap_path)); + mutt_buffer_strcpy (imap_path, s); - if (mx_is_imap (imap_path)) - return imap_complete (s, slen, imap_path); + if (mx_is_imap (mutt_b2s (imap_path))) + { + rc = imap_complete (s, slen, mutt_b2s (imap_path)); + mutt_buffer_pool_release (&imap_path); + return rc; + } + + mutt_buffer_pool_release (&imap_path); #endif + dirpart = mutt_buffer_pool_get (); + exp_dirpart = mutt_buffer_pool_get (); + filepart = mutt_buffer_pool_get (); + buf = mutt_buffer_pool_get (); + if (*s == '=' || *s == '+' || *s == '!') { - dirpart[0] = *s; - dirpart[1] = 0; + mutt_buffer_addch (dirpart, *s); if (*s == '!') - strfcpy (exp_dirpart, NONULL (Spoolfile), sizeof (exp_dirpart)); + mutt_buffer_strcpy (exp_dirpart, NONULL (Spoolfile)); else - strfcpy (exp_dirpart, NONULL (Maildir), sizeof (exp_dirpart)); + mutt_buffer_strcpy (exp_dirpart, NONULL (Maildir)); if ((p = strrchr (s, '/'))) { - char buf[_POSIX_PATH_MAX]; - if (mutt_concatn_path (buf, sizeof(buf), exp_dirpart, strlen(exp_dirpart), - s + 1, (size_t)(p - s - 1)) == NULL) - { - return -1; - } - strfcpy (exp_dirpart, buf, sizeof (exp_dirpart)); - mutt_substrcpy(dirpart, s, p+1, sizeof(dirpart)); - strfcpy (filepart, p + 1, sizeof (filepart)); + mutt_buffer_concatn_path (buf, + mutt_b2s (exp_dirpart), mutt_buffer_len (exp_dirpart), + s + 1, (size_t)(p - s - 1)); + mutt_buffer_strcpy (exp_dirpart, mutt_b2s (buf)); + mutt_buffer_substrcpy (dirpart, s, p+1); + mutt_buffer_strcpy (filepart, p + 1); } else - strfcpy (filepart, s + 1, sizeof (filepart)); - dirp = opendir (exp_dirpart); + mutt_buffer_strcpy (filepart, s + 1); + dirp = opendir (mutt_b2s (exp_dirpart)); } else { @@ -99,46 +111,45 @@ int mutt_complete (char *s, size_t slen) if (p == s) /* absolute path */ { p = s + 1; - strfcpy (dirpart, "/", sizeof (dirpart)); - exp_dirpart[0] = 0; - strfcpy (filepart, p, sizeof (filepart)); - dirp = opendir (dirpart); + mutt_buffer_strcpy (dirpart, "/"); + mutt_buffer_strcpy (filepart, p); + dirp = opendir (mutt_b2s (dirpart)); } else { - mutt_substrcpy(dirpart, s, p, sizeof(dirpart)); - strfcpy (filepart, p + 1, sizeof (filepart)); - strfcpy (exp_dirpart, dirpart, sizeof (exp_dirpart)); - mutt_expand_path (exp_dirpart, sizeof (exp_dirpart)); - dirp = opendir (exp_dirpart); + mutt_buffer_substrcpy (dirpart, s, p); + mutt_buffer_strcpy (filepart, p + 1); + mutt_buffer_strcpy (exp_dirpart, mutt_b2s (dirpart)); + mutt_buffer_expand_path (exp_dirpart); + dirp = opendir (mutt_b2s (exp_dirpart)); } } else { /* no directory name, so assume current directory. */ - dirpart[0] = 0; - strfcpy (filepart, s, sizeof (filepart)); + mutt_buffer_strcpy (filepart, s); dirp = opendir ("."); } } if (dirp == NULL) { - dprint (1, (debugfile, "mutt_complete(): %s: %s (errno %d).\n", exp_dirpart, strerror (errno), errno)); - return (-1); + dprint (1, (debugfile, "mutt_complete(): %s: %s (errno %d).\n", + mutt_b2s (exp_dirpart), strerror (errno), errno)); + goto cleanup; } /* * special case to handle when there is no filepart yet. find the first * file/directory which is not ``.'' or ``..'' */ - if ((len = mutt_strlen (filepart)) == 0) + if ((len = mutt_buffer_len (filepart)) == 0) { while ((de = readdir (dirp)) != NULL) { if (mutt_strcmp (".", de->d_name) != 0 && mutt_strcmp ("..", de->d_name) != 0) { - strfcpy (filepart, de->d_name, sizeof (filepart)); + mutt_buffer_strcpy (filepart, de->d_name); init++; break; } @@ -147,54 +158,60 @@ int mutt_complete (char *s, size_t slen) while ((de = readdir (dirp)) != NULL) { - if (mutt_strncmp (de->d_name, filepart, len) == 0) + if (mutt_strncmp (de->d_name, mutt_b2s (filepart), len) == 0) { if (init) { - for (i=0; filepart[i] && de->d_name[i]; i++) + char *fpch; + + for (i=0, fpch = filepart->data; *fpch && de->d_name[i]; i++, fpch++) { - if (filepart[i] != de->d_name[i]) - { - filepart[i] = 0; + if (*fpch != de->d_name[i]) break; - } } - filepart[i] = 0; + *fpch = 0; + mutt_buffer_fix_dptr (filepart); } else { - char buf[_POSIX_PATH_MAX]; struct stat st; - strfcpy (filepart, de->d_name, sizeof(filepart)); + mutt_buffer_strcpy (filepart, de->d_name); /* check to see if it is a directory */ - if (dirpart[0]) + if (mutt_buffer_len (dirpart)) { - strfcpy (buf, exp_dirpart, sizeof (buf)); - strfcpy (buf + strlen (buf), "/", sizeof (buf) - strlen (buf)); + mutt_buffer_strcpy (buf, mutt_b2s (exp_dirpart)); + mutt_buffer_addch (buf, '/'); } else - buf[0] = 0; - strfcpy (buf + strlen (buf), filepart, sizeof (buf) - strlen (buf)); - if (stat (buf, &st) != -1 && (st.st_mode & S_IFDIR)) - strfcpy (filepart + strlen (filepart), "/", - sizeof (filepart) - strlen (filepart)); + mutt_buffer_clear (buf); + mutt_buffer_addstr (buf, mutt_b2s (filepart)); + if (stat (mutt_b2s (buf), &st) != -1 && (st.st_mode & S_IFDIR)) + mutt_buffer_addch (filepart, '/'); init = 1; } } } closedir (dirp); - if (dirpart[0]) + if (mutt_buffer_len (dirpart)) { - strfcpy (s, dirpart, slen); - if (mutt_strcmp ("/", dirpart) != 0 && dirpart[0] != '=' && dirpart[0] != '+') + strfcpy (s, mutt_b2s (dirpart), slen); + if (mutt_strcmp ("/", mutt_b2s (dirpart)) != 0 && + mutt_b2s (dirpart)[0] != '=' && + mutt_b2s (dirpart)[0] != '+') strfcpy (s + strlen (s), "/", slen - strlen (s)); - strfcpy (s + strlen (s), filepart, slen - strlen (s)); + strfcpy (s + strlen (s), mutt_b2s (filepart), slen - strlen (s)); } else - strfcpy (s, filepart, slen); + strfcpy (s, mutt_b2s (filepart), slen); + +cleanup: + mutt_buffer_pool_release (&dirpart); + mutt_buffer_pool_release (&exp_dirpart); + mutt_buffer_pool_release (&filepart); + mutt_buffer_pool_release (&buf); return (init ? 0 : -1); } |