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 @@ ...@@ -40,14 +40,15 @@
40 #include <mailutils/io.h> 40 #include <mailutils/io.h>
41 41
42 #define LINECON_LINE_INFO 0x01 /* Emit line number information */ 42 #define LINECON_LINE_INFO 0x01 /* Emit line number information */
43 #define LINECON_LINE_INFO_STATIC 0x02 43 #define LINECON_LINE_INFO_STATIC 0x02 /* Line info starter is in static
44 storage */
45 #define LINECON_CONTINUATION 0x04 /* Line continuation in progress */
44 46
45 enum linecon_state 47 enum linecon_state
46 { 48 {
47 linecon_init, 49 linecon_init, /* Initial state */
48 linecon_escape, 50 linecon_escape, /* An escape was seen */
49 linecon_newline, 51 linecon_rollback /* Rollback in progress */
50 linecon_rollback
51 }; 52 };
52 53
53 struct linecon_data 54 struct linecon_data
...@@ -98,7 +99,6 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd, ...@@ -98,7 +99,6 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd,
98 switch (pd->state) 99 switch (pd->state)
99 { 100 {
100 case linecon_init: 101 case linecon_init:
101 case linecon_newline:
102 switch (*iptr) 102 switch (*iptr)
103 { 103 {
104 case '\\': 104 case '\\':
...@@ -107,8 +107,9 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd, ...@@ -107,8 +107,9 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd,
107 continue; 107 continue;
108 case '\n': 108 case '\n':
109 pd->line_number++; 109 pd->line_number++;
110 if (pd->state == linecon_newline) 110 if (pd->flags & LINECON_CONTINUATION)
111 { 111 {
112 pd->flags &= ~LINECON_CONTINUATION;
112 mu_asnprintf (&pd->buf, &pd->size, "%s %lu\n", 113 mu_asnprintf (&pd->buf, &pd->size, "%s %lu\n",
113 pd->line_info_starter, 114 pd->line_info_starter,
114 pd->line_number); 115 pd->line_number);
...@@ -128,8 +129,9 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd, ...@@ -128,8 +129,9 @@ _linecon_decoder (void *xd, enum mu_filter_command cmd,
128 { 129 {
129 pd->line_number++; 130 pd->line_number++;
130 iptr++; 131 iptr++;
131 pd->state = (pd->flags & LINECON_LINE_INFO) ? 132 pd->state = linecon_init;
132 linecon_newline : linecon_init; 133 if (pd->flags & LINECON_LINE_INFO)
134 pd->flags |= LINECON_CONTINUATION;
133 continue; 135 continue;
134 } 136 }
135 else 137 else
......
...@@ -156,8 +156,29 @@ text 4 ...@@ -156,8 +156,29 @@ text 4
156 text 5[]dnl 156 text 5[]dnl
157 ]) 157 ])
158 158
159 INLINECOM([line info facility],[icmt07 line-info],[-- -i ';line' ';'],
160 [; initial comment
161 this is line 2
162 this is line 3
163 ; A long contiguous
164 ; sequence
165 ; of comments
166 ; occupying several
167 ; lines
168 this is line 9
169 ],
170 [;line 2
171 this is line 2
172 this is line 3
173 ;line 9
174 this is line 9
175 ])
176
177 dnl -------------------------------------------------------------------
178
159 m4_define([FILTER_MODE],[encode]) 179 m4_define([FILTER_MODE],[encode])
160 INLINECOM([encode],[icmt07],[], 180
181 INLINECOM([encode],[icmt08],[],
161 [C'est dans dix ans je m'en irai 182 [C'est dans dix ans je m'en irai
162 J'entends le loup et le renard chanter 183 J'entends le loup et le renard chanter
163 J'entends le loup, le renard et la belette 184 J'entends le loup, le renard et la belette
...@@ -167,7 +188,7 @@ J'entends le loup et le renard chanter], ...@@ -167,7 +188,7 @@ J'entends le loup et le renard chanter],
167 ;J'entends le loup, le renard et la belette 188 ;J'entends le loup, le renard et la belette
168 ;J'entends le loup et le renard chanter]) 189 ;J'entends le loup et le renard chanter])
169 190
170 INLINECOM([encode multichar; add ws],[icmt07],[-- NB: -S], 191 INLINECOM([encode multichar; add ws],[icmt09],[-- NB: -S],
171 [Tri martolod yaouank 192 [Tri martolod yaouank
172 O voned da voyagi 193 O voned da voyagi
173 Gant'el oant bet kaset 194 Gant'el oant bet kaset
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 16
17 AT_SETUP([linecon filter]) 17 AT_SETUP([linecon filter])
18 AT_KEYWORDS([filter decode linecon]) 18 AT_KEYWORDS([filter decode linecon])
19 sed 's/\$//' > input <<EOT 19 sed 's/\$//' > input <<\EOT
20 input line 1 20 input line 1
21 input line 2 21 input line 2
22 a very\ 22 a very\
...@@ -27,7 +27,7 @@ it over several physical\ ...@@ -27,7 +27,7 @@ it over several physical\
27 a li\ne with \escapes 27 a li\ne with \escapes
28 backslash followed by a space \ $ 28 backslash followed by a space \ $
29 EOT 29 EOT
30 sed 's/\$//' > expout <<EOT 30 sed 's/\$//' > expout <<\EOT
31 input line 1 31 input line 1
32 input line 2 32 input line 2
33 a very long logical line split over several physical ones 33 a very long logical line split over several physical ones
...@@ -45,5 +45,45 @@ AT_CHECK([fltst linecon decode write < input], ...@@ -45,5 +45,45 @@ AT_CHECK([fltst linecon decode write < input],
45 45
46 AT_CLEANUP 46 AT_CLEANUP
47 47
48 dnl ---------------------------------------------------------------
49
50 AT_SETUP([linecon filter: line info facility])
51 AT_KEYWORDS([filter decode linecon line-info])
52 sed 's/\$//' > input <<\EOT
53 input line 1
54 input line 2
55 a very\$
56 long logical\
57 line spl\
58 it over several physical\
59 ones
60 a li\ne with \escapes
61 backslash followed by a space \ $
62 another\
63 split line\\\n
64 end of test
65 EOT
66 sed 's/\$//' > expout <<\EOT
67 input line 1
68 input line 2
69 a very long logical line split over several physical ones
70 ;line 8
71 a li\ne with \escapes
72 backslash followed by a space \ $
73 another split line\\\n
74 ;line 12
75 end of test
76 EOT
77
78 AT_CHECK([fltst linecon decode read -- -i ';line' < input],
79 [0],
80 [expout])
81
82 AT_CHECK([fltst linecon decode write -- -i ';line' < input],
83 [0],
84 [expout])
85
86 AT_CLEANUP
87
48 88
49 89
......