Commit 09f270fe1349f80425845de6d908becd06acdc51

Thomas de Grivel 2024-09-16T23:13:09

wip segv

diff --git a/httpd/fx/app/controllers/fx_controller.kc3 b/httpd/fx/app/controllers/fx_controller.kc3
index 61312b1..a459425 100644
--- a/httpd/fx/app/controllers/fx_controller.kc3
+++ b/httpd/fx/app/controllers/fx_controller.kc3
@@ -1,6 +1,5 @@
 defmodule FXController do
 
-  require EKC3
   require File
   require List
   require Str
@@ -62,11 +61,9 @@ defmodule FXController do
   def show_file = fn (path) {
     index = fx_index("./fx/", path)
     menu = FXView.render_menu(index)
-    title = path
-    page = FXView.render_show(menu, html)
+    page = FXView.render_show_file(menu, path)
     body = LayoutView.render(title, page)
     %HTTP.Response{body: body}
-
   }
 
   def route = fn (req) {
@@ -75,8 +72,8 @@ defmodule FXController do
         (req.url == "/fx" ||
          Str.starts_with?(req.url, "/fx/"))) do
       path = "." + req.url
-      show(path)
+      show_file(path)
     end
-  end
+  }
 
 end
diff --git a/httpd/fx/app/templates/fx/show_file.html.ekc3 b/httpd/fx/app/templates/fx/show_file.html.ekc3
new file mode 100644
index 0000000..0ed8a43
--- /dev/null
+++ b/httpd/fx/app/templates/fx/show_file.html.ekc3
@@ -0,0 +1,9 @@
+<div class="row">
+  <div class="bg-gray col-12 col-sm-4 col-lg-3 left-col">
+    <%= raw menu %>
+  </div>
+  <div class="col-12 col-sm-8 col-lg-9">
+    <h1><%= FXView.path_links(path) %></h1>
+    <%= path %>
+  </div>
+</div>
diff --git a/httpd/fx/app/views/fx_view.kc3 b/httpd/fx/app/views/fx_view.kc3
index 41614d7..534b172 100644
--- a/httpd/fx/app/views/fx_view.kc3
+++ b/httpd/fx/app/views/fx_view.kc3
@@ -1,10 +1,29 @@
 defmodule FXView do
 
+  require HTML
+  require List
+  require Str
+  require URL
+
+  def path_links = fn {
+    (path) {
+      [_dot, _fx | path_list] = Str.split(path, "/")
+      path_links(path_list, "/", [])
+    }
+    ([], _, acc) { List.join(List.reverse(acc), "\n") }
+    ([first | rest], url, acc) {
+      a = """
+<a href="#{URL.escape(url + first)}">#{HTML.escape(first)}</a>
+"""
+      path_links(rest, "#{url}/#{first}/", [a | acc])
+    }
+  }
+
   def menu_template =
     EKC3.load("app/templates/fx/menu.html.ekc3")
 
-  def show_template =
-    EKC3.load("app/templates/fx/show.html.ekc3")
+  def show_file_template =
+    EKC3.load("app/templates/fx/show_file.html.ekc3")
 
   def properties_template =
     EKC3.load("app/templates/fx/properties.html.ekc3")
@@ -13,8 +32,8 @@ defmodule FXView do
     EKC3.render(menu_template)
   }
 
