X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=query.c;h=398f3b4b9390d4210ee3aca1ceef3f97dc703087;hp=df02f4a0e028e0387074fdf02a54c5d98ca1456b;hb=61fec8f6b3bff64d96d016a14729ab1ea2c4a2e8;hpb=ba5e3af4ea19e1d20c80941c077039871ec84258 diff --git a/query.c b/query.c index df02f4a..398f3b4 100644 --- a/query.c +++ b/query.c @@ -11,15 +11,17 @@ # include "config.h" #endif +#include +#include +#include +#include +#include + #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 "lib/debug.h" #include @@ -27,7 +29,7 @@ #include typedef struct query { - ADDRESS *addr; + address_t *addr; char *name; char *other; struct query *next; @@ -45,7 +47,7 @@ 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 */ @@ -55,14 +57,14 @@ static int SecondColumn; static void query_menu (char *buf, size_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 = str_dup (r->name); + tmp->personal = m_strdup(r->name); mutt_addrlist_to_idna (tmp, NULL); return tmp; @@ -100,11 +102,11 @@ static QUERY *run_query (char *s, int quiet) if (first == NULL) { FirstColumn = 0; SecondColumn = 0; - first = (QUERY *) mem_calloc (1, sizeof (QUERY)); + first = p_new(QUERY, 1); cur = first; } else { - cur->next = (QUERY *) mem_calloc (1, sizeof (QUERY)); + cur->next = p_new(QUERY, 1); cur = cur->next; } @@ -118,15 +120,15 @@ static QUERY *run_query (char *s, int quiet) l = mutt_strwidth (p); if (l > FirstColumn) FirstColumn = l; - cur->name = str_dup (p); + cur->name = m_strdup(p); p = strtok (NULL, "\t\n"); if (p) { - cur->other = str_dup (p); + cur->other = m_strdup(p); } } } } - mem_free (&buf); + p_delete(&buf); fclose (fp); if (mutt_wait_filter (thepid)) { debug_print (1, ("Error: %s\n", msg)); @@ -185,7 +187,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, - str_len (table[num].data->name), 0); + m_strlen(table[num].data->name), 0); snprintf (s, slen, " %c %3d %s %-*.*s %s", table[num].tagged ? '*' : ' ', @@ -207,7 +209,7 @@ static int query_tag (MUTTMENU * menu, int n, int m) int mutt_query_complete (char *buf, size_t buflen) { QUERY *results = NULL; - ADDRESS *tmpa; + address_t *tmpa; if (!QueryCmd) { mutt_error _("Query command not defined."); @@ -223,7 +225,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_delete (&tmpa); mutt_clear_error (); return (0); } @@ -287,8 +289,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 *) mem_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; @@ -309,15 +310,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); - mem_free (&queryp->name); - mem_free (&queryp->other); + address_delete (&queryp->addr); + p_delete(&queryp->name); + p_delete(&queryp->other); results = queryp->next; - mem_free (&queryp); + p_delete(&queryp); queryp = results; } results = newresults; - mem_free (&QueryTable); + p_delete(&QueryTable); } else { /* append */ @@ -344,8 +345,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) menu->max++; if (op == OP_QUERY) { - menu->data = QueryTable = - (ENTRY *) mem_calloc (menu->max, sizeof (ENTRY)); + menu->data = QueryTable = p_new(ENTRY, menu->max); for (i = 0, queryp = results; queryp; queryp = queryp->next, i++) @@ -355,7 +355,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) int clear = 0; /* append */ - mem_realloc (&QueryTable, menu->max * sizeof (ENTRY)); + p_realloc(&QueryTable, menu->max); menu->data = QueryTable; @@ -376,23 +376,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_delete (&a); } break; @@ -412,10 +409,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) 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); @@ -433,53 +427,53 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) int tagged = 0; size_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 = str_len (buf); - rfc822_free_address (&tmpa); + curpos = m_strlen(buf); + address_delete (&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 = str_len (buf); - rfc822_free_address (&tmpa); + curpos = m_strlen(buf); + address_delete (&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_delete (&tmpa); } } queryp = results; while (queryp) { - rfc822_free_address (&queryp->addr); - mem_free (&queryp->name); - mem_free (&queryp->other); + address_delete (&queryp->addr); + p_delete(&queryp->name); + p_delete(&queryp->other); results = queryp->next; - mem_free (&queryp); + p_delete(&queryp); queryp = results; } - mem_free (&QueryTable); + p_delete(&QueryTable); /* tell whoever called me to redraw the screen when I return */ set_option (OPTNEEDREDRAW);