Commit fb60322362bfa7f16b2fb3760b26dcd312b6aa5f

Thomas de Grivel 2024-08-01T13:50:29

fix line numbers in buf

diff --git a/libkc3/buf.c b/libkc3/buf.c
index 01c4b44..d5a5fdf 100644
--- a/libkc3/buf.c
+++ b/libkc3/buf.c
@@ -77,12 +77,6 @@ sw buf_ignore (s_buf *buf, uw size)
       if ((r = buf_read_character_utf8(buf, &c)) < 0)
         return r;
       if (r > 0) {
-        if (c == '\n') {
-          buf->column = 0;
-          buf->line++;
-        }
-        else
-          buf->column++;
         i += r;
         continue;
       }
@@ -191,6 +185,7 @@ s_buf * buf_init (s_buf *buf, bool p_free, uw size, char *p)
   s_buf tmp = {0};
   assert(buf);
   tmp.free = p_free;
+  tmp.line = 1;
   tmp.ptr.pchar = p;
   tmp.size = size;
   *buf = tmp;
@@ -201,6 +196,7 @@ s_buf * buf_init_const (s_buf *buf, uw size, const char *p)
 {
   s_buf tmp = {0};
   assert(buf);
+  tmp.line = 1;
   tmp.ptr.pchar = (char *) p;
   tmp.read_only = true;
   tmp.size = size;
@@ -262,15 +258,6 @@ s_buf * buf_init_alloc (s_buf *buf, uw size)
   return buf_init(buf, true, size, p);
 }
 
-s_buf * buf_init_copy (s_buf *buf, const s_buf *src)
-{
-  if (buf != src) {
-    *buf = *src;
-    buf->free = false;
-  }
-  return buf;
-}
-
 s_buf * buf_init_str (s_buf *buf, bool p_free, s_str *p)
 {
   s_buf tmp = {0};
diff --git a/libkc3/buf.h b/libkc3/buf.h
index 30e8a5c..ab4ea5d 100644
--- a/libkc3/buf.h
+++ b/libkc3/buf.h
@@ -32,7 +32,6 @@ s_buf * buf_init_const (s_buf *buf, uw size, const char *p);
 s_buf * buf_init_1 (s_buf *buf, bool p_free, char *p);
 s_buf * buf_init_1_const (s_buf *buf, const char *p);
 s_buf * buf_init_alloc (s_buf *buf, uw size);
-s_buf * buf_init_copy (s_buf *buf, const s_buf *src);
 s_buf * buf_init_str (s_buf *buf, bool free, s_str *p);
 s_buf * buf_init_str_const (s_buf *buf, const s_str *p);
 s_buf * buf_init_str_copy (s_buf *buf, const s_str *str);
diff --git a/libkc3/data.c b/libkc3/data.c
index 18896c7..8437ae6 100644
--- a/libkc3/data.c
+++ b/libkc3/data.c
@@ -600,8 +600,6 @@ void * data_init_copy (const s_sym *type, void *data, const void *src)
     return array_init_copy(data, src);
   if (type == &g_sym_Bool)
     return bool_init_copy(data, src);
-  if (type == &g_sym_Buf)
-    return buf_init_copy(data, src);
   if (type == &g_sym_Call)
     return call_init_copy(data, src);
   if (type == &g_sym_Cfn)