started docs
This commit is contained in:
parent
4811047480
commit
2c2225c76f
Binary file not shown.
87
doc/index.uce
Normal file
87
doc/index.uce
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
|
||||
|
||||
|
||||
RENDER()
|
||||
{
|
||||
|
||||
String page = first(context->get["p"], "index");
|
||||
|
||||
<><html>
|
||||
<header>
|
||||
<link rel="stylesheet" href='style.css'></link>
|
||||
</header>
|
||||
<body>
|
||||
<h1>
|
||||
<a href="index.uce">UCE Docs</a>:
|
||||
<?= page ?>
|
||||
</h1>
|
||||
<?
|
||||
|
||||
if(page == "index")
|
||||
{
|
||||
for(auto file_name : ls("pages/"))
|
||||
{
|
||||
String ft = nibble(file_name, ".");
|
||||
?>
|
||||
<div><a href="?p=<?= ft ?>"><?= ft ?></a></div>
|
||||
<?
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto doc = split(file_get_contents("pages/"+page+".txt"), "\n");
|
||||
String layout_class = "text";
|
||||
?><div><?
|
||||
for(auto s : doc)
|
||||
{
|
||||
if(s == "")
|
||||
{
|
||||
|
||||
}
|
||||
else if(s.substr(0, 1) == ":")
|
||||
{
|
||||
layout_class = s.substr(1);
|
||||
?></div><?
|
||||
if(layout_class == "params")
|
||||
{
|
||||
?><h3>Parameters</h3><?
|
||||
}
|
||||
else if(layout_class == "sig")
|
||||
{
|
||||
?><h3>Signature</h3><?
|
||||
}
|
||||
else if(layout_class == "desc")
|
||||
{
|
||||
?><h3>Description</h3><?
|
||||
}
|
||||
else
|
||||
{
|
||||
?><h3><?= layout_class ?></h3><?
|
||||
}
|
||||
?><div class="<?= layout_class ?>"><?
|
||||
}
|
||||
else
|
||||
{
|
||||
if(s.substr(0, 1) == "-")
|
||||
{
|
||||
nibble(s, "-");
|
||||
?><li><?= (s) ?></li><?
|
||||
}
|
||||
else if(layout_class == "params")
|
||||
{
|
||||
?><div><b><?= trim(nibble(s, ":")) ?></b> : <?= trim(s) ?></div><?
|
||||
}
|
||||
else
|
||||
{
|
||||
?><div><?= (s) ?></div><?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html></>
|
||||
|
||||
}
|
||||
57
doc/pages/context.txt
Normal file
57
doc/pages/context.txt
Normal file
@ -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<UploadedFile> uploaded_files;
|
||||
|
||||
StringMap header;
|
||||
StringList set_cookies;
|
||||
|
||||
u64 random_seed;
|
||||
u64 random_index;
|
||||
|
||||
MemoryArena* mem;
|
||||
|
||||
String in;
|
||||
std::vector<std::ostringstream*> 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
|
||||
|
||||
|
||||
|
||||
11
doc/pages/draw_float.txt
Normal file
11
doc/pages/draw_float.txt
Normal file
@ -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.
|
||||
|
||||
11
doc/pages/draw_int.txt
Normal file
11
doc/pages/draw_int.txt
Normal file
@ -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.
|
||||
|
||||
11
doc/pages/filter.txt
Normal file
11
doc/pages/filter.txt
Normal file
@ -0,0 +1,11 @@
|
||||
:sig
|
||||
StringList filter(StringList items, function<bool (String)> f)
|
||||
vector<T> filter(vector<T> items, function<bool (T)> 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.
|
||||
10
doc/pages/first.txt
Normal file
10
doc/pages/first.txt
Normal file
@ -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.
|
||||
|
||||
13
doc/pages/generate_float.txt
Normal file
13
doc/pages/generate_float.txt
Normal file
@ -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.
|
||||
|
||||
13
doc/pages/generate_int.txt
Normal file
13
doc/pages/generate_int.txt
Normal file
@ -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.
|
||||
|
||||
13
doc/pages/html_escape.txt
Normal file
13
doc/pages/html_escape.txt
Normal file
@ -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;
|
||||
- > → >
|
||||
- " → "
|
||||
11
doc/pages/intval.txt
Normal file
11
doc/pages/intval.txt
Normal file
@ -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.
|
||||
|
||||
11
doc/pages/join.txt
Normal file
11
doc/pages/join.txt
Normal file
@ -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.
|
||||
|
||||
10
doc/pages/json_decode.txt
Normal file
10
doc/pages/json_decode.txt
Normal file
@ -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.
|
||||
|
||||
10
doc/pages/json_encode.txt
Normal file
10
doc/pages/json_encode.txt
Normal file
@ -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.
|
||||
|
||||
12
doc/pages/nibble.txt
Normal file
12
doc/pages/nibble.txt
Normal file
@ -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.
|
||||
|
||||
|
||||
10
doc/pages/noise01.txt
Normal file
10
doc/pages/noise01.txt
Normal file
@ -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.
|
||||
10
doc/pages/noise32.txt
Normal file
10
doc/pages/noise32.txt
Normal file
@ -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.
|
||||
10
doc/pages/noise64.txt
Normal file
10
doc/pages/noise64.txt
Normal file
@ -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.
|
||||
8
doc/pages/ob_clear.txt
Normal file
8
doc/pages/ob_clear.txt
Normal file
@ -0,0 +1,8 @@
|
||||
:sig
|
||||
void ob_clear()
|
||||
|
||||
:params
|
||||
-
|
||||
|
||||
:desc
|
||||
Discard the current output buffer.
|
||||
8
doc/pages/ob_get.txt
Normal file
8
doc/pages/ob_get.txt
Normal file
@ -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.
|
||||
8
doc/pages/ob_get_clear.txt
Normal file
8
doc/pages/ob_get_clear.txt
Normal file
@ -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.
|
||||
9
doc/pages/ob_start.txt
Normal file
9
doc/pages/ob_start.txt
Normal file
@ -0,0 +1,9 @@
|
||||
:sig
|
||||
void ob_start()
|
||||
|
||||
:params
|
||||
-
|
||||
|
||||
:desc
|
||||
Starts a new output buffer. All subsequent output will be directed into this buffer.
|
||||
|
||||
11
doc/pages/split.txt
Normal file
11
doc/pages/split.txt
Normal file
@ -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'.
|
||||
|
||||
10
doc/pages/trim.txt
Normal file
10
doc/pages/trim.txt
Normal file
@ -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.
|
||||
|
||||
12
doc/pages/var_dump.txt
Normal file
12
doc/pages/var_dump.txt
Normal file
@ -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.
|
||||
|
||||
98
doc/style.css
Normal file
98
doc/style.css
Normal file
@ -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;
|
||||
}
|
||||
@ -85,17 +85,6 @@ String join(StringList l, String delim)
|
||||
return(result);
|
||||
}
|
||||
|
||||
StringList filter(StringList items, std::function<bool (String)> 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;
|
||||
|
||||
@ -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<bool (String)> f);
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> filter(std::vector<T> items, std::function<bool (T)> f)
|
||||
{
|
||||
std::vector<T> new_items;
|
||||
for(auto item : items)
|
||||
{
|
||||
if(f(item))
|
||||
new_items.push_back(item);
|
||||
}
|
||||
return(new_items);
|
||||
}
|
||||
|
||||
template <class ...Args>
|
||||
String first(Args... args)
|
||||
{
|
||||
std::vector<String> 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");
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -6,4 +6,4 @@ By Steve Reid <steve@edmweb.com>
|
||||
*/
|
||||
|
||||
|
||||
String hash_sha1(String s, bool as_binary = false);
|
||||
String sha1(String s, bool as_binary = false);
|
||||
|
||||
@ -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"));
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -195,6 +195,7 @@ struct ServerState {
|
||||
|
||||
std::map<String, SharedUnit*> units;
|
||||
ServerSettings config;
|
||||
u32 request_count = 0;
|
||||
|
||||
};
|
||||
|
||||
@ -289,3 +290,4 @@ void print(Ts... args)
|
||||
{
|
||||
((*context->ob << args), ...);
|
||||
}
|
||||
|
||||
|
||||
@ -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<u64*>(&request.stats.time_start));
|
||||
request.ob_start();
|
||||
|
||||
@ -12,6 +12,7 @@ RENDER()
|
||||
Index
|
||||
</h1>
|
||||
<ul>
|
||||
<li><a href="../doc/index.uce">Help Docs</a></li>
|
||||
<li><a href="hello.uce">Hello</a></li>
|
||||
<li><a href="post.uce">Form Post</a></li>
|
||||
<li><a href="post-multipart.uce">Form Multipart Post</a></li>
|
||||
@ -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");
|
||||
?></pre>
|
||||
<pre><?= (var_dump(p)) ?></pre>
|
||||
<div><?
|
||||
|
||||
@ -11,8 +11,6 @@ RENDER()
|
||||
</h1>
|
||||
</>
|
||||
|
||||
|
||||
|
||||
<>
|
||||
Generate Some Numbers
|
||||
<pre><?
|
||||
@ -41,7 +39,7 @@ RENDER()
|
||||
?></pre>
|
||||
|
||||
<div>
|
||||
Sha1 of '1234': <?= hash_sha1("1234") ?>
|
||||
Sha1 of '1234': <?= sha1("1234") ?>
|
||||
</div>
|
||||
|
||||
Params
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user