X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=curs_lib.c;h=3e9f31a4cb57505cee82c78fc8773dd4ed4c5a04;hp=0678d28ac327021bc2c67406a706a573c9bccc39;hb=7a368b3670a90656b2e0e724ed3efd79221f3d31;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/curs_lib.c b/curs_lib.c index 0678d28..3e9f31a 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -1,32 +1,35 @@ /* + * Copyright notice from original mutt: * 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 - * 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. + * + * Parts were written/modified by: + * Nico Golde + * + * 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 +#include +#include + #include "mutt.h" +#include "enter.h" #include "mutt_menu.h" #include "mutt_curses.h" #include "pager.h" #include "mbyte.h" +#include "lib/debug.h" + +#include #include #include #include @@ -114,7 +117,7 @@ event_t mutt_getch (void) return (ch == ctrl ('G') ? err : ret); } -int _mutt_get_field ( /* const */ char *field, char *buf, size_t buflen, +int _mutt_get_field ( const char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles) { int ret; @@ -138,16 +141,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, mutt_strlen (msg), M_PASS); + rc = mutt_get_field (msg, buf, buflen, flags); unset_option (OPTUNBUFFEREDINPUT); - CLEARLINE (LINES - 1); + return (rc); } @@ -158,19 +159,6 @@ 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]; @@ -179,7 +167,6 @@ 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); } @@ -216,14 +203,14 @@ 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 = p_new(char, COLS + 1); snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no, def == M_YES ? no : yes); - answer_string_len = strlen (answer_string); + answer_string_len = m_strlen(answer_string); printw ("%.*s%s", COLS - answer_string_len, msg, answer_string); - FREE (&answer_string); + p_delete(&answer_string); - FOREVER { + for (;;) { mutt_refresh (); ch = mutt_getch (); if (CI_is_return (ch.ch)) @@ -239,7 +226,7 @@ int mutt_yesorno (const char *msg, int def) #else if ( #endif - (tolower (ch.ch) == 'y')) { + (tolower (ch.ch) == *yes)) { def = M_YES; break; } @@ -247,7 +234,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; } @@ -278,7 +265,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 (); @@ -295,7 +282,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 */ @@ -312,6 +299,36 @@ void mutt_curses_error (const char *fmt, ...) set_option (OPTMSGERR); } +#ifdef USE_SOCKET +void mutt_progress_bar (progress_t* progress, long pos) { + char posstr[SHORT_STRING]; + + if (!pos) { + if (!NetInc) + mutt_message (progress->msg); + else { + if (progress->size) + 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); + if (progress->size) + mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr); + else + mutt_message ("%s %s", progress->msg, posstr); + } +} +#endif + void mutt_curses_message (const char *fmt, ...) { char TmpErrorbuf[STRING]; @@ -363,13 +380,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) @@ -405,7 +421,7 @@ int mutt_do_pager (const char *banner, { int rc; - if (!Pager || mutt_strcmp (Pager, "builtin") == 0) + if (!Pager || m_strcmp(Pager, "builtin") == 0) rc = mutt_pager (banner, tempfile, do_color, info); else { char cmd[STRING]; @@ -450,7 +466,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, *redraw = REDRAW_FULL; } else { - char *pc = safe_malloc (mutt_strlen (prompt) + 3); + char *pc = p_new(char, m_strlen(prompt) + 3); sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */ mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0); @@ -460,7 +476,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, != 0) buf[0] = 0; MAYBE_REDRAW (*redraw); - FREE (&pc); + p_delete(&pc); } return 0; @@ -474,7 +490,7 @@ void mutt_ungetch (int ch, int op) tmp.op = op; if (UngetCount >= UngetBufLen) - safe_realloc (&KeyEvent, (UngetBufLen += 128) * sizeof (event_t)); + p_realloc(&KeyEvent, UngetBufLen += 128); KeyEvent[UngetCount++] = tmp; } @@ -515,7 +531,7 @@ int mutt_multi_choice (char *prompt, char *letters) mvaddstr (LINES - 1, 0, prompt); clrtoeol (); - FOREVER { + for (;;) { mutt_refresh (); ch = mutt_getch (); if (ch.ch == -1 || CI_is_return (ch.ch)) { @@ -530,7 +546,7 @@ int mutt_multi_choice (char *prompt, char *letters) } else if (ch.ch <= '9' && ch.ch > '0') { choice = ch.ch - '0'; - if (choice <= mutt_strlen (letters)) + if (choice <= m_strlen(letters)) break; } } @@ -551,7 +567,7 @@ int mutt_addwch (wchar_t wc) mbstate_t mbstate; size_t n1, n2; - memset (&mbstate, 0, sizeof (mbstate)); + p_clear(&mbstate, 1); if ((n1 = wcrtomb (buf, wc, &mbstate)) == (size_t) (-1) || (n2 = wcrtomb (buf + n1, 0, &mbstate)) == (size_t) (-1)) return -1; /* ERR */ @@ -579,8 +595,8 @@ void mutt_format_string (char *dest, size_t destlen, char scratch[MB_LEN_MAX]; mbstate_t mbstate1, mbstate2; - memset (&mbstate1, 0, sizeof (mbstate1)); - memset (&mbstate2, 0, sizeof (mbstate2)); + p_clear(&mbstate1, 1); + p_clear(&mbstate2, 1); --destlen; p = dest; for (; n && (k = mbrtowc (&wc, s, n, &mbstate1)); s += k, n -= k) { @@ -650,7 +666,7 @@ 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, m_strlen(s), arboreal); } void mutt_format_s (char *dest, @@ -675,10 +691,10 @@ void mutt_paddstr (int n, const char *s) wchar_t wc; int w; size_t k; - size_t len = mutt_strlen (s); + size_t len = m_strlen(s); mbstate_t mbstate; - memset (&mbstate, 0, sizeof (mbstate)); + p_clear(&mbstate, 1); for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k) { if (k == (size_t) (-1) || k == (size_t) (-2)) { k = (k == (size_t) (-1)) ? 1 : len; @@ -699,7 +715,7 @@ void mutt_paddstr (int n, const char *s) } /* - * mutt_strwidth is like mutt_strlen except that it returns the width + * mutt_strwidth is like m_strlenexcept that it returns the width * refering to the number of characters cells. */ @@ -713,9 +729,9 @@ int mutt_strwidth (const char *s) if (!s) return 0; - n = mutt_strlen (s); + n = m_strlen(s); - memset (&mbstate, 0, sizeof (mbstate)); + p_clear(&mbstate, 1); 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;