X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=complete.c;h=5e66da81290cac0f9fe34348a45405169674e206;hp=fcb9269ff8a233a949fb30b93104e4dbca785fa4;hb=38c7d971a4e206284e06e958511bb55694cb4deb;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/complete.c b/complete.c index fcb9269..5e66da8 100644 --- a/complete.c +++ b/complete.c @@ -1,19 +1,10 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2000 Michael R. Elkins - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -21,14 +12,16 @@ #endif #include "mutt.h" -#ifdef USE_IMAP -#include "mailbox.h" -#include "imap.h" -#endif +#include "mx.h" +#include #ifdef USE_NNTP #include "nntp.h" #endif +#include +#include +#include "lib/debug.h" + #include #include #include @@ -50,28 +43,26 @@ int mutt_complete (char *s, size_t slen) char dirpart[_POSIX_PATH_MAX], exp_dirpart[_POSIX_PATH_MAX]; char filepart[_POSIX_PATH_MAX]; -#ifdef USE_IMAP char imap_path[LONG_STRING]; -#endif - dprint (2, (debugfile, "mutt_complete: completing %s\n", s)); + debug_print (2, ("completing %s\n", s)); #ifdef USE_NNTP if (option (OPTNEWS)) { LIST *l = CurrentNewsSrv->list; - strfcpy (filepart, s, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), s); /* * special case to handle when there is no filepart yet. * find the first subscribed newsgroup */ - if ((len = mutt_strlen (filepart)) == 0) { + if ((len = m_strlen(filepart)) == 0) { for (; l; l = l->next) { NNTP_DATA *data = (NNTP_DATA *) l->data; if (data && data->subscribed) { - strfcpy (filepart, data->group, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), data->group); init++; l = l->next; break; @@ -83,7 +74,7 @@ int mutt_complete (char *s, size_t slen) NNTP_DATA *data = (NNTP_DATA *) l->data; if (data && data->subscribed && - mutt_strncmp (data->group, filepart, len) == 0) { + m_strncmp(data->group, filepart, len) == 0) { if (init) { for (i = 0; filepart[i] && data->group[i]; i++) { if (filepart[i] != data->group[i]) { @@ -94,7 +85,7 @@ int mutt_complete (char *s, size_t slen) filepart[i] = 0; } else { - strfcpy (filepart, data->group, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), data->group); init = 1; } } @@ -106,61 +97,55 @@ int mutt_complete (char *s, size_t slen) } #endif -#ifdef USE_IMAP /* we can use '/' as a delimiter, imap_complete rewrites it */ if (*s == '=' || *s == '+' || *s == '!') { - if (*s == '!') - p = NONULL (Spoolfile); - else - p = NONULL (Maildir); - - mutt_concat_path (imap_path, p, s + 1, sizeof (imap_path)); + const char *q = NONULL(*s == '!' ? Spoolfile : Maildir); + mutt_concat_path(imap_path, sizeof(imap_path), q, s + 1); } else - strfcpy (imap_path, s, sizeof (imap_path)); + m_strcpy(imap_path, sizeof(imap_path), s); - if (mx_is_imap (imap_path)) + if (mx_get_magic (imap_path) == M_IMAP) return imap_complete (s, slen, imap_path); -#endif if (*s == '=' || *s == '+' || *s == '!') { dirpart[0] = *s; dirpart[1] = 0; if (*s == '!') - strfcpy (exp_dirpart, NONULL (Spoolfile), sizeof (exp_dirpart)); + m_strcpy(exp_dirpart, sizeof(exp_dirpart), NONULL(Spoolfile)); else - strfcpy (exp_dirpart, NONULL (Maildir), sizeof (exp_dirpart)); + m_strcpy(exp_dirpart, sizeof(exp_dirpart), NONULL(Maildir)); if ((p = strrchr (s, '/'))) { char buf[_POSIX_PATH_MAX]; *p++ = 0; - mutt_concat_path (buf, exp_dirpart, s + 1, sizeof (buf)); - strfcpy (exp_dirpart, buf, sizeof (exp_dirpart)); + mutt_concat_path(buf, sizeof(buf), exp_dirpart, s + 1); + m_strcpy(exp_dirpart, sizeof(exp_dirpart), buf); snprintf (buf, sizeof (buf), "%s%s/", dirpart, s + 1); - strfcpy (dirpart, buf, sizeof (dirpart)); - strfcpy (filepart, p, sizeof (filepart)); + m_strcpy(dirpart, sizeof(dirpart), buf); + m_strcpy(filepart, sizeof(filepart), p); } else - strfcpy (filepart, s + 1, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), s + 1); dirp = opendir (exp_dirpart); } else { if ((p = strrchr (s, '/'))) { if (p == s) { /* absolute path */ p = s + 1; - strfcpy (dirpart, "/", sizeof (dirpart)); + m_strcpy(dirpart, sizeof(dirpart), "/"); exp_dirpart[0] = 0; - strfcpy (filepart, p, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), p); dirp = opendir (dirpart); } else { *p = 0; len = (size_t) (p - s); - strncpy (dirpart, s, len); + memcpy(dirpart, s, len); dirpart[len] = 0; p++; - strfcpy (filepart, p, sizeof (filepart)); - strfcpy (exp_dirpart, dirpart, sizeof (exp_dirpart)); + m_strcpy(filepart, sizeof(filepart), p); + m_strcpy(exp_dirpart, sizeof(exp_dirpart), dirpart); mutt_expand_path (exp_dirpart, sizeof (exp_dirpart)); dirp = opendir (exp_dirpart); } @@ -168,15 +153,13 @@ int mutt_complete (char *s, size_t slen) else { /* no directory name, so assume current directory. */ dirpart[0] = 0; - strfcpy (filepart, s, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), s); dirp = opendir ("."); } } if (dirp == NULL) { - dprint (1, - (debugfile, "mutt_complete(): %s: %s (errno %d).\n", exp_dirpart, - strerror (errno), errno)); + debug_print (1, ("%s: %s (errno %d).\n", exp_dirpart, strerror (errno), errno)); return (-1); } @@ -184,11 +167,11 @@ int mutt_complete (char *s, size_t slen) * 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 = m_strlen(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)); + if (m_strcmp(".", de->d_name) != 0 + && m_strcmp("..", de->d_name) != 0) { + m_strcpy(filepart, sizeof(filepart), de->d_name); init++; break; } @@ -196,7 +179,7 @@ int mutt_complete (char *s, size_t slen) } while ((de = readdir (dirp)) != NULL) { - if (mutt_strncmp (de->d_name, filepart, len) == 0) { + if (m_strncmp(de->d_name, filepart, len) == 0) { if (init) { for (i = 0; filepart[i] && de->d_name[i]; i++) { if (filepart[i] != de->d_name[i]) { @@ -210,19 +193,19 @@ int mutt_complete (char *s, size_t slen) char buf[_POSIX_PATH_MAX]; struct stat st; - strfcpy (filepart, de->d_name, sizeof (filepart)); + m_strcpy(filepart, sizeof(filepart), de->d_name); /* check to see if it is a directory */ if (dirpart[0]) { - strfcpy (buf, exp_dirpart, sizeof (buf)); - strfcpy (buf + strlen (buf), "/", sizeof (buf) - strlen (buf)); + m_strcpy(buf, sizeof(buf), exp_dirpart); + m_strcpy(buf + m_strlen(buf), sizeof(buf) - m_strlen(buf), "/"); } else buf[0] = 0; - strfcpy (buf + strlen (buf), filepart, sizeof (buf) - strlen (buf)); + m_strcpy(buf + m_strlen(buf), sizeof(buf) - m_strlen(buf), filepart); if (stat (buf, &st) != -1 && (st.st_mode & S_IFDIR)) - strfcpy (filepart + strlen (filepart), "/", - sizeof (filepart) - strlen (filepart)); + m_strcpy(filepart + m_strlen(filepart), + sizeof(filepart) - m_strlen(filepart), "/"); init = 1; } } @@ -230,14 +213,14 @@ int mutt_complete (char *s, size_t slen) closedir (dirp); if (dirpart[0]) { - strfcpy (s, dirpart, slen); - if (mutt_strcmp ("/", dirpart) != 0 && dirpart[0] != '=' + m_strcpy(s, slen, dirpart); + if (m_strcmp("/", dirpart) != 0 && dirpart[0] != '=' && dirpart[0] != '+') - strfcpy (s + strlen (s), "/", slen - strlen (s)); - strfcpy (s + strlen (s), filepart, slen - strlen (s)); + m_strcpy(s + m_strlen(s), slen - m_strlen(s), "/"); + m_strcpy(s + m_strlen(s), slen - m_strlen(s), filepart); } else - strfcpy (s, filepart, slen); + m_strcpy(s, slen, filepart); return (init ? 0 : -1); }