-  def render_show = fn (menu, html) {
-    EKC3.render(show_template)
+  def render_show_file = fn (menu, html) {
+    EKC3.render(show_file_template)
   }
 
 end
diff --git a/lib/kc3/0.1/str.facts b/lib/kc3/0.1/str.facts
index f207fdb..deed849 100644
--- a/lib/kc3/0.1/str.facts
+++ b/lib/kc3/0.1/str.facts
@@ -7,6 +7,12 @@ replace {Str.cast, :symbol_value,
 add {Str, :symbol, Str.ends_with?}
 replace {Str.ends_with?, :symbol_value,
          cfn Bool "str_ends_with" (Str, Str, Result)}
+add {Str, :symbol, Str.ftime}
+replace {Str.ftime, :symbol_value,
+         cfn Str "str_init_ftime" (Result, Time, Str)}
+add {Str, :symbol, Str.has_str?}
+replace {Str.has_str?, :symbol_value,
+         cfn Bool "str_has_str" (Str, Str, Result)}
 add {Str, :symbol, Str.rindex_character}
 replace {Str.rindex_character, :symbol_value,
          cfn Sw "str_rindex_character" (Str, Character)}
@@ -20,12 +26,9 @@ replace {Str.slice, :symbol_value, fn (str, start, end_) {
 add {Str, :symbol, Str.starts_with?}
 replace {Str.starts_with?, :symbol_value,
          cfn Bool "str_starts_with" (Str, Str, Result)}
-add {Str, :symbol, Str.has_str?}
-replace {Str.has_str?, :symbol_value,
-         cfn Bool "str_has_str" (Str, Str, Result)}
 add {Str, :symbol, Str.subst}
 replace {Str.subst, :symbol_value,
          cfn Str "str_init_subst" (Result, Str, Str, Str)}
-add {Str, :symbol, Str.ftime}
-replace {Str.ftime, :symbol_value,
-         cfn Str "str_init_ftime" (Result, Time, Str)}
+add {Str, :symbol, Str.split}
+replace {Str.split, :symbol_value,
+         cfn List "str_split" (Str, Str, Result)}
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 67fb444..24900c2 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -431,8 +431,11 @@ sw buf_parse_block (s_buf *buf, s_block *block)
     goto restore;
   }
   result += r;
-  if ((r = buf_ignore_spaces(buf)) <= 0)
+  if ((r = buf_ignore_spaces(buf)) <= 0) {
+    err_puts("buf_parse_block: buf_ignore_spaces");
+    assert(! "buf_parse_block: buf_ignore_spaces");
     goto restore;
+  }
   result += r;
   if ((r = buf_parse_block_inner(buf, short_form, block)) < 0) {
     err_puts("buf_parse_block: buf_parse_block_inner < 0");
@@ -545,7 +548,7 @@ sw buf_parse_block_inner (s_buf *buf, bool short_form, s_block *block)
       goto restore;
     }
     if (! r) {
-      if ((r = buf_read_1(buf, ";")) < 0) {
+      if ((r = buf_read_1(buf, ";")) <= 0) {
         err_write_1("buf_parse_block_inner: line ");
         err_inspect_sw_decimal(&buf->line);
         err_puts(": missing separator: ");
@@ -554,8 +557,6 @@ sw buf_parse_block_inner (s_buf *buf, bool short_form, s_block *block)
         assert(! "buf_parse_block_inner: missing separator");
         goto restore;
       }
-      if (! r)
-        goto restore;
     }
     result += r;
     if ((r = buf_parse_comments(buf)) < 0) {
@@ -2667,6 +2668,8 @@ sw buf_parse_list_tag (s_buf *buf, s_tag *dest)
   buf_save_restore_rpos(buf, &save);
   if ((r = buf_parse_tag(buf, &tmp)) <= 0) {
     err_puts("buf_parse_list_tag: buf_parse_tag");
+    err_inspect_buf(buf);
+    err_write_1("\n");
     assert(! "buf_parse_list_tag: buf_parse_tag");
     if (! r)
       r = -1;
diff --git a/libkc3/str.c b/libkc3/str.c
index 9d87e22..b4a5705 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -1048,6 +1048,36 @@ sw str_rindex_character (const s_str *str, character c)
   return result;
 }
 
+s_list ** str_split (const s_str *str, const s_str *separator,
+                     s_list **dest)
+{
+  s_buf buf;
+  s_str   *t_str;
+  s_list **t;
+  s_list  *tmp;
+  buf_init_str_const(&buf, str);
+  tmp = NULL;
+  t = &tmp;
+  while (1) {
+    *t = list_new(NULL);
+    (*t)->tag.type = TAG_STR;
+    t_str = &(*t)->tag.data.str;
+    if (! buf_read_until_str_into_str(&buf, separator, t_str)) {
+      if (! buf_read_to_str(&buf, t_str))
+        goto clean;
+      if (! t_str->size)
+        *t = list_delete(*t);
+      break;
+    }
+    t = &(*t)->next.data.list;
+  }
+  *dest = tmp;
+  return dest;
+ clean:
+  list_delete_all(tmp);
+  return NULL;
+}
+
 bool * str_starts_with (const s_str *str, const s_str *start,
                         bool *dest)
 {
diff --git a/libkc3/str.h b/libkc3/str.h
index ca99123..4d23b5f 100644
--- a/libkc3/str.h
+++ b/libkc3/str.h
@@ -126,6 +126,8 @@ sw            str_peek_u32 (const s_str *str, u32 *dest);
 sw            str_peek_u64 (const s_str *str, u64 *dest);
 sw            str_position_1 (const s_str *str, const char *token);
 sw            str_rindex_character (const s_str *str, character c);
+s_list **     str_split (const s_str *str, const s_str *separator,
+                         s_list **dest);
 bool *        str_starts_with (const s_str *str, const s_str *start,
                                bool *dest);
 uw *          str_sw_pos_to_uw (sw pos, uw max_pos, uw *dest);