X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=curs_lib.c;h=3e03810b76900f83760ffebb7320de467234bc27;hp=13c8118c19d73806608c6ed1aed67be32325dd5f;hb=8889846011afe0d33ff155acce9afef5af306ae0;hpb=0f44dc85fc1280372ffab911d701e703d803fb4b diff --git a/curs_lib.c b/curs_lib.c index 13c8118..3e03810 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -16,6 +16,7 @@ #endif #include "mutt.h" +#include "enter.h" #include "mutt_menu.h" #include "mutt_curses.h" #include "pager.h" @@ -24,6 +25,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -136,16 +138,14 @@ int _mutt_get_field ( /* const */ char *field, char *buf, size_t buflen, return (ret); } -int mutt_get_password (char *msg, char *buf, size_t buflen) +int mutt_get_field_unbuffered (char *msg, char *buf, size_t buflen, int flags) { int rc; - CLEARLINE (LINES - 1); - addstr (msg); set_option (OPTUNBUFFEREDINPUT); - rc = mutt_enter_string (buf, buflen, LINES - 1, safe_strlen (msg), M_PASS); + rc = mutt_get_field (msg, buf, buflen, flags); unset_option (OPTUNBUFFEREDINPUT); - CLEARLINE (LINES - 1); + return (rc); } @@ -214,12 +214,12 @@ int mutt_yesorno (const char *msg, int def) * ensure there is enough room for the answer and truncate the question * to fit. */ - answer_string = safe_malloc (COLS + 1); + answer_string = mem_malloc (COLS + 1); snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no, def == M_YES ? no : yes); - answer_string_len = safe_strlen (answer_string); + answer_string_len = str_len (answer_string); printw ("%.*s%s", COLS - answer_string_len, msg, answer_string); - FREE (&answer_string); + mem_free (&answer_string); FOREVER { mutt_refresh (); @@ -237,7 +237,7 @@ int mutt_yesorno (const char *msg, int def) #else if ( #endif - (tolower (ch.ch) == 'y')) { + (tolower (ch.ch) == *yes)) { def = M_YES; break; } @@ -245,7 +245,7 @@ int mutt_yesorno (const char *msg, int def) #ifdef HAVE_LANGINFO_YESEXPR reno_ok ? (regexec (&reno, answer, 0, 0, 0) == 0) : #endif - (tolower (ch.ch) == 'n')) { + (tolower (ch.ch) == *no)) { def = M_NO; break; } @@ -276,7 +276,7 @@ void mutt_query_exit (void) if (Timeout) timeout (-1); /* restore blocking operation */ if (mutt_yesorno (_("Exit Mutt-ng?"), M_YES) == M_YES) { - endwin (); + mutt_endwin (NULL); exit (1); } mutt_clear_error (); @@ -293,7 +293,7 @@ void mutt_curses_error (const char *fmt, ...) vsnprintf (Errorbuf, sizeof (Errorbuf), fmt, ap); va_end (ap); - dprint (1, (debugfile, "%s\n", Errorbuf)); + debug_print (1, ("%s\n", Errorbuf)); mutt_format_string (TmpErrorbuf, sizeof (TmpErrorbuf), 0, COLS - 2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); snprintf (Errorbuf, sizeof (Errorbuf), "%s", TmpErrorbuf); /* overkill */ @@ -310,6 +310,30 @@ void mutt_curses_error (const char *fmt, ...) set_option (OPTMSGERR); } +void mutt_progress_bar (progress_t* progress, long pos) { + char posstr[SHORT_STRING]; + + if (!pos) { + if (!NetInc) + mutt_message (progress->msg); + else { + mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), + progress->size); + progress->pos = 0; + } + } + + if (!NetInc) + return; + + if (pos > progress->pos + (NetInc << 10)) { + progress->pos = pos; + pos = pos / (NetInc << 10) * (NetInc << 10); + mutt_pretty_size (posstr, sizeof (posstr), pos); + mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr); + } +} + void mutt_curses_message (const char *fmt, ...) { char TmpErrorbuf[STRING]; @@ -361,13 +385,12 @@ void mutt_endwin (const char *msg) } } -void mutt_perror (const char *s) +void _mutt_perror (const char *s, const char* filename, int line) { char *p = strerror (errno); - dprint (1, (debugfile, "%s: %s (errno = %d)\n", s, - p ? p : "unknown error", errno)); - mutt_error ("%s: %s (errno = %d)", s, p ? p : _("unknown error"), errno); + debug_print (1, ("%s: %s (errno = %d)\n", s, p ? p : "unknown error", errno)); + mutt_error ("%s: %s (errno = %d) from %s:%i", s, p ? p : _("unknown error"), errno, filename, line); } int mutt_any_key_to_continue (const char *s) @@ -403,7 +426,7 @@ int mutt_do_pager (const char *banner, { int rc; - if (!Pager || safe_strcmp (Pager, "builtin") == 0) + if (!Pager || str_cmp (Pager, "builtin") == 0) rc = mutt_pager (banner, tempfile, do_color, info); else { char cmd[STRING]; @@ -448,7 +471,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, *redraw = REDRAW_FULL; } else { - char *pc = safe_malloc (safe_strlen (prompt) + 3); + char *pc = mem_malloc (str_len (prompt) + 3); sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */ mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0); @@ -458,7 +481,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, != 0) buf[0] = 0; MAYBE_REDRAW (*redraw); - FREE (&pc); + mem_free (&pc); } return 0; @@ -472,7 +495,7 @@ void mutt_ungetch (int ch, int op) tmp.op = op; if (UngetCount >= UngetBufLen) - safe_realloc (&KeyEvent, (UngetBufLen += 128) * sizeof (event_t)); + mem_realloc (&KeyEvent, (UngetBufLen += 128) * sizeof (event_t)); KeyEvent[UngetCount++] = tmp; } @@ -528,7 +551,7 @@ int mutt_multi_choice (char *prompt, char *letters) } else if (ch.ch <= '9' && ch.ch > '0') { choice = ch.ch - '0'; - if (choice <= safe_strlen (letters)) + if (choice <= str_len (letters)) break; } } @@ -648,7 +671,7 @@ static void mutt_format_s_x (char *dest, } mutt_format_string (dest, destlen, min_width, max_width, - right_justify, ' ', s, safe_strlen (s), arboreal); + right_justify, ' ', s, str_len (s), arboreal); } void mutt_format_s (char *dest, @@ -673,7 +696,7 @@ void mutt_paddstr (int n, const char *s) wchar_t wc; int w; size_t k; - size_t len = safe_strlen (s); + size_t len = str_len (s); mbstate_t mbstate; memset (&mbstate, 0, sizeof (mbstate)); @@ -697,7 +720,7 @@ void mutt_paddstr (int n, const char *s) } /* - * mutt_strwidth is like safe_strlen except that it returns the width + * mutt_strwidth is like str_len except that it returns the width * refering to the number of characters cells. */ @@ -711,7 +734,7 @@ int mutt_strwidth (const char *s) if (!s) return 0; - n = safe_strlen (s); + n = str_len (s); memset (&mbstate, 0, sizeof (mbstate)); for (w = 0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) {