summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-06-13 07:56:20 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-06-13 08:15:17 +0300
commit3a78309aa59c245c14e29d3e7eb953c6a2ea1035 (patch)
treec50b11921af9b4ea76c3128dbdd7d95eadc7b033
parent16383a0184fd266e33c7d16ef55ce0d39dd1206e (diff)
downloadmailutils-3a78309aa59c245c14e29d3e7eb953c6a2ea1035.tar.gz
mailutils-3a78309aa59c245c14e29d3e7eb953c6a2ea1035.tar.bz2
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
-rw-r--r--comsat/action.c31
-rw-r--r--include/mailutils/auth.h3
-rw-r--r--include/mailutils/cfg.h7
-rw-r--r--include/mailutils/diag.h7
-rw-r--r--include/mailutils/mailutils.h2
-rw-r--r--include/mailutils/sieve.h5
-rw-r--r--include/mailutils/stream.h8
-rw-r--r--include/mailutils/types.hin7
-rw-r--r--libmailutils/base/wicket.c4
-rw-r--r--libmailutils/cfg/Makefile.am3
-rw-r--r--libmailutils/cfg/cfg.h1
-rw-r--r--libmailutils/cfg/format.c6
-rw-r--r--libmailutils/cfg/lexer.l69
-rw-r--r--libmailutils/cfg/parser.y140
-rw-r--r--libmailutils/diag/diag.c44
-rw-r--r--libmailutils/stream/logstream.c42
-rw-r--r--libmailutils/tests/logstr.at35
-rw-r--r--libmailutils/tests/logstr.c46
-rw-r--r--libmailutils/tests/wicket.c2
-rw-r--r--libmu_auth/radius.c38
-rw-r--r--libmu_sieve/actions.c4
-rw-r--r--libmu_sieve/comparator.c12
-rw-r--r--libmu_sieve/extensions/moderator.c6
-rw-r--r--libmu_sieve/mem.c27
-rw-r--r--libmu_sieve/prog.c64
-rw-r--r--libmu_sieve/require.c2
-rw-r--r--libmu_sieve/runtime.c53
-rw-r--r--libmu_sieve/sieve-priv.h19
-rw-r--r--libmu_sieve/sieve.l90
-rw-r--r--libmu_sieve/sieve.y121
-rw-r--r--libmu_sieve/util.c32
-rw-r--r--libmu_sieve/variables.c2
-rw-r--r--mail/source.c12
-rw-r--r--mu/libexec/dbm.c31
-rw-r--r--mu/libexec/logger.c73
-rw-r--r--mu/libexec/wicket.c2
-rw-r--r--sieve/sieve.c9
-rw-r--r--sieve/tests/i-numeric.at2
38 files changed, 493 insertions, 568 deletions
diff --git a/comsat/action.c b/comsat/action.c
index 6ff766a82..24080a511 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -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);
}
diff --git a/include/mailutils/auth.h b/include/mailutils/auth.h
index 04dbfd37c..998779b69 100644
--- a/include/mailutils/auth.h
+++ b/include/mailutils/auth.h
@@ -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,
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index 8ccd7f4eb..de84af6e1 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -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);
diff --git a/include/mailutils/diag.h b/include/mailutils/diag.h
index 3b57aae9d..03a0eacc2 100644
--- a/include/mailutils/diag.h
+++ b/include/mailutils/diag.h
@@ -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);
diff --git a/include/mailutils/mailutils.h b/include/mailutils/mailutils.h
index 51cfe09c3..d5aadf85b 100644
--- a/include/mailutils/mailutils.h
+++ b/include/mailutils/mailutils.h
@@ -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>
diff --git a/include/mailutils/sieve.h b/include/mailutils/sieve.h
index 8d9c2c1a8..58a6037cb 100644
--- a/include/mailutils/sieve.h
+++ b/include/mailutils/sieve.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);
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index d200c2840..50cffc591 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -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 *
*/
diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin
index 2a0ee17fc..cc7709c9c 100644
--- a/include/mailutils/types.hin
+++ b/include/mailutils/types.hin
@@ -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
diff --git a/libmailutils/base/wicket.c b/libmailutils/base/wicket.c
index bb5ad2e7a..1acecff55 100644
--- a/libmailutils/base/wicket.c
+++ b/libmailutils/base/wicket.c
@@ -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)
diff --git a/libmailutils/cfg/Makefile.am b/libmailutils/cfg/Makefile.am
index 77aea6c61..51f67de6b 100644
--- a/libmailutils/cfg/Makefile.am
+++ b/libmailutils/cfg/Makefile.am
@@ -21,7 +21,8 @@ libcfg_la_SOURCES = \
driver.c\
format.c\
lexer.c\
- parser.c
+ parser.c\
+ cfg.h
localedir = $(datadir)/locale
AM_CPPFLAGS = \
diff --git a/libmailutils/cfg/cfg.h b/libmailutils/cfg/cfg.h
new file mode 100644
index 000000000..3b0ae34c3
--- /dev/null
+++ b/libmailutils/cfg/cfg.h
@@ -0,0 +1 @@
+#include <mailutils/yyloc.h>
diff --git a/libmailutils/cfg/format.c b/libmailutils/cfg/format.c
index a751c5793..78d84b1a0 100644
--- a/libmailutils/cfg/format.c
+++ b/libmailutils/cfg/format.c
@@ -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)
{
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
index 88f24861a..d164a109f 100644
--- a/libmailutils/cfg/lexer.l
+++ b/libmailutils/cfg/lexer.l
@@ -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;
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index 80b940f8a..b49dd0c11 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -40,10 +40,10 @@
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/cidr.h>
+#include "cfg.h"
int mu_cfg_parser_verbose;
static mu_list_t /* of mu_cfg_node_t */ parse_node_list;
-struct mu_locus mu_cfg_locus;
size_t mu_cfg_error_count;
static int _mu_cfg_errcnt;
@@ -57,7 +57,7 @@ char *_mu_line_finish (void);
static int
yyerror (char *s)
{
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus, "%s", s);
+ mu_error ("%s", s);
mu_cfg_error_count++;
return 0;
}
@@ -85,7 +85,7 @@ _node_set_parent (void *item, void *data)
}
static mu_cfg_node_t *
-mu_cfg_alloc_node (enum mu_cfg_node_type type, struct mu_locus *loc,
+mu_cfg_alloc_node (enum mu_cfg_node_type type, struct mu_locus_range *loc,
const char *tag, mu_config_value_t *label,
mu_list_t nodelist)
{
@@ -94,7 +94,7 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, struct mu_locus *loc,
size_t size = sizeof *np + strlen (tag) + 1;
np = mu_alloc (size);
np->type = type;
- np->locus = *loc;
+ mu_locus_range_copy (&np->locus, loc);
p = (char*) (np + 1);
np->tag = p;
strcpy (p, tag);
@@ -121,17 +121,15 @@ debug_print_node (mu_cfg_node_t *node)
if (node->type == mu_cfg_node_undefined)
{
/* Stay on the safe side */
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
- _("unknown statement type!"));
+ mu_error (_("unknown statement type!"));
mu_cfg_error_count++;
}
else
{
/* FIXME: How to print label? */
- mu_diag_at_locus (MU_LOG_DEBUG, &node->locus,
- "statement: %s, id: %s",
- node_type_str (node->type),
- node->tag ? node->tag : "(null)");
+ mu_error ("statement: %s, id: %s",
+ node_type_str (node->type),
+ node->tag ? node->tag : "(null)");
}
}
}
@@ -170,6 +168,9 @@ mu_cfg_create_node_list (mu_list_t *plist)
%}
+%locations
+%expect 1
+
%union {
mu_cfg_node_t node;
mu_cfg_node_t *pnode;
@@ -177,7 +178,6 @@ mu_cfg_create_node_list (mu_list_t *plist)
char *string;
mu_config_value_t value, *pvalue;
mu_list_t list;
- struct { const char *name; struct mu_locus locus; } ident;
}
%token <string> MU_TOK_IDENT MU_TOK_STRING MU_TOK_QSTRING MU_TOK_MSTRING
@@ -186,7 +186,7 @@ mu_cfg_create_node_list (mu_list_t *plist)
%type <value> value
%type <pvalue> tag vallist
%type <list> values list vlist
-%type <ident> ident
+%type <string> ident
%type <nodelist> stmtlist
%type <pnode> stmt simple block
@@ -217,32 +217,32 @@ stmt : simple
simple : ident vallist ';'
{
- $$ = mu_cfg_alloc_node (mu_cfg_node_param, &$1.locus,
- $1.name, $2,
- NULL);
+ struct mu_locus_range lr;
+ lr.beg = @1.beg;
+ lr.end = @3.end;
+ $$ = mu_cfg_alloc_node (mu_cfg_node_param, &lr, $1, $2, NULL);
}
;
block : ident tag '{' '}' opt_sc
{
- $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &$1.locus,
- $1.name, $2,
- NULL);
+ struct mu_locus_range lr;
+ lr.beg = @1.beg;
+ lr.end = @5.end;
+ $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &lr, $1, $2, NULL);
}
| ident tag '{' stmtlist '}' opt_sc
{
- $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &$1.locus,
- $1.name, $2, $4);
+ struct mu_locus_range lr;
+ lr.beg = @1.beg;
+ lr.end = @6.end;
+ $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &lr, $1, $2, $4);
mu_list_foreach ($4, _node_set_parent, $$);
}
;
ident : MU_TOK_IDENT
- {
- $$.name = $1;
- $$.locus = mu_cfg_locus;
- }
- ;
+ ;
tag : /* empty */
{
@@ -270,8 +270,7 @@ vallist : vlist
val.v.arg.v = mu_alloc (n * sizeof (val.v.arg.v[0]));
if (!val.v.arg.v)
{
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
- _("not enough memory"));
+ mu_error (_("not enough memory"));
abort();
}
@@ -292,9 +291,7 @@ vlist : value
int rc = mu_list_create (&$$);
if (rc)
{
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
- _("cannot create list: %s"),
- mu_strerror (rc));
+ mu_error (_("cannot create list: %s"), mu_strerror (rc));
abort ();
}
mu_list_append ($$, config_value_dup (&$1)); /* FIXME */
@@ -401,14 +398,15 @@ mu_cfg_parse (mu_cfg_tree_t **ptree)
mu_cfg_tree_t *tree;
mu_opool_t pool;
int save_mode = 0, mode;
- struct mu_locus save_locus = { NULL, };
+ struct mu_locus_range save_locus = MU_LOCUS_RANGE_INITIALIZER;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_GET_MODE,
&save_mode);
mode = save_mode | MU_LOGMODE_LOCUS;
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_MODE,
&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);
mu_cfg_set_debug ();
@@ -432,9 +430,10 @@ mu_cfg_parse (mu_cfg_tree_t **ptree)
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, MU_IOCTL_LOGSTREAM_SET_MODE,
&save_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);
- free (save_locus.mu_file);
+ mu_locus_range_deinit (&save_locus); /* FIXME: refcount? */
return rc;
}
@@ -480,7 +479,7 @@ mu_cfg_tree_union (mu_cfg_tree_t **pa, mu_cfg_tree_t **pb)
static mu_cfg_tree_t *
do_include (const char *name, struct mu_cfg_parse_hints *hints,
- struct mu_locus *loc)
+ struct mu_locus_range const *loc)
{
struct stat sb;
char *tmpname = NULL;
@@ -520,15 +519,15 @@ do_include (const char *name, struct mu_cfg_parse_hints *hints,
}
else if (errno == ENOENT)
{
- mu_diag_at_locus (MU_LOG_ERROR, loc,
- _("include file or directory does not exist"));
+ mu_diag_at_locus_range (MU_LOG_ERROR, loc,
+ _("include file or directory does not exist"));
mu_cfg_error_count++;
}
else
{
- mu_diag_at_locus (MU_LOG_ERROR, loc,
- _("cannot stat include file or directory: %s"),
- mu_strerror (errno));
+ mu_diag_at_locus_range (MU_LOG_ERROR, loc,
+ _("cannot stat include file or directory: %s"),
+ mu_strerror (errno));
mu_cfg_error_count++;
}
@@ -576,7 +575,7 @@ mu_cfg_tree_postprocess (mu_cfg_tree_t *tree, struct mu_cfg_parse_hints *hints)
}
else
{
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
+ mu_diag_at_locus_range (MU_LOG_ERROR, &node->locus,
_("argument to `program' is not a string"));
mu_cfg_error_count++;
mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
@@ -602,7 +601,7 @@ mu_cfg_tree_postprocess (mu_cfg_tree_t *tree, struct mu_cfg_parse_hints *hints)
}
else
{
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
+ mu_diag_at_locus_range (MU_LOG_ERROR, &node->locus,
_("argument to `include' is not a string"));
mu_cfg_error_count++;
}
@@ -760,8 +759,7 @@ push_section (struct scan_tree_data *dat, struct mu_cfg_section *sec)
struct mu_cfg_section_list *p = mu_alloc (sizeof *p);
if (!p)
{
- mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
- _("not enough memory"));
+ mu_error (_("not enough memory"));
mu_cfg_error_count++;
return 1;
}
@@ -782,7 +780,7 @@ pop_section (struct scan_tree_data *dat)
}
static int
-valcvt (const struct mu_locus *locus,
+valcvt (const struct mu_locus_range *locus,
void *tgt, mu_c_type_t type, mu_config_value_t *val)
{
int rc;
@@ -790,7 +788,7 @@ valcvt (const struct mu_locus *locus,
if (val->type != MU_CFG_STRING)
{
- mu_diag_at_locus (MU_LOG_ERROR, locus, _("expected string value"));
+ mu_diag_at_locus_range (MU_LOG_ERROR, locus, _("expected string value"));
mu_cfg_error_count++;
return 1;
}
@@ -798,8 +796,8 @@ valcvt (const struct mu_locus *locus,
rc = mu_str_to_c (val->v.string, type, tgt, &errmsg);
if (rc)
{
- mu_diag_at_locus (MU_LOG_ERROR, locus, "%s",
- errmsg ? errmsg : mu_strerror (rc));
+ mu_diag_at_locus_range (MU_LOG_ERROR, locus, "%s",
+ errmsg ? errmsg : mu_strerror (rc));
free (errmsg);
}
return rc;
@@ -810,7 +808,7 @@ struct set_closure
mu_list_t list;
int type;
struct scan_tree_data *sdata;
- const struct mu_locus *locus;
+ const struct mu_locus_range *locus;
};
static size_t config_type_size[] = {
@@ -840,7 +838,7 @@ _set_fun (void *item, void *data)
if ((size_t) clos->type >= MU_ARRAY_SIZE(config_type_size)
|| (size = config_type_size[clos->type]) == 0)
{
- mu_diag_at_locus (MU_LOG_EMERG, clos->locus,
+ mu_diag_at_locus_range (MU_LOG_EMERG, clos->locus,
_("INTERNAL ERROR at %s:%d: unhandled data type %d"),
__FILE__, __LINE__, clos->type);
mu_cfg_error_count++;
@@ -850,7 +848,8 @@ _set_fun (void *item, void *data)
tgt = mu_alloc (size);
if (!tgt)
{
- mu_diag_at_locus (MU_LOG_ERROR, clos->locus, _("not enough memory"));
+ mu_diag_at_locus_range (MU_LOG_ERROR, clos->locus,
+ _("not enough memory"));
mu_cfg_error_count++;
return 1;
}
@@ -870,9 +869,9 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
if (!param)
{
- mu_diag_at_locus (MU_LOG_ERROR, &node->locus,
- _("unknown keyword `%s'"),
- node->tag);
+ mu_diag_at_locus_range (MU_LOG_ERROR, &node->locus,
+ _("unknown keyword `%s'"),
+ node->tag);
mu_cfg_error_count++;
return 1;
}
@@ -887,7 +886,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
tgt = NULL;
else
{
- mu_diag_at_locus (MU_LOG_EMERG, &node->locus,
+ mu_diag_at_locus_range (MU_LOG_EMERG, &node->locus,
_("INTERNAL ERROR: cannot determine target offset for "
"%s"), param->ident);
abort ();
@@ -915,7 +914,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
break;
case MU_CFG_ARRAY:
- mu_diag_at_locus (MU_LOG_ERROR, &node->locus,
+ mu_diag_at_locus_range (MU_LOG_ERROR, &node->locus,
_("expected list, but found array"));
mu_cfg_error_count++;
return 1;
@@ -929,13 +928,13 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
{
if (!param->callback)
{
- mu_diag_at_locus (MU_LOG_EMERG, &node->locus,
+ mu_diag_at_locus_range (MU_LOG_EMERG, &node->locus,
_("INTERNAL ERROR: %s: callback not defined"),
node->tag);
abort ();
}
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS,
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE,
(void*) &node->locus);
if (param->callback (tgt, node->label))
return 1;
@@ -964,9 +963,9 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
{
if (mu_cfg_parser_verbose)
{
- mu_diag_at_locus (MU_LOG_WARNING, &node->locus,
- _("unknown section `%s'"),
- node->tag);
+ mu_diag_at_locus_range (MU_LOG_WARNING, &node->locus,
+ _("unknown section `%s'"),
+ node->tag);
}
return MU_CFG_ITER_SKIP;
}
@@ -983,7 +982,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
if (sec->parser)
{
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS,
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE,
(void*) &node->locus);
if (sec->parser (mu_cfg_section_start, node,
sec->label, &sec->target,
@@ -1041,7 +1040,7 @@ mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
struct scan_tree_data dat;
struct mu_cfg_iter_closure clos;
int save_mode = 0, mode;
- struct mu_locus save_locus = { NULL, };
+ struct mu_locus_range save_locus = MU_LOCUS_RANGE_INITIALIZER;
int rc;
dat.tree = tree;
@@ -1056,7 +1055,7 @@ mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_GET_LOCUS, &save_locus);
+ MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &save_locus);
if (push_section (&dat, sections))
return 1;
@@ -1070,8 +1069,7 @@ mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &save_mode);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS, &save_locus);
- free (save_locus.mu_file);
+ MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &save_locus);
return dat.error;
}
@@ -1124,7 +1122,7 @@ 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)
{
@@ -1136,7 +1134,7 @@ mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
np = mu_alloc (size);
np->type = type;
if (loc)
- np->locus = *loc;
+ mu_locus_range_copy (&np->locus, loc);
else
memset (&np->locus, 0, sizeof np->locus);
p = (char*) (np + 1);
@@ -1478,11 +1476,7 @@ mu_cfg_create_subtree (const char *path, mu_cfg_node_t **pnode)
char **argv;
enum mu_cfg_node_type type;
mu_cfg_node_t *node = NULL;
- struct mu_locus locus;
-
- locus.mu_file = "<int>";
- locus.mu_line = 0;
- locus.mu_col = 0;
+ struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER;
rc = split_cfg_path (path, &argc, &argv);
if (rc)
diff --git a/libmailutils/diag/diag.c b/libmailutils/diag/diag.c
index 185101bb7..b5a7482a6 100644
--- a/libmailutils/diag/diag.c
+++ b/libmailutils/diag/diag.c
@@ -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 ();
diff --git a/libmailutils/stream/logstream.c b/libmailutils/stream/logstream.c
index 437569c43..010cd9310 100644
--- a/libmailutils/stream/logstream.c
+++ b/libmailutils/stream/logstream.c
@@ -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;
diff --git a/libmailutils/tests/logstr.at b/libmailutils/tests/logstr.at
index 6d7d8db56..8a97dea0a 100644
--- a/libmailutils/tests/logstr.at
+++ b/libmailutils/tests/logstr.at
@@ -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
])
diff --git a/libmailutils/tests/logstr.c b/libmailutils/tests/logstr.c
index 66c1cc60e..638f9b8a7 100644
--- a/libmailutils/tests/logstr.c
+++ b/libmailutils/tests/logstr.c
@@ -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 },
diff --git a/libmailutils/tests/wicket.c b/libmailutils/tests/wicket.c
index 1d7794698..e5cf5b532 100644
--- a/libmailutils/tests/wicket.c
+++ b/libmailutils/tests/wicket.c
@@ -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)
{
diff --git a/libmu_auth/radius.c b/libmu_auth/radius.c
index acd563411..68d306196 100644
--- a/libmu_auth/radius.c
+++ b/libmu_auth/radius.c
@@ -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"));
diff --git a/libmu_sieve/actions.c b/libmu_sieve/actions.c
index 93b33e092..17daa7ef6 100644
--- a/libmu_sieve/actions.c
+++ b/libmu_sieve/actions.c
@@ -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;
}
diff --git a/libmu_sieve/comparator.c b/libmu_sieve/comparator.c
index 8b7e58319..e401b90d4 100644
--- a/libmu_sieve/comparator.c
+++ b/libmu_sieve/comparator.c
@@ -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);
diff --git a/libmu_sieve/extensions/moderator.c b/libmu_sieve/extensions/moderator.c
index 5ec61d2f4..2584f206c 100644
--- a/libmu_sieve/extensions/moderator.c
+++ b/libmu_sieve/extensions/moderator.c
@@ -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"));
}
diff --git a/libmu_sieve/mem.c b/libmu_sieve/mem.c
index 5a89fa8dc..f98e747c8 100644
--- a/libmu_sieve/mem.c
+++ b/libmu_sieve/mem.c
@@ -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)
{
diff --git a/libmu_sieve/prog.c b/libmu_sieve/prog.c
index dc2ae9338..a1dead4e6 100644
--- a/libmu_sieve/prog.c
+++ b/libmu_sieve/prog.c
@@ -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);
diff --git a/libmu_sieve/require.c b/libmu_sieve/require.c
index 597af98fd..b5c9699a7 100644
--- a/libmu_sieve/require.c
+++ b/libmu_sieve/require.c
@@ -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);
}
diff --git a/libmu_sieve/runtime.c b/libmu_sieve/runtime.c
index c5c1ab52f..b18b996b0 100644
--- a/libmu_sieve/runtime.c
+++ b/libmu_sieve/runtime.c
@@ -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
diff --git a/libmu_sieve/sieve-priv.h b/libmu_sieve/sieve-priv.h
index 041b4ea7c..ba5bad91e 100644
--- a/libmu_sieve/sieve-priv.h
+++ b/libmu_sieve/sieve-priv.h
@@ -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);
diff --git a/libmu_sieve/sieve.l b/libmu_sieve/sieve.l
index 099fc7774..a93245e70 100644
--- a/libmu_sieve/sieve.l
+++ b/libmu_sieve/sieve.l
@@ -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;
diff --git a/libmu_sieve/sieve.y b/libmu_sieve/sieve.y
index 067489f13..5499a5ece 100644
--- a/libmu_sieve/sieve.y
+++ b/libmu_sieve/sieve.y
@@ -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);
}
diff --git a/libmu_sieve/util.c b/libmu_sieve/util.c
index 7cc9227e4..e70fb103f 100644
--- a/libmu_sieve/util.c
+++ b/libmu_sieve/util.c
@@ -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;
diff --git a/libmu_sieve/variables.c b/libmu_sieve/variables.c
index 91550ef0a..212e1b6fc 100644
--- a/libmu_sieve/variables.c
+++ b/libmu_sieve/variables.c
@@ -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);
diff --git a/mail/source.c b/mail/source.c
index 802e298fd..80b7929f2 100644
--- a/mail/source.c
+++ b/mail/source.c
@@ -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;
}
diff --git a/mu/libexec/dbm.c b/mu/libexec/dbm.c
index 50fe4ec87..32d66c908 100644
--- a/mu/libexec/dbm.c
+++ b/mu/libexec/dbm.c
@@ -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)
diff --git a/mu/libexec/logger.c b/mu/libexec/logger.c
index d40f7d9b1..80be6fc9d 100644
--- a/mu/libexec/logger.c
+++ b/mu/libexec/logger.c
@@ -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);
diff --git a/mu/libexec/wicket.c b/mu/libexec/wicket.c
index a9d586a35..422d2f32f 100644
--- a/mu/libexec/wicket.c
+++ b/mu/libexec/wicket.c
@@ -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)
diff --git a/sieve/sieve.c b/sieve/sieve.c
index a87b26157..32c044fa7 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -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)
diff --git a/sieve/tests/i-numeric.at b/sieve/tests/i-numeric.at
index bdb40d961..8ec8a935d 100644
--- a/sieve/tests/i-numeric.at
+++ b/sieve/tests/i-numeric.at
@@ -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

Return to:

Send suggestions and report system problems to the System administrator.