From 38574f89db58f282e50bfefbc98c457201c7b574 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Fri, 29 May 2009 21:24:29 +0200 Subject: [PATCH] Add flags to mutt_read_line() for EOL-stripping and continuation support We use these to stop supporting EOL-escaping with \ which was wrong in most cases (e.g. $history_file), support is kept for reading config and mailcap files. Leaving CRLF in will be used for the pager. --- ChangeLog | 16 ++++++++++++++++ history.c | 6 +++--- init.c | 4 ++-- lib.c | 6 ++++-- lib.h | 6 +++++- mh.c | 6 +++--- mutt_ssl_gnutls.c | 2 +- pgp.c | 2 +- query.c | 2 +- rfc1524.c | 2 +- smime.c | 4 ++-- 11 files changed, 39 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7a6c45d3..11698a059 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2009-05-29 16:40 +0200 Rocco Rutte (d13500626ea6) + + * menu.c, pager.c, pattern.c: Fall back to search if no query exists + for search-(next|opposite) + + The pager had the fall-through to search, so for consistency do that + in other menues as well. + +2009-05-29 16:21 +0200 Rocco Rutte (4d0640457c77) + + * ChangeLog, pager.c: Fix pager search prompt for reverse search + + When doing a reverse search for the first time after switching to + the pager, SearchBack is always 0 and thus gave the wrong prompt, + change to using op directly. While I'm at it, unify search prompts. + 2009-05-29 13:27 +0200 Rocco Rutte (f1a1e50c375d) * doc/manual.xml.head: Manual: Fix markup of environment variables diff --git a/history.c b/history.c index 6585aa330..68528163d 100644 --- a/history.c +++ b/history.c @@ -68,7 +68,7 @@ void mutt_read_histfile (void) if ((f = fopen (HistFile, "r")) == NULL) return; - while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) + while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line, 0)) != NULL) { read = 0; if (sscanf (linebuf, "%d:%n", &hclass, &read) < 1 || read == 0 || @@ -107,7 +107,7 @@ static void shrink_histfile (void) return; line = 0; - while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) + while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line, 0)) != NULL) { if (sscanf (linebuf, "%d", &hclass) < 1 || hclass < 0) { @@ -133,7 +133,7 @@ static void shrink_histfile (void) { rewind (f); line = 0; - while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) + while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line, 0)) != NULL) { if (sscanf (linebuf, "%d", &hclass) < 1 || hclass < 0) { diff --git a/init.c b/init.c index f66d551bf..6cd7f6448 100644 --- a/init.c +++ b/init.c @@ -253,7 +253,7 @@ int mutt_extract_token (BUFFER *dest, BUFFER *tok, int flags) /* read line */ memset (&expn, 0, sizeof (expn)); - expn.data = mutt_read_line (NULL, &expn.dsize, fp, &line); + expn.data = mutt_read_line (NULL, &expn.dsize, fp, &line, 0); safe_fclose (&fp); mutt_wait_filter (pid); @@ -2268,7 +2268,7 @@ static int source_rc (const char *rcfile, BUFFER *err) } memset (&token, 0, sizeof (token)); - while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) + while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line, M_CONT)) != NULL) { conv=ConfigCharset && (*ConfigCharset) && Charset; if (conv) diff --git a/lib.c b/lib.c index ed5daed26..6fd243727 100644 --- a/lib.c +++ b/lib.c @@ -738,7 +738,7 @@ int mutt_rx_sanitize_string (char *dest, size_t destlen, const char *src) * If a line ends with "\", this char and the linefeed is removed, * and the next line is read too. */ -char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line) +char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line, int flags) { size_t offset = 0; char *ch; @@ -759,10 +759,12 @@ char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line) if ((ch = strchr (s + offset, '\n')) != NULL) { (*line)++; + if (flags & M_EOL) + return s; *ch = 0; if (ch > s && *(ch - 1) == '\r') *--ch = 0; - if (ch == s || *(ch - 1) != '\\') + if (!(flags & M_CONT) || ch == s || *(ch - 1) != '\\') return s; offset = ch - s - 1; } diff --git a/lib.h b/lib.h index 24c733436..6fabfd739 100644 --- a/lib.h +++ b/lib.h @@ -139,13 +139,17 @@ MUTT_LIB_WHERE int debuglevel MUTT_LIB_INITVAL(0); #define S_ERR 127 #define S_BKG 126 +/* Flags for mutt_read_line() */ +#define M_CONT (1<<0) /* \-continuation */ +#define M_EOL (1<<1) /* don't strip \n/\r\n */ + /* The actual library functions. */ FILE *safe_fopen (const char *, const char *); char *mutt_concatn_path (char *, size_t, const char *, size_t, const char *, size_t); char *mutt_concat_path (char *, const char *, const char *, size_t); -char *mutt_read_line (char *, size_t *, FILE *, int *); +char *mutt_read_line (char *, size_t *, FILE *, int *, int); char *mutt_skip_whitespace (char *); char *mutt_strlower (char *); char *mutt_substrcpy (char *, const char *, const char *, size_t); diff --git a/mh.c b/mh.c index d09dd487a..c696e733b 100644 --- a/mh.c +++ b/mh.c @@ -170,7 +170,7 @@ static void mh_read_sequences (struct mh_sequences *mhs, const char *path) if (!(fp = fopen (pathname, "r"))) return; - while ((buff = mutt_read_line (buff, &sz, fp, &line))) + while ((buff = mutt_read_line (buff, &sz, fp, &line, 0))) { if (!(t = strtok (buff, " \t:"))) continue; @@ -350,7 +350,7 @@ static void mh_update_sequences (CONTEXT * ctx) /* first, copy unknown sequences */ if ((ofp = fopen (sequences, "r"))) { - while ((buff = mutt_read_line (buff, &s, ofp, &l))) + while ((buff = mutt_read_line (buff, &s, ofp, &l, 0))) { if (!mutt_strncmp (buff, seq_unseen, mutt_strlen (seq_unseen))) continue; @@ -448,7 +448,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen, snprintf (sequences, sizeof (sequences), "%s/.mh_sequences", ctx->path); if ((ofp = fopen (sequences, "r"))) { - while ((buff = mutt_read_line (buff, &sz, ofp, &line))) + while ((buff = mutt_read_line (buff, &sz, ofp, &line, 0))) { if (unseen && !strncmp (buff, seq_unseen, mutt_strlen (seq_unseen))) { diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index dc3b3b3ba..ede93cd4e 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -513,7 +513,7 @@ static int tls_check_stored_hostname (const gnutls_datum *cert, buf[0] = '\0'; tls_fingerprint (GNUTLS_DIG_MD5, buf, sizeof (buf), cert); - while ((linestr = mutt_read_line(linestr, &linestrsize, fp, &linenum)) != NULL) + while ((linestr = mutt_read_line(linestr, &linestrsize, fp, &linenum, 0)) != NULL) { if(linestr[0] == '#' && linestr[1] == 'H') { diff --git a/pgp.c b/pgp.c index 6aa473ecd..325d47a66 100644 --- a/pgp.c +++ b/pgp.c @@ -151,7 +151,7 @@ static int pgp_copy_checksig (FILE *fpin, FILE *fpout) int lineno = 0; size_t linelen; - while ((line = mutt_read_line (line, &linelen, fpin, &lineno)) != NULL) + while ((line = mutt_read_line (line, &linelen, fpin, &lineno, 0)) != NULL) { if (regexec (PgpGoodSign.rx, line, 0, NULL, 0) == 0) { diff --git a/query.c b/query.c index 283aad75c..f2464b955 100644 --- a/query.c +++ b/query.c @@ -96,7 +96,7 @@ static QUERY *run_query (char *s, int quiet) fgets (msg, sizeof (msg), fp); if ((p = strrchr (msg, '\n'))) *p = '\0'; - while ((buf = mutt_read_line (buf, &buflen, fp, &dummy)) != NULL) + while ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL) { if ((p = strtok(buf, "\t\n"))) { diff --git a/rfc1524.c b/rfc1524.c index 528787085..bc709aef6 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -203,7 +203,7 @@ static int rfc1524_mailcap_parse (BODY *a, if ((fp = fopen (filename, "r")) != NULL) { - while (!found && (buf = mutt_read_line (buf, &buflen, fp, &line)) != NULL) + while (!found && (buf = mutt_read_line (buf, &buflen, fp, &line, M_CONT)) != NULL) { /* ignore comments */ if (*buf == '#') diff --git a/smime.c b/smime.c index d66949381..e4a784fbc 100644 --- a/smime.c +++ b/smime.c @@ -1632,7 +1632,7 @@ int smime_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) fflush (smimeerr); rewind (smimeerr); - line = mutt_read_line (line, &linelen, smimeerr, &lineno); + line = mutt_read_line (line, &linelen, smimeerr, &lineno, 0); if (linelen && !ascii_strcasecmp (line, "verification successful")) badsig = 0; @@ -1854,7 +1854,7 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) rewind (smimeerr); - line = mutt_read_line (line, &linelen, smimeerr, &lineno); + line = mutt_read_line (line, &linelen, smimeerr, &lineno, 0); if (linelen && !ascii_strcasecmp (line, "verification successful")) m->goodsig = 1; FREE (&line); -- 2.40.0