X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=query.c;h=ce1f052a8ded3e9b6d89b860b552162b76b43054;hp=c3e948d2956a1172666ce4360255325824228750;hb=711f787502b6a1a1c150b948a5ed9156c8ef9ba1;hpb=74a2265af51ce89bca845adc1d68f273c9933c13 diff --git a/query.c b/query.c index c3e948d..ce1f052 100644 --- a/query.c +++ b/query.c @@ -11,22 +11,26 @@ # include "config.h" #endif -#include "mutt.h" -#include "mutt_menu.h" -#include "mutt_idna.h" -#include "mapping.h" -#include "sort.h" - -#include "lib/mem.h" -#include "lib/intl.h" -#include "lib/str.h" - #include #include #include +#include +#include +#include +#include +#include +#include + +#include + +#include "mutt.h" +#include "alias.h" +#include "mutt_idna.h" +#include "sort.h" + typedef struct query { - ADDRESS *addr; + address_t *addr; char *name; char *other; struct query *next; @@ -44,24 +48,24 @@ static struct mapping_t QueryHelp[] = { {N_("Make Alias"), OP_CREATE_ALIAS}, {N_("Search"), OP_SEARCH}, {N_("Help"), OP_HELP}, - {NULL} + {NULL, OP_NULL} }; /* Variables for outsizing output format */ static int FirstColumn; static int SecondColumn; -static void query_menu (char *buf, size_t buflen, QUERY * results, +static void query_menu (char *buf, ssize_t buflen, QUERY * results, int retbuf); -static ADDRESS *result_to_addr (QUERY * r) +static address_t *result_to_addr (QUERY * r) { - static ADDRESS *tmp; + static address_t *tmp; - tmp = rfc822_cpy_adr (r->addr); + tmp = address_list_dup (r->addr); if (!tmp->next && !tmp->personal) - tmp->personal = safe_strdup (r->name); + tmp->personal = m_strdup(r->name); mutt_addrlist_to_idna (tmp, NULL); return tmp; @@ -74,7 +78,7 @@ static QUERY *run_query (char *s, int quiet) QUERY *cur = NULL; char cmd[_POSIX_PATH_MAX]; char *buf = NULL; - size_t buflen; + ssize_t buflen; int dummy = 0; char msg[STRING]; char *p; @@ -85,7 +89,7 @@ static QUERY *run_query (char *s, int quiet) mutt_expand_file_fmt (cmd, sizeof (cmd), QueryCmd, s); if ((thepid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) { - dprint (1, (debugfile, "unable to fork command: %s", cmd)); + debug_print (1, ("unable to fork command: %s\n", cmd)); return 0; } if (!quiet) @@ -99,11 +103,11 @@ static QUERY *run_query (char *s, int quiet) if (first == NULL) { FirstColumn = 0; SecondColumn = 0; - first = (QUERY *) safe_calloc (1, sizeof (QUERY)); + first = p_new(QUERY, 1); cur = first; } else { - cur->next = (QUERY *) safe_calloc (1, sizeof (QUERY)); + cur->next = p_new(QUERY, 1); cur = cur->next; } @@ -117,18 +121,18 @@ static QUERY *run_query (char *s, int quiet) l = mutt_strwidth (p); if (l > FirstColumn) FirstColumn = l; - cur->name = safe_strdup (p); + cur->name = m_strdup(p); p = strtok (NULL, "\t\n"); if (p) { - cur->other = safe_strdup (p); + cur->other = m_strdup(p); } } } } - FREE (&buf); + p_delete(&buf); fclose (fp); if (mutt_wait_filter (thepid)) { - dprint (1, (debugfile, "Error: %s\n", msg)); + debug_print (1, ("Error: %s\n", msg)); if (!quiet) mutt_error ("%s", msg); } @@ -155,11 +159,6 @@ static int query_search (MUTTMENU * m, regex_t * re, int n) if (table[n].data->addr->mailbox && !regexec (re, table[n].data->addr->mailbox, 0, NULL, 0)) return 0; -#ifdef EXACT_ADDRESS - if (table[n].data->addr->val && - !regexec (re, table[n].data->addr->val, 0, NULL, 0)) - return 0; -#endif } return REG_NOMATCH; @@ -169,7 +168,7 @@ static int query_search (MUTTMENU * m, regex_t * re, int n) * a menu entry for the requested item number. */ #define QUERY_MIN_COLUMN_LENGHT 20 /* Must be < 70/2 */ -static void query_entry (char *s, size_t slen, MUTTMENU * m, int num) +static void query_entry (char *s, ssize_t slen, MUTTMENU * m, int num) { ENTRY *table = (ENTRY *) m->data; char buf2[SHORT_STRING], buf[SHORT_STRING] = ""; @@ -189,7 +188,7 @@ static void query_entry (char *s, size_t slen, MUTTMENU * m, int num) mutt_format_string (buf2, sizeof (buf2), FirstColumn + 2, FirstColumn + 2, 0, ' ', table[num].data->name, - mutt_strlen (table[num].data->name), 0); + m_strlen(table[num].data->name), 0); snprintf (s, slen, " %c %3d %s %-*.*s %s", table[num].tagged ? '*' : ' ', @@ -208,10 +207,10 @@ static int query_tag (MUTTMENU * menu, int n, int m) return cur->tagged - ot; } -int mutt_query_complete (char *buf, size_t buflen) +int mutt_query_complete (char *buf, ssize_t buflen) { QUERY *results = NULL; - ADDRESS *tmpa; + address_t *tmpa; if (!QueryCmd) { mutt_error _("Query command not defined."); @@ -227,7 +226,7 @@ int mutt_query_complete (char *buf, size_t buflen) mutt_addrlist_to_local (tmpa); buf[0] = '\0'; rfc822_write_address (buf, buflen, tmpa, 0); - rfc822_free_address (&tmpa); + address_list_wipe(&tmpa); mutt_clear_error (); return (0); } @@ -237,7 +236,7 @@ int mutt_query_complete (char *buf, size_t buflen) return (0); } -void mutt_query_menu (char *buf, size_t buflen) +void mutt_query_menu (char *buf, ssize_t buflen) { if (!QueryCmd) { mutt_error _("Query command not defined."); @@ -255,7 +254,7 @@ void mutt_query_menu (char *buf, size_t buflen) } } -static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) +static void query_menu (char *buf, ssize_t buflen, QUERY * results, int retbuf) { MUTTMENU *menu; HEADER *msg = NULL; @@ -291,8 +290,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) for (queryp = results; queryp; queryp = queryp->next) menu->max++; - menu->data = QueryTable = - (ENTRY *) safe_calloc (menu->max, sizeof (ENTRY)); + menu->data = QueryTable = p_new(ENTRY, menu->max); for (i = 0, queryp = results; queryp; queryp = queryp->next, i++) QueryTable[i].data = queryp; @@ -313,15 +311,15 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) if (op == OP_QUERY) { queryp = results; while (queryp) { - rfc822_free_address (&queryp->addr); - FREE (&queryp->name); - FREE (&queryp->other); + address_list_wipe(&queryp->addr); + p_delete(&queryp->name); + p_delete(&queryp->other); results = queryp->next; - FREE (&queryp); + p_delete(&queryp); queryp = results; } results = newresults; - FREE (&QueryTable); + p_delete(&QueryTable); } else { /* append */ @@ -348,8 +346,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) menu->max++; if (op == OP_QUERY) { - menu->data = QueryTable = - (ENTRY *) safe_calloc (menu->max, sizeof (ENTRY)); + menu->data = QueryTable = p_new(ENTRY, menu->max); for (i = 0, queryp = results; queryp; queryp = queryp->next, i++) @@ -359,7 +356,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) int clear = 0; /* append */ - safe_realloc (&QueryTable, menu->max * sizeof (ENTRY)); + p_realloc(&QueryTable, menu->max); menu->data = QueryTable; @@ -380,23 +377,20 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) case OP_CREATE_ALIAS: if (menu->tagprefix) { - ADDRESS *naddr = NULL; + address_t *naddr = NULL; for (i = 0; i < menu->max; i++) if (QueryTable[i].tagged) { - ADDRESS *a = result_to_addr (QueryTable[i].data); - - rfc822_append (&naddr, a); - rfc822_free_address (&a); + address_list_append(&naddr, result_to_addr(QueryTable[i].data)); } mutt_create_alias (NULL, naddr); } else { - ADDRESS *a = result_to_addr (QueryTable[menu->current].data); + address_t *a = result_to_addr (QueryTable[menu->current].data); mutt_create_alias (NULL, a); - rfc822_free_address (&a); + address_list_wipe(&a); } break; @@ -408,18 +402,15 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) /* fall through to OP_MAIL */ case OP_MAIL: - msg = mutt_new_header (); - msg->env = mutt_new_envelope (); + msg = header_new(); + msg->env = envelope_new(); if (!menu->tagprefix) { msg->env->to = result_to_addr (QueryTable[menu->current].data); } else { for (i = 0; i < menu->max; i++) if (QueryTable[i].tagged) { - ADDRESS *a = result_to_addr (QueryTable[i].data); - - rfc822_append (&msg->env->to, a); - rfc822_free_address (&a); + address_list_append(&msg->env->to, result_to_addr(QueryTable[i].data)); } } ci_send_message (0, msg, NULL, Context, NULL); @@ -435,55 +426,55 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) /* if we need to return the selected entries */ if (retbuf && (done == 2)) { int tagged = 0; - size_t curpos = 0; + ssize_t curpos = 0; - memset (buf, 0, buflen); + p_clear(buf, buflen); /* check for tagged entries */ for (i = 0; i < menu->max; i++) { if (QueryTable[i].tagged) { if (curpos == 0) { - ADDRESS *tmpa = result_to_addr (QueryTable[i].data); + address_t *tmpa = result_to_addr (QueryTable[i].data); mutt_addrlist_to_local (tmpa); tagged = 1; rfc822_write_address (buf, buflen, tmpa, 0); - curpos = mutt_strlen (buf); - rfc822_free_address (&tmpa); + curpos = m_strlen(buf); + address_list_wipe(&tmpa); } else if (curpos + 2 < buflen) { - ADDRESS *tmpa = result_to_addr (QueryTable[i].data); + address_t *tmpa = result_to_addr (QueryTable[i].data); mutt_addrlist_to_local (tmpa); strcat (buf, ", "); /* __STRCAT_CHECKED__ */ rfc822_write_address ((char *) buf + curpos + 1, buflen - curpos - 1, tmpa, 0); - curpos = mutt_strlen (buf); - rfc822_free_address (&tmpa); + curpos = m_strlen(buf); + address_list_wipe(&tmpa); } } } /* then enter current message */ if (!tagged) { - ADDRESS *tmpa = result_to_addr (QueryTable[menu->current].data); + address_t *tmpa = result_to_addr (QueryTable[menu->current].data); mutt_addrlist_to_local (tmpa); rfc822_write_address (buf, buflen, tmpa, 0); - rfc822_free_address (&tmpa); + address_list_wipe(&tmpa); } } queryp = results; while (queryp) { - rfc822_free_address (&queryp->addr); - FREE (&queryp->name); - FREE (&queryp->other); + address_list_wipe(&queryp->addr); + p_delete(&queryp->name); + p_delete(&queryp->other); results = queryp->next; - FREE (&queryp); + p_delete(&queryp); queryp = results; } - FREE (&QueryTable); + p_delete(&QueryTable); /* tell whoever called me to redraw the screen when I return */ set_option (OPTNEEDREDRAW);