Commit 3a78309a 3a78309aa59c245c14e29d3e7eb953c6a2ea1035 by Sergey Poznyakoff

Switch to new locus types

* include/mailutils/types.hin (mu_locus): Remove.

* include/mailutils/diag.h (mu_diag_at_locus): Remove.
(mu_diag_at_locus_point,mu_diag_at_locus_range): New protos.
* include/mailutils/mailutils.h: Include locus.h

* include/mailutils/stream.h (MU_IOCTL_LOGSTREAM_GET_LOCUS)
(MU_IOCTL_LOGSTREAM_SET_LOCUS): Remove.
* libmailutils/stream/logstream.c (_log_ctl): Reflect this.
* libmailutils/tests/logstr.at: Remove the related test.
* libmailutils/tests/logstr.c: Ditto.

* libmailutils/cfg/Makefile.am: Add new header.
* libmailutils/cfg/cfg.h: New file.
* libmailutils/cfg/format.c: Use mu_locus_range
* libmailutils/cfg/lexer.l: Use the mu_linetrack facility
* libmailutils/cfg/parser.y: LIkewise.
* libmailutils/diag/diag.c (mu_diag_at_locus): Remove.
(mu_diag_at_locus_point,mu_diag_at_locus_range): New protos.

* comsat/action.c: Use mu_locus_point and mu_locus_range
instead of the removed mu_locus.
* include/mailutils/auth.h: Likewise.
* include/mailutils/cfg.h: Likewise.
* include/mailutils/sieve.h: Likewise.
* libmailutils/base/wicket.c: Likewise.
* libmailutils/tests/wicket.c: Likewise.
* libmu_auth/radius.c: Likewise.
* libmu_sieve/actions.c: Likewise.
* libmu_sieve/comparator.c: Likewise.
* libmu_sieve/extensions/moderator.c: Likewise.
* libmu_sieve/mem.c: Likewise.
* libmu_sieve/prog.c: Likewise.
* libmu_sieve/require.c: Likewise.
* libmu_sieve/runtime.c: Likewise.
* libmu_sieve/sieve-priv.h: Likewise.
* libmu_sieve/sieve.l: Use the mu_linetrack facility.
* libmu_sieve/sieve.y: Likewise.
* libmu_sieve/util.c: Use mu_locus_point and mu_locus_range
instead of the removed mu_locus
* libmu_sieve/variables.c: Likewise.
* mail/source.c: Likewise.
* mu/libexec/dbm.c: Likewise.
* mu/libexec/logger.c: Likewise.
* mu/libexec/wicket.c: Likewise.
* sieve/sieve.c: Likewise.
* sieve/tests/i-numeric.at: Update expected locations
1 parent 16383a01
......@@ -298,7 +298,7 @@ struct biffrc_environ
mu_stream_t logstr;
mu_message_t msg;
mu_stream_t input;
struct mu_locus locus;
struct mu_locus_range locus;
int use_default;
char *errbuf;
size_t errsize;
......@@ -523,16 +523,16 @@ eval_biffrc (struct biffrc_environ *env)
ws.ws_comment = "#";
wsflags = MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &env->locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &env->locus);
mu_stream_ioctl (env->logstr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &env->locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &env->locus);
while (mu_stream_getline (env->input, &stmt, &size, &n) == 0 && n > 0)
{
if (strncmp (stmt, "#line ", 6) == 0)
{
char *p;
env->locus.mu_line = strtoul (stmt + 6, &p, 10);
env->locus.beg.mu_line = strtoul (stmt + 6, &p, 10);
if (*p != '\n')
{
report_error (env, _("malformed #line directive: %s"));
......@@ -541,10 +541,10 @@ eval_biffrc (struct biffrc_environ *env)
{
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE,
&env->locus.mu_line);
&env->locus.beg.mu_line);
mu_stream_ioctl (env->logstr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE,
&env->locus.mu_line);
&env->locus.beg.mu_line);
}
continue;
}
......@@ -600,9 +600,9 @@ eval_biffrc (struct biffrc_environ *env)
free (stmt);
mu_wordsplit_free (&ws);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL);
mu_stream_ioctl (env->logstr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL);
}
void
......@@ -645,13 +645,14 @@ run_user_action (const char *device, mu_message_t msg)
if (!rcname)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
env.locus.mu_file = BIFF_RC;
env.locus.beg.mu_file = BIFF_RC;
}
else
env.locus.mu_file = rcname;
env.locus.beg.mu_file = rcname;
env.locus.mu_line = 1;
env.locus.mu_col = 0;
env.locus.beg.mu_line = 1;
env.locus.beg.mu_col = 0;
memset (&env.locus.end, 0, sizeof env.locus.end);
env.use_default = 0;
eval_biffrc (&env);
mu_stream_destroy (&env.input);
......@@ -679,9 +680,9 @@ run_user_action (const char *device, mu_message_t msg)
}
else
{
env.locus.mu_file = "<default>";
env.locus.mu_line = 1;
env.locus.mu_col = 0;
env.locus.beg.mu_file = "<default>";
env.locus.beg.mu_line = 1;
env.locus.beg.mu_col = 0;
eval_biffrc (&env);
mu_stream_destroy (&env.input);
}
......
......@@ -20,6 +20,7 @@
#define _MAILUTILS_AUTH_H
#include <mailutils/types.h>
#include <mailutils/locus.h>
#ifdef __cplusplus
extern "C" {
......@@ -77,7 +78,7 @@ int mu_wicket_set_get_ticket (mu_wicket_t wicket,
int mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename);
struct mu_debug_locus;
int mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus *loc,
int mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus_point *loc,
mu_url_t url, int parse_flags,
mu_url_t *pticket_url);
int mu_wicket_file_match_url (const char *name, mu_url_t url,
......
......@@ -23,6 +23,7 @@
#include <mailutils/debug.h>
#include <mailutils/opool.h>
#include <mailutils/util.h>
#include <mailutils/locus.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
......@@ -64,7 +65,7 @@ enum mu_cfg_node_type
struct mu_cfg_node
{
struct mu_locus locus;
struct mu_locus_range locus;
enum mu_cfg_node_type type;
char *tag;
mu_config_value_t *label;
......@@ -119,8 +120,6 @@ int mu_cfg_tree_union (mu_cfg_tree_t **pa, mu_cfg_tree_t **pb);
int mu_cfg_tree_postprocess (mu_cfg_tree_t *tree,
struct mu_cfg_parse_hints *hints);
extern struct mu_locus mu_cfg_locus;
mu_opool_t mu_cfg_lexer_pool (void);
#define MU_CFG_ITER_OK 0
......@@ -285,7 +284,7 @@ int mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file,
int mu_cfg_tree_create (struct mu_cfg_tree **ptree);
mu_cfg_node_t *mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
enum mu_cfg_node_type type,
const struct mu_locus *loc,
const struct mu_locus_range *loc,
const char *tag,
const char *label,
mu_list_t nodelist);
......
......@@ -24,6 +24,7 @@
#include <mailutils/types.h>
#include <mailutils/log.h>
#include <mailutils/debug.h>
#include <mailutils/locus.h>
#ifdef __cplusplus
extern "C" {
......@@ -51,8 +52,10 @@ void mu_diag_cont_printf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
void mu_diag_voutput (int, const char *, va_list);
void mu_diag_output (int, const char *, ...) MU_PRINTFLIKE(2,3);
void mu_diag_at_locus (int level, struct mu_locus const *loc,
const char *fmt, ...);
void mu_diag_at_locus_point (int level, struct mu_locus_point const *loc,
const char *fmt, ...);
void mu_diag_at_locus_range (int level, struct mu_locus_range const *loc,
const char *fmt, ...);
int mu_diag_level_to_syslog (int level);
const char *mu_diag_level_to_string (int level);
......
......@@ -36,7 +36,7 @@
#include <mailutils/header.h>
#include <mailutils/iterator.h>
#include <mailutils/kwd.h>
/* FIXME #include <mailutils/locus.h> */
#include <mailutils/locus.h>
#include <mailutils/sieve.h>
#include <mailutils/list.h>
#include <mailutils/locker.h>
......
......@@ -23,6 +23,7 @@
#include <stdarg.h>
#include <mailutils/mailutils.h>
#include <mailutils/cli.h>
#include <mailutils/locus.h>
#ifdef __cplusplus
extern "C" {
......@@ -287,7 +288,7 @@ int mu_sieve_set_dry_run (mu_sieve_machine_t mach, int val);
void mu_sieve_get_argc (mu_sieve_machine_t mach, size_t *args, size_t *tags);
mu_mailer_t mu_sieve_get_mailer (mu_sieve_machine_t mach);
int mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus *);
int mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus_range *);
char *mu_sieve_get_daemon_email (mu_sieve_machine_t mach);
const char *mu_sieve_get_identifier (mu_sieve_machine_t mach);
......@@ -324,7 +325,7 @@ const char *mu_sieve_type_str (mu_sieve_data_type type);
int mu_sieve_compile (mu_sieve_machine_t mach, const char *name);
int mu_sieve_compile_buffer (mu_sieve_machine_t mach,
const char *buf, int bufsize,
const char *fname, int line);
struct mu_locus_point const *pt);
int mu_sieve_mailbox (mu_sieve_machine_t mach, mu_mailbox_t mbox);
int mu_sieve_message (mu_sieve_machine_t mach, mu_message_t message);
int mu_sieve_disass (mu_sieve_machine_t mach);
......
......@@ -106,11 +106,9 @@ enum mu_buffer_type
*/
#define MU_IOCTL_LOGSTREAM_GET_SEVERITY 0
#define MU_IOCTL_LOGSTREAM_SET_SEVERITY 1
/* Get or set locus.
Arg: struct mu_locus *
*/
#define MU_IOCTL_LOGSTREAM_GET_LOCUS 2
#define MU_IOCTL_LOGSTREAM_SET_LOCUS 3
/* Codes 2 and 3 are reserved */
/* Get or set log mode.
Arg: int *
*/
......
......@@ -149,13 +149,6 @@ typedef unsigned int mu_debug_level_t;
#define MU_DEFAULT_RECORD _MU_DEFAULT_RECORD_
struct mu_locus
{
char *mu_file;
unsigned mu_line;
unsigned mu_col;
};
#ifdef __cplusplus
}
#endif
......
......@@ -248,7 +248,7 @@ _file_wicket_get_ticket (mu_wicket_t wicket, void *data,
}
int
mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus *loc,
mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus_point *loc,
mu_url_t url, int parse_flags,
mu_url_t *pticket_url)
{
......@@ -329,7 +329,7 @@ mu_wicket_file_match_url (const char *name, mu_url_t url,
{
mu_stream_t stream;
int rc;
struct mu_locus loc;
struct mu_locus_point loc;
rc = mu_file_stream_create (&stream, name, MU_STREAM_READ);
if (rc)
......
......@@ -21,7 +21,8 @@ libcfg_la_SOURCES = \
driver.c\
format.c\
lexer.c\
parser.c
parser.c\
cfg.h
localedir = $(datadir)/locale
AM_CPPFLAGS = \
......
#include <mailutils/yyloc.h>
......@@ -152,10 +152,10 @@ format_node (const mu_cfg_node_t *node, void *data)
{
struct tree_print *tp = data;
if ((tp->flags & MU_CF_FMT_LOCUS) && node->locus.mu_file)
if ((tp->flags & MU_CF_FMT_LOCUS) && node->locus.beg.mu_file)
mu_stream_printf (tp->stream, "# %lu \"%s\"\n",
(unsigned long) node->locus.mu_line,
node->locus.mu_file);
(unsigned long) node->locus.beg.mu_line,
node->locus.beg.mu_file);
format_level (tp->stream, tp->level);
switch (node->type)
{
......
......@@ -38,7 +38,10 @@
#include <mailutils/cfg.h>
#include <mailutils/list.h>
#include <mailutils/util.h>
#include <mailutils/locus.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include "cfg.h"
#include "parser.h"
void _mu_line_begin (void);
......@@ -66,7 +69,16 @@ static int (*char_to_strip)(char); /* Strip matching characters of each
static int isemptystr(int off);
static mu_opool_t pool;
static mu_linetrack_t trk;
static struct mu_locus_point string_beg;
#define YY_USER_ACTION \
do \
{ \
mu_linetrack_advance (trk, &yylloc, yytext, yyleng); \
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, \
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &yylloc); \
} \
while (0);
%}
%option nounput
......@@ -83,7 +95,7 @@ P [1-9][0-9]*
"/*" BEGIN(COMMENT);
<COMMENT>[^*\n]* /* eat anything that's not a '*' */
<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
<COMMENT>\n ++mu_cfg_locus.mu_line;
<COMMENT>\n ;
<COMMENT>"*"+"/" BEGIN (INITIAL);
/* End-of-line comments */
#debug=.*\n {
......@@ -91,9 +103,9 @@ P [1-9][0-9]*
mu_cfg_set_debug ();
mu_cfg_set_lex_debug ();
}
#.*\n { mu_cfg_locus.mu_line++; }
#.*\n ;
#.* /* end-of-file comment */;
"//".*\n { mu_cfg_locus.mu_line++; }
"//".*\n ;
"//".* /* end-of-file comment */;
/* Identifiers */
<INITIAL>{ID} {
......@@ -113,6 +125,7 @@ P [1-9][0-9]*
return MU_TOK_QSTRING; }
\"[^\\"\n]*\\. |
\"[^\\"\n]*\\\n { BEGIN (STR);
mu_locus_point_copy (&string_beg, &yylloc.beg);
_mu_line_begin ();
_mu_line_add_unescape_last (yytext + 1, yyleng - 1); }
<STR>[^\\"\n]*\\. |
......@@ -121,6 +134,10 @@ P [1-9][0-9]*
if (yyleng > 1)
_mu_line_add (yytext, yyleng - 1);
yylval.string = _mu_line_finish ();
mu_locus_point_copy (&yylloc.beg, &string_beg);
mu_locus_point_deinit (&string_beg);
return MU_TOK_QSTRING; }
/* Multiline strings */
"<<"(-" "?)?\\?{ID}[ \t]*#.*\n |
......@@ -130,8 +147,8 @@ P [1-9][0-9]*
"<<"(-" "?)?\"{ID}\"[ \t]*"//".*\n |
"<<"(-" "?)?\"{ID}\"[ \t]*\n {
BEGIN (ML);
mu_locus_point_copy (&string_beg, &yylloc.beg);
multiline_begin (yytext+2);
mu_cfg_locus.mu_line++;
}
<ML>.*\n { char *p = multiline_strip_tabs (yytext);
......@@ -142,21 +159,21 @@ P [1-9][0-9]*
multiline_delimiter = NULL;
BEGIN (INITIAL);
yylval.string = multiline_finish ();
mu_locus_point_copy (&yylloc.beg, &string_beg);
mu_locus_point_deinit (&string_beg);
/* FIXME: Adjust yylloc.end without retreating trk */
return MU_TOK_MSTRING;
}
mu_cfg_locus.mu_line++;
multiline_add (p); }
{WS} ;
/* Other tokens */
\n { mu_cfg_locus.mu_line++; }
\n ;
[,;{}()] return yytext[0];
. { if (mu_isprint (yytext[0]))
mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
_("stray character %c"), yytext[0]);
mu_error (_("stray character %c"), yytext[0]);
else
mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
_("stray character \\%03o"),
(unsigned char) yytext[0]);
mu_error (_("stray character \\%03o"), (unsigned char) yytext[0]);
mu_cfg_error_count++;
}
%%
......@@ -175,8 +192,7 @@ unescape_to_line (int c)
char t = mu_wordsplit_c_unquote_char (c);
if (t == c && t != '\\' && t != '\"')
{
mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
_("unknown escape sequence '\\%c'"), c);
mu_error (_("unknown escape sequence '\\%c'"), c);
mu_cfg_error_count++;
}
mu_opool_append_char (pool, t);
......@@ -365,29 +381,24 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
mu_cfg_set_lex_debug ();
/* Initialize locus: */
/* 1. Save file name in the lexer object pool and point `file' member
to this copy. Free full_name: it is not used after that. */
_mu_line_begin ();
_mu_line_add (full_name, strlen (full_name));
mu_cfg_locus.mu_file = _mu_line_finish ();
free (full_name);
/* 2. Initialize line number */
mu_cfg_locus.mu_line = 1;
/* Initialize tracker */
mu_linetrack_create (&trk, full_name, 2);
memset (&string_beg, 0, sizeof string_beg);
/* Parse configuration */
yyrestart (fp);
rc = mu_cfg_parse (return_tree);
fclose (fp);
if (flags & MU_CF_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("finished parsing file `%s'"),
mu_cfg_locus.mu_file);
mu_diag_output (MU_DIAG_INFO, _("finished parsing file `%s'"), full_name);
free (full_name);
mu_linetrack_destroy (&trk);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL);
return rc == 0 ? 0 : MU_ERR_FAILURE;
}
mu_opool_t
mu_cfg_lexer_pool ()
mu_cfg_lexer_pool (void)
{
mu_opool_t p = pool;
pool = NULL;
......
......@@ -57,25 +57,9 @@ mu_diag_output (int level, const char *fmt, ...)
}
void
mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...)
mu_vdiag_at_locus_range (int level, struct mu_locus_range const *loc,
const char *fmt, va_list ap)
{
va_list ap;
va_start (ap, fmt);
if (loc && loc->mu_file)
mu_stream_printf (mu_strerr, "\033f<%d>%s\033l<%u>\033c<%u>",
(unsigned) strlen (loc->mu_file), loc->mu_file,
loc->mu_line,
loc->mu_col);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
}
void
mu_diag_at_locus_range (int level, struct mu_locus_range const *loc,
const char *fmt, ...)
{
va_list ap;
struct mu_locus_range old = MU_LOCUS_RANGE_INITIALIZER;
int restore = 0;
......@@ -90,9 +74,7 @@ mu_diag_at_locus_range (int level, struct mu_locus_range const *loc,
}
}
va_start (ap, fmt);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
if (restore)
{
......@@ -103,6 +85,28 @@ mu_diag_at_locus_range (int level, struct mu_locus_range const *loc,
}
void
mu_diag_at_locus_range (int level, struct mu_locus_range const *loc,
const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_vdiag_at_locus_range (level, loc, fmt, ap);
va_end (ap);
}
void
mu_diag_at_locus_point (int level, struct mu_locus_point const *loc,
const char *fmt, ...)
{
va_list ap;
struct mu_locus_range lr = MU_LOCUS_RANGE_INITIALIZER;
lr.beg = *loc;
va_start (ap, fmt);
mu_vdiag_at_locus_range (level, &lr, fmt, ap);
va_end (ap);
}
void
mu_diag_vprintf (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
......
......@@ -480,48 +480,6 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
}
break;
case MU_IOCTL_LOGSTREAM_GET_LOCUS:
if (!arg)
return EINVAL;
else
{
struct mu_locus *ploc = arg;
if (sp->locrange.beg.mu_file)
{
ploc->mu_file = strdup (sp->locrange.beg.mu_file);
if (!ploc->mu_file)
return ENOMEM;
}
else
ploc->mu_file = NULL;
ploc->mu_line = sp->locrange.beg.mu_line;
ploc->mu_col = sp->locrange.beg.mu_col;
}
break;
case MU_IOCTL_LOGSTREAM_SET_LOCUS:
{
struct mu_locus *ploc = arg;
mu_ident_deref (sp->locrange.end.mu_file);
sp->locrange.end.mu_file = NULL;
if (arg)
{
status = lr_set_file (&sp->locrange, ploc->mu_file, 0, 0);
if (status)
return status;
lr_set_line (&sp->locrange, ploc->mu_line, 0);
lr_set_col (&sp->locrange, ploc->mu_col, 0);
}
else
{
mu_ident_deref (sp->locrange.beg.mu_file);
sp->locrange.beg.mu_file = NULL;
}
break;
}
case MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE:
if (!arg)
return EINVAL;
......
......@@ -34,46 +34,43 @@ emerg: and this one as well
one
two
emerg: three
05. set/get locus point
input:1: filename and line number
input:1.3: filename, line and column numbers
06. locus: file, line
05. locus: file, line
input:1: file, line
07. locus: file, line, col
06. locus: file, line, col
input:1.1-10: file, line, col
08. locus: file, line-range
07. locus: file, line-range
input:1-2: file, line-range
09. locus: file, line-range, col
08. locus: file, line-range, col
input:1.1-2.10: file, line-range, col
10. locus: file-range, line-range, col-range
09. locus: file-range, line-range, col-range
input:1.1-next:2.10: file-range, line-range, col-range
11. set locus line
10. set locus line
input:1.1-next:2.10: initial
input:8.1-next:2.10: locus line changed
12. advance locus line
11. advance locus line
input:1.1-next:5.10: initial
input:3.1-next:5.10: locus line advanced
13. set locus column
12. set locus column
input:1.1-next:2.10: initial
input:1.8-next:2.10: locus column changed
14. advance locus column
13. advance locus column
input:1.1-next:5.10: initial
input:1.5-next:5.10: locus line advanced
15. fmt: severity
14. fmt: severity
info: severity
16. fmt: locus (file, line)
15. fmt: locus (file, line)
a:10: one
17. fmt: locus (file, line, column)
16. fmt: locus (file, line, column)
a:10.5: one
18. fmt: locus (range)
17. fmt: locus (range)
a:10.5-b:14.8: one
19. fmt: locus; restore defaults
18. fmt: locus; restore defaults
a:10.5-b:14.8: one
default
20. fmt: locus; restore defaults, display locus
19. fmt: locus; restore defaults, display locus
a:10.5-b:14.8: one
input:1.1-next:5.10: default
21. fmt: set locus
20. fmt: set locus
a:10.5-b:14.8: one
a:10.5-b:14.8: default
])
......
......@@ -129,51 +129,6 @@ check_suppress_name (mu_stream_t str)
mu_stream_printf (str, "and this one as well\n");
}
/* Check setting locus point
Expected output:
input:1: filename and line number
input:1.3: filename, line and column numbers
*/
static void
set_locus_point (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus pt, pt2;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
pt.mu_file = "input";
pt.mu_line = 1;
pt.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &pt);
mu_stream_printf (str, "filename and line number\n");
pt.mu_file = "input";
pt.mu_line = 1;
pt.mu_col = 3;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &pt);
mu_stream_printf (str, "filename, line and column numbers\n");
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS, &pt2));
if (strcmp (pt.mu_file, pt2.mu_file))
mu_error ("%s:%d: mu_file differs\n", __FILE__, __LINE__);
if (pt.mu_line != pt2.mu_line)
mu_error ("%s:%d: mu_line differs\n", __FILE__, __LINE__);
if (pt.mu_col != pt2.mu_col)
mu_error ("%s:%d: mu_col differs\n", __FILE__, __LINE__);
/* FIXME: remove this after switching to mu_locus_point */
free (pt2.mu_file);
}
static void
comp_range (mu_stream_t str, struct mu_locus_range *lr1,
char const *file, int line)
......@@ -682,7 +637,6 @@ struct testcase testcases[] = {
{ "suppress severity", check_suppress },
{ "suppress severity name", check_suppress_name },
{ "severity mask", check_severity_mask },
{ "set/get locus point", set_locus_point },
{ "locus: file, line", lr_file_line },
{ "locus: file, line, col", lr_file_line_col },
{ "locus: file, line-range", lr_file_line2 },
......
......@@ -30,7 +30,7 @@ match_string (const char *str)
{
int rc;
mu_url_t u, url;
struct mu_locus loc;
struct mu_locus_point loc;
if ((rc = mu_url_create (&u, str)) != 0)
{
......
......@@ -84,7 +84,8 @@ enum parse_state
state_lhs,
state_op,
state_rhs,
state_delim
state_delim,
state_err
};
static int
......@@ -96,7 +97,7 @@ cb_request (void *data, mu_config_value_t *val)
enum parse_state state;
grad_locus_t loc;
char *name;
struct mu_locus locus;
struct mu_locus_range locus;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
......@@ -111,11 +112,11 @@ cb_request (void *data, mu_config_value_t *val)
}
if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS,
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE,
&locus) == 0)
{
loc.file = locus.mu_file;
loc.line = locus.mu_line;
loc.file = (char*) locus.beg.mu_file;
loc.line = locus.beg.mu_line;
}
else
{
......@@ -123,7 +124,7 @@ cb_request (void *data, mu_config_value_t *val)
loc.line = 0;
}
for (i = 0, state = state_lhs; i < ws.ws_wordc; i++)
for (i = 0, state = state_lhs; state != state_err && i < ws.ws_wordc; i++)
{
grad_avp_t *pair;
......@@ -146,23 +147,36 @@ cb_request (void *data, mu_config_value_t *val)
if (!pair)
{
mu_error (_("cannot create radius A/V pair `%s'"), name);
return 1;
state = state_err;
}
else
{
grad_avl_merge (plist, &pair);
state = state_delim;
}
grad_avl_merge (plist, &pair);
state = state_delim;
break;
case state_delim:
if (strcmp (ws.ws_wordv[i], ","))
{
mu_error (_("expected `,' but found `%s'"), ws.ws_wordv[i]);
return 1;
state = state_err;
}
state = state_lhs;
else
state = state_lhs;
break;
default:
abort ();
}
}
mu_wordsplit_free (&ws);
mu_wordsplit_free (&ws);
mu_locus_range_deinit (&locus);
if (state == state_err)
return 1;
if (state != state_delim && state != state_delim)
{
mu_error (_("malformed radius A/V list"));
......
......@@ -528,8 +528,8 @@ perms_tag_checker (mu_sieve_machine_t mach)
{
if (mu_parse_stream_perm_string (&flag, t->v.string, &p))
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
_("invalid permissions (near %s)"), p);
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("invalid permissions (near %s)"), p);
mu_i_sv_error (mach);
err = 1;
}
......
......@@ -174,7 +174,7 @@ mu_sieve_match_part_checker (mu_sieve_machine_t mach)
{
if (match)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("match type specified twice in call to `%s'"),
mach->identifier);
mu_i_sv_error (mach);
......@@ -209,7 +209,7 @@ mu_sieve_match_part_checker (mu_sieve_machine_t mach)
if (compname && strcmp (compname, "i;ascii-numeric"))
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
/* TRANSLATORS: Do not translate ':count'.
It is the name of a Sieve tag */
_("comparator %s is incompatible with "
......@@ -235,7 +235,7 @@ mu_sieve_match_part_checker (mu_sieve_machine_t mach)
break;
/* fall through */
default:
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_(":count requires second argument to be a list of one element"));
mu_i_sv_error (mach);
return 1;
......@@ -246,7 +246,7 @@ mu_sieve_match_part_checker (mu_sieve_machine_t mach)
char *p = mu_str_skip_class (argstr->orig, MU_CTYPE_DIGIT);
if (*p)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("second argument cannot be converted to number"));
mu_i_sv_error (mach);
return 1;
......@@ -258,7 +258,7 @@ mu_sieve_match_part_checker (mu_sieve_machine_t mach)
if (mu_sieve_str_to_relcmp (str, NULL, NULL))
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("invalid relational match `%s' in call to `%s'"),
str, mach->identifier);
mu_i_sv_error (mach);
......@@ -278,7 +278,7 @@ mu_sieve_match_part_checker (mu_sieve_machine_t mach)
compfun = mu_sieve_comparator_lookup (mach, compname, matchtype);
if (!compfun)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("comparator `%s' is incompatible with match type `%s' in call to `%s'"),
compname, match ? match->tag : "is",
mach->identifier);
......
......@@ -103,7 +103,7 @@ moderator_filter_message (mu_sieve_machine_t mach,
}
else if (mu_sieve_get_tag (mach, "program", SVT_STRING, &arg))
{
struct mu_locus locus;
struct mu_locus_range locrange;
rc = mu_sieve_machine_clone (mach, &newmach);
if (rc)
......@@ -112,10 +112,10 @@ moderator_filter_message (mu_sieve_machine_t mach,
mu_strerror (rc));
return 1;
}
mu_sieve_get_locus (mach, &locus);
mu_sieve_get_locus (mach, &locrange);
rc = mu_sieve_compile_buffer (newmach,
arg, strlen (arg),
locus.mu_file, locus.mu_line);
&locrange.beg);
if (rc)
mu_sieve_error (mach, _("cannot compile subprogram"));
}
......
......@@ -218,7 +218,7 @@ mu_i_sv_2nrealloc (mu_sieve_machine_t mach, void **pptr, size_t *pnmemb,
worth the trouble. */
if ((size_t) -1 / 3 * 2 / size <= nmemb)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("requested too much memory %zu * %zu"),
nmemb, size);
mu_sieve_abort (mach);
......@@ -232,19 +232,19 @@ mu_i_sv_2nrealloc (mu_sieve_machine_t mach, void **pptr, size_t *pnmemb,
*pnmemb = nmemb;
}
char *
mu_i_sv_id_canon (mu_sieve_machine_t mach, char const *name)
size_t
mu_i_sv_id_num (mu_sieve_machine_t mach, char const *name)
{
size_t i;
char *p;
if (!name)
return NULL;
abort ();
for (i = 0; i < mach->idcount; i++)
{
if (strcmp (mach->idspace[i], name) == 0)
return mach->idspace[i];
return i;
}
if (mach->idcount == mach->idmax)
......@@ -256,24 +256,11 @@ mu_i_sv_id_canon (mu_sieve_machine_t mach, char const *name)
}
p = mu_sieve_strdup (mach, name);
mach->idspace[mach->idcount++] = p;
mach->idspace[mach->idcount] = p;
return p;
return mach->idcount++;
}
size_t
mu_i_sv_id_num (mu_sieve_machine_t mach, char const *name)
{
size_t i;
for (i = 0; i < mach->idcount; i++)
{
if (mach->idspace[i] == name || strcmp (mach->idspace[i], name) == 0)
return i;
}
abort ();
}
char *
mu_i_sv_id_str (mu_sieve_machine_t mach, size_t n)
{
......
......@@ -35,32 +35,48 @@ mu_i_sv_code (struct mu_sieve_machine *mach, sieve_op_t op)
mach->prog[mach->pc++] = op;
}
static int
file_eq (char const *a, char const *b)
{
if (a)
return b ? (strcmp (a, b) == 0) : 1;
return b ? 0 : 1;
}
/* FIXME: 1. Only beg is stored
2. mu_col is not used
*/
int
mu_i_sv_locus (struct mu_sieve_machine *mach, struct mu_locus_range *lr)
{
if (!file_eq (mach->locus.mu_file, lr->beg.mu_file))
if (!mu_locus_point_same_file (&mach->locus.beg, &lr->beg))
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_source);
mu_i_sv_code (mach, (sieve_op_t) mu_i_sv_id_num (mach, lr->beg.mu_file));
mu_i_sv_code (mach, (sieve_op_t) (int) 0);
}
if (mach->locus.mu_line != lr->beg.mu_line)
if (mach->locus.beg.mu_line != lr->beg.mu_line)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_line);
mu_i_sv_code (mach, (sieve_op_t) lr->beg.mu_line);
mu_i_sv_code (mach, (sieve_op_t) (int) 0);
}
if (mach->locus.beg.mu_col != lr->beg.mu_col)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_col);
mu_i_sv_code (mach, (sieve_op_t) lr->beg.mu_col);
mu_i_sv_code (mach, (sieve_op_t) (int) 0);
}
if (!mu_locus_point_same_file (&mach->locus.end, &lr->end))
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_source);
mu_i_sv_code (mach, (sieve_op_t) mu_i_sv_id_num (mach, lr->end.mu_file));
mu_i_sv_code (mach, (sieve_op_t) (int) 1);
}
if (mach->locus.end.mu_line != lr->end.mu_line)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_line);
mu_i_sv_code (mach, (sieve_op_t) lr->end.mu_line);
mu_i_sv_code (mach, (sieve_op_t) (int) 1);
}
if (mach->locus.end.mu_col != lr->end.mu_col)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_col);
mu_i_sv_code (mach, (sieve_op_t) lr->end.mu_col);
mu_i_sv_code (mach, (sieve_op_t) (int) 1);
}
mach->locus = lr->beg;
mu_locus_range_copy (&mach->locus, lr);
return 0;
}
......@@ -155,7 +171,7 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
if (!tag)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("invalid tag name `%s' for `%s'"),
val->v.string, reg->name);
mu_i_sv_error (mach);
......@@ -175,7 +191,7 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
{
if (i + 1 == node->v.command.argcount)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("required argument for tag %s is missing"),
tag->name);
mu_i_sv_error (mach);
......@@ -192,11 +208,11 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
if (val->type != tag->argtype)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("type mismatch in argument to "
"tag `%s'"),
tag->name);
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("expected %s but passed %s"),
mu_sieve_type_str (tag->argtype),
mu_sieve_type_str (val->type));
......@@ -210,7 +226,7 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
{
if (!chk_list && (rc = mu_list_create (&chk_list)))
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("cannot create check list: %s"),
mu_strerror (rc));
mu_i_sv_error (mach);
......@@ -222,7 +238,7 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
rc = mu_list_append (chk_list, cf);
if (rc)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
"mu_list_append: %s",
mu_strerror (rc));
mu_i_sv_error (mach);
......@@ -243,7 +259,7 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
}
else
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("too many arguments in call to `%s'"),
reg->name);
mu_i_sv_error (mach);
......@@ -258,11 +274,11 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
/* compatible types */;
else
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("type mismatch in argument %lu to `%s'"),
(unsigned long) (exp_arg - reg->v.command.req_args + 1),
reg->name);
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("expected %s but passed %s"),
mu_sieve_type_str (*exp_arg),
mu_sieve_type_str (val->type));
......@@ -277,7 +293,7 @@ mu_i_sv_lint_command (struct mu_sieve_machine *mach,
if (!err && !opt_args && *exp_arg != SVT_VOID)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("too few arguments in call to `%s'"),
reg->name);
mu_i_sv_error (mach);
......
......@@ -56,7 +56,7 @@ mu_sieve_require (mu_sieve_machine_t mach, mu_sieve_slice_t list)
if (rc)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus, _("can't require %s"),
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus, _("can't require %s"),
name);
mu_i_sv_error (mach);
}
......
......@@ -34,26 +34,46 @@
void
_mu_i_sv_instr_source (mu_sieve_machine_t mach)
{
mach->locus.mu_file = mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 0, pc));
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS,
&mach->locus);
char const *file = mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 0, pc));
int what = SIEVE_RT_ARG (mach, 1, inum);
mu_locus_point_set_file (what ? &mach->locus.beg : &mach->locus.end, file);
if (INSTR_DEBUG (mach))
mu_i_sv_debug (mach, mach->pc - 1, "SOURCE %s", mach->locus.mu_file);
SIEVE_RT_ADJUST (mach, 1);
mu_i_sv_debug (mach, mach->pc - 2, "SOURCE %s %d", file, what);
SIEVE_RT_ADJUST (mach, 2);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
}
void
_mu_i_sv_instr_line (mu_sieve_machine_t mach)
{
mach->locus.mu_line = SIEVE_RT_ARG (mach, 0, line);
unsigned line = SIEVE_RT_ARG (mach, 0, line);
int what = SIEVE_RT_ARG (mach, 1, inum);
if (what == 0)
mach->locus.beg.mu_line = line;
else
mach->locus.end.mu_line = line;
if (INSTR_DEBUG (mach))
mu_i_sv_debug (mach, mach->pc - 1, "LINE %u %d", line, what);
SIEVE_RT_ADJUST (mach, 2);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS,
&mach->locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
}
void
_mu_i_sv_instr_col (mu_sieve_machine_t mach)
{
unsigned col = SIEVE_RT_ARG (mach, 0, line);
int what = SIEVE_RT_ARG (mach, 1, inum);
if (what == 0)
mach->locus.beg.mu_col = col;
else
mach->locus.end.mu_col = col;
if (INSTR_DEBUG (mach))
mu_i_sv_debug (mach, mach->pc - 1, "LINE %u",
mach->locus.mu_line);
SIEVE_RT_ADJUST (mach, 1);
mu_i_sv_debug (mach, mach->pc - 2, "COLUMN %u %d", col, what);
SIEVE_RT_ADJUST (mach, 2);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
}
static int
......@@ -173,14 +193,9 @@ mu_sieve_get_data (mu_sieve_machine_t mach)
}
int
mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus *loc)
mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus_range *loc)
{
if (mach->locus.mu_file)
{
*loc = mach->locus;
return 0;
}
return 1;
return mu_locus_range_copy (loc, &mach->locus);
}
mu_mailbox_t
......
......@@ -18,6 +18,8 @@
#include <mailutils/sieve.h>
#include <mailutils/assoc.h>
#include <mailutils/locus.h>
#include <mailutils/yyloc.h>
#include <setjmp.h>
#include <string.h>
#include <regex.h>
......@@ -38,13 +40,6 @@ typedef union
unsigned unum;
} sieve_op_t;
struct mu_locus_range
{
struct mu_locus beg;
struct mu_locus end;
};
#define YYLTYPE struct mu_locus_range
#define MU_SV_SAVED_ERR_STATE 0x01
#define MU_SV_SAVED_DBG_STATE 0x02
......@@ -62,7 +57,7 @@ enum mu_sieve_state
struct mu_sieve_machine
{
/* Static data */
struct mu_locus locus; /* Approximate location in the code */
struct mu_locus_range locus; /* Approximate location in the code */
mu_list_t memory_pool; /* Pool of allocated memory objects */
mu_list_t destr_list; /* List of destructor functions */
......@@ -118,9 +113,9 @@ struct mu_sieve_machine
/* Stream state info */
int state_flags;
int err_mode;
struct mu_locus err_locus;
struct mu_locus_range err_locus;
int dbg_mode;
struct mu_locus dbg_locus;
struct mu_locus_range dbg_locus;
/* User supplied data */
mu_stream_t errstream;
......@@ -182,7 +177,7 @@ int mu_sieve_yylex (void);
int mu_i_sv_lex_begin (const char *name);
int mu_i_sv_lex_begin_string (const char *buf, int bufsize,
const char *fname, int line);
struct mu_locus_point const *pt);
void mu_i_sv_lex_finish (void);
extern mu_sieve_machine_t mu_sieve_machine;
......@@ -204,6 +199,7 @@ void _mu_i_sv_instr_brz (mu_sieve_machine_t mach);
void _mu_i_sv_instr_brnz (mu_sieve_machine_t mach);
void _mu_i_sv_instr_source (mu_sieve_machine_t mach);
void _mu_i_sv_instr_line (mu_sieve_machine_t mach);
void _mu_i_sv_instr_col (mu_sieve_machine_t mach);
int mu_i_sv_load_add_dir (mu_sieve_machine_t mach, const char *name);
......@@ -244,7 +240,6 @@ void mu_i_sv_lint_command (struct mu_sieve_machine *mach,
size_t mu_i_sv_string_create (mu_sieve_machine_t mach, char *str);
char *mu_i_sv_id_canon (mu_sieve_machine_t mach, char const *name);
size_t mu_i_sv_id_num (mu_sieve_machine_t mach, char const *name);
char *mu_i_sv_id_str (mu_sieve_machine_t mach, size_t n);
void mu_i_sv_free_idspace (mu_sieve_machine_t mach);
......
......@@ -54,10 +54,8 @@ static void sieve_searchpath (void);
static char *str_unescape (char *text, size_t len);
static int isemptystr (char *text);
static mu_linetrack_t trk;
static ino_t sieve_source_inode;
struct mu_locus mu_sieve_locus;
static int newline;
static mu_stream_t input_stream;
static int
......@@ -71,8 +69,10 @@ fillbuf (char *buf, size_t max_size)
rc = mu_stream_read (input_stream, buf, max_size, &max_size);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_stream_read",
mu_sieve_locus.mu_file, rc);
struct mu_locus_point pt;
mu_linetrack_locus (trk, &pt);
mu_diag_funcall (MU_DIAG_ERROR, "mu_stream_read", pt.mu_file, rc);
mu_locus_point_deinit (&pt);
return 0;
}
return max_size;
......@@ -90,40 +90,33 @@ fillbuf (char *buf, size_t max_size)
yy_switch_to_buffer (s); \
} while (0)
static void
init_locus (char const *name, ino_t ino)
{
mu_sieve_locus.mu_file = mu_i_sv_id_canon (mu_sieve_machine, name);
mu_sieve_locus.mu_line = 1;
mu_sieve_locus.mu_col = 0;
newline = 0;
sieve_source_inode = ino;
}
#define YY_USER_ACTION \
do \
{ \
mu_linetrack_advance (trk, &yylloc, yytext, yyleng); \
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, \
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &yylloc); \
} \
while (0);
static void
advance_locus (void)
init_locus (char const *name, ino_t ino)
{
if (newline)
if (name)
{
mu_sieve_locus.mu_line++;
mu_sieve_locus.mu_col = 0;
yylloc.beg = yylloc.end = mu_sieve_locus;
MU_ASSERT (mu_linetrack_create (&trk, name, 2));
}
else
{
mu_sieve_locus.mu_col += yyleng;
yylloc.beg = yylloc.end = mu_sieve_locus;
yylloc.beg.mu_col -= yyleng;
}
newline = yytext[yyleng-1] == '\n';
mu_linetrack_destroy (&trk);
sieve_source_inode = ino;
}
#define YY_USER_ACTION advance_locus ();
struct buffer_ctx
{
struct buffer_ctx *prev;
struct mu_locus locus;
mu_linetrack_t trk;
struct mu_locus_range incl_range;
ino_t i_node;
mu_stream_t input;
LEX_BUFFER_STATE state;
......@@ -156,13 +149,12 @@ push_source (const char *name)
if (stat (name, &st))
{
mu_diag_at_locus (MU_LOG_ERROR, &mu_sieve_locus,
_("cannot stat `%s': %s"), name, strerror (errno));
mu_error (_("cannot stat `%s': %s"), name, strerror (errno));
mu_i_sv_error (mu_sieve_machine);
return 1;
}
if (mu_sieve_locus.mu_file && st.st_ino == sieve_source_inode)
if (yylloc.beg.mu_file && st.st_ino == sieve_source_inode)
{
yyerror (_("recursive inclusion"));
return 1;
......@@ -172,16 +164,14 @@ push_source (const char *name)
yyerror (_("recursive inclusion"));
if (ctx->prev)
{
mu_diag_at_locus (MU_LOG_ERROR, &ctx->prev->locus,
_("`%s' already included here"),
name);
mu_diag_at_locus_range (MU_LOG_ERROR, &ctx->incl_range,
_("`%s' already included here"),
name);
mu_i_sv_error (mu_sieve_machine);
}
else
{
mu_diag_at_locus (MU_LOG_ERROR, &mu_sieve_locus,
_("`%s' already included at top level"),
name);
mu_error (_("`%s' already included at top level"), name);
mu_i_sv_error (mu_sieve_machine);
}
return 1;
......@@ -190,19 +180,16 @@ push_source (const char *name)
rc = mu_file_stream_create (&stream, name, MU_STREAM_READ);
if (rc)
{
mu_diag_at_locus (MU_LOG_ERROR, &mu_sieve_locus,
_("cannot open file `%s': %s"),
name, mu_strerror (rc));
mu_error (_("cannot open file `%s': %s"), name, mu_strerror (rc));
mu_i_sv_error (mu_sieve_machine);
return 1;
}
/* Push current context */
if (mu_sieve_locus.mu_file)
if (trk)
{
advance_locus ();
ctx = mu_sieve_malloc (mu_sieve_machine, sizeof (*ctx));
ctx->locus = mu_sieve_locus;
ctx->trk = trk;
mu_locus_range_copy (&ctx->incl_range, &yylloc);
ctx->i_node = sieve_source_inode;
ctx->input = input_stream;
ctx->prev = context_stack;
......@@ -233,7 +220,9 @@ pop_source ()
}
/* Restore previous context */
input_stream = context_stack->input;
mu_sieve_locus = context_stack->locus;
mu_linetrack_destroy (&trk);
trk = context_stack->trk;
mu_locus_range_deinit (&context_stack->incl_range);
sieve_source_inode = context_stack->i_node;
RESTORE_BUFFER_STATE (context_stack->state);
ctx = context_stack->prev;
......@@ -449,12 +438,10 @@ mu_i_sv_lex_begin (const char *name)
int
mu_i_sv_lex_begin_string (const char *buf, int bufsize,
const char *fname, int line)
struct mu_locus_point const *pt)
{
int rc;
if (!fname)
return 1;
yyrestart (NULL);
rc = mu_static_memory_stream_create (&input_stream, buf, bufsize);
......@@ -465,7 +452,8 @@ mu_i_sv_lex_begin_string (const char *buf, int bufsize,
return 1;
}
init_locus (fname, 0);
init_locus (pt->mu_file, 0);
mu_linetrack_rebase (trk, pt);
return 0;
}
......@@ -643,9 +631,7 @@ line_finish (void)
}
else if (rc != MU_ERR_CANCELED)
{
mu_diag_at_locus (MU_LOG_ERROR, &mu_sieve_locus,
_("error expandind string: %s"),
mu_strerror (rc));
mu_error (_("error expandind string: %s"), mu_strerror (rc));
}
}
yylval.string = str;
......
......@@ -36,44 +36,6 @@ static struct mu_sieve_node *node_alloc (enum mu_sieve_node_type,
static void node_list_add (struct mu_sieve_node_list *list,
struct mu_sieve_node *node);
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
{ \
if (N) \
{ \
(Current).beg = YYRHSLOC(Rhs, 1).beg; \
(Current).end = YYRHSLOC(Rhs, N).end; \
} \
else \
{ \
(Current).beg = YYRHSLOC(Rhs, 0).end; \
(Current).end = (Current).beg; \
} \
} while (0)
#define LOCUS_EQ(a,b) \
((((a)->mu_file == (b)->mu_file) \
|| ((a)->mu_file && (b)->mu_file \
&& strcmp((a)->mu_file, (b)->mu_file) == 0)) \
&& (a)->mu_line == (b)->mu_line)
#define YY_LOCATION_PRINT(File, Loc) \
do \
{ \
if (LOCUS_EQ(&(Loc).beg, &(Loc).end)) \
fprintf(File, "%s:%u.%u-%u.%u", \
(Loc).beg.mu_file, \
(Loc).beg.mu_line, (Loc).beg.mu_col, \
(Loc).end.mu_line, (Loc).end.mu_col); \
else \
fprintf(File, "%s:%u.%u-%s:%u.%u", \
(Loc).beg.mu_file, \
(Loc).beg.mu_line, (Loc).beg.mu_col, \
(Loc).end.mu_file, \
(Loc).end.mu_line, (Loc).end.mu_col); \
} \
while (0)
%}
%error-verbose
......@@ -87,6 +49,7 @@ static void node_list_add (struct mu_sieve_node_list *list,
struct
{
char *ident;
struct mu_locus_range idloc;
size_t first;
size_t count;
} command;
......@@ -242,21 +205,21 @@ test : command
{
mu_sieve_registry_t *reg;
mu_sieve_machine->locus = @1.beg;
mu_locus_range_copy (&mu_sieve_machine->locus, &@1);
reg = mu_sieve_registry_lookup (mu_sieve_machine, $1.ident,
mu_sieve_record_test);
if (!reg)
{
mu_diag_at_locus (MU_LOG_ERROR, &@1.beg,
_("unknown test: %s"),
$1.ident);
mu_diag_at_locus_range (MU_LOG_ERROR, &$1.idloc,
_("unknown test: %s"),
$1.ident);
mu_i_sv_error (mu_sieve_machine);
}
else if (!reg->required)
{
mu_diag_at_locus (MU_LOG_ERROR, &@1.beg,
_("test `%s' has not been required"),
$1.ident);
mu_diag_at_locus_range (MU_LOG_ERROR, &$1.idloc,
_("test `%s' has not been required"),
$1.ident);
mu_i_sv_error (mu_sieve_machine);
}
......@@ -281,6 +244,7 @@ test : command
command : IDENT maybe_arglist
{
$$.ident = $1;
$$.idloc = @1;
$$.first = $2.first;
$$.count = $2.count;
}
......@@ -290,22 +254,22 @@ action : command
{
mu_sieve_registry_t *reg;
mu_sieve_machine->locus = @1.beg;
mu_locus_range_copy (&mu_sieve_machine->locus, &@1);
reg = mu_sieve_registry_lookup (mu_sieve_machine, $1.ident,
mu_sieve_record_action);
if (!reg)
{
mu_diag_at_locus (MU_LOG_ERROR, &@1.beg,
_("unknown action: %s"),
$1.ident);
mu_diag_at_locus_range (MU_LOG_ERROR, &$1.idloc,
_("unknown action: %s"),
$1.ident);
mu_i_sv_error (mu_sieve_machine);
}
else if (!reg->required)
{
mu_diag_at_locus (MU_LOG_ERROR, &@1.beg,
_("action `%s' has not been required"),
$1.ident);
mu_diag_at_locus_range (MU_LOG_ERROR, &$1.idloc,
_("action `%s' has not been required"),
$1.ident);
mu_i_sv_error (mu_sieve_machine);
}
......@@ -393,10 +357,7 @@ slist : STRING
int
yyerror (const char *s)
{
extern struct mu_locus mu_sieve_locus;
mu_sieve_machine->locus = mu_sieve_locus;
mu_diag_at_locus (MU_LOG_ERROR, &mu_sieve_locus, "%s", s);
mu_error ("%s", s);
mu_i_sv_error (mu_sieve_machine);
return 0;
}
......@@ -423,7 +384,7 @@ node_alloc (enum mu_sieve_node_type type, struct mu_locus_range *lr)
{
node->prev = node->next = NULL;
node->type = type;
node->locus = *lr;
mu_locus_range_copy (&node->locus, lr);
}
return node;
}
......@@ -1104,15 +1065,9 @@ copy_stream_state (mu_sieve_machine_t child, mu_sieve_machine_t parent)
{
child->state_flags = parent->state_flags;
child->err_mode = parent->err_mode;
child->err_locus = parent->err_locus;
if (child->err_locus.mu_file)
child->err_locus.mu_file =
mu_sieve_strdup (child, child->err_locus.mu_file);
mu_locus_range_copy (&child->err_locus, &parent->err_locus);
child->dbg_mode = parent->dbg_mode;
child->dbg_locus = parent->dbg_locus;
if (child->dbg_locus.mu_file)
child->dbg_locus.mu_file =
mu_sieve_strdup (child, child->dbg_locus.mu_file);
mu_locus_range_copy (&child->dbg_locus, &parent->dbg_locus);
child->errstream = parent->errstream;
mu_stream_ref (child->errstream);
child->dbgstream = parent->dbgstream;
......@@ -1266,9 +1221,9 @@ mu_sieve_machine_dup (mu_sieve_machine_t const in, mu_sieve_machine_t *out)
mach->state_flags = in->state_flags;
mach->err_mode = in->err_mode;
mach->err_locus = in->err_locus;
mu_locus_range_copy (&mach->err_locus, &in->err_locus);
mach->dbg_mode = in->dbg_mode;
mach->dbg_locus = in->dbg_locus;
mu_locus_range_copy (&mach->dbg_locus, &in->dbg_locus);
copy_stream_state (mach, in);
......@@ -1456,8 +1411,7 @@ mu_sieve_machine_destroy (mu_sieve_machine_t *pmach)
}
int
with_machine (mu_sieve_machine_t mach, char const *name,
int (*thunk) (void *), void *data)
with_machine (mu_sieve_machine_t mach, int (*thunk) (void *), void *data)
{
int rc = 0;
mu_stream_t save_errstr;
......@@ -1523,11 +1477,21 @@ static int
sieve_parse (void)
{
int rc;
int old_mode, mode;
sieve_tree = NULL;
yydebug = mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE3);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &old_mode);
mode = old_mode | MU_LOGMODE_LOCUS;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
rc = yyparse ();
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &old_mode);
mu_i_sv_lex_finish ();
if (rc)
mu_i_sv_error (mu_sieve_machine);
......@@ -1547,9 +1511,8 @@ sieve_parse (void)
mu_i_sv_code (mu_sieve_machine, (sieve_op_t) (sieve_instr_t) 0);
/* Clear location, so that mu_i_sv_locus will do its job. */
mu_sieve_machine->locus.mu_file = NULL;
mu_sieve_machine->locus.mu_line = 0;
mu_sieve_machine->locus.mu_col = 0;
/* FIXME: is it still needed? */
mu_locus_range_deinit (&mu_sieve_machine->locus);
tree_code (mu_sieve_machine, sieve_tree);
mu_i_sv_code (mu_sieve_machine, (sieve_op_t) (sieve_instr_t) 0);
......@@ -1581,22 +1544,21 @@ sieve_compile_file (void *name)
int
mu_sieve_compile (mu_sieve_machine_t mach, const char *name)
{
return with_machine (mach, name, sieve_compile_file, (void *) name);
return with_machine (mach, sieve_compile_file, (void *) name);
}
struct strbuf
{
const char *ptr;
size_t size;
const char *file;
int line;
struct mu_locus_point const *pt;
};
static int
sieve_compile_strbuf (void *name)
{
struct strbuf *buf = name;
if (mu_i_sv_lex_begin_string (buf->ptr, buf->size, buf->file, buf->line) == 0)
if (mu_i_sv_lex_begin_string (buf->ptr, buf->size, buf->pt) == 0)
return sieve_parse ();
return MU_ERR_FAILURE;
}
......@@ -1604,14 +1566,13 @@ sieve_compile_strbuf (void *name)
int
mu_sieve_compile_buffer (mu_sieve_machine_t mach,
const char *str, int strsize,
const char *fname, int line)
struct mu_locus_point const *loc)
{
struct strbuf buf;
buf.ptr = str;
buf.size = strsize;
buf.file = fname;
buf.line = line;
return with_machine (mach, fname, sieve_compile_strbuf, &buf);
buf.pt = loc;
return with_machine (mach, sieve_compile_strbuf, &buf);
}
......
......@@ -205,12 +205,6 @@ mu_sieve_error (mu_sieve_machine_t mach, const char *fmt, ...)
va_start (ap, fmt);
mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_ERROR);
if (mach->locus.mu_file)
mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>",
MU_LOGMODE_LOCUS,
(unsigned) strlen (mach->locus.mu_file),
mach->locus.mu_file,
mach->locus.mu_line);
if (mach->identifier)
mu_stream_printf (mach->errstream, "%s: ", mach->identifier);
mu_stream_vprintf (mach->errstream, fmt, ap);
......@@ -253,11 +247,11 @@ mu_i_sv_debug (mu_sieve_machine_t mach, size_t pc, const char *fmt, ...)
unsigned severity = MU_LOG_DEBUG;
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
if (mach->locus.mu_file)
if (mach->locus.beg.mu_file)
{
int mode = mach->dbg_mode | MU_LOGMODE_LOCUS;
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &mach->locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
}
......@@ -281,11 +275,11 @@ mu_i_sv_debug_command (mu_sieve_machine_t mach,
unsigned severity = MU_LOG_DEBUG;
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
if (mach->locus.mu_file)
if (mach->locus.beg.mu_file)
{
int mode = mach->dbg_mode | MU_LOGMODE_LOCUS;
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &mach->locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
}
......@@ -309,12 +303,6 @@ mu_i_sv_trace (mu_sieve_machine_t mach, const char *what)
return;
mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG);
if (mach->locus.mu_file)
mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>",
MU_LOGMODE_LOCUS,
(unsigned) strlen (mach->locus.mu_file),
mach->locus.mu_file,
mach->locus.mu_line);
mu_stream_printf (mach->errstream, "%zu: %s %s", mach->msgno, what,
mach->identifier);
for (i = 0; i < mach->argcount; i++)
......@@ -333,8 +321,6 @@ mu_sieve_log_action (mu_sieve_machine_t mach, const char *action,
if (!mach->logger)
return;
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &mach->locus);
va_start (ap, fmt);
mach->logger (mach, action, fmt, ap);
va_end (ap);
......@@ -479,13 +465,15 @@ mu_sieve_stream_save (mu_sieve_machine_t mach)
if (mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &mach->err_mode) == 0
&& mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS, &mach->err_locus) == 0)
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE,
&mach->err_locus) == 0)
mach->state_flags |= MU_SV_SAVED_ERR_STATE;
if (mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &mach->dbg_mode) == 0
&& mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS, &mach->dbg_locus) == 0)
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE,
&mach->dbg_locus) == 0)
mach->state_flags |= MU_SV_SAVED_DBG_STATE;
mach->state_flags |= MU_SV_SAVED_STATE;
......@@ -502,7 +490,7 @@ mu_sieve_stream_restore (mu_sieve_machine_t mach)
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mach->err_mode);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &mach->err_locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->err_locus);
}
if (mach->dbgstream != mach->errstream
......@@ -511,7 +499,7 @@ mu_sieve_stream_restore (mu_sieve_machine_t mach)
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mach->dbg_mode);
mu_stream_ioctl (mach->dbgstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &mach->dbg_locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->dbg_locus);
}
mach->state_flags = 0;
......
......@@ -226,7 +226,7 @@ set_tag_checker (mu_sieve_machine_t mach)
*mu_sieve_get_tag_n (mach, j + 1) = *t;
else if (prec == tmp_prec)
{
mu_diag_at_locus (MU_LOG_ERROR, &mach->locus,
mu_diag_at_locus_range (MU_LOG_ERROR, &mach->locus,
_("%s and %s can't be used together"),
tmp.tag, t->tag);
mu_i_sv_error (mach);
......
......@@ -49,7 +49,7 @@ mail_source (int argc, char **argv)
{
mu_stream_t input;
int save_term;
struct mu_locus locus;
struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER;
int rc;
if (argc != 2)
......@@ -69,15 +69,15 @@ mail_source (int argc, char **argv)
save_term = interactive;
interactive = 0;
locus.mu_file = argv[1];
locus.mu_line = 0;
locus.mu_col = 0;
locus.beg.mu_file = argv[1];
locus.beg.mu_line = 0;
locus.beg.mu_col = 0;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &locus);
mail_mainloop (source_readline, input, 0);
interactive = save_term;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL);
mu_stream_unref (input);
return 0;
}
......
......@@ -260,15 +260,17 @@ input_getline (struct iobuf *inp)
inp->length = mu_rtrim_class (inp->buffer, MU_CTYPE_ENDLN);
if (inp->buffer[0] == '#' && !is_dbm_directive (inp))
{
struct mu_locus loc;
struct mu_locus_range loc;
mu_stream_ioctl (mu_strerr,
MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_GET_LOCUS,
MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE,
&loc);
loc.mu_line = strtoul (inp->buffer + 1, NULL, 10);
loc.beg.mu_line = strtoul (inp->buffer + 1, NULL, 10);
mu_stream_ioctl (mu_strerr,
MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_LOCUS,
MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE,
&loc);
free (loc.mu_file);
mu_locus_range_deinit (&loc);
continue;
}
break;
......@@ -1322,7 +1324,8 @@ add_records (int mode, int replace)
const char *flt_argv[] = { "inline-comment", "#", "-S", "-i", "#", NULL };
int rc;
int save_log_mode = 0, log_mode;
struct mu_locus save_locus = { NULL, }, locus;
struct mu_locus_range save_locus = MU_LOCUS_RANGE_INITIALIZER,
locus = MU_LOCUS_RANGE_INITIALIZER;
struct mu_dbm_datum key, contents;
struct iobuf input;
struct mu_wordsplit ws;
......@@ -1364,18 +1367,21 @@ add_records (int mode, int replace)
/* Configure error stream to output input file location before each error
message */
locus.mu_file = input_file ? input_file : "<stdin>";
locus.mu_line = 0;
locus.mu_col = 0;
locus.beg.mu_file = input_file ? input_file : "<stdin>";
locus.beg.mu_line = 0;
locus.beg.mu_col = 0;
memset (&locus.end, 0, sizeof locus.end);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_GET_MODE,
&save_log_mode);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_GET_LOCUS,
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE,
&save_locus);
log_mode = save_log_mode | MU_LOGMODE_LOCUS;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_MODE,
&log_mode);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_LOCUS,
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE,
&locus);
/* Initialize I/O data */
......@@ -1443,7 +1449,8 @@ add_records (int mode, int replace)
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_MODE,
&save_log_mode);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_LOCUS,
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE,
&save_locus);
if (known_meta_data)
......
......@@ -26,7 +26,7 @@ static char logger_args_doc[] = N_("[TEXT]");
static char *input_file = NULL;
static int logger_type = MU_STRERR_STDERR;
static int log_severity = MU_LOG_ERROR;
static struct mu_locus locus;
static struct mu_locus_range locus;
static int syslog_facility = LOG_USER;
static int syslog_priority = LOG_ERR;
static char *syslog_tag = NULL;
......@@ -83,32 +83,67 @@ set_severity (struct mu_parseopt *po, struct mu_option *opt,
}
static void
set_locus (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
parse_locus_point (char **ptr, struct mu_locus_point *pt,
struct mu_parseopt *po)
{
char *str = *ptr;
char *s;
locus.mu_file = mu_strdup (arg);
s = strchr (arg, ':');
s = strchr (str, ':');
if (s)
{
char *end;
*s++ = 0;
locus.mu_line = strtoul (s, &s, 10);
if (*s == ':')
if (*str)
mu_locus_point_init (pt, str);
pt->mu_line = strtoul (s, &end, 10);
if (end == s)
{
mu_parseopt_error (po, _("bad line number: %s"), s);
exit (po->po_exit_error);
}
s = end;
if (*s == '.' || *s == ':')
{
locus.mu_col = strtoul (s + 1, &s, 10);
if (*s)
s++;
pt->mu_col = strtoul (s, &end, 10);
if (end == s)
{
mu_parseopt_error (po, _("bad column number: %s"), arg);
mu_parseopt_error (po, _("bad column number: %s"), s);
exit (po->po_exit_error);
}
}
else if (*s)
{
mu_parseopt_error (po, _("bad line number: %s"), arg);
exit (po->po_exit_error);
s = end;
}
}
else
{
mu_parseopt_error (po, _("missing line number after %s"), s);
exit (po->po_exit_error);
}
*ptr = s;
}
static void
set_locus (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
char *s;
char *tmp;
tmp = mu_strdup (arg);
s = tmp;
parse_locus_point (&s, &locus.beg, po);
if (*s == '-')
{
mu_locus_point_init (&locus.end, locus.beg.mu_file);
locus.end.mu_line = locus.beg.mu_line;
locus.end.mu_col = locus.end.mu_col;
s++;
parse_locus_point (&s, &locus.end, po);
}
if (*s)
mu_parseopt_error (po, _("locus format error near %s"), s);
}
static struct mu_option logger_options[] = {
......@@ -127,7 +162,7 @@ static struct mu_option logger_options[] = {
{ "severity", 's', N_("SEV"), MU_OPTION_DEFAULT,
N_("log at Mailutils severity level SEV"),
mu_c_string, NULL, set_severity },
{ "locus", 'l', N_("FILE:LINE[:COL]"), MU_OPTION_DEFAULT,
{ "locus", 'l', N_("FILE:LINE[.COL][-FILE:LINE[.COL]]"), MU_OPTION_DEFAULT,
N_("set locus for logging"),
mu_c_string, NULL, set_locus },
{ "tag", 't', N_("TAG"), MU_OPTION_DEFAULT,
......@@ -166,9 +201,9 @@ main (int argc, char **argv)
mode = MU_LOGMODE_SEVERITY | MU_LOGMODE_LOCUS;
mu_stream_ioctl (logger, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
if (locus.mu_file)
if (locus.beg.mu_file)
mu_stream_ioctl (logger, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &locus);
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &locus);
mu_stream_ioctl (logger, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &log_severity);
......
......@@ -52,7 +52,7 @@ wicket_match (mu_stream_t stream, const char *str)
{
int rc, ret;
mu_url_t u, url;
struct mu_locus loc;
struct mu_locus_point loc;
int flags = MU_URL_PARSE_ALL;
if (wicket_verbose > 2)
......
......@@ -495,8 +495,13 @@ main (int argc, char *argv[])
mu_sieve_set_logger (mach, _sieve_action_log);
if (expression_option)
rc = mu_sieve_compile_buffer (mach, script, strlen (script),
"stdin", 1);
{
struct mu_locus_point pt;
pt.mu_file = "stdin";
pt.mu_line = 1;
pt.mu_col = 0;
rc = mu_sieve_compile_buffer (mach, script, strlen (script), &pt);
}
else
rc = mu_sieve_compile (mach, script);
if (rc)
......
......@@ -38,7 +38,7 @@ if header :comparator "i;ascii-numeric" :contains "X-Number" "15"
discard;
}
],[78],[],
[sieve: prog:4.1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
[sieve: prog:4.4-65: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
])
AT_CLEANUP
......