X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=init.c;h=76bb0851db9685033c52b2b880acaf5fdcbc83a8;hp=ff8c03bd81bc41885b08c72ba0bb6853bc3e3667;hb=9c35e6b2c6568130f29a4dfeeca73862bed015fe;hpb=a8477ebaa09990b3688164cbe5cf661c4189541d diff --git a/init.c b/init.c index ff8c03b..76bb085 100644 --- a/init.c +++ b/init.c @@ -12,6 +12,8 @@ #endif #include "mutt.h" +#include "buffer.h" +#include "ascii.h" #include "mapping.h" #include "mutt_curses.h" #include "history.h" @@ -60,7 +62,7 @@ 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)); + syn_t* tmp = mem_malloc (sizeof (syn_t)); tmp->f = str_dup (CurRCFile); tmp->l = CurRCLine; tmp->n = n; @@ -70,8 +72,8 @@ static void syn_add (int n, int o) { /* 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) @@ -133,176 +135,6 @@ int mutt_option_index (char *s) 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; @@ -323,7 +155,7 @@ static void add_to_list (LIST ** list, const char *str) } 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; @@ -382,7 +214,7 @@ static int add_to_spam_list (SPAM_LIST ** list, const char *pat, * the template, and leaving t pointed at the current item. */ t = last; - FREE(t->template); + mem_free(t->template); break; } if (!last->next) @@ -434,8 +266,8 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat) 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; } @@ -444,8 +276,8 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat) 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; } @@ -468,12 +300,12 @@ static void remove_from_list (LIST ** l, const char *str) 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; @@ -559,10 +391,10 @@ static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data, 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; } @@ -680,10 +512,10 @@ static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data, /* 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. */ @@ -873,7 +705,7 @@ static int parse_alias (BUFFER * buf, BUFFER * s, unsigned long data, 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 */ @@ -977,7 +809,7 @@ static int parse_my_hdr (BUFFER * buf, BUFFER * s, unsigned long data, /* 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; @@ -1099,16 +931,16 @@ static void mutt_restore_default (struct option_t *p) 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 == '!') { @@ -1119,9 +951,9 @@ static void mutt_restore_default (struct option_t *p) 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); @@ -1242,7 +1074,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, 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]; @@ -1269,7 +1101,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, 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) { @@ -1328,19 +1160,19 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, } } - 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); @@ -1584,7 +1416,7 @@ static int source_rc (const char *rcfile, BUFFER * err) mutt_error (_("Error in %s, line %d: %s"), rcfile, line, err->data); if (--rc < -MAXERRS) { if (conv) - FREE (¤tline); + mem_free (¤tline); break; } } @@ -1593,10 +1425,10 @@ static int source_rc (const char *rcfile, BUFFER * err) 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); @@ -1681,7 +1513,7 @@ int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err) r = 0; finish: if (expn.destroy) - FREE (&expn.data); + mem_free (&expn.data); return (r); } @@ -2003,13 +1835,13 @@ int mutt_query_variables (LIST * queries) 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; } @@ -2045,11 +1877,11 @@ static int mutt_execute_commands (LIST * p) 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; } @@ -2123,7 +1955,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) 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 @@ -2196,7 +2028,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) memset (&token, 0, sizeof (token)); parse_my_hdr (&token, &buf, 0, &err); - FREE (&token.data); + mem_free (&token.data); } if ((p = getenv ("EMAIL")) != NULL) @@ -2264,11 +2096,11 @@ void mutt_init (int skip_sys_rc, LIST * commands) } 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 @@ -2327,7 +2159,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) 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) @@ -2384,14 +2216,14 @@ int mutt_dump_variables (void) { ((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; }