diff --git a/bin/uce_fastcgi.debug.linux.bin b/bin/uce_fastcgi.debug.linux.bin
index 8ac7e49..6dc25d1 100755
Binary files a/bin/uce_fastcgi.debug.linux.bin and b/bin/uce_fastcgi.debug.linux.bin differ
diff --git a/doc/index.uce b/doc/index.uce
new file mode 100644
index 0000000..892af4e
--- /dev/null
+++ b/doc/index.uce
@@ -0,0 +1,87 @@
+
+
+
+
+RENDER()
+{
+
+ String page = first(context->get["p"], "index");
+
+ <>
+
+
+
+ UCE Docs:
+ = page ?>
+
+
+
+ if(page == "index")
+ {
+ for(auto file_name : ls("pages/"))
+ {
+ String ft = nibble(file_name, ".");
+ ?>
+
+
+ }
+ }
+ else
+ {
+ auto doc = split(file_get_contents("pages/"+page+".txt"), "\n");
+ String layout_class = "text";
+ ?>
+ for(auto s : doc)
+ {
+ if(s == "")
+ {
+
+ }
+ else if(s.substr(0, 1) == ":")
+ {
+ layout_class = s.substr(1);
+ ?>
+ if(layout_class == "params")
+ {
+ ?>Parameters
+ }
+ else if(layout_class == "sig")
+ {
+ ?>Signature
+ }
+ else if(layout_class == "desc")
+ {
+ ?>Description
+ }
+ else
+ {
+ ?>= layout_class ?>
+ }
+ ?>
+ }
+ else
+ {
+ if(s.substr(0, 1) == "-")
+ {
+ nibble(s, "-");
+ ?>
= (s) ?>
+ }
+ else if(layout_class == "params")
+ {
+ ?>
= trim(nibble(s, ":")) ?> : = trim(s) ?>
+ }
+ else
+ {
+ ?>
= (s) ?>
+ }
+ }
+ }
+ }
+
+ ?>
+
+ >
+
+}
diff --git a/doc/pages/context.txt b/doc/pages/context.txt
new file mode 100644
index 0000000..881801b
--- /dev/null
+++ b/doc/pages/context.txt
@@ -0,0 +1,57 @@
+:sig
+Request* context;
+//
+struct Request {
+
+ ServerState* server;
+
+ StringMap params;
+ StringMap get;
+ StringMap post;
+ StringMap cookies;
+ StringMap session;
+
+ DTree var;
+
+ String session_id = "";
+ String session_name = "";
+ std::vector
uploaded_files;
+
+ StringMap header;
+ StringList set_cookies;
+
+ u64 random_seed;
+ u64 random_index;
+
+ MemoryArena* mem;
+
+ String in;
+ std::vector ob_stack;
+ std::ostringstream* ob;
+ String out;
+ String err;
+
+ bool is_finished = false;
+
+ struct Flags {
+ bool log_request = true;
+ } flags;
+
+ struct Stats {
+ u32 bytes_written;
+ f64 time_init;
+ f64 time_start;
+ f64 time_end;
+ } stats;
+
+ void invoke(String file_name);
+ void invoke(String file_name, DTree& call_param);
+
+ void ob_start();
+
+};
+
+:desc
+
+
+
diff --git a/doc/pages/draw_float.txt b/doc/pages/draw_float.txt
new file mode 100644
index 0000000..dfd240b
--- /dev/null
+++ b/doc/pages/draw_float.txt
@@ -0,0 +1,11 @@
+:sig
+f64 draw_float(f64 from, f64 to)
+
+:params
+from : minimum value
+to : maximum value
+return value : a noise value between 'from' and 'to'
+
+:desc
+This function works exactly like generate_float(), but context->random_index is used for the 'index' value and context->random_seed is used for the seed. After this function has been called, the context->random_index is increased by one. At the start of every request, context->random_seed is automatically populated with a new seed value.
+
diff --git a/doc/pages/draw_int.txt b/doc/pages/draw_int.txt
new file mode 100644
index 0000000..4a60084
--- /dev/null
+++ b/doc/pages/draw_int.txt
@@ -0,0 +1,11 @@
+:sig
+u64 draw_int(u64 from, u64 to)
+
+:params
+from : minimum value
+to : maximum value
+return value : a noise value between 'from' and 'to'
+
+:desc
+This function works exactly like generate_int(), but context->random_index is used for the 'index' value and context->random_seed is used for the seed. After this function has been called, the context->random_index is increased by one. At the start of every request, context->random_seed is automatically populated with a new seed value.
+
diff --git a/doc/pages/filter.txt b/doc/pages/filter.txt
new file mode 100644
index 0000000..fb2873b
--- /dev/null
+++ b/doc/pages/filter.txt
@@ -0,0 +1,11 @@
+:sig
+StringList filter(StringList items, function f)
+vector filter(vector items, function f)
+
+:params
+items : list of items to be filtered
+f : a function that decides which items should be in the new list
+return value : a new list
+
+:desc
+Returns a list containing the members of 'items' for which 'f' returned boolean true.
diff --git a/doc/pages/first.txt b/doc/pages/first.txt
new file mode 100644
index 0000000..731a094
--- /dev/null
+++ b/doc/pages/first.txt
@@ -0,0 +1,10 @@
+:sig
+String first(String... args)
+
+:params
+args : a variable number of String arguments
+return value : first of the 'args' that was not empty.
+
+:desc
+Given a variable number of String parameters, the first() function returns the first of these parameters that was not empty. Leading and trailing whitespace characters are not considered, resulting in a string that contains only whitespace characters being considered empty.
+
diff --git a/doc/pages/generate_float.txt b/doc/pages/generate_float.txt
new file mode 100644
index 0000000..aff7df3
--- /dev/null
+++ b/doc/pages/generate_float.txt
@@ -0,0 +1,13 @@
+:sig
+f64 generate_float(f64 from, f64 to, u64 index, u64 seed = 0)
+
+:params
+from : minimum result
+to : maximum result
+index : index position to generate number from
+seed : seed position to generate number from (defaults to 0)
+return value : noise value
+
+:desc
+Generates a noise value between 'from' and 'to', given the 'index' and 'seed' numbers.
+
diff --git a/doc/pages/generate_int.txt b/doc/pages/generate_int.txt
new file mode 100644
index 0000000..1e179ab
--- /dev/null
+++ b/doc/pages/generate_int.txt
@@ -0,0 +1,13 @@
+:sig
+u64 generate_int(u64 from, u64 to, u64 index, u64 seed = 0)
+
+:params
+from : minimum result
+to : maximum result
+index : index position to generate number from
+seed : seed position to generate number from (defaults to 0)
+return value : noise value
+
+:desc
+Generates a noise value between 'from' and 'to', given the 'index' and 'seed' numbers.
+
diff --git a/doc/pages/html_escape.txt b/doc/pages/html_escape.txt
new file mode 100644
index 0000000..802d86a
--- /dev/null
+++ b/doc/pages/html_escape.txt
@@ -0,0 +1,13 @@
+:sig
+String html_escape(String s)
+
+:params
+s : string to be escaped
+return value : an HTML-safe escaped version of 's'
+
+:desc
+Returns a version of the input string where the following characters have been replace by HTML entities:
+- & → &
+- < → lt;
+- > → >
+- " → "
diff --git a/doc/pages/intval.txt b/doc/pages/intval.txt
new file mode 100644
index 0000000..110cc3a
--- /dev/null
+++ b/doc/pages/intval.txt
@@ -0,0 +1,11 @@
+:sig
+u64 int_val(String s, u32 base = 10)
+
+:params
+s : string to be converted
+base : number system base (default 10)
+return value : a u64 containing the number (0 if no number could be identified).
+
+:desc
+Extracts an integer from a String.
+
diff --git a/doc/pages/join.txt b/doc/pages/join.txt
new file mode 100644
index 0000000..f21e8b1
--- /dev/null
+++ b/doc/pages/join.txt
@@ -0,0 +1,11 @@
+:sig
+String join(StringList l, String delim = "\n")
+
+:params
+l : list of strings to be joined
+delim : delimiter (defaults to newline character)
+return value : a string containing items joined by 'delim'
+
+:desc
+Joins the items contained in 'l' into a single String.
+
diff --git a/doc/pages/json_decode.txt b/doc/pages/json_decode.txt
new file mode 100644
index 0000000..5b5f86f
--- /dev/null
+++ b/doc/pages/json_decode.txt
@@ -0,0 +1,10 @@
+:sig
+DTree json_decode(String s)
+
+:params
+s : string containing JSON data
+return value : a DTree object containing the deserialized JSON data
+
+:desc
+Deserializes 's' into a DTree structure.
+
diff --git a/doc/pages/json_encode.txt b/doc/pages/json_encode.txt
new file mode 100644
index 0000000..4d5e8b9
--- /dev/null
+++ b/doc/pages/json_encode.txt
@@ -0,0 +1,10 @@
+:sig
+String json_encode(DTree t)
+
+:params
+t : DTree object to be serialized
+return value : string containing the JSON result
+
+:desc
+Serializes a DTree structure 't' into a String in JSON notation.
+
diff --git a/doc/pages/nibble.txt b/doc/pages/nibble.txt
new file mode 100644
index 0000000..30e1064
--- /dev/null
+++ b/doc/pages/nibble.txt
@@ -0,0 +1,12 @@
+:sig
+String nibble(String& haystack, String delim)
+
+:params
+haystack : string to be nibbled at
+delim : delimiter
+return value : string before first occurrence of 'delim'
+
+:desc
+Returns the part of 'haystack' before the first occurrence of 'delim', removing the corresponding part from 'haystack' (including 'delim'). If the substring 'delim' does not occurr in 'haystack', the entire string is returned and 'haystack' is set to an empty string.
+
+
diff --git a/doc/pages/noise01.txt b/doc/pages/noise01.txt
new file mode 100644
index 0000000..487e9e6
--- /dev/null
+++ b/doc/pages/noise01.txt
@@ -0,0 +1,10 @@
+:sig
+u32 noise01(u64 index, u64 seed = 0)
+
+:params
+index : index position
+seed : seed set (defaults to 0)
+return value : a noise value from 0 to 1
+
+:desc
+Generates a noise value in the range from 0 to 1 for the given 'index' and 'seed' values.
diff --git a/doc/pages/noise32.txt b/doc/pages/noise32.txt
new file mode 100644
index 0000000..72fd746
--- /dev/null
+++ b/doc/pages/noise32.txt
@@ -0,0 +1,10 @@
+:sig
+u32 noise32(u32 index, u32 seed = 0)
+
+:params
+index : index position
+seed : seed set (defaults to 0)
+return value : a noise value given the 'index' and 'seed' values.
+
+:desc
+Generates a noise value for the given 'index' and 'seed' values.
diff --git a/doc/pages/noise64.txt b/doc/pages/noise64.txt
new file mode 100644
index 0000000..dea885e
--- /dev/null
+++ b/doc/pages/noise64.txt
@@ -0,0 +1,10 @@
+:sig
+u32 noise64(u64 index, u64 seed = 0)
+
+:params
+index : index position
+seed : seed set (defaults to 0)
+return value : a noise value given the 'index' and 'seed' values.
+
+:desc
+Generates a noise value for the given 'index' and 'seed' values.
diff --git a/doc/pages/ob_clear.txt b/doc/pages/ob_clear.txt
new file mode 100644
index 0000000..8401478
--- /dev/null
+++ b/doc/pages/ob_clear.txt
@@ -0,0 +1,8 @@
+:sig
+void ob_clear()
+
+:params
+-
+
+:desc
+Discard the current output buffer.
diff --git a/doc/pages/ob_get.txt b/doc/pages/ob_get.txt
new file mode 100644
index 0000000..b159e87
--- /dev/null
+++ b/doc/pages/ob_get.txt
@@ -0,0 +1,8 @@
+:sig
+String ob_get()
+
+:params
+return value : content of the current output buffer
+
+:desc
+Returns the contents of the current output buffer.
diff --git a/doc/pages/ob_get_clear.txt b/doc/pages/ob_get_clear.txt
new file mode 100644
index 0000000..9a72953
--- /dev/null
+++ b/doc/pages/ob_get_clear.txt
@@ -0,0 +1,8 @@
+:sig
+String ob_get_clear()
+
+:params
+return value : content of the current output buffer
+
+:desc
+Returns the contents of the current output buffer and then discards the buffer.
diff --git a/doc/pages/ob_start.txt b/doc/pages/ob_start.txt
new file mode 100644
index 0000000..473d44d
--- /dev/null
+++ b/doc/pages/ob_start.txt
@@ -0,0 +1,9 @@
+:sig
+void ob_start()
+
+:params
+-
+
+:desc
+Starts a new output buffer. All subsequent output will be directed into this buffer.
+
diff --git a/doc/pages/split.txt b/doc/pages/split.txt
new file mode 100644
index 0000000..3c918d8
--- /dev/null
+++ b/doc/pages/split.txt
@@ -0,0 +1,11 @@
+:sig
+StringList split(String str, String delim = "\n")
+
+:params
+str : string to be split
+delim : delimiter (defaults to newline character)
+return value : a list of strings
+
+:desc
+Splits 'str' into multiple strings based on the given delimiter 'delim'.
+
diff --git a/doc/pages/trim.txt b/doc/pages/trim.txt
new file mode 100644
index 0000000..0612b43
--- /dev/null
+++ b/doc/pages/trim.txt
@@ -0,0 +1,10 @@
+:sig
+String trim(String raw)
+
+:params
+raw : string to be trimmed
+return value : string with leading and trailing whitespace characters removed
+
+:desc
+Returns a string where leading an trailing whitespace characters have been trimmed off.
+
diff --git a/doc/pages/var_dump.txt b/doc/pages/var_dump.txt
new file mode 100644
index 0000000..b469a7d
--- /dev/null
+++ b/doc/pages/var_dump.txt
@@ -0,0 +1,12 @@
+:sig
+String var_dump(StringMap t, String prefix = "", String postfix = "\n")
+String var_dump(StringList t, String prefix = "", String postfix = "\n")
+String var_dump(DTree t, String prefix = "", String postfix = "\n")
+
+:params
+t : object to be dumped into a string
+return value : string containing a human-friendly representation of 't'
+
+:desc
+Returns a string representation of 't' intended for debugging.
+
diff --git a/doc/style.css b/doc/style.css
new file mode 100644
index 0000000..c586c2c
--- /dev/null
+++ b/doc/style.css
@@ -0,0 +1,98 @@
+* {
+ font-family: inherit;
+ font-size: inherit;
+ box-sizing: inherit;
+ color: inherit;
+ line-height: inherit;
+}
+
+body {
+ max-width: 1024px;
+ margin: 0;
+ margin-left: auto;
+ margin-right: auto;
+ padding-left: 16px;
+ padding-right: 16px;
+ font-family: Tahoma, Helvetica, Arial;
+ font-size: 1.2em;
+ box-sizing: border-box;
+ background: #24f;
+ color: white;
+ line-height: 150%;
+}
+
+a {
+ color: yellow;
+}
+
+h1 {
+ font-size: 200%;
+ padding-top: 16px;
+ padding-bottom: 16px;
+ border-bottom: 8px solid rgba(0,0,0,0.5);
+ margin: 0;
+ margin-bottom: 8px;
+}
+
+form > div, label {
+ display: block;
+ padding-top: 8px;
+ padding-bottom: 8px;
+}
+
+input, textarea {
+ background: rgba(0,0,0,0.2);
+ border: 2px solid rgba(255,255,255,0.2);
+}
+
+input[type=submit], button {
+ padding: 8px;
+ cursor: pointer;
+}
+
+input[type=submit]:hover, button:hover {
+ color: yellow;
+ background: rgba(0,0,0,0.5);
+}
+
+input[type=text], textarea {
+ padding: 8px;
+ width: 100%;
+}
+
+input[type=text]:hover, textarea:hover {
+ background: rgba(0,0,0,0.25);
+}
+
+textarea {
+ height: 20%;
+}
+
+pre {
+ height: 20%;
+ overflow: auto;
+ padding: 8px;
+ border: 2px solid rgba(0,0,0,0.2);
+ background: rgba(100,100,100,0.15);
+ font-family: monospace;
+ white-space: pre-wrap;
+}
+
+h3 {
+
+}
+
+.sig {
+ font-family: monospace;
+ white-space: pre;
+ font-size: 120%;
+}
+
+.params {
+
+}
+
+.params b {
+ font-family: monospace;
+ white-space: pre;
+}
diff --git a/src/lib/functionlib.cpp b/src/lib/functionlib.cpp
index 90deed0..6570f1e 100644
--- a/src/lib/functionlib.cpp
+++ b/src/lib/functionlib.cpp
@@ -85,17 +85,6 @@ String join(StringList l, String delim)
return(result);
}
-StringList filter(StringList items, std::function f)
-{
- StringList new_items;
- for(auto item : items)
- {
- if(f(item))
- new_items.push_back(item);
- }
- return(new_items);
-}
-
String html_escape(String s)
{
String result;
diff --git a/src/lib/functionlib.h b/src/lib/functionlib.h
index 1557e36..7bd6a78 100644
--- a/src/lib/functionlib.h
+++ b/src/lib/functionlib.h
@@ -8,18 +8,34 @@ StringList split(String str, String delim = "\n");
String join(StringList l, String delim = "\n");
String nibble(String& haystack, String delim);
void json_consume_space(String s, u32& i);
-StringList filter(StringList items, std::function f);
+
+template
+std::vector filter(std::vector items, std::function f)
+{
+ std::vector new_items;
+ for(auto item : items)
+ {
+ if(f(item))
+ new_items.push_back(item);
+ }
+ return(new_items);
+}
+
+template
+String first(Args... args)
+{
+ std::vector vec = {args...};
+ for(auto s : vec)
+ if(trim(s) != "")
+ return(s);
+ return("");
+}
String html_escape(String s);
String html_escape(u64 a);
String html_escape(f64 a);
String json_encode(DTree t);
-String json_decode_String(String s, u32& i, char termination_char = '"');
-String json_decode_keyword(String s, u32& i);
-String json_decode_number(String s, u32& i);
-DTree json_decode_value(String s, u32& i);
-DTree json_decode_map(String s, u32& i);
DTree json_decode(String s);
String var_dump(StringMap map, String prefix = "", String postfix = "\n");
diff --git a/src/lib/hash.cpp b/src/lib/hash.cpp
index c992c65..298f52b 100644
--- a/src/lib/hash.cpp
+++ b/src/lib/hash.cpp
@@ -257,7 +257,7 @@ unsigned char c;
/* ================ end of sha1.c ================ */
String
-hash_sha1(String s, bool as_binary)
+sha1(String s, bool as_binary)
{
unsigned char v[20];
SHA1_CTX ctx;
diff --git a/src/lib/hash.h b/src/lib/hash.h
index 7608dd8..23b0067 100644
--- a/src/lib/hash.h
+++ b/src/lib/hash.h
@@ -6,4 +6,4 @@ By Steve Reid
*/
-String hash_sha1(String s, bool as_binary = false);
+String sha1(String s, bool as_binary = false);
diff --git a/src/lib/sys.cpp b/src/lib/sys.cpp
index e374d82..f7b84de 100644
--- a/src/lib/sys.cpp
+++ b/src/lib/sys.cpp
@@ -438,4 +438,7 @@ void on_child_exit(int sig)
}
}
-
+StringList ls(String dir)
+{
+ return(split(trim(shell_exec("ls -1 "+shell_escape(dir))), "\n"));
+}
diff --git a/src/lib/sys.h b/src/lib/sys.h
index 651a9ca..ee9a022 100644
--- a/src/lib/sys.h
+++ b/src/lib/sys.h
@@ -13,7 +13,7 @@ void set_cwd(String path);
time_t file_mtime(String file_name);
void unlink(String file_name);
String expand_path(String path);
-void on_segfault(int sig);
+StringList ls(String dir);
f64 microtime();
u64 time();
@@ -38,3 +38,4 @@ StringMap memcache_get_multiple(u64 connection, StringList keys);
pid_t parent_pid = 0;
pid_t my_pid = 0;
+void on_segfault(int sig);
diff --git a/src/lib/types.h b/src/lib/types.h
index 2a792e3..9878a50 100644
--- a/src/lib/types.h
+++ b/src/lib/types.h
@@ -195,6 +195,7 @@ struct ServerState {
std::map units;
ServerSettings config;
+ u32 request_count = 0;
};
@@ -289,3 +290,4 @@ void print(Ts... args)
{
((*context->ob << args), ...);
}
+
diff --git a/src/linux_fastcgi.cpp b/src/linux_fastcgi.cpp
index db04823..cfa632e 100644
--- a/src/linux_fastcgi.cpp
+++ b/src/linux_fastcgi.cpp
@@ -41,10 +41,11 @@ int handle_complete(FastCGIRequest& request) {
// printf("(i) request handle\n");
context = &request;
+ server_state.request_count += 1;
request.server = &server_state;
request.stats.time_start = microtime();
request.header["Content-Type"] = context->server->config.CONTENT_TYPE;
- request.get = parse_query(request.params["QUERY_String"]);
+ request.get = parse_query(request.params["QUERY_STRING"]);
request.random_index = 0;
request.random_seed = noise64(*reinterpret_cast(&request.stats.time_start));
request.ob_start();
diff --git a/test/index.uce b/test/index.uce
index b229de8..18b1a9b 100644
--- a/test/index.uce
+++ b/test/index.uce
@@ -12,6 +12,7 @@ RENDER()
Index
+ - Help Docs
- Hello
- Form Post
- Form Multipart Post
@@ -30,6 +31,7 @@ RENDER()
print("Worker PID: ", my_pid, "\n");
print("Parent PID: ", parent_pid, " \n");
print("Output buffer size: ", context->ob->str().length(), " \n");
+ print("Request #", context->server->request_count, "\n");
?>
= (var_dump(p)) ?>
diff --git a/test/random.uce b/test/random.uce
index 994538d..ea92559 100644
--- a/test/random.uce
+++ b/test/random.uce
@@ -11,8 +11,6 @@ RENDER()
>
-
-
<>
Generate Some Numbers
@@ -41,7 +39,7 @@ RENDER()
?>
- Sha1 of '1234': = hash_sha1("1234") ?>
+ Sha1 of '1234': = sha1("1234") ?>
Params