[augeas-devel] augeas: master - Report line/column number when get/put test fails

David Lutterkort lutter at fedoraproject.org
Tue Oct 20 13:20:15 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=4b92965fc2529e462d8ce6f8ff88caa019a89345
Commit:        4b92965fc2529e462d8ce6f8ff88caa019a89345
Parent:        5ac622b5832ee30aec53b6f04fc238341145d1b3
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Tue Oct 20 14:35:07 2009 +0200
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Tue Oct 20 14:35:07 2009 +0200

Report line/column number when get/put test fails

  * src/builtin.c (make_exn_lns_error): add line/column number in error
    message
  * src/internal.c (calc_line_ofs): moved here from transform.c
  * src/internal.h (calc_line_ofs): declare prototype
  * src/transform.c (calc_line_ofs): moved to internal.c
---
 src/builtin.c   |    6 ++++--
 src/internal.c  |   12 ++++++++++++
 src/internal.h  |    3 +++
 src/transform.c |   14 --------------
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/builtin.c b/src/builtin.c
index f42d45f..b311063 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -92,9 +92,11 @@ static struct value *make_exn_lns_error(struct info *info,
     }
     if (err->pos >= 0) {
         char *pos = format_pos(text, err->pos);
+        size_t line, ofs;
+        calc_line_ofs(text, err->pos, &line, &ofs);
         exn_printf_line(v,
-                        "Error encountered here (%d characters into string)",
-                        err->pos);
+                     "Error encountered at %d:%d (%d characters into string)",
+                        (int) line, (int) ofs, err->pos);
         if (pos != NULL)
             exn_printf_line(v, "%s", pos);
         free(pos);
diff --git a/src/internal.c b/src/internal.c
index 718caf8..4df027f 100644
--- a/src/internal.c
+++ b/src/internal.c
@@ -390,6 +390,18 @@ int xasprintf(char **strp, const char *format, ...) {
   return result;
 }
 
+void calc_line_ofs(const char *text, size_t pos, size_t *line, size_t *ofs) {
+    *line = 1;
+    *ofs = 0;
+    for (const char *t = text; t < text + pos; t++) {
+        *ofs += 1;
+        if (*t == '\n') {
+            *ofs = 0;
+            *line += 1;
+        }
+    }
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/src/internal.h b/src/internal.h
index e564f89..9ea668a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -267,6 +267,9 @@ const char *xstrerror(int errnum, char *buf, size_t len);
 /* Like asprintf, but set *STRP to NULL on error */
 int xasprintf(char **strp, const char *format, ...);
 
+/* Calculate line and column number of character POS in TEXT */
+void calc_line_ofs(const char *text, size_t pos, size_t *line, size_t *ofs);
+
 /* Struct: augeas
  * The data structure representing a connection to Augeas. */
 struct augeas {
diff --git a/src/transform.c b/src/transform.c
index e2ea7db..51857a1 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -258,20 +258,6 @@ static int err_set(struct augeas *aug, char **ep, const char *sub,
     return (r < 0) ? -1 : 0;
 }
 
-static void
-calc_line_ofs(const char *text, size_t pos, size_t *line, size_t *ofs)
-{
-    *line = 1;
-    *ofs = 0;
-    for (const char *t = text; t < text + pos; t++) {
-        *ofs += 1;
-        if (*t == '\n') {
-            *ofs = 0;
-            *line += 1;
-        }
-    }
-}
-
 /* Record an error in the tree. The error will show up underneath
  * /augeas/FILENAME/error. PATH is the path to the toplevel node in the
  * tree where the lens application happened. When STATUS is NULL, just




More information about the augeas-devel mailing list