$value) { switch ($spec) { case "d": $delim = $value; break; case "b": $bytes = $value; break; case "f": $fields = $value; break; } } $result = []; if ($bytes) { $func = "substr"; } else { $func = function($a, $o = 0, $l = 0) { return join(" ", array_slice($a, $o, $l ? $l+1 : count($a)-$o)); }; } foreach ($lines as $line) { if ($bytes) { $spec = $bytes; } else { $line = split($delim, $line); $spec = $fields; } if ($spec[0] == "-") { $result[] = $func($line, 0, $spec[1]); } elseif ($spec[1] == "-") { if (empty($spec[2])) { $result[] = $func($line, $spec[0]); } else { $result[] = $func($line, $spec[0], $spec[2]-$spec[0]); } } else { $result[] = $line{$spec[0]}; } } return $result; } function head($file, $lines = 1) { $ld = []; if (($fd = fopen($file, "r"))) { while ($lines--) { $ld[] = fgets($fd); } } return $ld; } function ns($file) { return str_replace("/", "\\", str_replace("//", "/", trim($file, "/."))); } function urlpath($dir, $file) { return (strlen($dir) ? $dir . "/" : "") . urlencode($file); } function ls($dir, $invert = false) { fprintf(OUTPUT, "\n"); } function ml($file) { $pi = pathinfo($file); if (ctype_upper($pi["filename"][0])) { fprintf(OUTPUT, "

Methods:

\n"); $el = $pi["dirname"] . "/" . $pi["filename"]; ls($el, true); } } function md($file) { $r = fopen($file, "r"); $md = MarkdownDocument::createFromStream($r); $md->compile(); $md->writeHtml(OUTPUT); unset($md); fclose($r); // BS Markdown seeks around... fseek(OUTPUT, 0, SEEK_END); ml($file); } $r = new http\Env\Request; $u = new http\Url($r->getRequestUrl()); $t = ["css"=>"text/css", "js"=>"application/javascript"]; switch($u->path) { case "/index.js": case "/index.css": $s = new http\Env\Response; $s->setHeader("Content-type", $t[pathinfo($u->path, PATHINFO_EXTENSION)]); $s->setBody(new http\Message\Body(fopen(basename($u->path), "r"))); $s->send(); exit; } if (is_dir(".".$u->path)) { ls(".".$u->path); } else { md(".".$u->path); } ?> <?=$u->path?>