<?php require __DIR__ . '/git.php'; $repo = new Git($_REQUEST['r']); $oid = $_REQUEST['o']; $repo->validateObjectID($oid); $path = htmlspecialchars($_REQUEST['p'], ENT_QUOTES, 'UTF-8'); $data = str_replace("\t", ' ', str_replace('<', '<', str_replace('>', '>', $repo->catFile($oid)))); if (preg_match('/\\.d$/', $path)) { $syntax = array('type' => array('auto', 'body', 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'creal', 'dchar', 'double', 'float', 'idouble', 'ifloat', 'int', 'ireal', 'long', 'real', 'short', 'ubyte', 'ucent', 'uint', 'ulong', 'ushort', 'void', 'wchar'), 'keyword' => array('abstract', 'alias', 'align', 'asm', 'assert', 'auto', 'body', 'bool', 'break', 'byte', 'case', 'cast', 'catch', 'cdouble', 'cent', 'cfloat', 'char', 'class', 'const', 'continue', 'creal', 'dchar', 'debug', 'default', 'delegate', 'delete', 'deprecated', 'do', 'double', 'else', 'enum', 'export', 'extern', 'false', 'final', 'finally', 'float', 'for', 'foreach', 'foreach_reverse', 'function', 'goto', 'idouble', 'if', 'ifloat', 'immutable', 'import', 'in', 'inout', 'int', 'interface', 'invariant', 'ireal', 'is', 'lazy', 'long', 'macro (unused)', 'mixin', 'module', 'new', 'nothrow', 'null', 'out', 'override', 'package', 'pragma', 'private', 'protected', 'public', 'pure', 'real', 'ref', 'return', 'scope', 'shared', 'short', 'static', 'struct', 'super', 'switch', 'synchronized', 'template', 'this', 'throw', 'true', 'try', 'typedef', 'typeid', 'typeof', 'ubyte', 'ucent', 'uint', 'ulong', 'union', 'unittest', 'ushort', 'version', 'void', 'volatile', 'wchar', 'while', 'with', '__FILE__', '__MODULE__', '__LINE__', '__FUNCTION__', '__PRETTY_FUNCTION__', '__gshared', '__traits', '__vector', '__parameters'), 'token' => array('/', '/=', '.', '..', '...', '&', '&=', '&&', '|', '|=', '||', '-', '-=', '--', '+', '+=', '++', '<', '<=', '<<', '<<=', '<>', '<>=', '>', '>=', '>>=', '>>>=', '>>', '>>>', '!', '!=', '!<>', '!<>=', '!<', '!<=', '!>', '!>=', '(', ')', '[', ']', '{', '}', '?', ',', ';', ':', '$', '=', '==', '*', '*=', '%', '%=', '^', '^=', '^^', '^^=', '~', '~=', '@', '=>', '#')); foreach ($syntax as $key => $list) { usort($syntax[$key], function ($a, $b) { return strlen($a) < strlen($b); }); } $src = $data; $dst = ''; $context = null; function syntax($class = null) { global $context, $dst; if ($context != $class) { if ($context) { $dst .= '</code>'; } $context = $class; $dst .= "<code class=\"syntax-{$class}\">"; } } $patterns = array('type' => '/^(' . implode($syntax['type'], '|') . ')[^a-zA-Z_]/', 'keyword' => '/^(' . implode($syntax['keyword'], '|') . ')[^a-zA-Z_]/', 'token' => '{^(' . implode(array_map(function ($ptn) { return preg_quote($ptn);