X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=curs_lib.c;h=da846bbbc8d85ba33446dd36dc67edbe29669f13;hp=0f38f054869eb9056cc472e8c416fb28ae0e6b26;hb=0bf7fde20048a2b0c5af096545979d678aba44cf;hpb=6833ce8bdca2d64e14485118f2a4417b7e1cb1b1 diff --git a/curs_lib.c b/curs_lib.c index 0f38f05..da846bb 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -1,5 +1,6 @@ /* * Copyright (C) 1996-2002 Michael R. Elkins + * Copyright (C) 2004 g10 Code GmbH * * 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 @@ -57,6 +58,20 @@ void mutt_refresh (void) refresh (); } +/* Make sure that the next refresh does a full refresh. This could be + optmized by not doing it at all if DISPLAY is set as this might + indicate that a GUI based pinentry was used. Having an option to + customize this is of course the Mutt way. */ +void mutt_need_hard_redraw (void) +{ + if (!getenv ("DISPLAY")) + { + keypad (stdscr, TRUE); + clearok (stdscr, TRUE); + set_option (OPTNEEDREDRAW); + } +} + event_t mutt_getch (void) { int ch; @@ -139,6 +154,19 @@ void mutt_clear_error (void) CLEARLINE (LINES-1); } +static void fix_end_of_file (const char *data) +{ + FILE *fp; + int c; + + if ((fp = safe_fopen (data, "a+")) == NULL) + return; + fseek (fp,-1,SEEK_END); + if ((c = fgetc(fp)) != '\n') + fputc ('\n', fp); + safe_fclose (&fp); +} + void mutt_edit_file (const char *editor, const char *data) { char cmd[LONG_STRING]; @@ -147,6 +175,7 @@ void mutt_edit_file (const char *editor, const char *data) mutt_expand_file_fmt (cmd, sizeof (cmd), editor, data); if (mutt_system (cmd) == -1) mutt_error (_("Error running \"%s\"!"), cmd); + fix_end_of_file (data); keypad (stdscr, TRUE); clearok (stdscr, TRUE); } @@ -170,7 +199,7 @@ int mutt_yesorno (const char *msg, int def) answer[1] = 0; reyes_ok = (expr = nl_langinfo (YESEXPR)) && expr[0] == '^' && - !regcomp (&reyes, expr, REG_NOSUB|REG_EXTENDED); + !regcomp (&reyes, expr, REG_NOSUB|REG_EXTENDED); reno_ok = (expr = nl_langinfo (NOEXPR)) && expr[0] == '^' && !regcomp (&reno, expr, REG_NOSUB|REG_EXTENDED); #endif @@ -204,21 +233,21 @@ int mutt_yesorno (const char *msg, int def) #ifdef HAVE_LANGINFO_YESEXPR answer[0] = ch.ch; if (reyes_ok ? - (regexec (& reyes, answer, 0, 0, 0) == 0) : + (regexec (& reyes, answer, 0, 0, 0) == 0) : #else if ( #endif - (tolower (ch.ch) == 'y')) + (tolower (ch.ch) == 'y')) { def = M_YES; break; } else if ( #ifdef HAVE_LANGINFO_YESEXPR - reno_ok ? - (regexec (& reno, answer, 0, 0, 0) == 0) : + reno_ok ? + (regexec (& reno, answer, 0, 0, 0) == 0) : #endif - (tolower (ch.ch) == 'n')) + (tolower (ch.ch) == 'n')) { def = M_NO; break; @@ -271,7 +300,7 @@ void mutt_curses_error (const char *fmt, ...) dprint (1, (debugfile, "%s\n", Errorbuf)); mutt_format_string (Errorbuf, sizeof (Errorbuf), - 0, COLS-2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); + 0, COLS-2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); if (!option (OPTKEEPQUIET)) { @@ -295,7 +324,7 @@ void mutt_curses_message (const char *fmt, ...) va_end (ap); mutt_format_string (Errorbuf, sizeof (Errorbuf), - 0, COLS-2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); + 0, COLS-2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); if (!option (OPTKEEPQUIET)) { @@ -376,9 +405,9 @@ int mutt_any_key_to_continue (const char *s) } int mutt_do_pager (const char *banner, - const char *tempfile, - int do_color, - pager_t *info) + const char *tempfile, + int do_color, + pager_t *info) { int rc; @@ -425,17 +454,17 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, mutt_refresh (); buf[0] = 0; _mutt_select_file (buf, blen, M_SEL_FOLDER | (multiple ? M_SEL_MULTI : 0), - files, numfiles); + files, numfiles); *redraw = REDRAW_FULL; } else { char *pc = safe_malloc (mutt_strlen (prompt) + 3); - sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */ + sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */ mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0); if (_mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files, numfiles) - != 0) + != 0) buf[0] = 0; MAYBE_REDRAW (*redraw); FREE (&pc); @@ -479,8 +508,8 @@ void mutt_curs_set (int cursor) SavedCursor = cursor; if (curs_set (cursor) == ERR) { - if (cursor == 1) /* cnorm */ - curs_set (2); /* cvvis */ + if (cursor == 1) /* cnorm */ + curs_set (2); /* cvvis */ } } #endif @@ -507,14 +536,14 @@ int mutt_multi_choice (char *prompt, char *letters) p = strchr (letters, ch.ch); if (p) { - choice = p - letters + 1; - break; + choice = p - letters + 1; + break; } else if (ch.ch <= '9' && ch.ch > '0') { - choice = ch.ch - '0'; - if (choice <= mutt_strlen (letters)) - break; + choice = ch.ch - '0'; + if (choice <= mutt_strlen (letters)) + break; } } BEEP (); @@ -551,10 +580,10 @@ int mutt_addwch (wchar_t wc) */ void mutt_format_string (char *dest, size_t destlen, - int min_width, int max_width, - int right_justify, char m_pad_char, - const char *s, size_t n, - int arboreal) + int min_width, int max_width, + int right_justify, char m_pad_char, + const char *s, size_t n, + int arboreal) { char *p; int w; @@ -603,10 +632,10 @@ void mutt_format_string (char *dest, size_t destlen, */ static void mutt_format_s_x (char *dest, - size_t destlen, - const char *prefix, - const char *s, - int arboreal) + size_t destlen, + const char *prefix, + const char *s, + int arboreal) { int right_justify = 1; char *p; @@ -625,21 +654,21 @@ static void mutt_format_s_x (char *dest, } mutt_format_string (dest, destlen, min_width, max_width, - right_justify, ' ', s, mutt_strlen (s), arboreal); + right_justify, ' ', s, mutt_strlen (s), arboreal); } void mutt_format_s (char *dest, - size_t destlen, - const char *prefix, - const char *s) + size_t destlen, + const char *prefix, + const char *s) { mutt_format_s_x (dest, destlen, prefix, s, 0); } void mutt_format_s_tree (char *dest, - size_t destlen, - const char *prefix, - const char *s) + size_t destlen, + const char *prefix, + const char *s) { mutt_format_s_x (dest, destlen, prefix, s, 1); } @@ -651,30 +680,14 @@ void mutt_format_s_tree (char *dest, void mutt_paddstr (int n, const char *s) { - wchar_t wc; - int w; - size_t k; size_t len = mutt_strlen (s); - mbstate_t mbstate; - memset (&mbstate, 0, sizeof (mbstate)); - for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k) + for (; len && *s; s += 1, len -= 1) { - if (k == (size_t)(-1) || k == (size_t)(-2)) - { - k = (k == (size_t)(-1)) ? 1 : len; - wc = replacement_char (); - } - if (!IsWPrint (wc)) - wc = '?'; - w = wcwidth (wc); - if (w >= 0) - { - if (w > n) - break; - addnstr ((char *)s, k); - n -= w; - } + if (1 > n) + break; + addnstr ((char *)s, 1); + n -= 1; } while (n-- > 0) addch (' '); @@ -683,30 +696,10 @@ void mutt_paddstr (int n, const char *s) /* * mutt_strwidth is like mutt_strlen except that it returns the width * refering to the number of characters cells. + * AK: since we remove all that multibyte-character-stuff, it is equal to mutt_strlen */ int mutt_strwidth (const char *s) { - wchar_t wc; - int w; - size_t k, n; - mbstate_t mbstate; - - if (!s) return 0; - - n = mutt_strlen (s); - - memset (&mbstate, 0, sizeof (mbstate)); - for (w=0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) - { - if (k == (size_t)(-1) || k == (size_t)(-2)) - { - k = (k == (size_t)(-1)) ? 1 : n; - wc = replacement_char (); - } - if (!IsWPrint (wc)) - wc = '?'; - w += wcwidth (wc); - } - return w; + return mutt_strlen(s); }