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.
Showing
17 changed files
with
366 additions
and
111 deletions
... | @@ -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 | ... | ... |
... | @@ -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> | ... | ... |
... | @@ -159,6 +159,15 @@ enum mu_buffer_type | ... | @@ -159,6 +159,15 @@ enum mu_buffer_type |
159 | */ | 159 | */ |
160 | #define MU_IOCTL_LOGSTREAM_CLONE 14 | 160 | #define MU_IOCTL_LOGSTREAM_CLONE 14 |
161 | 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 | ||
170 | |||
162 | /* Opcodes for MU_IOCTL_XSCRIPTSTREAM */ | 171 | /* Opcodes for MU_IOCTL_XSCRIPTSTREAM */ |
163 | /* Swap transcript levels. | 172 | /* Swap transcript levels. |
164 | Arg: int *X | 173 | Arg: int *X | ... | ... |
... | @@ -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,51 +9,93 @@ | ... | @@ -9,51 +9,93 @@ |
9 | #include <mailutils/stdstream.h> | 9 | #include <mailutils/stdstream.h> |
10 | 10 | ||
11 | void | 11 | void |
12 | mu_lrange_debug (struct mu_locus_range const *loc, | 12 | mu_stream_print_locus_range (mu_stream_t stream, |
13 | char const *fmt, ...) | 13 | struct mu_locus_range const *loc) |
14 | { | 14 | { |
15 | va_list ap; | 15 | if (loc->beg.mu_col == 0) |
16 | int rc, mode; | ||
17 | |||
18 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | ||
19 | MU_IOCTL_LOGSTREAM_GET_MODE, &mode); | ||
20 | if (rc == 0) | ||
21 | { | 16 | { |
22 | int new_mode = mode & ~MU_LOGMODE_LOCUS; | 17 | if (loc->end.mu_file |
23 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | 18 | && (!mu_locus_point_same_file (&loc->beg, &loc->end) |
24 | MU_IOCTL_LOGSTREAM_SET_MODE, &new_mode); | 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); | ||
25 | } | 28 | } |
26 | 29 | else | |
27 | if (loc->beg.mu_col == 0) | 30 | { |
28 | mu_debug_log_begin ("%s:%u", loc->beg.mu_file, loc->beg.mu_line); | 31 | if (loc->end.mu_file |
29 | else if (!mu_locus_point_same_file (&loc->beg, &loc->end)) | 32 | && !mu_locus_point_same_file (&loc->beg, &loc->end)) |
30 | mu_debug_log_begin ("%s:%u.%u-%s:%u.%u", | 33 | mu_stream_printf (stream, "%s:%u.%u-%s:%u.%u", |
31 | loc->beg.mu_file, | 34 | loc->beg.mu_file, |
32 | loc->beg.mu_line, loc->beg.mu_col, | 35 | loc->beg.mu_line, loc->beg.mu_col, |
33 | loc->end.mu_file, | 36 | loc->end.mu_file, |
34 | loc->end.mu_line, loc->end.mu_col); | 37 | loc->end.mu_line, loc->end.mu_col); |
35 | else if (loc->beg.mu_line != loc->end.mu_line) | 38 | else if (loc->end.mu_file && loc->beg.mu_line != loc->end.mu_line) |
36 | mu_debug_log_begin ("%s:%u.%u-%u.%u", | 39 | mu_stream_printf (stream, "%s:%u.%u-%u.%u", |
37 | loc->beg.mu_file, | 40 | loc->beg.mu_file, |
38 | loc->beg.mu_line, loc->beg.mu_col, | 41 | loc->beg.mu_line, loc->beg.mu_col, |
39 | loc->end.mu_line, loc->end.mu_col); | 42 | loc->end.mu_line, loc->end.mu_col); |
40 | else if (loc->beg.mu_col != loc->end.mu_col) | 43 | else if (loc->end.mu_file && loc->beg.mu_col != loc->end.mu_col) |
41 | mu_debug_log_begin ("%s:%u.%u-%u", | 44 | mu_stream_printf (stream, "%s:%u.%u-%u", |
42 | loc->beg.mu_file, | 45 | loc->beg.mu_file, |
43 | loc->beg.mu_line, loc->beg.mu_col, | 46 | loc->beg.mu_line, loc->beg.mu_col, |
44 | loc->end.mu_col); | 47 | loc->end.mu_col); |
45 | else | 48 | else |
46 | mu_debug_log_begin ("%s:%u.%u", | 49 | mu_stream_printf (stream, "%s:%u.%u", |
47 | loc->beg.mu_file, | 50 | loc->beg.mu_file, |
48 | loc->beg.mu_line, loc->beg.mu_col); | 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 | } | ||
49 | 65 | ||
50 | mu_stream_write (mu_strerr, ": ", 2, NULL); | 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 | ||
78 | mu_lrange_debug (struct mu_locus_range const *loc, | ||
79 | char const *fmt, ...) | ||
80 | { | ||
81 | va_list ap; | ||
82 | int rc, mode; | ||
83 | |||
84 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | ||
85 | MU_IOCTL_LOGSTREAM_GET_MODE, &mode); | ||
86 | if (rc == 0) | ||
87 | { | ||
88 | int new_mode = mode & ~MU_LOGMODE_LOCUS; | ||
89 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | ||
90 | MU_IOCTL_LOGSTREAM_SET_MODE, &new_mode); | ||
91 | } | ||
51 | 92 | ||
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); | ... | ... |
... | @@ -30,6 +30,7 @@ | ... | @@ -30,6 +30,7 @@ |
30 | #include <mailutils/nls.h> | 30 | #include <mailutils/nls.h> |
31 | #include <mailutils/stream.h> | 31 | #include <mailutils/stream.h> |
32 | #include <mailutils/debug.h> | 32 | #include <mailutils/debug.h> |
33 | #include <mailutils/locus.h> | ||
33 | #include <mailutils/sys/logstream.h> | 34 | #include <mailutils/sys/logstream.h> |
34 | 35 | ||
35 | char *_mu_severity_str[] = { | 36 | char *_mu_severity_str[] = { |
... | @@ -69,25 +70,77 @@ mu_severity_to_string (unsigned n, const char **pstr) | ... | @@ -69,25 +70,77 @@ mu_severity_to_string (unsigned n, const char **pstr) |
69 | return 0; | 70 | return 0; |
70 | } | 71 | } |
71 | 72 | ||
73 | static void | ||
74 | lr_set_line (struct mu_locus_range *loc, unsigned val, int end) | ||
75 | { | ||
76 | if (end) | ||
77 | loc->end.mu_line = val; | ||
78 | else | ||
79 | loc->beg.mu_line = val; | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | lr_set_col (struct mu_locus_range *loc, unsigned val, int end) | ||
84 | { | ||
85 | if (end) | ||
86 | loc->end.mu_col = val; | ||
87 | else | ||
88 | loc->beg.mu_col = val; | ||
89 | } | ||
90 | |||
72 | static int | 91 | static int |
73 | _locus_set_file (struct mu_locus *loc, const char *file, size_t len) | 92 | lr_set_file (struct mu_locus_range *loc, char const *fname, unsigned len, |
93 | int end) | ||
74 | { | 94 | { |
75 | free (loc->mu_file); | 95 | char const *refname; |
76 | if (file) | 96 | struct mu_locus_point *pt = end ? &loc->end : &loc->beg; |
97 | int rc; | ||
98 | |||
99 | if (fname == NULL) | ||
77 | { | 100 | { |
78 | loc->mu_file = malloc (len + 1); | 101 | refname = NULL; |
79 | if (!loc->mu_file) | 102 | rc = 0; |
80 | return ENOMEM; | ||
81 | memcpy (loc->mu_file, file, len); | ||
82 | loc->mu_file[len] = 0; | ||
83 | } | 103 | } |
104 | else if (len == 0) | ||
105 | rc = mu_ident_ref (fname, &refname); | ||
84 | else | 106 | else |
85 | loc->mu_file = NULL; | 107 | { |
108 | char *name; | ||
109 | |||
110 | name = malloc (len + 1); | ||
111 | if (!name) | ||
112 | return errno; | ||
113 | memcpy (name, fname, len); | ||
114 | name[len] = 0; | ||
115 | rc = mu_ident_ref (name, &refname); | ||
116 | free (name); | ||
117 | } | ||
118 | if (rc) | ||
119 | return rc; | ||
120 | mu_ident_deref (pt->mu_file); | ||
121 | pt->mu_file = refname; | ||
86 | return 0; | 122 | return 0; |
87 | } | 123 | } |
88 | 124 | ||
89 | #define _locus_set_line(loc, line) ((loc)->mu_line = line) | 125 | /* Field modification map (binary): |
90 | #define _locus_set_col(loc, col) ((loc)->mu_col = col) | 126 | |
127 | FfLlCc | ||
128 | |||
129 | The bits f, l, and c (file, line, and column) are toggled cyclically. | ||
130 | The value 0 means locus beg, 1 meand locus end. | ||
131 | The bits F, L, and C are set once and indicate that the corresponding | ||
132 | bit was toggled at least once. | ||
133 | */ | ||
134 | #define FMM_COL 0 | ||
135 | #define FMM_LINE 1 | ||
136 | #define FMM_FILE 2 | ||
137 | |||
138 | #define FMM_SHIFT(n) ((n)<<1) | ||
139 | #define FMM_MASK(n) (0x3 << FMM_SHIFT (n)) | ||
140 | #define FMM_VAL(m,n) (((m) >> FMM_SHIFT (n)) & 0x1) | ||
141 | #define FMM_SET(m,n,v) ((m) = ((m) & ~FMM_MASK (n)) | (((v) << FMM_SHIFT (n))|0x2)) | ||
142 | #define FMM_CYCLE(m, n) \ | ||
143 | FMM_SET ((m), (n), ((FMM_VAL ((m), (n)) + 1) % 2)) | ||
91 | 144 | ||
92 | static int | 145 | static int |
93 | _log_write (struct _mu_stream *str, const char *buf, size_t size, | 146 | _log_write (struct _mu_stream *str, const char *buf, size_t size, |
... | @@ -96,8 +149,8 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, | ... | @@ -96,8 +149,8 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, |
96 | struct _mu_log_stream *sp = (struct _mu_log_stream *)str; | 149 | struct _mu_log_stream *sp = (struct _mu_log_stream *)str; |
97 | unsigned severity = sp->severity; | 150 | unsigned severity = sp->severity; |
98 | int logmode = sp->logmode; | 151 | int logmode = sp->logmode; |
99 | struct mu_locus loc = sp->locus; | 152 | struct mu_locus_range loc; |
100 | const char *fname = NULL; | 153 | int fmm = 0; |
101 | unsigned flen = 0; | 154 | unsigned flen = 0; |
102 | int save_locus = 0; | 155 | int save_locus = 0; |
103 | int rc; | 156 | int rc; |
... | @@ -120,6 +173,10 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, | ... | @@ -120,6 +173,10 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, |
120 | n = __x; \ | 173 | n = __x; \ |
121 | } while (0) | 174 | } while (0) |
122 | 175 | ||
176 | loc = sp->locrange; | ||
177 | mu_ident_ref (loc.beg.mu_file, &loc.beg.mu_file); | ||
178 | mu_ident_ref (loc.end.mu_file, &loc.end.mu_file); | ||
179 | |||
123 | /* Tell them we've consumed everything */ | 180 | /* Tell them we've consumed everything */ |
124 | *pnwrite = size; | 181 | *pnwrite = size; |
125 | 182 | ||
... | @@ -167,21 +224,24 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, | ... | @@ -167,21 +224,24 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, |
167 | case 'l': | 224 | case 'l': |
168 | /* Input line (decimal) */ | 225 | /* Input line (decimal) */ |
169 | READNUM (n); | 226 | READNUM (n); |
170 | _locus_set_line (&loc, n); | 227 | lr_set_line (&loc, n, FMM_VAL (fmm, FMM_LINE)); |
228 | FMM_CYCLE (fmm, FMM_LINE); | ||
171 | logmode |= MU_LOGMODE_LOCUS; | 229 | logmode |= MU_LOGMODE_LOCUS; |
172 | break; | 230 | break; |
173 | 231 | ||
174 | case 'c': | 232 | case 'c': |
175 | /* Column in input line (decimal) */ | 233 | /* Column in input line (decimal) */ |
176 | READNUM (n); | 234 | READNUM (n); |
177 | _locus_set_col (&loc, n); | 235 | lr_set_col (&loc, n, FMM_VAL (fmm, FMM_COL)); |
236 | FMM_CYCLE (fmm, FMM_COL); | ||
178 | logmode |= MU_LOGMODE_LOCUS; | 237 | logmode |= MU_LOGMODE_LOCUS; |
179 | break; | 238 | break; |
180 | 239 | ||
181 | case 'f': | 240 | case 'f': |
182 | /* File name. Format: <N>S */ | 241 | /* File name. Format: <N>S */ |
183 | READNUM (flen); | 242 | READNUM (flen); |
184 | fname = buf; | 243 | lr_set_file (&loc, buf, flen, FMM_VAL (fmm, FMM_FILE)); |
244 | FMM_CYCLE (fmm, FMM_FILE); | ||
185 | buf += flen; | 245 | buf += flen; |
186 | size -= flen; | 246 | size -= flen; |
187 | logmode |= MU_LOGMODE_LOCUS; | 247 | logmode |= MU_LOGMODE_LOCUS; |
... | @@ -197,50 +257,28 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, | ... | @@ -197,50 +257,28 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, |
197 | if (severity >= _mu_severity_num) | 257 | if (severity >= _mu_severity_num) |
198 | severity = MU_LOG_EMERG; | 258 | severity = MU_LOG_EMERG; |
199 | 259 | ||
200 | if (fname) | ||
201 | { | ||
202 | loc.mu_file = NULL; | ||
203 | _locus_set_file (&loc, fname, flen); | ||
204 | } | ||
205 | |||
206 | if (save_locus) | 260 | if (save_locus) |
207 | { | 261 | { |
208 | _locus_set_file (&sp->locus, loc.mu_file, strlen (loc.mu_file)); | 262 | sp->locrange = loc; |
209 | _locus_set_line (&sp->locus, loc.mu_line); | 263 | mu_ident_ref (sp->locrange.beg.mu_file, &sp->locrange.beg.mu_file); |
210 | _locus_set_col (&sp->locus, loc.mu_col); | 264 | mu_ident_ref (sp->locrange.end.mu_file, &sp->locrange.end.mu_file); |
211 | } | 265 | } |
212 | 266 | ||
213 | if (severity < sp->threshold) | 267 | if (severity < sp->threshold) |
268 | rc = 0; | ||
269 | else | ||
214 | { | 270 | { |
215 | if (fname) | ||
216 | free (loc.mu_file); | ||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM, | 271 | mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM, |
221 | MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity); | 272 | MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity); |
222 | 273 | ||
223 | if (logmode & MU_LOGMODE_LOCUS) | 274 | if ((logmode & MU_LOGMODE_LOCUS) && loc.beg.mu_file) |
224 | { | ||
225 | if (loc.mu_file) | ||
226 | { | 275 | { |
227 | mu_stream_write (sp->transport, loc.mu_file, | 276 | mu_stream_print_locus_range (sp->transport, &loc); |
228 | strlen (loc.mu_file), NULL); | 277 | mu_stream_write (sp->transport, ": ", 2, NULL); |
229 | mu_stream_write (sp->transport, ":", 1, NULL); | ||
230 | if (loc.mu_line) | ||
231 | mu_stream_printf (sp->transport, "%u", loc.mu_line); | ||
232 | mu_stream_write (sp->transport, ":", 1, NULL); | ||
233 | if (loc.mu_col) | ||
234 | mu_stream_printf (sp->transport, "%u:", loc.mu_col); | ||
235 | mu_stream_write (sp->transport, " ", 1, NULL); | ||
236 | } | ||
237 | } | 278 | } |
238 | 279 | ||
239 | if (fname) | ||
240 | free (loc.mu_file); | ||
241 | |||
242 | if ((logmode & MU_LOGMODE_SEVERITY) && | 280 | if ((logmode & MU_LOGMODE_SEVERITY) && |
243 | !(sp->sevmask & MU_DEBUG_LEVEL_MASK(severity))) | 281 | !(sp->sevmask & MU_DEBUG_LEVEL_MASK (severity))) |
244 | { | 282 | { |
245 | char *s = gettext (_mu_severity_str[severity]); | 283 | char *s = gettext (_mu_severity_str[severity]); |
246 | rc = mu_stream_write (sp->transport, s, strlen (s), NULL); | 284 | rc = mu_stream_write (sp->transport, s, strlen (s), NULL); |
... | @@ -248,7 +286,12 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, | ... | @@ -248,7 +286,12 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, |
248 | return rc; | 286 | return rc; |
249 | mu_stream_write (sp->transport, ": ", 2, NULL); | 287 | mu_stream_write (sp->transport, ": ", 2, NULL); |
250 | } | 288 | } |
251 | return mu_stream_write (sp->transport, buf, size, NULL); | 289 | rc = mu_stream_write (sp->transport, buf, size, NULL); |
290 | } | ||
291 | |||
292 | mu_ident_deref (loc.beg.mu_file); | ||
293 | mu_ident_deref (loc.end.mu_file); | ||
294 | return rc; | ||
252 | } | 295 | } |
253 | 296 | ||
254 | static int | 297 | static int |
... | @@ -375,72 +418,133 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg) | ... | @@ -375,72 +418,133 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg) |
375 | sp->logmode = *(int*)arg; | 418 | sp->logmode = *(int*)arg; |
376 | break; | 419 | break; |
377 | 420 | ||
421 | case MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE: | ||
422 | { | ||
423 | struct mu_locus_range *lr = arg; | ||
424 | if (!arg) | ||
425 | { | ||
426 | mu_ident_deref (sp->locrange.beg.mu_file); | ||
427 | mu_ident_deref (sp->locrange.end.mu_file); | ||
428 | memset (&sp->locrange, 0, sizeof sp->locrange); | ||
429 | } | ||
430 | else | ||
431 | { | ||
432 | char const *begname, *endname; | ||
433 | |||
434 | status = mu_ident_ref (lr->beg.mu_file, &begname); | ||
435 | if (status) | ||
436 | return status; | ||
437 | status = mu_ident_ref (lr->end.mu_file, &endname); | ||
438 | if (status) | ||
439 | { | ||
440 | mu_ident_deref (begname); | ||
441 | return status; | ||
442 | } | ||
443 | mu_ident_deref (sp->locrange.beg.mu_file); | ||
444 | sp->locrange.beg.mu_file = begname; | ||
445 | sp->locrange.beg.mu_line = lr->beg.mu_line; | ||
446 | sp->locrange.beg.mu_col = lr->beg.mu_col; | ||
447 | |||
448 | mu_ident_deref (sp->locrange.end.mu_file); | ||
449 | sp->locrange.end.mu_file = endname; | ||
450 | sp->locrange.end.mu_line = lr->end.mu_line; | ||
451 | sp->locrange.end.mu_col = lr->end.mu_col; | ||
452 | } | ||
453 | } | ||
454 | break; | ||
455 | |||
456 | case MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE: | ||
457 | if (!arg) | ||
458 | return EINVAL; | ||
459 | else | ||
460 | { | ||
461 | struct mu_locus_range *lr = arg; | ||
462 | char const *begname, *endname; | ||
463 | |||
464 | status = mu_ident_ref (sp->locrange.beg.mu_file, &begname); | ||
465 | if (status) | ||
466 | return status; | ||
467 | status = mu_ident_ref (sp->locrange.end.mu_file, &endname); | ||
468 | if (status) | ||
469 | { | ||
470 | mu_ident_deref (begname); | ||
471 | return status; | ||
472 | } | ||
473 | lr->beg.mu_file = begname; | ||
474 | lr->beg.mu_line = sp->locrange.beg.mu_line; | ||
475 | lr->beg.mu_col = sp->locrange.beg.mu_col; | ||
476 | lr->end.mu_file = endname; | ||
477 | lr->end.mu_line = sp->locrange.end.mu_line; | ||
478 | lr->end.mu_col = sp->locrange.end.mu_col; | ||
479 | } | ||
480 | break; | ||
481 | |||
378 | case MU_IOCTL_LOGSTREAM_GET_LOCUS: | 482 | case MU_IOCTL_LOGSTREAM_GET_LOCUS: |
379 | if (!arg) | 483 | if (!arg) |
380 | return EINVAL; | 484 | return EINVAL; |
381 | else | 485 | else |
382 | { | 486 | { |
383 | struct mu_locus *ploc = arg; | 487 | struct mu_locus *ploc = arg; |
384 | if (sp->locus.mu_file) | 488 | if (sp->locrange.beg.mu_file) |
385 | { | 489 | { |
386 | ploc->mu_file = strdup (sp->locus.mu_file); | 490 | ploc->mu_file = strdup (sp->locrange.beg.mu_file); |
387 | if (!ploc->mu_file) | 491 | if (!ploc->mu_file) |
388 | return ENOMEM; | 492 | return ENOMEM; |
389 | } | 493 | } |
390 | else | 494 | else |
391 | ploc->mu_file = NULL; | 495 | ploc->mu_file = NULL; |
392 | ploc->mu_line = sp->locus.mu_line; | 496 | ploc->mu_line = sp->locrange.beg.mu_line; |
393 | ploc->mu_col = sp->locus.mu_col; | 497 | ploc->mu_col = sp->locrange.beg.mu_col; |
394 | } | 498 | } |
395 | break; | 499 | break; |
396 | 500 | ||
397 | case MU_IOCTL_LOGSTREAM_SET_LOCUS: | 501 | case MU_IOCTL_LOGSTREAM_SET_LOCUS: |
398 | { | 502 | { |
399 | struct mu_locus *ploc = arg; | 503 | struct mu_locus *ploc = arg; |
400 | if (!arg) | 504 | |
505 | mu_ident_deref (sp->locrange.end.mu_file); | ||
506 | sp->locrange.end.mu_file = NULL; | ||
507 | if (arg) | ||
401 | { | 508 | { |
402 | free (sp->locus.mu_file); | 509 | status = lr_set_file (&sp->locrange, ploc->mu_file, 0, 0); |
403 | sp->locus.mu_file = NULL; | 510 | if (status) |
404 | sp->locus.mu_line = 0; | 511 | return status; |
405 | sp->locus.mu_col = 0; | 512 | lr_set_line (&sp->locrange, ploc->mu_line, 0); |
513 | lr_set_col (&sp->locrange, ploc->mu_col, 0); | ||
406 | } | 514 | } |
407 | else | 515 | else |
408 | { | 516 | { |
409 | if (ploc->mu_file) | 517 | mu_ident_deref (sp->locrange.beg.mu_file); |
410 | _locus_set_file (&sp->locus, ploc->mu_file, | 518 | sp->locrange.beg.mu_file = NULL; |
411 | strlen (ploc->mu_file)); | ||
412 | if (ploc->mu_line) | ||
413 | _locus_set_line (&sp->locus, ploc->mu_line); | ||
414 | if (ploc->mu_col) | ||
415 | _locus_set_col (&sp->locus, ploc->mu_col); | ||
416 | } | 519 | } |
520 | |||
417 | break; | 521 | break; |
418 | } | 522 | } |
419 | 523 | ||
420 | case MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE: | 524 | case MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE: |
421 | if (!arg) | 525 | if (!arg) |
422 | return EINVAL; | 526 | return EINVAL; |
423 | sp->locus.mu_line = *(unsigned*)arg; | 527 | sp->locrange.beg.mu_line = *(unsigned*)arg; |
424 | break; | 528 | break; |
425 | 529 | ||
426 | case MU_IOCTL_LOGSTREAM_SET_LOCUS_COL: | 530 | case MU_IOCTL_LOGSTREAM_SET_LOCUS_COL: |
427 | if (!arg) | 531 | if (!arg) |
428 | return EINVAL; | 532 | return EINVAL; |
429 | sp->locus.mu_col = *(unsigned*)arg; | 533 | sp->locrange.beg.mu_col = *(unsigned*)arg; |
430 | break; | 534 | break; |
431 | 535 | ||
432 | case MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE: | 536 | case MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE: |
433 | if (!arg) | 537 | if (!arg) |
434 | sp->locus.mu_line++; | 538 | sp->locrange.beg.mu_line++; |
435 | else | 539 | else |
436 | sp->locus.mu_line += *(int*)arg; | 540 | sp->locrange.beg.mu_line += *(int*)arg; |
437 | break; | 541 | break; |
438 | 542 | ||
439 | case MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL: | 543 | case MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL: |
440 | if (!arg) | 544 | if (!arg) |
441 | sp->locus.mu_col++; | 545 | sp->locrange.beg.mu_col++; |
442 | else | 546 | else |
443 | sp->locus.mu_col += *(int*)arg; | 547 | sp->locrange.beg.mu_col += *(int*)arg; |
444 | break; | 548 | break; |
445 | 549 | ||
446 | case MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY: | 550 | case MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY: |
... | @@ -484,14 +588,12 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg) | ... | @@ -484,14 +588,12 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg) |
484 | newp->threshold = sp->threshold; | 588 | newp->threshold = sp->threshold; |
485 | newp->logmode = sp->logmode; | 589 | newp->logmode = sp->logmode; |
486 | newp->sevmask = sp->sevmask; | 590 | newp->sevmask = sp->sevmask; |
487 | if (sp->locus.mu_file) | 591 | newp->locrange = sp->locrange; |
488 | { | 592 | mu_ident_ref (sp->locrange.beg.mu_file, |
489 | newp->locus.mu_file = strdup (sp->locus.mu_file); | 593 | &sp->locrange.beg.mu_file); |
490 | if (!newp->locus.mu_file) | 594 | mu_ident_ref (sp->locrange.end.mu_file, |
491 | return ENOMEM; | 595 | &sp->locrange.end.mu_file); |
492 | } | 596 | |
493 | newp->locus.mu_line = sp->locus.mu_line; | ||
494 | newp->locus.mu_col = sp->locus.mu_col; | ||
495 | *(mu_stream_t*) arg = str; | 597 | *(mu_stream_t*) arg = str; |
496 | } | 598 | } |
497 | break; | 599 | break; | ... | ... |
... | @@ -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\ | ... | ... |
libmailutils/tests/logstr.at
0 → 100644
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 |
libmailutils/tests/logstr.c
0 → 100644
This diff is collapsed.
Click to expand it.
... | @@ -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 | ... | ... |
-
Please register or sign in to post a comment