diff --git a/.ikc3_history b/.ikc3_history
index d6d4bd2..7922d2c 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,20 +1,3 @@
-List.reverse([1, 2, 3, 4])
-List.map([1, 2, 3, 4], fn (x) { x * 2 })
-List.has?([1, 2, 3, 4], 1)
-List.has?([1, 2, 3, 4], 0)
-quote if true do if true do %KC3.Operator{} end end
-quote if true do if true do %KC3.Operator{sym: :-} end end
-quote if true do if true do %KC3.Operator{sym: :-, symbol_value: void} end end
-quote if true do if true do %KC3.Operator{sym: :-, symbol_value: void} else 0 end else 1 end
-a = ?
-b = ?
-a = ? ; void
-Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { puts(fact.object); 1 })
-EKC3.html_escape("plop <1>")
-Facts.first_with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { fact.object })
-first_operator = Facts.first_with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { fact.object })
-first_operator
-List.append([1, 2, 3], 4)
HTTPd.routes
a = :dir
file = %{type: :dir}
@@ -97,3 +80,20 @@ List.first(Str.split((Str) HTTP.mime_type(File.ext("Plop.html")), "/"))
first(Str.split((Str) HTTP.mime_type(File.ext("Plop.html")), "/"))
(Sym) first(Str.split((Str) HTTP.mime_type(File.ext("Plop.html")), "/"))
SH.run("file -b ${SH.escape(path)}")
+size = 10
+if (size > 1024 * 1024 * 1024 * 1024) do
+if (size > 1024 * 1024 * 1024 * 1024) do
+ s = size * 10 / 1024 / 1024 / 1024 / 1024
+"#{s / 10}.#{s % 10}Tb"
+size = 100
+if (size > 1024) do
+s = size * 10 / 1024
+"#{s / 10}.#{s % 10}Kb"
+quote %
+10 % 3
+human_size(1024)
+human_size(1025)
+human_size(1024)
+human_size(2024024)
+human_size(100)
+Str.size("abc")
diff --git a/httpd/fx/app/views/fx_view.kc3 b/httpd/fx/app/views/fx_view.kc3
index 35fe815..f7bc787 100644
--- a/httpd/fx/app/views/fx_view.kc3
+++ b/httpd/fx/app/views/fx_view.kc3
@@ -28,11 +28,14 @@ defmodule FXView do
def render_properties = fn (properties) {
EKC3.render(properties_template)
}
-
+
def render_show_file_preview = fn (path, size) {
+ file_size = File.size(path)
mime = HTTP.mime_type(File.ext(path))
mime_first = (Sym) first(Str.split((Str) mime, "/"))
- if (mime_first == :image && File.size(path) > 11024024) do
+ if (mime_first == :image &&
+ size == :small &&
+ file_size > 11024024) do
preview = ""
else
file_path = "/file" + Str.slice(path, 4, -1)
@@ -52,13 +55,14 @@ defmodule FXView do
end
"""<pre class="#{size}">#{HTML.escape(file)}</pre>"""
else
- HTML.escape(mime)
+ HTML.escape(system(["file", "-b", path]))
end
end
end
end
end
- """<div class="#{size}">#{preview}<hr /></div>"""
+ """<span class="size">#{HTML.escape(human_size(file_size))}</span>
+ <div class="#{size}">#{preview}<hr /></div>"""
}
def render_show_file = fn (path, menu, file, properties) {
diff --git a/httpd/fx/static/_assets/app.js b/httpd/fx/static/_assets/app.js
index 7a0e5c9..e33e045 100644
--- a/httpd/fx/static/_assets/app.js
+++ b/httpd/fx/static/_assets/app.js
@@ -7395,8 +7395,7 @@
};
for (var _i = numberOfChecks; _i > 0; _i--) {
var _ret = _loop(_i);
- if (_ret === "break")
- break;
+ if (_ret === "break") break;
}
}
if (state.placement !== firstFittingPlacement) {
diff --git a/ikc3/.ikc3_history b/ikc3/.ikc3_history
index f0d64fa..030b287 100644
--- a/ikc3/.ikc3_history
+++ b/ikc3/.ikc3_history
@@ -1,14 +1,3 @@
-a = ?
-Facts.with_tags(Facts.env_facts(), KC3, :operator, a, fn (fact) { puts(a); 1 })
-to_lisp(quote a = ? <- 1 ; 2)
-to_lisp(quote a = 1 ; 2)
-to_lisp(quote a = ? <- 1 ; 2)
-q
-exit
-to_lisp(quote a = ? <- 1 ; 2)
-quote if true do if true do %KC3.Operator{} end end
-quote if true do if true do unquote(%KC3.Operator{}) end end
-quote if true do if true do %KC3.Operator{sym: :a} end end
to_lisp(quote a = ? <- 1 ; 2)
quote if true do if true do %KC3.Operator{symbol_value: void} end end
quote if true do if true do %KC3.Operator{sym: :-, symbol_value: void} end end
@@ -97,3 +86,14 @@ a = cow 1
a <- 2
a
system(["ls"])
+size = 10
+if (size > 1024) do
+s = size * 10 / 1024
+"#{s / 10}.#{s % 10}Kb"
+size = 10
+if (size > 1024) do
+s = size * 10 / 1024
+"#{s}"
+else
+"#{size}b"
+end
diff --git a/lib/kc3/0.1/file.kc3 b/lib/kc3/0.1/file.kc3
index b95dcff..ed83001 100644
--- a/lib/kc3/0.1/file.kc3
+++ b/lib/kc3/0.1/file.kc3
@@ -23,6 +23,11 @@ defmodule File do
def stat = cfn File.Stat "file_stat" (Str, Result)
+ def size = fn (path) {
+ st = stat(path)
+ st.st_size
+ }
+
def read = cfn Str "file_read" (Str, Result)
end
diff --git a/lib/kc3/0.1/kc3.facts b/lib/kc3/0.1/kc3.facts
index 9f206ea..114ce48 100644
--- a/lib/kc3/0.1/kc3.facts
+++ b/lib/kc3/0.1/kc3.facts
@@ -310,3 +310,27 @@ add {KC3, :symbol, KC3.fork}
replace {KC3.fork, :symbol_value, cfn S32 "fork" ()}
add {KC3, :symbol, KC3.system}
replace {KC3.system, :symbol_value, cfn Str "kc3_system" (List, Result)}
+add {KC3, :symbol, KC3.human_size}
+replace {KC3.human_size, :symbol_value, fn (size) {
+ if (size >= 1024 * 1024 * 1024 * 1024) do
+ s = size * 10 / 1024 / 1024 / 1024 / 1024
+ "#{s / 10}.#{s mod 10}Tb"
+ else
+ if (size >= 1024 * 1024 * 1024) do
+ s = size * 10 / 1024 / 1024 / 1024
+ "#{s / 10}.#{s mod 10}Gb"
+ else
+ if (size >= 1024 * 1024) do
+ s = size * 10 / 1024 / 1024
+ "#{s / 10}.#{s mod 10}Mb"
+ else
+ if (size >= 1024) do
+ s = size * 10 / 1024
+ "#{s / 10}.#{s mod 10}Kb"
+ else
+ "#{size}b"
+ end
+ end
+ end
+ end
+}}
diff --git a/lib/kc3/0.1/str.facts b/lib/kc3/0.1/str.facts
index deed849..d9ef3d2 100644
--- a/lib/kc3/0.1/str.facts
+++ b/lib/kc3/0.1/str.facts
@@ -32,3 +32,5 @@ replace {Str.subst, :symbol_value,
add {Str, :symbol, Str.split}
replace {Str.split, :symbol_value,
cfn List "str_split" (Str, Str, Result)}
+add {Str, :symbol, Str.size}
+replace {Str.size, :symbol_value, cfn Tag "str_size" (Str, Result)}
diff --git a/libkc3/str.c b/libkc3/str.c
index 66fa30b..e2853f5 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -1048,6 +1048,15 @@ sw str_rindex_character (const s_str *str, character c)
return result;
}
+s_tag * str_size (const s_str *str, s_tag *dest)
+{
+ s_tag tmp;
+ tag_init_uw(&tmp, str->size);
+ tag_integer_reduce(&tmp);
+ *dest = tmp;
+ return dest;
+}
+
s_list ** str_split (const s_str *str, const s_str *separator,
s_list **dest)
{
diff --git a/libkc3/str.h b/libkc3/str.h
index 4d23b5f..a5985f8 100644
--- a/libkc3/str.h
+++ b/libkc3/str.h
@@ -126,6 +126,7 @@ 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_tag * str_size (const s_str *str, s_tag *dest);
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,
diff --git a/libkc3/tag.c b/libkc3/tag.c
index b078dc6..5f4ea73 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -721,6 +721,11 @@ s_tag * tag_integer_reduce (s_tag *tag)
integer_reduce(&j, tag);
integer_clean(&j);
return tag;
+ case TAG_SW:
+ integer_init_sw(&j, tag->data.sw);
+ integer_reduce(&j, tag);
+ integer_clean(&j);
+ return tag;
case TAG_U8:
integer_init_u8(&j, tag->data.u8);
integer_reduce(&j, tag);
@@ -741,6 +746,11 @@ s_tag * tag_integer_reduce (s_tag *tag)
integer_reduce(&j, tag);
integer_clean(&j);
return tag;
+ case TAG_UW:
+ integer_init_uw(&j, tag->data.uw);
+ integer_reduce(&j, tag);
+ integer_clean(&j);
+ return tag;
default:
break;
}