X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=enter.c;h=4841111211276eb0391a3991f3f82f98ab4224a6;hp=f3270010416fd41c7fad4b054b1d843288051e1e;hb=1dc7032b59cc5b91d70076ed228bda8caf65a7f3;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/enter.c b/enter.c index f327001..4841111 100644 --- a/enter.c +++ b/enter.c @@ -1,31 +1,27 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2000 Michael R. Elkins * Copyright (C) 2000 Edmund Grimley Evans - * - * 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 "config.h" #endif +#include + #include "mutt.h" +#include "enter.h" #include "mutt_menu.h" #include "mutt_curses.h" #include "keymap.h" #include "history.h" +#include "buffy.h" + #include @@ -138,7 +134,7 @@ size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, char *buf) k != (size_t) (-1) && k != (size_t) (-2); buf += k) { if (i >= wbuflen) { wbuflen = i + 20; - safe_realloc (&wbuf, wbuflen * sizeof (*wbuf)); + p_realloc(&wbuf, wbuflen); } wbuf[i++] = wc; } @@ -150,11 +146,11 @@ size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, char *buf) * Replace part of the wchar_t buffer, from FROM to CURPOS, by BUF. */ -static void replace_part (ENTER_STATE * state, size_t from, char *buf) +static void replace_part (ENTER_STATE *state, size_t from, const char *buf) { /* Save the suffix */ size_t savelen = state->lastchar - state->curpos; - wchar_t *savebuf = safe_calloc (savelen, sizeof (wchar_t)); + wchar_t *savebuf = p_new(wchar_t, savelen); memcpy (savebuf, state->wbuf + state->curpos, savelen * sizeof (wchar_t)); @@ -164,14 +160,14 @@ static void replace_part (ENTER_STATE * state, size_t from, char *buf) /* Make space for suffix */ if (state->curpos + savelen > state->wbuflen) { state->wbuflen = state->curpos + savelen; - safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t)); + p_realloc(&state->wbuf, state->wbuflen); } /* Restore suffix */ memcpy (state->wbuf + state->curpos, savebuf, savelen * sizeof (wchar_t)); state->lastchar = state->curpos + savelen; - FREE (&savebuf); + p_delete(&savebuf); } /* @@ -274,19 +270,19 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, if (ch != OP_NULL) { first = 0; - if (ch != OP_EDITOR_COMPLETE) + if (ch != OP_EDITOR_COMPLETE && ch != OP_EDITOR_COMPLETE_QUERY) state->tabs = 0; redraw = M_REDRAW_LINE; switch (ch) { case OP_EDITOR_HISTORY_UP: state->curpos = state->lastchar; - replace_part (state, 0, mutt_history_prev (hclass)); + replace_part(state, 0, mutt_history_prev(hclass)); redraw = M_REDRAW_INIT; break; case OP_EDITOR_HISTORY_DOWN: state->curpos = state->lastchar; - replace_part (state, 0, mutt_history_next (hclass)); + replace_part(state, 0, mutt_history_next(hclass)); redraw = M_REDRAW_INIT; break; @@ -446,7 +442,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, if (flags & M_EFILE) { first = 1; /* clear input if user types a real key later */ my_wcstombs (buf, buflen, state->wbuf, state->curpos); - mutt_buffy (buf, buflen); + buffy_next (buf, buflen); state->curpos = state->lastchar = my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf); break; @@ -456,6 +452,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, /* fall through to completion routine (M_FILE) */ case OP_EDITOR_COMPLETE: + case OP_EDITOR_COMPLETE_QUERY: state->tabs++; if (flags & M_CMD) { for (i = state->curpos; i && state->wbuf[i - 1] != ' '; i--); @@ -473,14 +470,14 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, } if (!mutt_complete (buf, buflen)) { templen = state->lastchar - i; - safe_realloc (&tempbuf, templen * sizeof (wchar_t)); + p_realloc(&tempbuf, templen); } else BEEP (); replace_part (state, i, buf); } - else if (flags & M_ALIAS) { + else if (flags & M_ALIAS && ch == OP_EDITOR_COMPLETE) { /* invoke the alias-menu to get more addresses */ for (i = state->curpos; i && state->wbuf[i - 1] != ',' && state->wbuf[i - 1] != ':'; i--); @@ -493,10 +490,20 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, goto bye; } break; - } - else if (flags & M_COMMAND) { + } else if (flags & M_ALIAS && ch == OP_EDITOR_COMPLETE_QUERY) { + /* invoke the query-menu to get more addresses */ + if ((i = state->curpos)) { + for (; i && state->wbuf[i - 1] != ','; i--); + for (; i < state->curpos && state->wbuf[i] == ' '; i++); + } + my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); + mutt_query_complete (buf, buflen); + replace_part (state, i, buf); + rv = 1; + goto bye; + } else if (flags & M_COMMAND) { my_wcstombs (buf, buflen, state->wbuf, state->curpos); - i = strlen (buf); + i = str_len (buf); if (i && buf[i - 1] == '=' && mutt_var_value_complete (buf, buflen, i)) state->tabs = 0; @@ -531,7 +538,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, if (!mutt_complete (buf, buflen)) { templen = state->lastchar; - safe_realloc (&tempbuf, templen * sizeof (wchar_t)); + p_realloc(&tempbuf, templen); memcpy (tempbuf, state->wbuf, templen * sizeof (wchar_t)); } else @@ -542,24 +549,6 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, goto self_insert; break; - case OP_EDITOR_COMPLETE_QUERY: - if (flags & M_ALIAS) { - /* invoke the query-menu to get more addresses */ - if ((i = state->curpos)) { - for (; i && state->wbuf[i - 1] != ','; i--); - for (; i < state->curpos && state->wbuf[i] == ' '; i++); - } - - my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); - mutt_query_complete (buf, buflen); - replace_part (state, i, buf); - - rv = 1; - goto bye; - } - else - goto self_insert; - case OP_EDITOR_QUOTE_CHAR: { event_t event; @@ -648,9 +637,9 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, char **tfiles; *numfiles = 1; - tfiles = safe_calloc (*numfiles, sizeof (char *)); + tfiles = p_new(char *, *numfiles); mutt_expand_path (buf, buflen); - tfiles[0] = safe_strdup (buf); + tfiles[0] = str_dup (buf); *files = tfiles; } rv = 0; @@ -659,7 +648,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, else if (wc && (wc < ' ' || IsWPrint (wc))) { /* why? */ if (state->lastchar >= state->wbuflen) { state->wbuflen = state->lastchar + 20; - safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t)); + p_realloc(&state->wbuf, state->wbuflen); } memmove (state->wbuf + state->curpos + 1, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t)); @@ -675,7 +664,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, bye: - FREE (&tempbuf); + p_delete(&tempbuf); return rv; } @@ -684,8 +673,8 @@ void mutt_free_enter_state (ENTER_STATE ** esp) if (!esp) return; - FREE (&(*esp)->wbuf); - FREE (esp); + p_delete(&(*esp)->wbuf); + p_delete(esp); } /*