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.
Showing
4 changed files
with
105 additions
and
17 deletions
This diff is collapsed.
Click to expand it.
... | @@ -14,12 +14,14 @@ | ... | @@ -14,12 +14,14 @@ |
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | m4_pushdef([FILTER_MODE],[decode]) | ||
18 | |||
17 | dnl ------------------------------------------------------------------- | 19 | dnl ------------------------------------------------------------------- |
18 | dnl INLINECOM(NAME, [KW = `'], [OPTS = `'], [TEXT], [OUTPUT = `']) | 20 | dnl INLINECOM(NAME, [KW = `'], [OPTS = `'], [TEXT], [OUTPUT = `']) |
19 | dnl ------------------------------------------------------------------- | 21 | dnl ------------------------------------------------------------------- |
20 | m4_pushdef([INLINECOM],[ | 22 | m4_pushdef([INLINECOM],[ |
21 | AT_SETUP([inline-comment: $1]) | 23 | AT_SETUP([inline-comment: $1]) |
22 | AT_KEYWORDS([filter inline-comment icmt $2]) | 24 | AT_KEYWORDS([filter FILTER_MODE inline-comment icmt $2]) |
23 | sed 's/\$.*//' > input <<EOT | 25 | sed 's/\$.*//' > input <<EOT |
24 | $4 | 26 | $4 |
25 | EOT | 27 | EOT |
... | @@ -27,10 +29,10 @@ sed 's/\$.*//' > expout <<EOT | ... | @@ -27,10 +29,10 @@ sed 's/\$.*//' > expout <<EOT |
27 | $5 | 29 | $5 |
28 | EOT | 30 | EOT |
29 | 31 | ||
30 | AT_CHECK([fltst inline-comment decode read $3 < input], | 32 | AT_CHECK([fltst inline-comment FILTER_MODE read $3 < input], |
31 | [0], | 33 | [0], |
32 | [expout]) | 34 | [expout]) |
33 | AT_CHECK([fltst inline-comment decode write $3 < input], | 35 | AT_CHECK([fltst inline-comment FILTER_MODE write $3 < input], |
34 | [0], | 36 | [0], |
35 | [expout]) | 37 | [expout]) |
36 | AT_CLEANUP | 38 | AT_CLEANUP |
... | @@ -108,6 +110,74 @@ text 4 | ... | @@ -108,6 +110,74 @@ text 4 |
108 | text 5[]dnl | 110 | text 5[]dnl |
109 | ]) | 111 | ]) |
110 | 112 | ||
113 | INLINECOM([multichar comment starter],[icmt05],[-- rem], | ||
114 | [Text line 1 | ||
115 | rem remark text | ||
116 | Text line 2 | ||
117 | remark text (sic!) | ||
118 | Text line 3 | ||
119 | ], | ||
120 | [Text line 1 | ||
121 | Text line 2 | ||
122 | Text line 3 | ||
123 | ]) | ||
124 | |||
125 | INLINECOM([multichar comment starter; follow ws; follow ws mode],[icmt06], | ||
126 | [-- rem -S], | ||
127 | [Text line 1 | ||
128 | rem remark text | ||
129 | Text line 2 | ||
130 | remark text (sic!) | ||
131 | Text line 3 | ||
132 | ], | ||
133 | [Text line 1 | ||
134 | Text line 2 | ||
135 | remark text (sic!) | ||
136 | Text line 3 | ||
137 | ]) | ||
138 | |||
139 | INLINECOM([multichar; squeeze; remove empty],[icmt06],[-- rem -S -r], | ||
140 | [rem comment 1 | ||
141 | text 1 | ||
142 | rem comment 2 | ||
143 | rem comment 3 | ||
144 | text 2 | ||
145 | |||
146 | text 3 | ||
147 | |||
148 | $ | ||
149 | text 4 | ||
150 | text 5 | ||
151 | ], | ||
152 | [text 1 | ||
153 | text 2 | ||
154 | text 3 | ||
155 | text 4 | ||
156 | text 5[]dnl | ||
157 | ]) | ||
158 | |||
159 | m4_define([FILTER_MODE],[encode]) | ||
160 | INLINECOM([encode],[icmt07],[], | ||
161 | [C'est dans dix ans je m'en irai | ||
162 | J'entends le loup et le renard chanter | ||
163 | J'entends le loup, le renard et la belette | ||
164 | J'entends le loup et le renard chanter], | ||
165 | [;C'est dans dix ans je m'en irai | ||
166 | ;J'entends le loup et le renard chanter | ||
167 | ;J'entends le loup, le renard et la belette | ||
168 | ;J'entends le loup et le renard chanter]) | ||
169 | |||
170 | INLINECOM([encode multichar; add ws],[icmt07],[-- NB: -S], | ||
171 | [Tri martolod yaouank | ||
172 | O voned da voyagi | ||
173 | Gant'el oant bet kaset | ||
174 | Betek an douar nevez], | ||
175 | [NB: Tri martolod yaouank | ||
176 | NB: O voned da voyagi | ||
177 | NB: Gant'el oant bet kaset | ||
178 | NB: Betek an douar nevez]) | ||
111 | 179 | ||
112 | m4_popdef([INLINECOM]) | 180 | m4_popdef([INLINECOM]) |
181 | m4_popdef([FILTER_MODE]) | ||
182 | |||
113 | # End of inline-comment.at | 183 | # End of inline-comment.at | ... | ... |
... | @@ -447,12 +447,35 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) | ... | @@ -447,12 +447,35 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) |
447 | size_t size = 0; | 447 | size_t size = 0; |
448 | size_t n = 0; | 448 | size_t n = 0; |
449 | char *prefix = "\t"; | 449 | char *prefix = "\t"; |
450 | mu_stream_t outstr, flt; | ||
451 | char *argv[3]; | ||
450 | 452 | ||
451 | fprintf (stdout, _("Interpolating: %lu\n"), | 453 | fprintf (stdout, _("Interpolating: %lu\n"), |
452 | (unsigned long) mspec->msg_part[0]); | 454 | (unsigned long) mspec->msg_part[0]); |
453 | 455 | ||
454 | mailvar_get (&prefix, "indentprefix", mailvar_type_string, 0); | 456 | mailvar_get (&prefix, "indentprefix", mailvar_type_string, 0); |
455 | 457 | ||
458 | fflush (ofile); | ||
459 | rc = mu_stdio_stream_create (&outstr, fileno (ofile), MU_STREAM_WRITE); | ||
460 | if (rc) | ||
461 | { | ||
462 | mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create", NULL, rc); | ||
463 | return rc; | ||
464 | } | ||
465 | argv[0] = "INLINE-COMMENT"; | ||
466 | argv[1] = prefix; | ||
467 | argv[2] = NULL; | ||
468 | rc = mu_filter_create_args (&flt, outstr, "INLINE-COMMENT", | ||
469 | 2, argv, | ||
470 | MU_FILTER_ENCODE, | ||
471 | MU_STREAM_WRITE); | ||
472 | mu_stream_unref (outstr); | ||
473 | if (rc) | ||
474 | { | ||
475 | mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_create_args", NULL, rc); | ||
476 | return rc; | ||
477 | } | ||
478 | |||
456 | if (*(int*)data) | 479 | if (*(int*)data) |
457 | { | 480 | { |
458 | size_t i, num = 0; | 481 | size_t i, num = 0; |
... | @@ -468,20 +491,15 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) | ... | @@ -468,20 +491,15 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) |
468 | { | 491 | { |
469 | const char *value; | 492 | const char *value; |
470 | 493 | ||
471 | fprintf (ofile, "%s%s: ", prefix, sptr); | 494 | mu_stream_printf (flt, "%s: ", sptr); |
472 | if (mu_header_sget_value (hdr, sptr, &value) == 0) | 495 | if (mu_header_sget_value (hdr, sptr, &value) == 0) |
473 | { | 496 | { |
474 | for (; *value; value++) | 497 | mu_stream_write (flt, value, strlen (value), NULL); |
475 | { | 498 | mu_stream_write (flt, "\n", 1, NULL); |
476 | fputc (*value, ofile); | ||
477 | if (*value == '\n') | ||
478 | fprintf (ofile, "%s", prefix); | ||
479 | } | 499 | } |
480 | fputc ('\n', ofile); | ||
481 | } | 500 | } |
482 | } | 501 | } |
483 | } | 502 | mu_stream_write (flt, "\n", 1, NULL); |
484 | fprintf (ofile, "%s\n", prefix); | ||
485 | mu_message_get_body (mesg, &body); | 503 | mu_message_get_body (mesg, &body); |
486 | rc = mu_body_get_streamref (body, &stream); | 504 | rc = mu_body_get_streamref (body, &stream); |
487 | } | 505 | } |
... | @@ -494,11 +512,11 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) | ... | @@ -494,11 +512,11 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) |
494 | return rc; | 512 | return rc; |
495 | } | 513 | } |
496 | 514 | ||
497 | /* FIXME: Use mu_stream_copy? */ | 515 | mu_stream_copy (flt, stream, 0, NULL); |
498 | while (mu_stream_getline (stream, &buffer, &size, &n) == 0 && n != 0) | 516 | |
499 | fprintf (ofile, "%s%s", prefix, buffer); | ||
500 | free (buffer); | ||
501 | mu_stream_destroy (&stream); | 517 | mu_stream_destroy (&stream); |
518 | mu_stream_destroy (&flt); | ||
519 | |||
502 | return 0; | 520 | return 0; |
503 | } | 521 | } |
504 | 522 | ... | ... |
... | @@ -217,7 +217,7 @@ struct mailvar_symbol mailvar_tab[] = | ... | @@ -217,7 +217,7 @@ struct mailvar_symbol mailvar_tab[] = |
217 | set_replyregex }, | 217 | set_replyregex }, |
218 | { { "save", }, | 218 | { { "save", }, |
219 | MAILVAR_TYPEMASK (mailvar_type_boolean), | 219 | MAILVAR_TYPEMASK (mailvar_type_boolean), |
220 | N_("stored aborted messages in the user's dead.file") }, | 220 | N_("store aborted messages in the user's dead.file") }, |
221 | { { "screen", }, | 221 | { { "screen", }, |
222 | MAILVAR_TYPEMASK (mailvar_type_number), | 222 | MAILVAR_TYPEMASK (mailvar_type_number), |
223 | N_("number of lines on terminal screen"), | 223 | N_("number of lines on terminal screen"), | ... | ... |
-
Please register or sign in to post a comment