/*
+ * Copyright notice from original mutt:
* Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
- *
- * 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
#include "mutt.h"
#include "mapping.h"
#include "mutt_curses.h"
-#include "mutt_regex.h"
#include "history.h"
#include "keymap.h"
#include "mbyte.h"
#include "mutt_ssl.h"
#endif
-
-
#include "mx.h"
#include "init.h"
-#include "mailbox.h"
+
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+#include "lib/rx.h"
+#include "lib/list.h"
+#include "lib/debug.h"
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
+/* for synonym warning reports: synonym found during parsing */
+typedef struct {
+ char* f; /* file */
+ int l; /* line */
+ int n; /* new name (index) */
+ int o; /* old name (index) */
+} syn_t;
+
+/* for synonym warning reports: list of synonyms found */
+list2_t* Synonyms;
+/* for synonym warning reports: current rc file */
+char* CurRCFile = NULL;
+/* for synonym warning reports: current rc line */
+int CurRCLine = 0;
+
+/* for synonym warning reports: adds synonym to end of list */
+static void syn_add (int n, int o) {
+ syn_t* tmp = safe_malloc (sizeof (syn_t));
+ tmp->f = safe_strdup (CurRCFile);
+ tmp->l = CurRCLine;
+ tmp->n = n;
+ tmp->o = o;
+ list_push_back (&Synonyms, tmp);
+}
+
+/* for synonym warning reports: free single item (for list_del()) */
+static void syn_del (void** p) {
+ FREE(&(*(syn_t**) p)->f);
+ FREE(p);
+}
+
void toggle_quadoption (int opt)
{
int n = opt / 4;
int i;
for (i = 0; MuttVars[i].option; i++)
- if (mutt_strcmp (s, MuttVars[i].option) == 0)
+ if (mutt_strcmp (s, MuttVars[i].option) == 0) {
+ if (MuttVars[i].type == DT_SYN)
+ syn_add (mutt_option_index ((char *) MuttVars[i].data), i);
return (MuttVars[i].type ==
DT_SYN ? mutt_option_index ((char *) MuttVars[i].data) : i);
+ }
return (-1);
}
}
} while (pc && *pc != '`');
if (!pc) {
- dprint (1, (debugfile, "mutt_get_token: mismatched backtics\n"));
+ debug_print (1, ("mismatched backtics\n"));
return (-1);
}
- cmd = mutt_substrdup (tok->dptr, pc);
+ cmd = str_substrdup (tok->dptr, pc);
if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {
- dprint (1,
- (debugfile, "mutt_get_token: unable to fork command: %s",
- cmd));
+ debug_print (1, ("unable to fork command: %s\n", cmd));
FREE (&cmd);
return (-1);
}
if (*tok->dptr == '{') {
tok->dptr++;
if ((pc = strchr (tok->dptr, '}'))) {
- var = mutt_substrdup (tok->dptr, pc);
+ var = str_substrdup (tok->dptr, pc);
tok->dptr = pc + 1;
}
}
else {
for (pc = tok->dptr; isalpha ((unsigned char) *pc) || *pc == '_';
pc++);
- var = mutt_substrdup (tok->dptr, pc);
+ var = str_substrdup (tok->dptr, pc);
tok->dptr = pc;
}
if (var && (env = getenv (var)))
}
}
-static int add_to_rx_list (RX_LIST ** list, const char *s, int flags,
+static int add_to_rx_list (list2_t** list, const char *s, int flags,
BUFFER * err)
{
- RX_LIST *t, *last = NULL;
- REGEXP *rx;
+ rx_t* rx;
+ int i = 0;
if (!s || !*s)
return 0;
- if (!(rx = mutt_compile_regexp (s, flags))) {
+ if (!(rx = rx_compile (s, flags))) {
snprintf (err->data, err->dsize, "Bad regexp: %s\n", s);
return -1;
}
- /* check to make sure the item is not already on this list */
- for (last = *list; last; last = last->next) {
- if (ascii_strcasecmp (rx->pattern, last->rx->pattern) == 0) {
- /* already on the list, so just ignore it */
- last = NULL;
- break;
- }
- if (!last->next)
- break;
- }
-
- if (!*list || last) {
- t = mutt_new_rx_list ();
- t->rx = rx;
- if (last) {
- last->next = t;
- last = last->next;
- }
- else
- *list = last = t;
- }
- else /* duplicate */
- mutt_free_regexp (&rx);
-
+ i = rx_lookup ((*list), rx->pattern);
+ if (i >= 0)
+ rx_free (&rx);
+ else
+ list_push_back (list, rx);
return 0;
}
const char *templ, BUFFER * err)
{
SPAM_LIST *t = NULL, *last = NULL;
- REGEXP *rx;
+ rx_t* rx;
int n;
const char *p;
if (!pat || !*pat || !templ)
return 0;
- if (!(rx = mutt_compile_regexp (pat, REG_ICASE))) {
+ if (!(rx = rx_compile (pat, REG_ICASE))) {
snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat);
return -1;
}
* the template, and leaving t pointed at the current item.
*/
t = last;
- safe_free (&t->template);
+ FREE(t->template);
break;
}
if (!last->next)
spam = *list;
if (spam->rx && !mutt_strcmp (spam->rx->pattern, pat)) {
*list = spam->next;
- mutt_free_regexp (&spam->rx);
- safe_free (&spam->template);
- safe_free (&spam);
+ rx_free (&spam->rx);
+ FREE(&spam->template);
+ FREE(&spam);
return 1;
}
for (spam = prev->next; spam;) {
if (!mutt_strcmp (spam->rx->pattern, pat)) {
prev->next = spam->next;
- mutt_free_regexp (&spam->rx);
- safe_free (&spam->template);
- safe_free (&spam);
+ rx_free (&spam->rx);
+ FREE(spam->template);
+ FREE(spam);
spam = prev->next;
++nremoved;
}
}
}
-static int remove_from_rx_list (RX_LIST ** l, const char *str)
+static int remove_from_rx_list (list2_t** l, const char *str)
{
- RX_LIST *p, *last = NULL;
- int rv = -1;
+ int i = 0;
if (mutt_strcmp ("*", str) == 0) {
- mutt_free_rx_list (l); /* ``unCMD *'' means delete all current entries */
- rv = 0;
+ list_del (l, (list_del_t*) rx_free);
+ return (0);
}
else {
- p = *l;
- last = NULL;
- while (p) {
- if (ascii_strcasecmp (str, p->rx->pattern) == 0) {
- mutt_free_regexp (&p->rx);
- if (last)
- last->next = p->next;
- else
- (*l) = p->next;
- FREE (&p);
- rv = 0;
- }
- else {
- last = p;
- p = p->next;
- }
+ i = rx_lookup ((*l), str);
+ if (i >= 0) {
+ rx_t* r = list_pop_idx ((*l), i);
+ rx_free (&r);
+ return (0);
}
}
- return (rv);
+ return (-1);
}
static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
return 0;
}
-#if 0
-static int _parse_rx_list (BUFFER * buf, BUFFER * s, unsigned long data,
- BUFFER * err, int flags)
-{
- do {
- mutt_extract_token (buf, s, 0);
- if (add_to_rx_list ((RX_LIST **) data, buf->data, flags, err) != 0)
- return -1;
-
- }
- while (MoreArgs (s));
-
- return 0;
-}
-
-static int parse_rx_list (BUFFER * buf, BUFFER * s, unsigned long data,
- BUFFER * err)
-{
- return _parse_rx_list (buf, s, data, err, REG_ICASE);
-}
-
-static int parse_rx_unlist (BUFFER * buf, BUFFER * s, unsigned long data,
- BUFFER * err)
-{
- do {
- mutt_extract_token (buf, s, 0);
- if (mutt_strcmp (buf->data, "*") == 0) {
- mutt_free_rx_list ((RX_LIST **) data);
- break;
- }
- remove_from_rx_list ((RX_LIST **) data, buf->data);
- }
- while (MoreArgs (s));
-
- return 0;
-}
-#endif
-
static void _alternates_clean (void)
{
int i;
/* "*" is a special case. */
if (!mutt_strcmp (buf->data, "*")) {
mutt_free_spam_list (&SpamList);
- mutt_free_rx_list (&NoSpamList);
+ list_del (&NoSpamList, (list_del_t*) rx_free);
return 0;
}
}
else
for (tmp = Aliases; tmp; tmp = tmp->next) {
- if (mutt_strcasecmp (buf->data, tmp->name) == 0) {
+ if (safe_strcasecmp (buf->data, tmp->name) == 0) {
if (CurrentMenu == MENU_ALIAS) {
tmp->del = 1;
set_option (OPTFORCEREDRAWINDEX);
mutt_extract_token (buf, s, 0);
- dprint (2, (debugfile, "parse_alias: First token is '%s'.\n", buf->data));
+ debug_print (2, ("first token is '%s'.\n", buf->data));
/* check to see if an alias with this name already exists */
for (; tmp; tmp = tmp->next) {
- if (!mutt_strcasecmp (tmp->name, buf->data))
+ if (!safe_strcasecmp (tmp->name, buf->data))
break;
last = tmp;
}
mutt_extract_token (buf, s,
M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON);
- dprint (2, (debugfile, "parse_alias: Second token is '%s'.\n", buf->data));
+ debug_print (2, ("second token is '%s'.\n", buf->data));
tmp->addr = mutt_parse_adrlist (tmp->addr, buf->data);
if (last)
last->next = tmp;
return -1;
}
#ifdef DEBUG
- if (debuglevel >= 2) {
+ if (DebugLevel >= 2) {
ADDRESS *a;
for (a = tmp->addr; a; a = a->next) {
if (!a->group)
- dprint (2, (debugfile, "parse_alias: %s\n", a->mailbox));
+ debug_print (2, ("%s\n", a->mailbox));
else
- dprint (2, (debugfile, "parse_alias: Group %s\n", a->mailbox));
+ debug_print (2, ("group %s\n", a->mailbox));
}
}
#endif
{
int i, flags = 0;
- if (mutt_strncmp ("reverse-", s, 8) == 0) {
+ if (safe_strncmp ("reverse-", s, 8) == 0) {
s += 8;
flags = SORT_REVERSE;
}
- if (mutt_strncmp ("last-", s, 5) == 0) {
+ if (safe_strncmp ("last-", s, 5) == 0) {
s += 5;
flags |= SORT_LAST;
}
break;
case DT_RX:
{
- REGEXP *pp = (REGEXP *) p->data;
+ rx_t* pp = (rx_t*) p->data;
if (!p->init && pp->pattern)
p->init = (unsigned long) safe_strdup (pp->pattern);
switch (p->type & DT_MASK) {
case DT_STR:
if (p->init)
- mutt_str_replace ((char **) p->data, (char *) p->init);
+ str_replace ((char **) p->data, (char *) p->init);
break;
case DT_PATH:
if (p->init) {
strfcpy (path, (char *) p->init, sizeof (path));
mutt_expand_path (path, sizeof (path));
- mutt_str_replace ((char **) p->data, path);
+ str_replace ((char **) p->data, path);
}
break;
case DT_ADDR:
break;
case DT_RX:
{
- REGEXP *pp = (REGEXP *) p->data;
+ rx_t *pp = (rx_t *) p->data;
int flags = 0;
FREE (&pp->pattern);
FREE (&pp->rx);
}
else
- mutt_str_replace (&pp->pattern, (char *) p->init);
+ str_replace (&pp->pattern, (char *) p->init);
}
}
break;
query = 1;
s->dptr++;
}
- else if (mutt_strncmp ("no", s->dptr, 2) == 0) {
+ else if (safe_strncmp ("no", s->dptr, 2) == 0) {
s->dptr += 2;
unset = !unset;
}
- else if (mutt_strncmp ("inv", s->dptr, 3) == 0) {
+ else if (safe_strncmp ("inv", s->dptr, 3) == 0) {
s->dptr += 3;
inv = !inv;
}
}
}
else if (DTYPE (MuttVars[idx].type) == DT_RX) {
- REGEXP *ptr = (REGEXP *) MuttVars[idx].data;
+ rx_t *ptr = (rx_t *) MuttVars[idx].data;
regex_t *rx;
int e, flags = 0;
size_t buflen;
pid_t pid;
- dprint (2, (debugfile, "Reading configuration file '%s'.\n", rcfile));
+ debug_print (2, ("reading configuration file '%s'.\n", rcfile));
+ str_replace (&CurRCFile, rcfile);
+ CurRCLine = 0;
if ((f = mutt_open_read (rcfile, &pid)) == NULL) {
snprintf (err->data, err->dsize, "%s: %s", rcfile, strerror (errno));
memset (&token, 0, sizeof (token));
while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) {
+ CurRCLine++;
conv = ConfigCharset && (*ConfigCharset) && Charset;
if (conv) {
currentline = safe_strdup (linebuf);
/* return the completed command */
strncpy (buffer, Completed, len - spaces);
}
- else if (!mutt_strncmp (buffer, "set", 3)
- || !mutt_strncmp (buffer, "unset", 5)
- || !mutt_strncmp (buffer, "reset", 5)
- || !mutt_strncmp (buffer, "toggle", 6)) { /* complete variables */
+ else if (!safe_strncmp (buffer, "set", 3)
+ || !safe_strncmp (buffer, "unset", 5)
+ || !safe_strncmp (buffer, "reset", 5)
+ || !safe_strncmp (buffer, "toggle", 6)) { /* complete variables */
char *prefixes[] = { "no", "inv", "?", "&", 0 };
pt++;
/* loop through all the possible prefixes (no, inv, ...) */
- if (!mutt_strncmp (buffer, "set", 3)) {
+ if (!safe_strncmp (buffer, "set", 3)) {
for (num = 0; prefixes[num]; num++) {
- if (!mutt_strncmp (pt, prefixes[num], mutt_strlen (prefixes[num]))) {
+ if (!safe_strncmp (pt, prefixes[num], mutt_strlen (prefixes[num]))) {
pt += mutt_strlen (prefixes[num]);
break;
}
strncpy (pt, Completed, buffer + len - pt - spaces);
}
- else if (!mutt_strncmp (buffer, "exec", 4)) {
+ else if (!safe_strncmp (buffer, "exec", 4)) {
struct binding_t *menu = km_get_table (CurrentMenu);
if (!menu && CurrentMenu != MENU_PAGER)
if (*pt == '=') /* abort if no var before the '=' */
return 0;
- if (mutt_strncmp (buffer, "set", 3) == 0) {
+ if (safe_strncmp (buffer, "set", 3) == 0) {
int idx;
strfcpy (var, pt, sizeof (var));
return (-1);
}
-#ifdef DEBUG
-static void start_debug (void)
-{
- time_t t;
- int i;
- char buf[_POSIX_PATH_MAX];
- char buf2[_POSIX_PATH_MAX];
-
- /* rotate the old debug logs */
- for (i = 3; i >= 0; i--) {
- snprintf (buf, sizeof (buf), "%s/.muttdebug%d", NONULL (Homedir), i);
- snprintf (buf2, sizeof (buf2), "%s/.muttdebug%d", NONULL (Homedir),
- i + 1);
- rename (buf, buf2);
- }
- if ((debugfile = safe_fopen (buf, "w")) != NULL) {
- t = time (0);
- setbuf (debugfile, NULL); /* don't buffer the debugging output! */
- fprintf (debugfile,
- "Mutt-ng %s started at %s.\nDebugging at level %d.\n\n",
- MUTT_VERSION, asctime (localtime (&t)), debuglevel);
- }
-}
-#endif
-
static int mutt_execute_commands (LIST * p)
{
BUFFER err, token;
Shell = safe_strdup ((p = getenv ("SHELL")) ? p : "/bin/sh");
}
-#ifdef DEBUG
- /* Start up debugging mode if requested */
- if (debuglevel > 0)
- start_debug ();
-#endif
+ debug_start(Homedir);
/* And about the host... */
uname (&utsname);
/* some systems report the FQDN instead of just the hostname */
if ((p = strchr (utsname.nodename, '.'))) {
- Hostname = mutt_substrdup (utsname.nodename, p);
+ Hostname = str_substrdup (utsname.nodename, p);
p++;
strfcpy (buffer, p, sizeof (buffer)); /* save the domain for below */
}
if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r"))) {
buffer[0] = '\0';
fgets (buffer, sizeof (buffer), f);
- p = &buffer;
+ p = (char*) &buffer;
SKIPWS (p);
i = p;
while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r')
if (mutt_execute_commands (commands) != 0)
need_pause = 1;
+ /* warn about synonym variables */
+ if (!list_empty(Synonyms)) {
+ int i = 0;
+ fprintf (stderr, _("Warning: the following synonym variables were found:\n"));
+ for (i = 0; i < Synonyms->length; i++)
+ fprintf (stderr, "$%s ($%s should be used) (%s:%d)\n",
+ MuttVars[((syn_t*) Synonyms->data[i])->o].option,
+ MuttVars[((syn_t*) Synonyms->data[i])->n].option,
+ NONULL(((syn_t*) Synonyms->data[i])->f),
+ ((syn_t*) Synonyms->data[i])->l);
+ fprintf (stderr, _("Warning: Synonym variables are scheduled for removal.\n"));
+ list_del (&Synonyms, syn_del);
+ need_pause = 1;
+ }
+ /* this is not needed during runtime */
+ FREE(&CurRCFile);
+
if (need_pause && !option (OPTNOCURSES)) {
if (mutt_any_key_to_continue (NULL) == -1)
mutt_exit (1);
return c->data;
return 0;
}
+
+static int opt_cmp (const void* a, const void* b) {
+ return (mutt_strcmp ((*(struct option_t**) a)->option,
+ (*(struct option_t**) b)->option));
+}
+
+/* dump out the value of all the variables we have */
+int mutt_dump_variables (void) {
+ int i;
+
+ char errbuff[STRING];
+ char command[STRING];
+ list2_t* tmp = NULL;
+
+ BUFFER err, token;
+
+ memset (&err, 0, sizeof (err));
+ memset (&token, 0, sizeof (token));
+
+ err.data = errbuff;
+ err.dsize = sizeof (errbuff);
+
+ /* get all non-synonyms into list... */
+ for (i = 0; MuttVars[i].option; i++) {
+ if (MuttVars[i].type == DT_SYN)
+ continue;
+ list_push_back (&tmp, &MuttVars[i]);
+ }
+ if (!list_empty(tmp)) {
+ /* ...and dump list sorted */
+ qsort (tmp->data, tmp->length, sizeof (void*), opt_cmp);
+ for (i = 0; i < tmp->length; i++) {
+ snprintf (command, sizeof (command), "set ?%s\n",
+ ((struct option_t*) tmp->data[i])->option);
+ if (mutt_parse_rc_line (command, &token, &err) == -1) {
+ fprintf (stderr, "%s\n", err.data);
+ FREE (&token.data);
+ list_del (&tmp, NULL);
+ return 1;
+ }
+ printf("%s\n", err.data);
+ }
+ }
+ FREE (&token.data);
+ list_del (&tmp, NULL);
+ return 0;
+}