Commit 04474c29 04474c2918cc831e953dc37ae1d90cac170cd5b0 by Sergey Poznyakoff

Improve the inline-comment filter.

* libmailutils/filter/inline-comment.c: Recognize multi-char
comment sequences.
Implement encode mode.
* libmailutils/tests/inline-comment.at: Test the new modes.

* mail/escape.c (quote0): Re-implement using inline-comment
encode mode.
* mail/mailvar.c (mailvar_tab): Fix a typo.
1 parent 88009983
......@@ -14,12 +14,14 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
m4_pushdef([FILTER_MODE],[decode])
dnl -------------------------------------------------------------------
dnl INLINECOM(NAME, [KW = `'], [OPTS = `'], [TEXT], [OUTPUT = `'])
dnl -------------------------------------------------------------------
m4_pushdef([INLINECOM],[
AT_SETUP([inline-comment: $1])
AT_KEYWORDS([filter inline-comment icmt $2])
AT_KEYWORDS([filter FILTER_MODE inline-comment icmt $2])
sed 's/\$.*//' > input <<EOT
$4
EOT
......@@ -27,10 +29,10 @@ sed 's/\$.*//' > expout <<EOT
$5
EOT
AT_CHECK([fltst inline-comment decode read $3 < input],
AT_CHECK([fltst inline-comment FILTER_MODE read $3 < input],
[0],
[expout])
AT_CHECK([fltst inline-comment decode write $3 < input],
AT_CHECK([fltst inline-comment FILTER_MODE write $3 < input],
[0],
[expout])
AT_CLEANUP
......@@ -108,6 +110,74 @@ text 4
text 5[]dnl
])
INLINECOM([multichar comment starter],[icmt05],[-- rem],
[Text line 1
rem remark text
Text line 2
remark text (sic!)
Text line 3
],
[Text line 1
Text line 2
Text line 3
])
INLINECOM([multichar comment starter; follow ws; follow ws mode],[icmt06],
[-- rem -S],
[Text line 1
rem remark text
Text line 2
remark text (sic!)
Text line 3
],
[Text line 1
Text line 2
remark text (sic!)
Text line 3
])
INLINECOM([multichar; squeeze; remove empty],[icmt06],[-- rem -S -r],
[rem comment 1
text 1
rem comment 2
rem comment 3
text 2
text 3
$
text 4
text 5
],
[text 1
text 2
text 3
text 4
text 5[]dnl
])
m4_define([FILTER_MODE],[encode])
INLINECOM([encode],[icmt07],[],
[C'est dans dix ans je m'en irai
J'entends le loup et le renard chanter
J'entends le loup, le renard et la belette
J'entends le loup et le renard chanter],
[;C'est dans dix ans je m'en irai
;J'entends le loup et le renard chanter
;J'entends le loup, le renard et la belette
;J'entends le loup et le renard chanter])
INLINECOM([encode multichar; add ws],[icmt07],[-- NB: -S],
[Tri martolod yaouank
O voned da voyagi
Gant'el oant bet kaset
Betek an douar nevez],
[NB: Tri martolod yaouank
NB: O voned da voyagi
NB: Gant'el oant bet kaset
NB: Betek an douar nevez])
m4_popdef([INLINECOM])
m4_popdef([FILTER_MODE])
# End of inline-comment.at
......
......@@ -447,12 +447,35 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
size_t size = 0;
size_t n = 0;
char *prefix = "\t";
mu_stream_t outstr, flt;
char *argv[3];
fprintf (stdout, _("Interpolating: %lu\n"),
(unsigned long) mspec->msg_part[0]);
mailvar_get (&prefix, "indentprefix", mailvar_type_string, 0);
fflush (ofile);
rc = mu_stdio_stream_create (&outstr, fileno (ofile), MU_STREAM_WRITE);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create", NULL, rc);
return rc;
}
argv[0] = "INLINE-COMMENT";
argv[1] = prefix;
argv[2] = NULL;
rc = mu_filter_create_args (&flt, outstr, "INLINE-COMMENT",
2, argv,
MU_FILTER_ENCODE,
MU_STREAM_WRITE);
mu_stream_unref (outstr);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_create_args", NULL, rc);
return rc;
}
if (*(int*)data)
{
size_t i, num = 0;
......@@ -468,20 +491,15 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
{
const char *value;
fprintf (ofile, "%s%s: ", prefix, sptr);
mu_stream_printf (flt, "%s: ", sptr);
if (mu_header_sget_value (hdr, sptr, &value) == 0)
{
for (; *value; value++)
{
fputc (*value, ofile);
if (*value == '\n')
fprintf (ofile, "%s", prefix);
}
fputc ('\n', ofile);
mu_stream_write (flt, value, strlen (value), NULL);
mu_stream_write (flt, "\n", 1, NULL);
}
}
}
fprintf (ofile, "%s\n", prefix);
mu_stream_write (flt, "\n", 1, NULL);
mu_message_get_body (mesg, &body);
rc = mu_body_get_streamref (body, &stream);
}
......@@ -494,11 +512,11 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
return rc;
}
/* FIXME: Use mu_stream_copy? */
while (mu_stream_getline (stream, &buffer, &size, &n) == 0 && n != 0)
fprintf (ofile, "%s%s", prefix, buffer);
free (buffer);
mu_stream_copy (flt, stream, 0, NULL);
mu_stream_destroy (&stream);
mu_stream_destroy (&flt);
return 0;
}
......
......@@ -217,7 +217,7 @@ struct mailvar_symbol mailvar_tab[] =
set_replyregex },
{ { "save", },
MAILVAR_TYPEMASK (mailvar_type_boolean),
N_("stored aborted messages in the user's dead.file") },
N_("store aborted messages in the user's dead.file") },
{ { "screen", },
MAILVAR_TYPEMASK (mailvar_type_number),
N_("number of lines on terminal screen"),
......