Indenting of examples
@@ -66,7 +66,7 @@ char buf[256];
ssize_t sz = mrecv(s, buf, sizeof(buf), -1);
s = crlf_detach(s, -1);
tcp_close(s);
-`
+ `,
}
http_protocol = {
@@ -938,6 +938,29 @@ for(i = 0; i != 1000000; ++i) {
},
]
+// Trims whitespeace around the rectangular area of text.
+function trimrect(t) {
+ // Trim empty lines at the top and the bottom.
+ var lns = t.split("\n")
+ var lines = []
+ for(var i = 0; i < lns.length; i++) {
+ if(lns[i].trim().length > 0) lines.push(lns[i])
+ }
+ // Determine minimal left indent.
+ var indent = -1
+ for(var i = 0; i < lines.length; i++) {
+ var n = lines[i].length - lines[i].trimLeft().length
+ if(n < indent || indent == -1) indent = n
+ }
+ // Trim the whitespace from the left and the right.
+ lns = []
+ for(var i = 0; i < lines.length; i++) {
+ lns.push(lines[i].substr(indent).trimRight())
+ }
+ return lns.join("\n")
+}
+
+// Generate man page for one function.
function generate_man_page(fx, mem) {
var t = "";
@@ -1107,7 +1130,7 @@ The function returns **EINVAL** error in case the list is malformed or if it con
t += "# EXAMPLE\n\n"
var example = fx.example
if(example == undefined) example = fx.protocol.example
- t += "```c" + example + "```\n"
+ t += "```c\n" + trimrect(example) + "\n```\n"
}
return t
