From ed157718223eaca5f02a5fff4a801643a07dff0b Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Thu, 1 Mar 2012 22:00:11 -0800
Subject: * match.c (search_form): search_form works with relative positions
 now, but match_line returns absolute, and so needs to be offset by -c->base.
 (h_trailer, h_fun): Bugfix: return the absolute position, rather than
 relative c->pos. The return value of these functions becomes the return value
 of do_match_line, so the semantics has to agree.

---
 ChangeLog | 8 ++++++++
 match.c   | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0abff845..6a2cd0b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-03-01  Kaz Kylheku  <kaz@kylheku.com>
+
+	* match.c (search_form): search_form works with relative positions now,
+	but match_line returns absolute, and so needs to be offset by -c->base.
+	(h_trailer, h_fun): Bugfix: return the absolute position, rather than
+	relative c->pos. The return value of these functions becomes the return
+	value of do_match_line, so the semantics has to agree.
+
 2012-03-01  Kaz Kylheku  <kaz@kylheku.com>
 
 	* match.c (sem_error, file_err): Bugfix: pull text formatted source
diff --git a/match.c b/match.c
index 7b22b51d..2b1bd482 100644
--- a/match.c
+++ b/match.c
@@ -442,6 +442,7 @@ static val search_form(match_line_ctx *c, val needle_form, val from_end)
       cons_bind (new_bindings, new_pos,
                  match_line(ml_specline_pos(*c, spec, pos)));
       if (new_pos) {
+        new_pos = minus(new_pos, c->base);
         c->bindings = new_bindings;
         return cons(pos, minus(new_pos, pos));
       }
@@ -979,7 +980,7 @@ static val h_trailer(match_line_ctx *c)
   }
 
   LOG_MATCH("trailer", new_pos);
-  return cons(c->bindings, c->pos);
+  return cons(c->bindings, plus(c->pos, c->base));
 }
 
 static val h_fun(match_line_ctx *c)
@@ -1075,7 +1076,7 @@ static val h_eol(match_line_ctx *c)
 
   if (length_str_le(c->dataline, c->pos)) {
     LOG_MATCH("eol", c->pos);
-    return cons(c->bindings, c->pos);
+    return cons(c->bindings, plus(c->pos, c->base));
   }
   LOG_MISMATCH("eol");
   return nil;
-- 
cgit v1.2.3