Commit c72d18e7e8080ad060cbb7609eebf42b922945ab

Thomas de Grivel 2024-10-29T15:02:10

wip httpd

diff --git a/httpd/httpd.c b/httpd/httpd.c
index ff87be2..a36224a 100644
--- a/httpd/httpd.c
+++ b/httpd/httpd.c
@@ -33,6 +33,7 @@ int main (int argc, char **argv)
   char *p;
   s32 r = 1;
   s32 skip = 0;
+  s_str str;
   time_t t;
   s_tag tmp = {0};
   const struct tm *utc = NULL;
@@ -42,6 +43,22 @@ int main (int argc, char **argv)
     p = argv[0] + 1;
     while (*p) {
       switch (*p) {
+      case 'D':
+        if (argc <= skip || ! argv[skip]) {
+          err_puts("kc3_httpd: -D without an argument");
+          assert(! "kc3_httpd: -D without an argument");
+          kc3_clean(NULL);
+          return 1;
+        }
+        str_init_1(&str, NULL, argv[1]);
+        if (! facts_open_file(&g_kc3_env.facts, &str)) {
+          err_puts("kc3_httpd: -D: facts_open_file");
+          assert(! "kc3_httpd: -D: facts_open_file");
+          kc3_clean(NULL);
+          return 1;
+        }
+        skip++;
+        break;
       case 'd':
         daemonize = false;
         break;
diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index 94900c9..781930e 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -3393,6 +3393,7 @@ sw buf_inspect_struct_type (s_buf *buf, const s_struct_type *st)
 {
   s_array offset_array;
   uw offset_array_dimension;
+  s_pretty_save pretty_save;
   sw r;
   sw result = 0;
   assert(buf);
@@ -3400,19 +3401,24 @@ sw buf_inspect_struct_type (s_buf *buf, const s_struct_type *st)
   assert(sym_is_module(st->module));
   assert(st->offset);
   assert(st->size);
-  if ((r = buf_write_1(buf, "%StructType{module: ")) < 0)
+  if ((r = buf_write_1(buf, "%StructType{")) < 0)
+    return r;
+  result += r;
+  pretty_save_init(&pretty_save, &buf->pretty);
+  pretty_indent_from_column(&buf->pretty, 0);
+  if ((r = buf_write_1(buf, "module: ")) < 0)
     return r;
   result += r;
   if ((r = buf_inspect_sym(buf, &st->module)) < 0)
     return r;
   result += r;
-  if ((r = buf_write_1(buf, ", map: ")) < 0)
+  if ((r = buf_write_1(buf, ",\nmap: ")) < 0)
     return r;
   result += r;
   if ((r = buf_inspect_map(buf, &st->map)) < 0)
     return r;
   result += r;
-  if ((r = buf_write_1(buf, ", offset: ")) < 0)
+  if ((r = buf_write_1(buf, ",\noffset: ")) < 0)
     return r;
   result += r;
   offset_array_dimension = st->map.count;
@@ -3424,7 +3430,7 @@ sw buf_inspect_struct_type (s_buf *buf, const s_struct_type *st)
   }
   result += r;
   array_clean(&offset_array);
-  if ((r = buf_write_1(buf, ", size: ")) < 0)
+  if ((r = buf_write_1(buf, ",\nsize: ")) < 0)
     return r;
   result += r;
   if ((r = buf_inspect_uw(buf, &st->size)) < 0)
@@ -3433,6 +3439,7 @@ sw buf_inspect_struct_type (s_buf *buf, const s_struct_type *st)
   if ((r = buf_write_1(buf, "}")) < 0)
     return r;
   result += r;
+  pretty_save_clean(&pretty_save, &buf->pretty);
   return result;
 }
 
diff --git a/libkc3/facts.c b/libkc3/facts.c
index 509e14a..e6e2741 100644
--- a/libkc3/facts.c
+++ b/libkc3/facts.c
@@ -651,15 +651,6 @@ sw facts_open_file_create (s_facts *facts, const s_str *path)
   fp = file_open(path->ptr.pchar, "wb");
   if (! fp)
     return -1;
-  if (facts_count(facts)) {
-    /* TODO: clear facts
-       facts_close(facts);
-       facts_remove_all(facts);
-    */
-    err_puts("facts_open_file: not implemented");
-    assert(! "facts_open_file: not implemented");
-    return -1;
-  }
   out = buf_new_alloc(BUF_SIZE);
   buf_file_open_w(out, fp);
   if ((r = facts_dump(facts, out)) < 0)
diff --git a/libkc3/fn.c b/libkc3/fn.c
index 1d27b84..ce3c8af 100644
--- a/libkc3/fn.c
+++ b/libkc3/fn.c
@@ -122,6 +122,7 @@ s_fn * fn_init_copy (s_fn *fn, const s_fn *src)
     fn_clean(&tmp);
     return NULL;
   }
+  tmp.ident = src->ident;
   *fn = tmp;
   return fn;
 }