Commit 4e7f5b5c 4e7f5b5c08095818d7876a86ad6657c57c9a8ad1 by Sergey Poznyakoff

Fix logstream to support mu_locus_range.

* include/mailutils/locus.h (mu_stream_print_locus_range)
(mu_stream_vlprintf, mu_stream_lprintf, mu_lrange_debug): New protos.
* include/mailutils/stream.h (MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE)
(MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE): New ioctls.
* include/mailutils/sys/logstream.h (_mu_log_stream): Replace
locus with struct mu_locus_range locrange.
* libmailutils/locus/debug.c: Rewrite.
* libmailutils/locus/ident.c (mu_ident_ref): Accept NULL argument.
Fix initialization.
(mu_ident_deref): Accept NULL argument.
* libmailutils/stream/logstream.c: Rewrite.
* libmailutils/tests/.gitignore: Update.
* libmailutils/tests/Makefile.am: Add new tests.
* libmailutils/tests/testsuite.at: Likewise.
* libmailutils/tests/logstr.at: New testcase.
* libmailutils/tests/logstr.c: New file.
* libmailutils/tests/xscript.at: Minor change.
* sieve/tests/i-numeric.at: Minor change.
1 parent 7bca245a
...@@ -106,7 +106,7 @@ int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset); ...@@ -106,7 +106,7 @@ int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset);
106 if (mu_debug_line_info) \ 106 if (mu_debug_line_info) \
107 { \ 107 { \
108 mu_debug_log_begin ("\033X<%d>%s:%d: ", \ 108 mu_debug_log_begin ("\033X<%d>%s:%d: ", \
109 MU_LOGMODE_LOCUS, __FILE__, __LINE__); \ 109 MU_LOGMODE_LOCUS, __FILE__, __LINE__); \
110 mu_debug_log_end s; \ 110 mu_debug_log_end s; \
111 } \ 111 } \
112 else \ 112 else \
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
2 #define _MAILUTILS_LOCUS_H 2 #define _MAILUTILS_LOCUS_H
3 3
4 #include <string.h> 4 #include <string.h>
5 #include <stdarg.h>
5 6
6 struct mu_locus_point 7 struct mu_locus_point
7 { 8 {
...@@ -49,6 +50,17 @@ void mu_locus_tracker_advance (struct mu_locus_track *trk, ...@@ -49,6 +50,17 @@ void mu_locus_tracker_advance (struct mu_locus_track *trk,
49 char const *text, size_t leng); 50 char const *text, size_t leng);
50 void mu_locus_tracker_retreat (struct mu_locus_track *trk, size_t n); 51 void mu_locus_tracker_retreat (struct mu_locus_track *trk, size_t n);
51 52
53 void mu_stream_print_locus_range (mu_stream_t stream,
54 struct mu_locus_range const *loc);
55
56 void mu_stream_vlprintf (mu_stream_t stream,
57 struct mu_locus_range const *loc,
58 char const *fmt, va_list ap);
59 void mu_stream_lprintf (mu_stream_t stream,
60 struct mu_locus_range const *loc,
61 char const *fmt, ...);
62 void mu_lrange_debug (struct mu_locus_range const *loc,
63 char const *fmt, ...);
52 64
53 65
54 #endif 66 #endif
......
...@@ -32,8 +32,8 @@ extern "C" { ...@@ -32,8 +32,8 @@ extern "C" {
32 #define MU_LOG_ALERT 6 32 #define MU_LOG_ALERT 6
33 #define MU_LOG_EMERG 7 33 #define MU_LOG_EMERG 7
34 34
35 #define MU_LOGMODE_SEVERITY 0x0001 35 #define MU_LOGMODE_SEVERITY 0x0001
36 #define MU_LOGMODE_LOCUS 0x0002 36 #define MU_LOGMODE_LOCUS 0x0002
37 37
38 int mu_log_stream_create (mu_stream_t *, mu_stream_t); 38 int mu_log_stream_create (mu_stream_t *, mu_stream_t);
39 int mu_syslog_stream_create (mu_stream_t *, int); 39 int mu_syslog_stream_create (mu_stream_t *, int);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
36 #include <mailutils/header.h> 36 #include <mailutils/header.h>
37 #include <mailutils/iterator.h> 37 #include <mailutils/iterator.h>
38 #include <mailutils/kwd.h> 38 #include <mailutils/kwd.h>
39 /* FIXME #include <mailutils/locus.h> */
39 #include <mailutils/sieve.h> 40 #include <mailutils/sieve.h>
40 #include <mailutils/list.h> 41 #include <mailutils/list.h>
41 #include <mailutils/locker.h> 42 #include <mailutils/locker.h>
......
...@@ -83,7 +83,7 @@ enum mu_buffer_type ...@@ -83,7 +83,7 @@ enum mu_buffer_type
83 /* Opcodes common for various families */ 83 /* Opcodes common for various families */
84 #define MU_IOCTL_OP_GET 0 84 #define MU_IOCTL_OP_GET 0
85 #define MU_IOCTL_OP_SET 1 85 #define MU_IOCTL_OP_SET 1
86 86
87 /* Opcodes for MU_IOCTL_PROGSTREAM */ 87 /* Opcodes for MU_IOCTL_PROGSTREAM */
88 #define MU_IOCTL_PROG_STATUS 0 88 #define MU_IOCTL_PROG_STATUS 0
89 #define MU_IOCTL_PROG_PID 1 89 #define MU_IOCTL_PROG_PID 1
...@@ -158,6 +158,15 @@ enum mu_buffer_type ...@@ -158,6 +158,15 @@ enum mu_buffer_type
158 Arg: mu_stream_t* 158 Arg: mu_stream_t*
159 */ 159 */
160 #define MU_IOCTL_LOGSTREAM_CLONE 14 160 #define MU_IOCTL_LOGSTREAM_CLONE 14
161
162 /* Get locus range.
163 Arg: struct mu_locus_range *
164 */
165 #define MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE 15
166 /* Set locus range.
167 Arg: struct mu_locus_range *
168 */
169 #define MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE 16
161 170
162 /* Opcodes for MU_IOCTL_XSCRIPTSTREAM */ 171 /* Opcodes for MU_IOCTL_XSCRIPTSTREAM */
163 /* Swap transcript levels. 172 /* Swap transcript levels.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 19
20 #include <mailutils/types.h> 20 #include <mailutils/types.h>
21 #include <mailutils/sys/stream.h> 21 #include <mailutils/sys/stream.h>
22 #include <mailutils/locus.h>
22 23
23 struct _mu_log_stream 24 struct _mu_log_stream
24 { 25 {
...@@ -30,7 +31,7 @@ struct _mu_log_stream ...@@ -30,7 +31,7 @@ struct _mu_log_stream
30 int logmode; /* Mode flags */ 31 int logmode; /* Mode flags */
31 int sevmask; /* Mask out the output of severity level for 32 int sevmask; /* Mask out the output of severity level for
32 these severities. */ 33 these severities. */
33 struct mu_locus locus; /* Location */ 34 struct mu_locus_range locrange; /* Location in the source file */
34 }; 35 };
35 36
36 void _mu_log_stream_setup (struct _mu_log_stream *sp, mu_stream_t transport); 37 void _mu_log_stream_setup (struct _mu_log_stream *sp, mu_stream_t transport);
......
...@@ -9,12 +9,78 @@ ...@@ -9,12 +9,78 @@
9 #include <mailutils/stdstream.h> 9 #include <mailutils/stdstream.h>
10 10
11 void 11 void
12 mu_stream_print_locus_range (mu_stream_t stream,
13 struct mu_locus_range const *loc)
14 {
15 if (loc->beg.mu_col == 0)
16 {
17 if (loc->end.mu_file
18 && (!mu_locus_point_same_file (&loc->beg, &loc->end)
19 || loc->beg.mu_line != loc->end.mu_line))
20 mu_stream_printf (stream, "%s:%u-%u",
21 loc->beg.mu_file,
22 loc->beg.mu_line,
23 loc->end.mu_line);
24 else
25 mu_stream_printf (stream, "%s:%u",
26 loc->beg.mu_file,
27 loc->beg.mu_line);
28 }
29 else
30 {
31 if (loc->end.mu_file
32 && !mu_locus_point_same_file (&loc->beg, &loc->end))
33 mu_stream_printf (stream, "%s:%u.%u-%s:%u.%u",
34 loc->beg.mu_file,
35 loc->beg.mu_line, loc->beg.mu_col,
36 loc->end.mu_file,
37 loc->end.mu_line, loc->end.mu_col);
38 else if (loc->end.mu_file && loc->beg.mu_line != loc->end.mu_line)
39 mu_stream_printf (stream, "%s:%u.%u-%u.%u",
40 loc->beg.mu_file,
41 loc->beg.mu_line, loc->beg.mu_col,
42 loc->end.mu_line, loc->end.mu_col);
43 else if (loc->end.mu_file && loc->beg.mu_col != loc->end.mu_col)
44 mu_stream_printf (stream, "%s:%u.%u-%u",
45 loc->beg.mu_file,
46 loc->beg.mu_line, loc->beg.mu_col,
47 loc->end.mu_col);
48 else
49 mu_stream_printf (stream, "%s:%u.%u",
50 loc->beg.mu_file,
51 loc->beg.mu_line, loc->beg.mu_col);
52 }
53 }
54
55 void
56 mu_stream_vlprintf (mu_stream_t stream,
57 struct mu_locus_range const *loc,
58 char const *fmt, va_list ap)
59 {
60 mu_stream_print_locus_range (stream, loc);
61 mu_stream_write (stream, ": ", 2, NULL);
62 mu_stream_vprintf (mu_strerr, fmt, ap);
63 mu_stream_write (stream, "\n", 1, NULL);
64 }
65
66 void
67 mu_stream_lprintf (mu_stream_t stream,
68 struct mu_locus_range const *loc,
69 char const *fmt, ...)
70 {
71 va_list ap;
72 va_start (ap, fmt);
73 mu_stream_vlprintf (stream, loc, fmt, ap);
74 va_end (ap);
75 }
76
77 void
12 mu_lrange_debug (struct mu_locus_range const *loc, 78 mu_lrange_debug (struct mu_locus_range const *loc,
13 char const *fmt, ...) 79 char const *fmt, ...)
14 { 80 {
15 va_list ap; 81 va_list ap;
16 int rc, mode; 82 int rc, mode;
17 83
18 rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, 84 rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
19 MU_IOCTL_LOGSTREAM_GET_MODE, &mode); 85 MU_IOCTL_LOGSTREAM_GET_MODE, &mode);
20 if (rc == 0) 86 if (rc == 0)
...@@ -23,37 +89,13 @@ mu_lrange_debug (struct mu_locus_range const *loc, ...@@ -23,37 +89,13 @@ mu_lrange_debug (struct mu_locus_range const *loc,
23 rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, 89 rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
24 MU_IOCTL_LOGSTREAM_SET_MODE, &new_mode); 90 MU_IOCTL_LOGSTREAM_SET_MODE, &new_mode);
25 } 91 }
26 92
27 if (loc->beg.mu_col == 0)
28 mu_debug_log_begin ("%s:%u", loc->beg.mu_file, loc->beg.mu_line);
29 else if (!mu_locus_point_same_file (&loc->beg, &loc->end))
30 mu_debug_log_begin ("%s:%u.%u-%s:%u.%u",
31 loc->beg.mu_file,
32 loc->beg.mu_line, loc->beg.mu_col,
33 loc->end.mu_file,
34 loc->end.mu_line, loc->end.mu_col);
35 else if (loc->beg.mu_line != loc->end.mu_line)
36 mu_debug_log_begin ("%s:%u.%u-%u.%u",
37 loc->beg.mu_file,
38 loc->beg.mu_line, loc->beg.mu_col,
39 loc->end.mu_line, loc->end.mu_col);
40 else if (loc->beg.mu_col != loc->end.mu_col)
41 mu_debug_log_begin ("%s:%u.%u-%u",
42 loc->beg.mu_file,
43 loc->beg.mu_line, loc->beg.mu_col,
44 loc->end.mu_col);
45 else
46 mu_debug_log_begin ("%s:%u.%u",
47 loc->beg.mu_file,
48 loc->beg.mu_line, loc->beg.mu_col);
49
50 mu_stream_write (mu_strerr, ": ", 2, NULL);
51
52 va_start (ap, fmt); 93 va_start (ap, fmt);
53 mu_stream_vprintf (mu_strerr, fmt, ap); 94 mu_stream_lprintf (mu_strerr, loc, fmt, ap);
54 va_end (ap); 95 va_end (ap);
55 mu_debug_log_nl (); 96
56 if (rc == 0) 97 if (rc == 0)
57 mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, 98 mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
58 MU_IOCTL_LOGSTREAM_SET_MODE, &mode); 99 MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
100
59 } 101 }
......
...@@ -20,10 +20,13 @@ mu_ident_ref (char const *name, char const **refname) ...@@ -20,10 +20,13 @@ mu_ident_ref (char const *name, char const **refname)
20 int rc; 20 int rc;
21 struct mu_ident_ref *ref, **refptr; 21 struct mu_ident_ref *ref, **refptr;
22 22
23 if (!name)
24 return EINVAL;
25 if (!refname) 23 if (!refname)
26 return MU_ERR_OUT_PTR_NULL; 24 return MU_ERR_OUT_PTR_NULL;
25 if (!name)
26 {
27 *refname = NULL;
28 return 0;
29 }
27 30
28 if (!nametab) 31 if (!nametab)
29 { 32 {
...@@ -46,6 +49,7 @@ mu_ident_ref (char const *name, char const **refname) ...@@ -46,6 +49,7 @@ mu_ident_ref (char const *name, char const **refname)
46 mu_assoc_remove (nametab, name); 49 mu_assoc_remove (nametab, name);
47 return rc; 50 return rc;
48 } 51 }
52 *refptr = ref;
49 ref->count = 0; 53 ref->count = 0;
50 break; 54 break;
51 55
...@@ -68,9 +72,7 @@ mu_ident_deref (char const *name) ...@@ -68,9 +72,7 @@ mu_ident_deref (char const *name)
68 struct mu_ident_ref *ref; 72 struct mu_ident_ref *ref;
69 int rc; 73 int rc;
70 74
71 if (!name) 75 if (!name || !nametab)
72 return EINVAL;
73 if (!nametab)
74 return 0; 76 return 0;
75 77
76 rc = mu_assoc_lookup (nametab, name, &ref); 78 rc = mu_assoc_lookup (nametab, name, &ref);
......
...@@ -19,6 +19,7 @@ fsfolder ...@@ -19,6 +19,7 @@ fsfolder
19 globtest 19 globtest
20 imapio 20 imapio
21 listop 21 listop
22 logstr
22 mailcap 23 mailcap
23 mimehdr 24 mimehdr
24 modmesg 25 modmesg
......
...@@ -54,6 +54,7 @@ noinst_PROGRAMS = \ ...@@ -54,6 +54,7 @@ noinst_PROGRAMS = \
54 globtest\ 54 globtest\
55 imapio\ 55 imapio\
56 listop\ 56 listop\
57 logstr\
57 mailcap\ 58 mailcap\
58 mimehdr\ 59 mimehdr\
59 modtofsaf\ 60 modtofsaf\
...@@ -106,6 +107,7 @@ TESTSUITE_AT = \ ...@@ -106,6 +107,7 @@ TESTSUITE_AT = \
106 inline-comment.at\ 107 inline-comment.at\
107 linecon.at\ 108 linecon.at\
108 list.at\ 109 list.at\
110 logstr.at\
109 mailcap.at\ 111 mailcap.at\
110 mimehdr.at\ 112 mimehdr.at\
111 modmesg00.at\ 113 modmesg00.at\
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2017 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
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/>.
16
17 AT_SETUP(Logger stream)
18 AT_KEYWORDS([logstream])
19 AT_CHECK([logstr],
20 [0],
21 [00. simple print
22 hello world
23 01. severity
24 info: one
25 emerg: two
26 mode was: 0x0001
27 02. suppress severity
28 info: this message is seen
29 emerg: and this one as well
30 03. suppress severity name
31 info: this message is seen
32 emerg: and this one as well
33 04. severity mask
34 one
35 two
36 emerg: three
37 05. set/get locus point
38 input:1: filename and line number
39 input:1.3: filename, line and column numbers
40 06. locus: file, line
41 input:1: file, line
42 07. locus: file, line, col
43 input:1.1-10: file, line, col
44 08. locus: file, line-range
45 input:1-2: file, line-range
46 09. locus: file, line-range, col
47 input:1.1-2.10: file, line-range, col
48 10. locus: file-range, line-range, col-range
49 input:1.1-next:2.10: file-range, line-range, col-range
50 11. set locus line
51 input:1.1-next:2.10: initial
52 input:8.1-next:2.10: locus line changed
53 12. advance locus line
54 input:1.1-next:5.10: initial
55 input:3.1-next:5.10: locus line advanced
56 13. set locus column
57 input:1.1-next:2.10: initial
58 input:1.8-next:2.10: locus column changed
59 14. advance locus column
60 input:1.1-next:5.10: initial
61 input:1.5-next:5.10: locus line advanced
62 15. fmt: severity
63 info: severity
64 16. fmt: locus (file, line)
65 a:10: one
66 17. fmt: locus (file, line, column)
67 a:10.5: one
68 18. fmt: locus (range)
69 a:10.5-b:14.8: one
70 19. fmt: locus; restore defaults
71 a:10.5-b:14.8: one
72 default
73 20. fmt: locus; restore defaults, display locus
74 a:10.5-b:14.8: one
75 input:1.1-next:5.10: default
76 21. fmt: set locus
77 a:10.5-b:14.8: one
78 a:10.5-b:14.8: default
79 ])
80 AT_CLEANUP
...\ No newline at end of file ...\ No newline at end of file
...@@ -152,6 +152,10 @@ m4_include([strin.at]) ...@@ -152,6 +152,10 @@ m4_include([strin.at])
152 m4_include([strout.at]) 152 m4_include([strout.at])
153 m4_include([strerr.at]) 153 m4_include([strerr.at])
154 154
155 AT_BANNER([Streams])
156 m4_include([logstr.at])
157 m4_include([xscript.at])
158
155 m4_include([list.at]) 159 m4_include([list.at])
156 m4_include([address.at]) 160 m4_include([address.at])
157 m4_include([wordsplit.at]) 161 m4_include([wordsplit.at])
...@@ -208,4 +212,3 @@ m4_include([msgset.at]) ...@@ -208,4 +212,3 @@ m4_include([msgset.at])
208 212
209 m4_include([globtest.at]) 213 m4_include([globtest.at])
210 214
211 m4_include([xscript.at])
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
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 AT_BANNER([Transcript stream])
18 AT_SETUP([Transcript stream]) 17 AT_SETUP([Transcript stream])
19 AT_KEYWORDS([stream xscript]) 18 AT_KEYWORDS([stream xscript])
20 AT_DATA([input],[first line 19 AT_DATA([input],[first line
......
...@@ -38,7 +38,7 @@ if header :comparator "i;ascii-numeric" :contains "X-Number" "15" ...@@ -38,7 +38,7 @@ if header :comparator "i;ascii-numeric" :contains "X-Number" "15"
38 discard; 38 discard;
39 } 39 }
40 ],[78],[], 40 ],[78],[],
41 [sieve: prog:4:1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header' 41 [sieve: prog:4.1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
42 ]) 42 ])
43 AT_CLEANUP 43 AT_CLEANUP
44 44
......
1 atconfig 1 atconfig
2 atlocal 2 atlocal
3 bs 3 bs
4 cwdrepl
4 fldel 5 fldel
5 lstuid 6 lstuid
6 package.m4 7 package.m4
......