#endif
#include "mutt.h"
+#include "buffer.h"
+#include "ascii.h"
#include "mapping.h"
#include "mutt_curses.h"
#include "history.h"
/* 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));
+ syn_t* tmp = mem_malloc (sizeof (syn_t));
tmp->f = str_dup (CurRCFile);
tmp->l = CurRCLine;
tmp->n = n;
/* for synonym warning reports: free single item (for list_del()) */
static void syn_del (void** p) {
- FREE(&(*(syn_t**) p)->f);
- FREE(p);
+ mem_free(&(*(syn_t**) p)->f);
+ mem_free(p);
}
void toggle_quadoption (int opt)
return (-1);
}
-int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags)
-{
- char ch;
- char qc = 0; /* quote char */
- char *pc;
-
- /* reset the destination pointer to the beginning of the buffer */
- dest->dptr = dest->data;
-
- SKIPWS (tok->dptr);
- while ((ch = *tok->dptr)) {
- if (!qc) {
- if ((ISSPACE (ch) && !(flags & M_TOKEN_SPACE)) ||
- (ch == '#' && !(flags & M_TOKEN_COMMENT)) ||
- (ch == '=' && (flags & M_TOKEN_EQUAL)) ||
- (ch == ';' && !(flags & M_TOKEN_SEMICOLON)) ||
- ((flags & M_TOKEN_PATTERN) && strchr ("~!|", ch)))
- break;
- }
-
- tok->dptr++;
-
- if (ch == qc)
- qc = 0; /* end of quote */
- else if (!qc && (ch == '\'' || ch == '"') && !(flags & M_TOKEN_QUOTE))
- qc = ch;
- else if (ch == '\\' && qc != '\'') {
- if (!*tok->dptr)
- return -1; /* premature end of token */
- switch (ch = *tok->dptr++) {
- case 'c':
- case 'C':
- if (!*tok->dptr)
- return -1; /* premature end of token */
- mutt_buffer_addch (dest, (toupper ((unsigned char) *tok->dptr)
- - '@') & 0x7f);
- tok->dptr++;
- break;
- case 'r':
- mutt_buffer_addch (dest, '\r');
- break;
- case 'n':
- mutt_buffer_addch (dest, '\n');
- break;
- case 't':
- mutt_buffer_addch (dest, '\t');
- break;
- case 'f':
- mutt_buffer_addch (dest, '\f');
- break;
- case 'e':
- mutt_buffer_addch (dest, '\033');
- break;
- default:
- if (isdigit ((unsigned char) ch) &&
- isdigit ((unsigned char) *tok->dptr) &&
- isdigit ((unsigned char) *(tok->dptr + 1))) {
-
- mutt_buffer_addch (dest,
- (ch << 6) + (*tok->dptr << 3) + *(tok->dptr +
- 1) - 3504);
- tok->dptr += 2;
- }
- else
- mutt_buffer_addch (dest, ch);
- }
- }
- else if (ch == '^' && (flags & M_TOKEN_CONDENSE)) {
- if (!*tok->dptr)
- return -1; /* premature end of token */
- ch = *tok->dptr++;
- if (ch == '^')
- mutt_buffer_addch (dest, ch);
- else if (ch == '[')
- mutt_buffer_addch (dest, '\033');
- else if (isalpha ((unsigned char) ch))
- mutt_buffer_addch (dest, toupper ((unsigned char) ch) - '@');
- else {
- mutt_buffer_addch (dest, '^');
- mutt_buffer_addch (dest, ch);
- }
- }
- else if (ch == '`' && (!qc || qc == '"')) {
- FILE *fp;
- pid_t pid;
- char *cmd, *ptr;
- size_t expnlen;
- BUFFER expn;
- int line = 0;
-
- pc = tok->dptr;
- do {
- if ((pc = strpbrk (pc, "\\`"))) {
- /* skip any quoted chars */
- if (*pc == '\\')
- pc += 2;
- }
- } while (pc && *pc != '`');
- if (!pc) {
- debug_print (1, ("mismatched backtics\n"));
- return (-1);
- }
- cmd = str_substrdup (tok->dptr, pc);
- if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {
- debug_print (1, ("unable to fork command: %s\n", cmd));
- FREE (&cmd);
- return (-1);
- }
- FREE (&cmd);
-
- tok->dptr = pc + 1;
-
- /* read line */
- memset (&expn, 0, sizeof (expn));
- expn.data = mutt_read_line (NULL, &expn.dsize, fp, &line);
- fclose (fp);
- mutt_wait_filter (pid);
-
- /* if we got output, make a new string consiting of the shell ouptput
- plus whatever else was left on the original line */
- /* BUT: If this is inside a quoted string, directly add output to
- * the token */
- if (expn.data && qc) {
- mutt_buffer_addstr (dest, expn.data);
- FREE (&expn.data);
- }
- else if (expn.data) {
- expnlen = str_len (expn.data);
- tok->dsize = expnlen + str_len (tok->dptr) + 1;
- ptr = safe_malloc (tok->dsize);
- memcpy (ptr, expn.data, expnlen);
- strcpy (ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */
- if (tok->destroy)
- FREE (&tok->data);
- tok->data = ptr;
- tok->dptr = ptr;
- tok->destroy = 1; /* mark that the caller should destroy this data */
- ptr = NULL;
- FREE (&expn.data);
- }
- }
- else if (ch == '$' && (!qc || qc == '"')
- && (*tok->dptr == '{' || isalpha ((unsigned char) *tok->dptr))) {
- char *env = NULL, *var = NULL;
-
- if (*tok->dptr == '{') {
- tok->dptr++;
- if ((pc = strchr (tok->dptr, '}'))) {
- var = str_substrdup (tok->dptr, pc);
- tok->dptr = pc + 1;
- }
- }
- else {
- for (pc = tok->dptr; isalnum ((unsigned char) *pc) || *pc == '_';
- pc++);
- var = str_substrdup (tok->dptr, pc);
- tok->dptr = pc;
- }
- if (var && (env = getenv (var)))
- mutt_buffer_addstr (dest, env);
- FREE (&var);
- }
- else
- mutt_buffer_addch (dest, ch);
- }
- mutt_buffer_addch (dest, 0); /* terminate the string */
- SKIPWS (tok->dptr);
- return 0;
-}
-
static void add_to_list (LIST ** list, const char *str)
{
LIST *t, *last = NULL;
}
if (!*list || last) {
- t = (LIST *) safe_calloc (1, sizeof (LIST));
+ t = (LIST *) mem_calloc (1, sizeof (LIST));
t->data = str_dup (str);
if (last) {
last->next = t;
* the template, and leaving t pointed at the current item.
*/
t = last;
- FREE(t->template);
+ mem_free(t->template);
break;
}
if (!last->next)
if (spam->rx && !str_cmp (spam->rx->pattern, pat)) {
*list = spam->next;
rx_free (&spam->rx);
- FREE(&spam->template);
- FREE(&spam);
+ mem_free(&spam->template);
+ mem_free(&spam);
return 1;
}
if (!str_cmp (spam->rx->pattern, pat)) {
prev->next = spam->next;
rx_free (&spam->rx);
- FREE(spam->template);
- FREE(spam);
+ mem_free(spam->template);
+ mem_free(spam);
spam = prev->next;
++nremoved;
}
last = NULL;
while (p) {
if (ascii_strcasecmp (str, p->data) == 0) {
- FREE (&p->data);
+ mem_free (&p->data);
if (last)
last->next = p->next;
else
(*l) = p->next;
- FREE (&p);
+ mem_free (&p);
}
else {
last = p;
if ((data && res) || (!data && !res)) {
if (mutt_parse_rc_line (tmp->data, &token, err) == -1) {
mutt_error ("Error: %s", err->data);
- FREE (&token.data);
+ mem_free (&token.data);
return (-1);
}
- FREE (&token.data);
+ mem_free (&token.data);
}
return 0;
}
/* Add to the spam list. */
if (add_to_spam_list (&SpamList, buf->data, templ.data, err) != 0) {
- FREE (&templ.data);
+ mem_free (&templ.data);
return -1;
}
- FREE (&templ.data);
+ mem_free (&templ.data);
}
/* If not, try to remove from the nospam list. */
if (!tmp) {
/* create a new alias */
- tmp = (ALIAS *) safe_calloc (1, sizeof (ALIAS));
+ tmp = (ALIAS *) mem_calloc (1, sizeof (ALIAS));
tmp->self = tmp;
tmp->name = str_dup (buf->data);
/* give the main addressbook code a chance */
/* see if there is already a field by this name */
if (ascii_strncasecmp (buf->data, tmp->data, keylen) == 0) {
/* replace the old value */
- FREE (&tmp->data);
+ mem_free (&tmp->data);
tmp->data = buf->data;
memset (buf, 0, sizeof (BUFFER));
return 0;
rx_t *pp = (rx_t *) p->data;
int flags = 0;
- FREE (&pp->pattern);
+ mem_free (&pp->pattern);
if (pp->rx) {
regfree (pp->rx);
- FREE (&pp->rx);
+ mem_free (&pp->rx);
}
if (p->init) {
char *s = (char *) p->init;
- pp->rx = safe_calloc (1, sizeof (regex_t));
+ pp->rx = mem_calloc (1, sizeof (regex_t));
if (str_cmp (p->option, "mask") != 0)
flags |= mutt_which_case ((const char *) p->init);
if (str_cmp (p->option, "mask") == 0 && *s == '!') {
fprintf (stderr,
_("mutt_restore_default(%s): error in regexp: %s\n"),
p->option, pp->pattern);
- FREE (&pp->pattern);
+ mem_free (&pp->pattern);
regfree (pp->rx);
- FREE (&pp->rx);
+ mem_free (&pp->rx);
}
else
str_replace (&pp->pattern, (char *) p->init);
if (DTYPE (MuttVars[idx].type) == DT_ADDR)
rfc822_free_address ((ADDRESS **) MuttVars[idx].data);
else
- FREE ((void *) MuttVars[idx].data);
+ mem_free ((void *) MuttVars[idx].data);
}
else if (query || *s->dptr != '=') {
char _tmp[STRING];
if (DTYPE (MuttVars[idx].type) == DT_ADDR)
rfc822_free_address ((ADDRESS **) MuttVars[idx].data);
else
- FREE ((void *) MuttVars[idx].data);
+ mem_free ((void *) MuttVars[idx].data);
mutt_extract_token (tmp, s, 0);
if (DTYPE (MuttVars[idx].type) == DT_PATH) {
}
}
- rx = (regex_t *) safe_malloc (sizeof (regex_t));
+ rx = (regex_t *) mem_malloc (sizeof (regex_t));
if ((e = REGCOMP (rx, p, flags)) != 0) {
regerror (e, rx, err->data, err->dsize);
regfree (rx);
- FREE (&rx);
+ mem_free (&rx);
break;
}
/* get here only if everything went smootly */
if (ptr->pattern) {
- FREE (&ptr->pattern);
+ mem_free (&ptr->pattern);
regfree ((regex_t *) ptr->rx);
- FREE (&ptr->rx);
+ mem_free (&ptr->rx);
}
ptr->pattern = str_dup (tmp->data);
mutt_error (_("Error in %s, line %d: %s"), rcfile, line, err->data);
if (--rc < -MAXERRS) {
if (conv)
- FREE (¤tline);
+ mem_free (¤tline);
break;
}
}
rc = -1;
}
if (conv)
- FREE (¤tline);
+ mem_free (¤tline);
}
- FREE (&token.data);
- FREE (&linebuf);
+ mem_free (&token.data);
+ mem_free (&linebuf);
fclose (f);
if (pid != -1)
mutt_wait_filter (pid);
r = 0;
finish:
if (expn.destroy)
- FREE (&expn.data);
+ mem_free (&expn.data);
return (r);
}
snprintf (command, sizeof (command), "set ?%s\n", p->data);
if (mutt_parse_rc_line (command, &token, &err) == -1) {
fprintf (stderr, "%s\n", err.data);
- FREE (&token.data);
+ mem_free (&token.data);
return 1;
}
printf ("%s\n", err.data);
}
- FREE (&token.data);
+ mem_free (&token.data);
return 0;
}
for (; p; p = p->next) {
if (mutt_parse_rc_line (p->data, &token, &err) != 0) {
fprintf (stderr, _("Error in command line: %s\n"), err.data);
- FREE (&token.data);
+ mem_free (&token.data);
return (-1);
}
}
- FREE (&token.data);
+ mem_free (&token.data);
return 0;
}
else
#endif /* DOMAIN */
if (*DOMAIN != '@') {
- Fqdn = safe_malloc (str_len (DOMAIN) + str_len (Hostname) + 2);
+ Fqdn = mem_malloc (str_len (DOMAIN) + str_len (Hostname) + 2);
sprintf (Fqdn, "%s.%s", NONULL (Hostname), DOMAIN); /* __SPRINTF_CHECKED__ */
}
else
memset (&token, 0, sizeof (token));
parse_my_hdr (&token, &buf, 0, &err);
- FREE (&token.data);
+ mem_free (&token.data);
}
if ((p = getenv ("EMAIL")) != NULL)
}
else {
strfcpy (buffer, Muttrc, sizeof (buffer));
- FREE (&Muttrc);
+ mem_free (&Muttrc);
mutt_expand_path (buffer, sizeof (buffer));
Muttrc = str_dup (buffer);
}
- FREE (&AliasFile);
+ mem_free (&AliasFile);
AliasFile = str_dup (NONULL (Muttrc));
/* Process the global rc file if it exists and the user hasn't explicity
need_pause = 1;
}
/* this is not needed during runtime */
- FREE(&CurRCFile);
+ mem_free(&CurRCFile);
if (need_pause && !option (OPTNOCURSES)) {
if (mutt_any_key_to_continue (NULL) == -1)
((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);
+ mem_free (&token.data);
list_del (&tmp, NULL);
return 1;
}
printf("%s\n", err.data);
}
}
- FREE (&token.data);
+ mem_free (&token.data);
list_del (&tmp, NULL);
return 0;
}