X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=htdocs%2Flib%2FTools.class.php;h=7e02c68e90406d60be7dabbd829e66de8a17ec59;hb=07f0862d6ef4a14a812381a30931a46a51dbc87d;hp=d7f9075bff8522dabfc6525cdda50009cea3edae;hpb=394a07ff3e283f94c7ead44e8bd02d44c223314b;p=phpgitweb.git diff --git a/htdocs/lib/Tools.class.php b/htdocs/lib/Tools.class.php index d7f9075..7e02c68 100644 --- a/htdocs/lib/Tools.class.php +++ b/htdocs/lib/Tools.class.php @@ -17,6 +17,44 @@ */ class Tools { + /* octal constants (sys/stat.h) */ + const S_IFMT = 0170000; + const S_IFGITLINK = 0160000; /* GIT defined */ + const S_IFLNK = 0120000; + const S_IFREG = 0100000; + const S_IFDIR = 0040000; + const S_IPERMS = 0000777; + const S_IXUSR = 0000100; + + public static function get_filetype($mode, $exec = false) { + if(!preg_match('/^[0-7]+$/', $mode)) + return $mode; + + $mode = octdec($mode); + + if(($mode & self::S_IFMT) == self::S_IFGITLINK) + return 'submodule'; + else if(($mode & self::S_IFMT) == self::S_IFDIR) + return 'directory'; + else if(($mode & self::S_IFMT) == self::S_IFLNK) + return 'symlink'; + else if(($mode & self::S_IFMT) == self::S_IFREG) { + if($exec && ($mode & self::S_IXUSR)) + return 'executable'; + return 'file'; + } else + return 'unknown'; + } + + public static function is_regular_file($mode) { + $mode = octdec($mode); + return (($mode & self::S_IFMT) == self::S_IFREG); + } + + public static function get_file_permissions($mode) { + $mode = octdec($mode); + return sprintf("%04o",($mode & self::S_IPERMS)); + } public static function age_calculate($last_change) { $result = array(); @@ -90,6 +128,19 @@ class Tools { return $offset; } + public static function replaceTabs($line) { + while(($pos = strpos($line, "\t")) !== false) { + $spacecount = 8 - ($pos % 8); + $i = 1; + while($line[$pos + $i] == "\t") { //maybe a little bit faster ;) + $i++; + $spacecount += 8; + } + $line = substr($line, 0, $pos).str_repeat(' ', $spacecount).substr($line, $pos + $i); + } + return $line; + } + } ?> \ No newline at end of file