Commit 06fb6b02 06fb6b02b42973f8a036cd7288fe7e1f609801b7 by Sergey Poznyakoff

Test line info facility

* libmailutils/tests/inline-comment.at: Add line info tests.
* libmailutils/tests/linecon.at: Likewise.
* libmailutils/filter/linecon.c (LINECON_CONTINUATION): New flag.
(linecon_newline): Remove.
(_linecon_decoder): Correctly determine the end of continuation
in case when the last line contained standalone escapes.
1 parent 75755ec7
......@@ -40,14 +40,15 @@
#include <mailutils/io.h>
#define LINECON_LINE_INFO 0x01 /* Emit line number information */
#define LINECON_LINE_INFO_STATIC 0x02
#define LINECON_LINE_INFO_STATIC 0x02 /* Line info starter is in static
storage */
#define LINECON_CONTINUATION 0x04 /* Line continuation in progress */
enum linecon_state
{
linecon_init,
linecon_escape,
linecon_newline,
linecon_rollback
linecon_init, /* Initial state */
linecon_escape, /* An escape was seen */
linecon_rollback /* Rollback in progress */
};
struct linecon_data
......@@ -98,7 +99,6 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd,
switch (pd->state)
{
case linecon_init:
case linecon_newline:
switch (*iptr)
{
case '\\':
......@@ -107,8 +107,9 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd,
continue;
case '\n':
pd->line_number++;
if (pd->state == linecon_newline)
if (pd->flags & LINECON_CONTINUATION)
{
pd->flags &= ~LINECON_CONTINUATION;
mu_asnprintf (&pd->buf, &pd->size, "%s %lu\n",
pd->line_info_starter,
pd->line_number);
......@@ -128,8 +129,9 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd,
{
pd->line_number++;
iptr++;
pd->state = (pd->flags & LINECON_LINE_INFO) ?
linecon_newline : linecon_init;
pd->state = linecon_init;
if (pd->flags & LINECON_LINE_INFO)
pd->flags |= LINECON_CONTINUATION;
continue;
}
else
......
......@@ -156,8 +156,29 @@ text 4
text 5[]dnl
])
INLINECOM([line info facility],[icmt07 line-info],[-- -i ';line' ';'],
[; initial comment
this is line 2
this is line 3
; A long contiguous
; sequence
; of comments
; occupying several
; lines
this is line 9
],
[;line 2
this is line 2
this is line 3
;line 9
this is line 9
])
dnl -------------------------------------------------------------------
m4_define([FILTER_MODE],[encode])
INLINECOM([encode],[icmt07],[],
INLINECOM([encode],[icmt08],[],
[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
......@@ -167,7 +188,7 @@ 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],
INLINECOM([encode multichar; add ws],[icmt09],[-- NB: -S],
[Tri martolod yaouank
O voned da voyagi
Gant'el oant bet kaset
......
......@@ -16,7 +16,7 @@
AT_SETUP([linecon filter])
AT_KEYWORDS([filter decode linecon])
sed 's/\$//' > input <<EOT
sed 's/\$//' > input <<\EOT
input line 1
input line 2
a very\
......@@ -27,7 +27,7 @@ it over several physical\
a li\ne with \escapes
backslash followed by a space \ $
EOT
sed 's/\$//' > expout <<EOT
sed 's/\$//' > expout <<\EOT
input line 1
input line 2
a very long logical line split over several physical ones
......@@ -45,5 +45,45 @@ AT_CHECK([fltst linecon decode write < input],
AT_CLEANUP
dnl ---------------------------------------------------------------
AT_SETUP([linecon filter: line info facility])
AT_KEYWORDS([filter decode linecon line-info])
sed 's/\$//' > input <<\EOT
input line 1
input line 2
a very\$
long logical\
line spl\
it over several physical\
ones
a li\ne with \escapes
backslash followed by a space \ $
another\
split line\\\n
end of test
EOT
sed 's/\$//' > expout <<\EOT
input line 1
input line 2
a very long logical line split over several physical ones
;line 8
a li\ne with \escapes
backslash followed by a space \ $
another split line\\\n
;line 12
end of test
EOT
AT_CHECK([fltst linecon decode read -- -i ';line' < input],
[0],
[expout])
AT_CHECK([fltst linecon decode write -- -i ';line' < input],
[0],
[expout])
AT_CLEANUP
......