X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=index.php;h=5c4b909b5057fe201b23b09978d73c0a785222dd;hb=4199b3fd65d963057c82c1541df6e2f786e6bd9d;hp=5c4f5a77e4513ae8f7c8c75b1b5653e26d0f4e17;hpb=d3e33e708a783c634a3f8f5db634a7f03f8520f4;p=mdref%2Fmdref diff --git a/index.php b/index.php index 5c4f5a7..5c4b909 100644 --- a/index.php +++ b/index.php @@ -62,31 +62,25 @@ function head($file, $lines = 1) { return $ld; } -function tail($file, $lines = 1) { - $bs = 512; - $fs = 0; - $ld = []; - if (is_resource($file) || ($file = fopen($file, "r"))) { - fseek($file, 0, SEEK_END); - $fs = ftell($file); - $fp = $fs; - $ls = ""; - while ($fp > 0 && count($ld) < $lines) { - do { - fseek($file, -min($fp, $bs), SEEK_CUR); - $fp = ftell($file); - $ls = fread($file, $fs-$fp) . $ls; - } while ($fp > 0 && -1 === ($eol = strrpos($ls, "\n", $ls))); - - array_unshift($ld, substr($ls, $eol)); - $ls = substr($ls, 0, $eol-1); +function ns($path) { + $ns = ""; + $parts = explode("/", $path); + $upper = ctype_upper($path[0]); + for ($i = 0; $i < count($parts); ++$i) { + if (!strlen($parts[$i]) || $parts[$i] === ".") { + continue; + } + if (strlen($ns)) { + if ($upper && !ctype_upper($parts[$i][0])) { + $ns .= "::"; + } else { + $ns .= "\\"; + } } + $ns .= $parts[$i]; + $upper = ctype_upper($parts[$i][0]); } - - return $ld; -} - -function ns($file) { + return $ns; return str_replace("/", "\\", str_replace("//", "/", trim($file, "/."))); } @@ -97,43 +91,27 @@ function urlpath($dir, $file) { function ls($dir) { $dir = rtrim(is_dir($dir) ? $dir : dirname($dir) ."/". basename($dir, ".md"), "/"); printf("