diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-06-13 07:56:20 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-06-13 08:15:17 +0300 |
commit | 3a78309aa59c245c14e29d3e7eb953c6a2ea1035 (patch) | |
tree | c50b11921af9b4ea76c3128dbdd7d95eadc7b033 /libmu_sieve | |
parent | 16383a0184fd266e33c7d16ef55ce0d39dd1206e (diff) | |
download | mailutils-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
Diffstat (limited to 'libmu_sieve')
-rw-r--r-- | libmu_sieve/actions.c | 4 | ||||
-rw-r--r-- | libmu_sieve/comparator.c | 12 | ||||
-rw-r--r-- | libmu_sieve/extensions/moderator.c | 6 | ||||
-rw-r--r-- | libmu_sieve/mem.c | 27 | ||||
-rw-r--r-- | libmu_sieve/prog.c | 64 | ||||
-rw-r--r-- | libmu_sieve/require.c | 2 | ||||
-rw-r--r-- | libmu_sieve/runtime.c | 53 | ||||
-rw-r--r-- | libmu_sieve/sieve-priv.h | 19 | ||||
-rw-r--r-- | libmu_sieve/sieve.l | 90 | ||||
-rw-r--r-- | libmu_sieve/sieve.y | 121 | ||||
-rw-r--r-- | libmu_sieve/util.c | 32 | ||||
-rw-r--r-- | libmu_sieve/variables.c | 2 |
12 files changed, 190 insertions, 242 deletions
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; |