Commit f2980e5a f2980e5a1a7495e31f75b979b258bd0fffdb310e by Sergey Poznyakoff

Redo sieve debugging support

Instead of keeping individual debug flags for each Sieve machine,
use global debugging mechanism, category "sieve".  The following
levels are defined:

  trace1  -  print parse tree before optimization
  trace2  -  print parse tree after optimization
  trace3  -  print parser traces
  trace4  -  print tests and actions being executed
  trace8  -  print disassembled code, don't run
  trace9  -  print each Sieve instruction being executed

* include/mailutils/sieve.h (mu_sieve_get_debug_level)
(mu_sieve_set_debug_level): Remove.
(mu_sieve_is_dry_run,mu_sieve_set_dry_run
* lib/script.c (mu_script_debug_flags): Redo.
* lib/sieve.c (sieve_init): Remove call to obsoleted
mu_sieve_set_debug_level.

* examples/numaddr.c: Use mu_sieve_trace
* libmu_sieve/extensions/list.c: Likewise.
* libmu_sieve/extensions/moderator.c: Likewise.
* libmu_sieve/extensions/pipe.c: Likewise.
* libmu_sieve/extensions/spamd.c: Likewise.
* libmu_sieve/extensions/timestamp.c: Likewise.
* libmu_sieve/extensions/vacation.c: Likewise.
* libmu_sieve/tests.c: Likewise.

* libmu_sieve/runtime.c (INSTR_DEBUG,INSTR_DISASS): Rewrite.
(mu_sieve_get_debug_level): Remove.
(mu_sieve_is_dry_run_: Rewrite.
(mu_sieve_set_dry_run): New function.
(mu_sieve_disass): Rewrite.
* libmu_sieve/sieve-priv.h (mu_sieve_machine) <debug_level>: Remove.
<dry_run>: New field.
* libmu_sieve/sieve.y (mu_sieve_set_debug_level): Remove.
* libmu_sieve/util.c (mu_sieve_trace): New function.
* sieve/sieve.c: Rewrite support for --dry-run and --debug.

* sieve/tests/ext.at: Use --libdir-prefix instead of -L
1 parent 4e162e9b
...@@ -84,10 +84,7 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -84,10 +84,7 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
84 struct val_ctr vc; 84 struct val_ctr vc;
85 int rc; 85 int rc;
86 86
87 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 87 mu_sieve_trace (mach, "NUMADDR");
88 {
89 mu_sieve_debug (mach, "NUMADDR");
90 }
91 88
92 /* Retrieve required arguments: */ 89 /* Retrieve required arguments: */
93 /* First argument: list of header names */ 90 /* First argument: list of header names */
......
...@@ -231,13 +231,15 @@ void *mu_sieve_get_data (mu_sieve_machine_t mach); ...@@ -231,13 +231,15 @@ void *mu_sieve_get_data (mu_sieve_machine_t mach);
231 void mu_sieve_set_data (mu_sieve_machine_t mach, void *); 231 void mu_sieve_set_data (mu_sieve_machine_t mach, void *);
232 mu_message_t mu_sieve_get_message (mu_sieve_machine_t mach); 232 mu_message_t mu_sieve_get_message (mu_sieve_machine_t mach);
233 size_t mu_sieve_get_message_num (mu_sieve_machine_t mach); 233 size_t mu_sieve_get_message_num (mu_sieve_machine_t mach);
234 int mu_sieve_get_debug_level (mu_sieve_machine_t mach); 234
235 int mu_sieve_is_dry_run (mu_sieve_machine_t mach);
236 int mu_sieve_set_dry_run (mu_sieve_machine_t mach, int val);
237
235 mu_mailer_t mu_sieve_get_mailer (mu_sieve_machine_t mach); 238 mu_mailer_t mu_sieve_get_mailer (mu_sieve_machine_t mach);
236 int mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus *); 239 int mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus *);
237 char *mu_sieve_get_daemon_email (mu_sieve_machine_t mach); 240 char *mu_sieve_get_daemon_email (mu_sieve_machine_t mach);
238 const char *mu_sieve_get_identifier (mu_sieve_machine_t mach); 241 const char *mu_sieve_get_identifier (mu_sieve_machine_t mach);
239 242
240 void mu_sieve_set_debug_level (mu_sieve_machine_t mach, int level);
241 void mu_sieve_set_logger (mu_sieve_machine_t mach, 243 void mu_sieve_set_logger (mu_sieve_machine_t mach,
242 mu_sieve_action_log_t logger); 244 mu_sieve_action_log_t logger);
243 void mu_sieve_set_mailer (mu_sieve_machine_t mach, mu_mailer_t mailer); 245 void mu_sieve_set_mailer (mu_sieve_machine_t mach, mu_mailer_t mailer);
......
...@@ -39,6 +39,8 @@ struct mu_script_fun *script_tab[] = { ...@@ -39,6 +39,8 @@ struct mu_script_fun *script_tab[] = {
39 int 39 int
40 mu_script_debug_flags (const char *arg, char **endp) 40 mu_script_debug_flags (const char *arg, char **endp)
41 { 41 {
42 mu_debug_level_t lev;
43
42 for (; *arg; arg++) 44 for (; *arg; arg++)
43 { 45 {
44 switch (*arg) 46 switch (*arg)
...@@ -48,11 +50,15 @@ mu_script_debug_flags (const char *arg, char **endp) ...@@ -48,11 +50,15 @@ mu_script_debug_flags (const char *arg, char **endp)
48 break; 50 break;
49 51
50 case 't': 52 case 't':
51 mu_script_debug_sieve |= MU_SIEVE_DEBUG_TRACE; 53 mu_debug_get_category_level (mu_sieve_debug_handle, &lev);
54 mu_debug_set_category_level (mu_sieve_debug_handle,
55 lev | MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE4));
52 break; 56 break;
53 57
54 case 'i': 58 case 'i':
55 mu_script_debug_sieve |= MU_SIEVE_DEBUG_INSTR; 59 mu_debug_get_category_level (mu_sieve_debug_handle, &lev);
60 mu_debug_set_category_level (mu_sieve_debug_handle,
61 lev | MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE9));
56 break; 62 break;
57 63
58 case 'l': 64 case 'l':
......
...@@ -81,7 +81,6 @@ sieve_init (const char *prog, mu_script_descr_t *pdescr) ...@@ -81,7 +81,6 @@ sieve_init (const char *prog, mu_script_descr_t *pdescr)
81 rc = mu_sieve_machine_init (&mach); 81 rc = mu_sieve_machine_init (&mach);
82 if (rc == 0) 82 if (rc == 0)
83 { 83 {
84 mu_sieve_set_debug_level (mach, mu_script_debug_sieve);
85 if (mu_script_sieve_log) 84 if (mu_script_sieve_log)
86 mu_sieve_set_logger (mach, _sieve_action_log); 85 mu_sieve_set_logger (mach, _sieve_action_log);
87 rc = mu_sieve_compile (mach, prog); 86 rc = mu_sieve_compile (mach, prog);
......
...@@ -152,10 +152,7 @@ list_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -152,10 +152,7 @@ list_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
152 struct header_closure clos; 152 struct header_closure clos;
153 int result; 153 int result;
154 154
155 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 155 mu_sieve_trace (mach, "LIST");
156 {
157 mu_sieve_debug (mach, "LIST");
158 }
159 156
160 memset (&clos, 0, sizeof clos); 157 memset (&clos, 0, sizeof clos);
161 if (mu_sieve_tag_lookup (tags, "delim", &arg)) 158 if (mu_sieve_tag_lookup (tags, "delim", &arg))
......
...@@ -273,11 +273,8 @@ moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -273,11 +273,8 @@ moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
273 int discard = 0; 273 int discard = 0;
274 int ismime; 274 int ismime;
275 275
276 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 276 mu_sieve_trace (mach, "moderator_test %lu",
277 { 277 (unsigned long) mu_sieve_get_message_num (mach));
278 mu_sieve_debug (mach, "moderator_test %lu",
279 (unsigned long) mu_sieve_get_message_num (mach));
280 }
281 278
282 msg = mu_sieve_get_message (mach); 279 msg = mu_sieve_get_message (mach);
283 mu_message_is_multipart (msg, &ismime); 280 mu_message_is_multipart (msg, &ismime);
......
...@@ -105,10 +105,7 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test) ...@@ -105,10 +105,7 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
105 } 105 }
106 cmd = val->v.string; 106 cmd = val->v.string;
107 107
108 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 108 mu_sieve_trace (mach, test ? "PIPE (test)" : "PIPE (action)");
109 {
110 mu_sieve_debug (mach, test ? "PIPE (test)" : "PIPE (action)");
111 }
112 109
113 if (mu_sieve_is_dry_run (mach)) 110 if (mu_sieve_is_dry_run (mach))
114 return 0; 111 return 0;
......
...@@ -368,11 +368,8 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -368,11 +368,8 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
368 mu_header_t hdr; 368 mu_header_t hdr;
369 mu_debug_handle_t lev = 0; 369 mu_debug_handle_t lev = 0;
370 370
371 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 371 mu_sieve_trace (mach, "spamd_test %lu",
372 { 372 (unsigned long) mu_sieve_get_message_num (mach));
373 mu_sieve_debug (mach, "spamd_test %lu",
374 (unsigned long) mu_sieve_get_message_num (mach));
375 }
376 373
377 if (mu_sieve_is_dry_run (mach)) 374 if (mu_sieve_is_dry_run (mach))
378 return 0; 375 return 0;
......
...@@ -57,10 +57,7 @@ timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -57,10 +57,7 @@ timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
57 time_t tlimit, tval; 57 time_t tlimit, tval;
58 int rc; 58 int rc;
59 59
60 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 60 mu_sieve_trace (mach, "TIMESTAMP");
61 {
62 mu_sieve_debug (mach, "TIMESTAMP");
63 }
64 61
65 /* Retrieve required arguments: */ 62 /* Retrieve required arguments: */
66 /* First argument: header name */ 63 /* First argument: header name */
......
...@@ -136,10 +136,7 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, ...@@ -136,10 +136,7 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
136 static int 136 static int
137 diag (mu_sieve_machine_t mach) 137 diag (mu_sieve_machine_t mach)
138 { 138 {
139 if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE) 139 mu_sieve_trace (mach, "VACATION");
140 {
141 mu_sieve_debug (mach, "VACATION");
142 }
143 140
144 mu_sieve_log_action (mach, "VACATION", NULL); 141 mu_sieve_log_action (mach, "VACATION", NULL);
145 return mu_sieve_is_dry_run (mach); 142 return mu_sieve_is_dry_run (mach);
......
...@@ -28,8 +28,9 @@ ...@@ -28,8 +28,9 @@
28 #define SIEVE_ADJUST(m,n) (m)->pc+=(n) 28 #define SIEVE_ADJUST(m,n) (m)->pc+=(n)
29 29
30 #define INSTR_DEBUG(m) \ 30 #define INSTR_DEBUG(m) \
31 ((m)->debug_level & (MU_SIEVE_DEBUG_INSTR|MU_SIEVE_DEBUG_DISAS)) 31 (mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE9))
32 #define INSTR_DISASS(m) ((m)->debug_level & MU_SIEVE_DEBUG_DISAS) 32 #define INSTR_DISASS(m) \
33 (mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE8))
33 34
34 void 35 void
35 _mu_i_sv_instr_nop (mu_sieve_machine_t mach) 36 _mu_i_sv_instr_nop (mu_sieve_machine_t mach)
...@@ -263,12 +264,6 @@ mu_sieve_get_message_num (mu_sieve_machine_t mach) ...@@ -263,12 +264,6 @@ mu_sieve_get_message_num (mu_sieve_machine_t mach)
263 return mach->msgno; 264 return mach->msgno;
264 } 265 }
265 266
266 int
267 mu_sieve_get_debug_level (mu_sieve_machine_t mach)
268 {
269 return mach->debug_level;
270 }
271
272 const char * 267 const char *
273 mu_sieve_get_identifier (mu_sieve_machine_t mach) 268 mu_sieve_get_identifier (mu_sieve_machine_t mach)
274 { 269 {
...@@ -278,7 +273,15 @@ mu_sieve_get_identifier (mu_sieve_machine_t mach) ...@@ -278,7 +273,15 @@ mu_sieve_get_identifier (mu_sieve_machine_t mach)
278 int 273 int
279 mu_sieve_is_dry_run (mu_sieve_machine_t mach) 274 mu_sieve_is_dry_run (mu_sieve_machine_t mach)
280 { 275 {
281 return mach->debug_level & MU_SIEVE_DRY_RUN; 276 return mach->dry_run;
277 }
278
279 int
280 mu_sieve_set_dry_run (mu_sieve_machine_t mach, int val)
281 {
282 if (mach->state != mu_sieve_state_compiled)
283 return EINVAL; //FIXME: another error code
284 return mach->dry_run = val;
282 } 285 }
283 286
284 int 287 int
...@@ -304,12 +307,15 @@ sieve_run (mu_sieve_machine_t mach) ...@@ -304,12 +307,15 @@ sieve_run (mu_sieve_machine_t mach)
304 int 307 int
305 mu_sieve_disass (mu_sieve_machine_t mach) 308 mu_sieve_disass (mu_sieve_machine_t mach)
306 { 309 {
307 int level = mach->debug_level; 310 mu_debug_level_t lev;
308 int rc; 311 int rc;
309 312
310 mach->debug_level = MU_SIEVE_DEBUG_INSTR | MU_SIEVE_DEBUG_DISAS; 313 mu_debug_get_category_level (mu_sieve_debug_handle, &lev);
314 mu_debug_set_category_level (mu_sieve_debug_handle,
315 MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE8)
316 | MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE9));
311 rc = sieve_run (mach); 317 rc = sieve_run (mach);
312 mach->debug_level = level; 318 mu_debug_set_category_level (mu_sieve_debug_handle, lev);
313 return rc; 319 return rc;
314 } 320 }
315 321
......
...@@ -77,7 +77,7 @@ struct mu_sieve_machine ...@@ -77,7 +77,7 @@ struct mu_sieve_machine
77 long reg; /* Numeric register */ 77 long reg; /* Numeric register */
78 mu_list_t stack; /* Runtime stack */ 78 mu_list_t stack; /* Runtime stack */
79 79
80 int debug_level; /* Debugging level */ 80 int dry_run; /* Dry-run mode */
81 jmp_buf errbuf; /* Target location for non-local exits */ 81 jmp_buf errbuf; /* Target location for non-local exits */
82 const char *identifier; /* Name of action or test being executed */ 82 const char *identifier; /* Name of action or test being executed */
83 83
......
...@@ -1037,7 +1037,7 @@ mu_sieve_machine_inherit (mu_sieve_machine_t const parent, ...@@ -1037,7 +1037,7 @@ mu_sieve_machine_inherit (mu_sieve_machine_t const parent,
1037 return rc; 1037 return rc;
1038 1038
1039 child->logger = parent->logger; 1039 child->logger = parent->logger;
1040 child->debug_level = parent->debug_level; 1040 child->dry_run = parent->dry_run;
1041 *pmach = child; 1041 *pmach = child;
1042 return 0; 1042 return 0;
1043 } 1043 }
...@@ -1071,7 +1071,7 @@ mu_sieve_machine_dup (mu_sieve_machine_t const in, mu_sieve_machine_t *out) ...@@ -1071,7 +1071,7 @@ mu_sieve_machine_dup (mu_sieve_machine_t const in, mu_sieve_machine_t *out)
1071 mach->reg = 0; 1071 mach->reg = 0;
1072 mach->stack = NULL; 1072 mach->stack = NULL;
1073 1073
1074 mach->debug_level = in->debug_level; 1074 mach->dry_run = in->dry_run;
1075 1075
1076 mach->errstream = in->errstream; 1076 mach->errstream = in->errstream;
1077 mu_stream_ref (mach->errstream); 1077 mu_stream_ref (mach->errstream);
...@@ -1100,12 +1100,6 @@ mu_sieve_set_diag_stream (mu_sieve_machine_t mach, mu_stream_t str) ...@@ -1100,12 +1100,6 @@ mu_sieve_set_diag_stream (mu_sieve_machine_t mach, mu_stream_t str)
1100 } 1100 }
1101 1101
1102 void 1102 void
1103 mu_sieve_set_debug_level (mu_sieve_machine_t mach, int level)
1104 {
1105 mach->debug_level = level;
1106 }
1107
1108 void
1109 mu_sieve_set_logger (mu_sieve_machine_t mach, mu_sieve_action_log_t logger) 1103 mu_sieve_set_logger (mu_sieve_machine_t mach, mu_sieve_action_log_t logger)
1110 { 1104 {
1111 mach->logger = logger; 1105 mach->logger = logger;
......
...@@ -119,8 +119,7 @@ sieve_test_address (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -119,8 +119,7 @@ sieve_test_address (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
119 int rc; 119 int rc;
120 size_t count; 120 size_t count;
121 121
122 if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) 122 mu_sieve_trace (mach, "ADDRESS");
123 mu_sieve_debug (mach, "ADDRESS");
124 123
125 h = mu_sieve_value_get (args, 0); 124 h = mu_sieve_value_get (args, 0);
126 if (!h) 125 if (!h)
...@@ -183,8 +182,7 @@ sieve_test_header (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -183,8 +182,7 @@ sieve_test_header (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
183 size_t count, mcount = 0; 182 size_t count, mcount = 0;
184 struct header_closure clos; 183 struct header_closure clos;
185 184
186 if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) 185 mu_sieve_trace (mach, "HEADER");
187 mu_sieve_debug (mach, "HEADER");
188 186
189 h = mu_sieve_value_get (args, 0); 187 h = mu_sieve_value_get (args, 0);
190 if (!h) 188 if (!h)
...@@ -267,8 +265,7 @@ sieve_test_envelope (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -267,8 +265,7 @@ sieve_test_envelope (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
267 int rc; 265 int rc;
268 size_t count; 266 size_t count;
269 267
270 if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) 268 mu_sieve_trace (mach, "ENVELOPE");
271 mu_sieve_debug (mach, "ENVELOPE");
272 269
273 h = mu_sieve_value_get (args, 0); 270 h = mu_sieve_value_get (args, 0);
274 if (!h) 271 if (!h)
...@@ -334,8 +331,7 @@ sieve_test_exists (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -334,8 +331,7 @@ sieve_test_exists (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
334 mu_header_t header = NULL; 331 mu_header_t header = NULL;
335 mu_sieve_value_t *val; 332 mu_sieve_value_t *val;
336 333
337 if (mach->debug_level & MU_SIEVE_DEBUG_TRACE) 334 mu_sieve_trace (mach, "EXISTS");
338 mu_sieve_debug (mach, "EXISTS");
339 335
340 mu_message_get_header (mu_sieve_get_message (mach), &header); 336 mu_message_get_header (mu_sieve_get_message (mach), &header);
341 val = mu_sieve_value_get (args, 0); 337 val = mu_sieve_value_get (args, 0);
......
...@@ -230,6 +230,27 @@ mu_sieve_debug (mu_sieve_machine_t mach, const char *fmt, ...) ...@@ -230,6 +230,27 @@ mu_sieve_debug (mu_sieve_machine_t mach, const char *fmt, ...)
230 } 230 }
231 231
232 void 232 void
233 mu_sieve_trace (mu_sieve_machine_t mach, const char *fmt, ...)
234 {
235 va_list ap;
236
237 if (!mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE4))
238 return;
239
240 va_start (ap, fmt);
241 mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG);
242 if (mach->locus.mu_file)
243 mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>",
244 MU_LOGMODE_LOCUS,
245 (unsigned) strlen (mach->locus.mu_file),
246 mach->locus.mu_file,
247 mach->locus.mu_line);
248 mu_stream_vprintf (mach->errstream, fmt, ap);
249 mu_stream_write (mach->errstream, "\n", 1, NULL);
250 va_end (ap);
251 }
252
253 void
233 mu_sieve_log_action (mu_sieve_machine_t mach, const char *action, 254 mu_sieve_log_action (mu_sieve_machine_t mach, const char *action,
234 const char *fmt, ...) 255 const char *fmt, ...)
235 { 256 {
......
...@@ -55,45 +55,46 @@ int sieve_debug; ...@@ -55,45 +55,46 @@ int sieve_debug;
55 int verbose; 55 int verbose;
56 char *script; 56 char *script;
57 int expression_option; 57 int expression_option;
58 int dry_run;
58 59
59 static int sieve_print_locus = 1; /* Should the log messages include the 60 static int sieve_print_locus = 1; /* Should the log messages include the
60 locus */ 61 locus */
61 62
62 static void 63 static void
63 set_debug_level (const char *arg) 64 modify_debug_flags (mu_debug_level_t set, mu_debug_level_t clr)
64 { 65 {
65 mu_debug_level_t lev; 66 mu_debug_level_t lev;
66 67
68 mu_debug_get_category_level (mu_sieve_debug_handle, &lev);
69 mu_debug_set_category_level (mu_sieve_debug_handle, (lev & ~clr) | set);
70 }
71
72 static void
73 set_debug_level (const char *arg)
74 {
67 for (; *arg; arg++) 75 for (; *arg; arg++)
68 { 76 {
69 switch (*arg) 77 switch (*arg)
70 { 78 {
71 case 'T': 79 case 'T':
72 mu_debug_get_category_level (mu_sieve_debug_handle, &lev); 80 modify_debug_flags (MU_DEBUG_LEVEL_UPTO(MU_DEBUG_TRACE9),
73 mu_debug_set_category_level (mu_sieve_debug_handle, 81 MU_DEBUG_LEVEL_MASK(MU_DEBUG_ERROR));
74 lev |
75 (MU_DEBUG_LEVEL_UPTO(MU_DEBUG_TRACE9) &
76 ~MU_DEBUG_LEVEL_MASK(MU_DEBUG_ERROR)));
77 break; 82 break;
78 83
79 case 'P': 84 case 'P':
80 mu_debug_get_category_level (mu_sieve_debug_handle, &lev); 85 modify_debug_flags (MU_DEBUG_LEVEL_MASK(MU_DEBUG_PROT), 0);
81 mu_debug_set_category_level (mu_sieve_debug_handle,
82 lev | MU_DEBUG_LEVEL_MASK(MU_DEBUG_PROT));
83 break; 86 break;
84 87
85 case 'g': 88 case 'g':
86 mu_debug_get_category_level (mu_sieve_debug_handle, &lev); 89 modify_debug_flags (MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE1), 0);
87 mu_debug_set_category_level (mu_sieve_debug_handle,
88 lev | MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE1));
89 break; 90 break;
90 91
91 case 't': 92 case 't':
92 sieve_debug |= MU_SIEVE_DEBUG_TRACE; 93 modify_debug_flags (MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE4), 0);
93 break; 94 break;
94 95
95 case 'i': 96 case 'i':
96 sieve_debug |= MU_SIEVE_DEBUG_INSTR; 97 modify_debug_flags (MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE9), 0);
97 break; 98 break;
98 99
99 default: 100 default:
...@@ -103,13 +104,6 @@ set_debug_level (const char *arg) ...@@ -103,13 +104,6 @@ set_debug_level (const char *arg)
103 } 104 }
104 105
105 static void 106 static void
106 cli_dry_run (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
107 {
108 sieve_debug |= MU_SIEVE_DRY_RUN;
109 verbose = 1;
110 }
111
112 static void
113 cli_compile_and_dump (struct mu_parseopt *po, struct mu_option *opt, 107 cli_compile_and_dump (struct mu_parseopt *po, struct mu_option *opt,
114 char const *arg) 108 char const *arg)
115 { 109 {
...@@ -138,10 +132,10 @@ cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt, ...@@ -138,10 +132,10 @@ cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt,
138 } 132 }
139 133
140 static struct mu_option sieve_options[] = { 134 static struct mu_option sieve_options[] = {
141 { "no-actions", 'n', NULL, MU_OPTION_DEFAULT, 135 { "dry-run", 'n', NULL, MU_OPTION_DEFAULT,
142 N_("do not execute any actions, just print what would be done"), 136 N_("do not execute any actions, just print what would be done"),
143 mu_c_string, NULL, cli_dry_run }, 137 mu_c_bool, &dry_run },
144 { "dry-run", 0, NULL, MU_OPTION_ALIAS }, 138 { "no-actions", 0, NULL, MU_OPTION_ALIAS },
145 { "keep-going", 'k', NULL, MU_OPTION_DEFAULT, 139 { "keep-going", 'k', NULL, MU_OPTION_DEFAULT,
146 N_("keep on going if execution fails on a message"), 140 N_("keep on going if execution fails on a message"),
147 mu_c_bool, &keep_going }, 141 mu_c_bool, &keep_going },
...@@ -159,7 +153,7 @@ static struct mu_option sieve_options[] = { ...@@ -159,7 +153,7 @@ static struct mu_option sieve_options[] = {
159 mu_c_string, &mu_ticket_file }, 153 mu_c_string, &mu_ticket_file },
160 { "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL, 154 { "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL,
161 N_("debug flags (defaults to \"" D_DEFAULT "\")"), 155 N_("debug flags (defaults to \"" D_DEFAULT "\")"),
162 mu_c_string, NULL, cli_debug }, 156 mu_c_string, NULL, cli_debug, D_DEFAULT },
163 { "verbose", 'v', NULL, MU_OPTION_DEFAULT, 157 { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
164 N_("log all actions"), 158 N_("log all actions"),
165 mu_c_bool, &verbose }, 159 mu_c_bool, &verbose },
...@@ -334,7 +328,7 @@ sieve_mailbox (mu_sieve_machine_t mach) ...@@ -334,7 +328,7 @@ sieve_mailbox (mu_sieve_machine_t mach)
334 } 328 }
335 329
336 /* Open the mailbox read-only if we aren't going to modify it. */ 330 /* Open the mailbox read-only if we aren't going to modify it. */
337 if (sieve_debug & MU_SIEVE_DRY_RUN) 331 if (mu_sieve_is_dry_run (mach))
338 rc = mu_mailbox_open (mbox, MU_STREAM_READ); 332 rc = mu_mailbox_open (mbox, MU_STREAM_READ);
339 else 333 else
340 rc = mu_mailbox_open (mbox, MU_STREAM_RDWR); 334 rc = mu_mailbox_open (mbox, MU_STREAM_RDWR);
...@@ -360,7 +354,7 @@ sieve_mailbox (mu_sieve_machine_t mach) ...@@ -360,7 +354,7 @@ sieve_mailbox (mu_sieve_machine_t mach)
360 rc = mu_sieve_mailbox (mach, mbox); 354 rc = mu_sieve_mailbox (mach, mbox);
361 355
362 cleanup: 356 cleanup:
363 if (mbox && !(sieve_debug & MU_SIEVE_DRY_RUN)) 357 if (mbox && !dry_run)
364 { 358 {
365 int e; 359 int e;
366 360
...@@ -405,7 +399,9 @@ main (int argc, char *argv[]) ...@@ -405,7 +399,9 @@ main (int argc, char *argv[])
405 mu_register_all_formats (); 399 mu_register_all_formats ();
406 400
407 mu_cli (argc, argv, &cli, sieve_capa, NULL, &argc, &argv); 401 mu_cli (argc, argv, &cli, sieve_capa, NULL, &argc, &argv);
408 402 if (dry_run)
403 verbose++;
404
409 if (argc == 0) 405 if (argc == 0)
410 { 406 {
411 mu_error (_("script must be specified")); 407 mu_error (_("script must be specified"));
...@@ -448,7 +444,7 @@ main (int argc, char *argv[]) ...@@ -448,7 +444,7 @@ main (int argc, char *argv[])
448 return EX_OK; 444 return EX_OK;
449 } 445 }
450 446
451 mu_sieve_set_debug_level (mach, sieve_debug); 447 mu_sieve_set_dry_run (mach, dry_run);
452 448
453 if (mbox_url && strcmp (mbox_url, "-") == 0) 449 if (mbox_url && strcmp (mbox_url, "-") == 0)
454 rc = sieve_message (mach); 450 rc = sieve_message (mach);
......
...@@ -32,7 +32,7 @@ if numaddr [[ "to", "cc" ]] :over 5 ...@@ -32,7 +32,7 @@ if numaddr [[ "to", "cc" ]] :over 5
32 MUT_MBCOPY($abs_top_srcdir/testsuite/spool/bigto.mbox) 32 MUT_MBCOPY($abs_top_srcdir/testsuite/spool/bigto.mbox)
33 33
34 sieve MUT_SIEVE_CMDLINE dnl 34 sieve MUT_SIEVE_CMDLINE dnl
35 --clearpath -L "${abs_top_builddir}/examples" -f ./bigto.mbox prog 35 --clearpath --libdir-prefix= "${abs_top_builddir}/examples" -f ./bigto.mbox prog
36 ], 36 ],
37 [0], 37 [0],
38 [], 38 [],
......