home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / Io.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  32.4 KB  |  855 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpDocumentor                                                          |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
  7. // | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
  8. // | Web           http://www.phpdoc.org                                    |
  9. // | Mirror        http://phpdocu.sourceforge.net/                          |
  10. // | PEAR          http://pear.php.net/package-info.php?pacid=137           |
  11. // +------------------------------------------------------------------------+
  12. // | This source file is subject to version 3.00 of the PHP License,        |
  13. // | that is available at http://www.php.net/license/3_0.txt.               |
  14. // | If you did not receive a copy of the PHP license and are unable to     |
  15. // | obtain it through the world-wide-web, please send a note to            |
  16. // | license@php.net so we can mail you a copy immediately.                 |
  17. // +------------------------------------------------------------------------+
  18. //
  19.  
  20. /**
  21.  * Class to handle file and user io opperations
  22.  *
  23.  * @author    Joshua Eichorn <jeichorn@phpdoc.org>
  24.  * @version    $Id: Io.inc,v 1.80.2.9 2003/09/19 04:28:09 CelloG Exp $
  25.  * @package     phpDocumentor
  26.  */
  27. /**
  28.  * Class to handle file and user io opperations
  29.  *
  30.  * @author    Joshua Eichorn <jeichorn@phpdoc.org>
  31.  * @version    $Id: Io.inc,v 1.80.2.9 2003/09/19 04:28:09 CelloG Exp $
  32.  * @package     phpDocumentor
  33.  */
  34. class Io 
  35. {
  36.     
  37.     /**
  38.      * Holds all the options that are avaible to the cmd line interface
  39.      * and to the different web interfaces
  40.      */
  41.     var $phpDocOptions;
  42.     /**
  43.      * Format: array(array(regexp-ready string to search for whole path,
  44.      * regexp-ready string to search for basename of ignore strings),...)
  45.      * @var false|array
  46.      */
  47.     var $ignore = false;
  48.  
  49.     /**
  50.      * creates an array $this->phpDocOptions and sets program options in it.
  51.      * Array is in the format of:
  52.      * <pre>
  53.      * [filename][tag][] = "f";
  54.      * [filename][tag][] = "-file";
  55.      * [filename][desc] "name of file to parse"
  56.      * </pre>
  57.      */
  58.     function Io()
  59.     {
  60.         $this->phpDocOptions['filename']['tag'] = array( "-f", "--filename");
  61.         $this->phpDocOptions['filename']['desc'] = "name of file(s) to parse ',' file1,file2.  Can contain complete path and * ? wildcards";
  62.         $this->phpDocOptions['filename']['type'] = "path";
  63.  
  64.         $this->phpDocOptions['directory']['tag'] = array( "-d", "--directory");
  65.         $this->phpDocOptions['directory']['desc'] = "name of a directory(s) to parse directory1,directory2";
  66.         $this->phpDocOptions['directory']['type'] = "path";
  67.  
  68.         $this->phpDocOptions['examplesdir']['tag'] = array( "-ed", "--examplesdir");
  69.         $this->phpDocOptions['examplesdir']['desc'] = "full path of the directory to look for example files from @example tags";
  70.         $this->phpDocOptions['examplesdir']['type'] = "path";
  71.  
  72.         $this->phpDocOptions['templatebase']['tag'] = array( "-tb", "--templatebase");
  73.         $this->phpDocOptions['templatebase']['desc'] = "base location of all templates for this parse.";
  74.         $this->phpDocOptions['templatebase']['type'] = "path";
  75.  
  76.         $this->phpDocOptions['target']['tag'] = array("-t", "--target");
  77.         $this->phpDocOptions['target']['desc'] = "path where to save the generated files";
  78.         $this->phpDocOptions['target']['type'] = "path";
  79.         
  80.         $this->phpDocOptions['ignore']['tag'] = array("-i", "--ignore");
  81.         $this->phpDocOptions['ignore']['desc'] = "file(s) that will be ignored, multiple separated by ','.  Wildcards * and ? are ok";
  82.         $this->phpDocOptions['ignore']['type'] = "path";
  83.  
  84.         $this->phpDocOptions['ignoretags']['tag'] = array("-it", "--ignore-tags");
  85.         $this->phpDocOptions['ignoretags']['desc'] = "tags to ignore for this parse.  @package, @subpackage, @access and @ignore may not be ignored.";
  86.         $this->phpDocOptions['ignoretags']['type'] = "value";
  87.  
  88.         $this->phpDocOptions['hidden']['tag'] = array("-dh", "--hidden");
  89.         $this->phpDocOptions['hidden']['desc'] = "set equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off";
  90.         $this->phpDocOptions['hidden']['type'] = "value";
  91.  
  92.         $this->phpDocOptions['quiet']['tag'] = array("-q", "--quiet");
  93.         $this->phpDocOptions['quiet']['desc'] = "do not display parsing/conversion messages.  Useful for cron jobs on/off default off";
  94.         $this->phpDocOptions['quiet']['type'] = "value";
  95.  
  96.         $this->phpDocOptions['title']['tag'] = array("-ti","--title");
  97.         $this->phpDocOptions['title']['desc'] = "title of generated documentation, default is 'Generated Documentation'";
  98.         $this->phpDocOptions['title']['type'] = "value";
  99.  
  100.         $this->phpDocOptions['help']['tag'] = array("-h", "--help");
  101.         $this->phpDocOptions['help']['desc'] = "    show this help message";
  102.  
  103.         $this->phpDocOptions['useconfig']['tag'] = array("-c","--useconfig");
  104.         $this->phpDocOptions['useconfig']['desc'] = "Use a Config file in the users/ subdirectory for all command-line options";
  105.         $this->phpDocOptions['useconfig']['type'] = "value";
  106.  
  107.         $this->phpDocOptions['parseprivate']['tag'] = array("-pp","--parseprivate");
  108.         $this->phpDocOptions['parseprivate']['desc'] = "parse @internal and elements marked private with @access.  Use on/off, default off";
  109.         $this->phpDocOptions['parseprivate']['type'] = "value";
  110.  
  111.         $this->phpDocOptions['packageoutput']['tag'] = array("-po","--packageoutput");
  112.         $this->phpDocOptions['packageoutput']['desc'] = "output documentation only for selected packages.  Use a comma-delimited list";
  113.         $this->phpDocOptions['packageoutput']['type'] = "value";
  114.  
  115.         $this->phpDocOptions['defaultpackagename']['tag'] = array("-dn","--defaultpackagename");
  116.         $this->phpDocOptions['defaultpackagename']['desc'] = "name to use for the default package.  If not specified, uses 'default'";
  117.         $this->phpDocOptions['defaultpackagename']['type'] = "value";
  118.  
  119.         $this->phpDocOptions['defaultcategoryname']['tag'] = array("-dc","--defaultcategoryname");
  120.         $this->phpDocOptions['defaultcategoryname']['desc'] = "name to use for the default category.  If not specified, uses 'default'";
  121.         $this->phpDocOptions['defaultcategoryname']['type'] = "value";
  122.  
  123.         $this->phpDocOptions['output']['tag'] = array("-o","--output");
  124.         $this->phpDocOptions['output']['desc'] = "output information to use separated by ','.  Format: output:converter:templatedir like \"HTML:frames:phpedit\"";
  125.         $this->phpDocOptions['output']['type'] = "value";
  126.  
  127.         $this->phpDocOptions['converterparams']['tag'] = array("-cp","--converterparams");
  128.         $this->phpDocOptions['converterparams']['desc'] = "dynamic parameters for a converter, separate values with commas";
  129.         $this->phpDocOptions['converterparams']['type'] = "value";
  130.  
  131.         $this->phpDocOptions['customtags']['tag'] = array("-ct","--customtags");
  132.         $this->phpDocOptions['customtags']['desc'] = "custom tags, will be recognized and put in tags[] instead of unknowntags[]";
  133.         $this->phpDocOptions['customtags']['type'] = "value";
  134.  
  135.         $this->phpDocOptions['sourcecode']['tag'] = array("-s","--sourcecode");
  136.         $this->phpDocOptions['sourcecode']['desc'] = "generate highlighted sourcecode for every parsed file (PHP 4.3.0+ only) on/off default off";
  137.         $this->phpDocOptions['sourcecode']['type'] = "value";
  138.  
  139.         $this->phpDocOptions['javadocdesc']['tag'] = array("-j","--javadocdesc");
  140.         $this->phpDocOptions['javadocdesc']['desc'] = "JavaDoc-compliant description parsing.  Use on/off, default off (more flexibility)";
  141.         $this->phpDocOptions['javadocdesc']['type'] = "value";
  142.  
  143.         $this->phpDocOptions['pear']['tag'] = array("-p","--pear");
  144.         $this->phpDocOptions['pear']['desc'] = "Parse a PEAR-style repository (package is directory, _members are @access private) on/off default off";
  145.         $this->phpDocOptions['pear']['type'] = "value";
  146.  
  147.         $this->phpDocOptions['general']['message'] ="You can have multiple directories and multiple files, as well as a combination of both options";
  148.     }
  149.  
  150.     
  151.     /**
  152.      * create the help message for display on the command-line
  153.      * @return string a string containing a help message
  154.      */
  155.     function displayHelpMsg()
  156.     {
  157.         unset($ret);
  158.         $ret = "\n";
  159.         foreach($this->phpDocOptions as $data)
  160.         {
  161.             unset($tag);
  162.             $tag = "";
  163.             if (isset($data['tag']))
  164.             {
  165.                 if (is_array($data['tag'])) {
  166.                     foreach($data['tag'] as $param) {
  167.                         $tag .= "$param    ";
  168.                     }
  169.                 }
  170.         $taglen = 34;
  171.         $outputwidth = 79;
  172.         $tagspace = str_repeat(" ",$taglen);
  173.                 $tmp = "  ".trim($tag).$tagspace;
  174.                 $tmp = substr($tmp,0,$taglen);
  175.                 $d = wordwrap(ltrim($data['desc']),($outputwidth-$taglen));
  176.         $dt = explode("\n",$d);
  177.         $dt[0] = $tmp .$dt[0];
  178.         for($i=1;$i<count($dt);$i++)
  179.         {
  180.             $dt[$i] = $tagspace.$dt[$i];
  181.         }
  182.         $ret .= implode("\n",$dt)."\n\n";
  183.         
  184.             }
  185.         }
  186.         $ret .= "\n".wordwrap($data['message'],$outputwidth)."\n";
  187.         return $ret; 
  188.     }
  189.     
  190.     /**
  191.      * calls {@link file_exists()} for each value in include_path,
  192.      * then calls {@link is_readable()} when it finds the file
  193.      * @param string
  194.      * @return boolean
  195.      */
  196.     function isIncludeable($filename)
  197.     {
  198.         $ip = get_include_path();
  199.         if (PHPDOCUMENTOR_WINDOWS)
  200.         {
  201.             $ip = explode(';', $ip);
  202.         } else {
  203.             $ip = explode(':', $ip);
  204.         }
  205.         foreach($ip as $path)
  206.         {
  207.             if ($a = realpath($path . DIRECTORY_SEPARATOR . $filename))
  208.             {
  209.                 if (is_readable($a))
  210.                 {
  211.                     return true;
  212.                 }
  213.             }
  214.         }
  215.         return false;
  216.     }
  217.  
  218.     /**
  219.      * Parses $_SERVER['argv'] and creates a setup array
  220.      * @return array a setup array
  221.      * @global array command-line arguments
  222.      */
  223.     function parseArgv()
  224.     {
  225.         // defaults for setting
  226.         $setting['hidden'] = "off";
  227.         $setting['template'] = 'templates' . PATH_DELIMITER .'default' . PATH_DELIMITER;
  228.  
  229.         $valnext = "junk";
  230.         if(array_key_exists('argv',$_SERVER) && is_array($_SERVER['argv']))
  231.         {
  232.             foreach ( $_SERVER['argv'] as $cmd )
  233.             {
  234.                 //if($cmd === 'phpdoc' || basename($cmd)==='phpdoc')
  235.                 //    continue;
  236.  
  237.                 if ($cmd == '-h' || $cmd == '--help')
  238.                 {
  239.                     echo $this->displayHelpMsg();
  240.                     die();
  241.                 }
  242.                 $setting[$valnext] = $cmd;
  243.                 foreach( $this->phpDocOptions as $name => $data )
  244.                 {
  245.                     if (!empty($data['tag']))
  246.                     {
  247.                         if (in_array($cmd,$data['tag']))
  248.                         {
  249.                             $valnext = $name;
  250.                             break;
  251.                         } 
  252.                         else
  253.                         {
  254.                             $valnext = "junk";
  255.                         }
  256.                     }
  257.                 }
  258.                 if ($valnext == 'junk' && (strpos(trim($cmd),'-') === 0))
  259.                 {
  260.                     addErrorDie(PDERROR_UNKNOWN_COMMANDLINE,$cmd);
  261.                 }
  262.             }
  263.         } else
  264.         {
  265.             echo "Please use php-cli.exe in windows, or set register_argc_argv On";
  266.             die;
  267.         }
  268.         /* $setting will always have at least 2 elements
  269.         [hidden] => off
  270.         [template] => templates/default
  271.          */
  272.         if (count($setting) < 3) {
  273.             echo $this->displayhelpMsg();
  274.             die();
  275.         }
  276.         return $setting;
  277.     }
  278.  
  279.  
  280.     /**
  281.      * @return array list of files in a directory
  282.      * @param string $directory full path to the directory you want the list of
  283.      * @param off|on whether to list files that begin with . like .bash_history
  284.      */
  285.     function dirList($directory,$hidden = "off")
  286.     {
  287.         $ret = false;
  288.         if (@is_dir($directory))
  289.         {
  290.             $ret = array();
  291.             $d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
  292.             while($d && $entry=$d->read()) {
  293.                 if (strcmp($entry,".") != 0 && strcmp($entry,"..") != 0) {
  294.                 if ($hidden == "off")
  295.                 {
  296.                     if (substr($entry,0,1) == ".")
  297.                     {
  298.                         $getentry = false;
  299.                     } else {
  300.                         $getentry = true;
  301.                     }
  302.         
  303.                 } else {
  304.                     $getentry = true;
  305.                 }
  306.         
  307.                 if ($getentry == true)
  308.                 {
  309.                     if (is_file($directory . PATH_DELIMITER . $entry)) {
  310.                         $ret[] = $directory . PATH_DELIMITER . $entry;
  311.                     }
  312.                     if (is_dir($directory . PATH_DELIMITER . $entry)) {
  313.                         $tmp = $this->dirList($directory . PATH_DELIMITER . $entry, $hidden);
  314.                         if (is_array($tmp)) {
  315.                             foreach($tmp as $ent) {
  316.                                 $ret[] = $ent;
  317.                             }
  318.                         }
  319.                     }
  320.                 }
  321.             }
  322.         }
  323.         if ($d) $d->close();
  324.         } else {
  325.             die("directory: '$directory'  not found\n");
  326.         }
  327.         return $ret;
  328.     }
  329.  
  330.     /**
  331.      * Retrieve common directory (case-insensitive in windows)
  332.      *
  333.      * takes the list of files, and returns the subdirectory they share in common,
  334.      * so in this list:
  335.      *
  336.      * <code>
  337.      * array(
  338.      * "/dir1/dir2/subdir/dir3/filename.ext",
  339.      * "/dir1/dir2/subdir/dir4/filename.ext",
  340.      * "/dir1/dir2/mydir/dir5/filename.ext");
  341.      * </code>
  342.      *
  343.      * getBase will return "/dir1/dir2"
  344.      * @param array array of strings
  345.      */
  346.     function getBase($filelist)
  347.     {
  348.         foreach($filelist as $path)
  349.         {
  350.             if (!isset($masterPath))
  351.             {
  352.                 $masterPath = str_replace('\\','/',dirname($path));
  353.             } else
  354.             {
  355.                 if (dirname($path) != $masterPath)
  356.                 {
  357.                     $mp = split(PATH_DELIMITER,$masterPath);
  358.                     $np = split(PATH_DELIMITER,str_replace('\\','/',dirname($path)));
  359.                     if (count($np) < count($mp))
  360.                     {
  361.                         $masterPath = join($np, PATH_DELIMITER);
  362.                     } else
  363.                     {
  364.                         $test = false;
  365.                         $found = false;
  366.                         for($i=0;$i < count($mp) && $i < count($np);$i++)
  367.                         {
  368.                             if (PHPDOCUMENTOR_WINDOWS)
  369.                             {
  370.                                 if (strtolower($mp[$i]) != strtolower($np[$i])) $found = $i;
  371.                             } else
  372.                             {
  373.                                 if ($mp[$i] != $np[$i]) $found = $i;
  374.                             }
  375.                         }
  376.                         if ($found !== false)
  377.                         {
  378.                             $mp = array_slice($mp,0,$found);
  379.                             $masterPath = join($mp,PATH_DELIMITER);
  380.                         }
  381.                     }
  382.                 }
  383.             }
  384.         }
  385.         return $masterPath;
  386.     }
  387.     
  388.     /**
  389.      * Retrieve tutorial subdirectories and their contents from the list of
  390.      * files to parse
  391.      * @param array array of paths (strings)
  392.      * @return array array(filelist - tutorials, tutorials)
  393.      */
  394.     function getTutorials($filelist)
  395.     {
  396.         $list = $tutorials = array();
  397.         foreach($filelist as $file)
  398.         {
  399.             if (strpos($file,'tutorials/') !== false)
  400.             {
  401.                 $tutedir = explode('/',substr($file,strpos($file,'tutorials/')));
  402.                 array_shift($tutedir);
  403.                 if (count($tutedir) <= 3)
  404.                 {
  405.                     $res = array();
  406.                     // kludge - will need to fix for 2.0
  407.                     $res['category'] = $GLOBALS['phpDocumentor_DefaultCategoryName'];
  408.                     $res['package'] = array_shift($tutedir);
  409.                     $res['subpackage'] = '';
  410.                     if (count($tutedir) > 1)
  411.                     $res['subpackage'] = array_shift($tutedir);
  412.                     $f = array_shift($tutedir);
  413.                     $res['tutename'] = $f;
  414.                     $f = explode('.',$f);
  415.                     $res['tutetype'] = array_pop($f);
  416.                     if ($res['tutetype'] == 'ini') continue;
  417.                     $res['path'] = $file;
  418.                     if (@file_exists($file . '.ini'))
  419.                     {
  420.                         $res['ini'] = phpDocumentor_parse_ini_file($file . '.ini', true);
  421.                     } else
  422.                     {
  423.                         $res['ini'] = false;
  424.                     }
  425.                     $tutorials[] = $res;
  426.                 }
  427.             } else $list[] = $file;
  428.         }
  429.         return array($list,$tutorials);
  430.     }
  431.     
  432.     /**
  433.      * @param string base directory from {@link getBase()}
  434.      * @param array file list from {@link dirList()}
  435.      * @return array array(filelist - README/INSTALL/CHANGELOG,
  436.      *                     README/INSTALL/CHANGELOG)
  437.      */
  438.     function getReadmeInstallChangelog($base,$filelist)
  439.     {
  440.         $list = $ric = array();
  441.         $names = array('README', 'INSTALL', 'CHANGELOG', 'FAQ', 'NEWS');
  442.         foreach($filelist as $file)
  443.         {
  444.             if ((dirname($file) == $base) && in_array(strtoupper(basename($file)), $names))
  445.             { // be sure to change $this->checkIgnore() if any other files are added here!!
  446.                 $ric[] = $file;
  447.             } else
  448.             {
  449.                 $list[] = $file;
  450.             }
  451.         }
  452.         return array($list,$ric);
  453.     }
  454.     
  455.     function getDirTree($dir, $base_dir, $ignore = array(), $hidden="off")
  456.     {
  457.         $allfiles = $this->dirList($dir,$hidden);
  458.         $struc = array();
  459.         foreach($allfiles as $file)
  460.         {
  461.             if ($this->checkIgnore(basename($file),dirname($file),$ignore)) continue;
  462.             $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir)))+1);
  463.             if (!$path) $path = '/';
  464.             $file1 = $file;
  465.             $file = basename($file);
  466.             $ext = array_pop(explode('.',$file));
  467.             if (strlen($ext) == strlen($file)) $ext = '';
  468.             $struc[$path][] = array('file' => $file,'ext' => $ext,'path' => $file1);
  469.         }
  470.         uksort($struc,'strnatcasecmp');
  471.         foreach($struc as $key => $ind)
  472.         {
  473.             usort($ind,'Ioinc_sortfiles');
  474.             $struc[$key] = $ind;
  475.             $save = $key;
  476.             if ($key != '/')
  477.             {
  478.                 $key = explode('/',$key);
  479.                 while (count($key))
  480.                 {
  481.                     array_pop($key);
  482.                     if (isset($struc[join('/',$key)]))
  483.                     {
  484.                         $struc[join('/',$key)][substr($save,strlen(join('/',$key)) + 1)] = $ind;
  485.                         unset($struc[$save]);
  486.                     }
  487.                 }
  488.             }
  489.         }
  490.         foreach($struc as $key => $ind)
  491.         {
  492.             if ($key != '/')
  493.             {
  494.                 if (count(explode('/',$key)) == 1)
  495.                 {
  496.                     $struc['/'][$key] = $struc[$key];
  497.                     unset($struc[$key]);
  498.                 }
  499.             }
  500.         }
  501.         $tempstruc = $struc;
  502.         unset($tempstruc['/']);
  503.         $leftover_dirs = array_keys($tempstruc);
  504.         $splitdirs = array();
  505.         foreach($leftover_dirs as $dir)
  506.         {
  507.             $splitdirs[] = explode('/',$dir);
  508.         }
  509.         $leftover_dirs = array();
  510.  
  511.         foreach($splitdirs as $dir)
  512.         {
  513.             $save = join($dir,'/');
  514.             $struc['/'] = setup_dirs($struc['/'], $dir, $tempstruc[$save]);
  515.             unset($struc[$save]);
  516.         }
  517.         uksort($struc['/'],'Ioinc_mystrucsort');
  518.         return $struc;
  519.     }
  520.     
  521.     /**
  522.      * Reads a file and returns it as a string
  523.      * Does basic error checking
  524.      *
  525.      * file extensions are set in {@link phpdoc.inc}
  526.      *
  527.      * @global array PHP File extensions, used to validate that $path is a PHP File
  528.      * @global array PHP File extensions in a CVS repository, used to validate that $path is a PHP File
  529.      * @param    string    $path
  530.      */
  531.     function readPhpFile($path, $quietMode = false)
  532.     {
  533.         global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_phpfile_exts;
  534.         // tiberiusblue addition
  535.         $cvsExt = $_phpDocumentor_cvsphpfile_exts; 
  536.         $ext = $_phpDocumentor_phpfile_exts;
  537.         if (file_exists($path))
  538.         {
  539.             if (is_file($path))
  540.             {
  541.                 // check extension
  542.                 $tmp = explode(".",$path);
  543.                 // tiberiusblue addition
  544.                 $tmp2 = $tmp;
  545.                 if (in_array(array_pop($tmp),$ext))
  546.                 {
  547.                     phpDocumentor_out(" -- Parsing file\n");
  548.                     flush();
  549.                     $fp = fopen($path,"r");
  550.                     $ret = fread($fp,filesize($path));
  551.                     fclose($fp);
  552.                     return $ret;
  553.                 } elseif (in_array(array_pop($tmp2),$cvsExt)) 
  554.                 { 
  555.                     phpDocumentor_out(" CVS file [EXPERIMENTAL]\n"); 
  556.                     flush();
  557.                     $fp = fopen($path,"r"); 
  558.                     $ret = fread($fp,filesize($path)); 
  559.                     fclose($fp); 
  560.                     $ret = strstr($ret,"<?");
  561.                     $ret = substr($ret,0,strpos($ret,"@\n"));
  562.                     $ret = str_replace("@@","@",$ret); 
  563.                     return $ret; 
  564.                 } else
  565.                 {
  566.                     phpDocumentor_out(" -- File not parsed, not a php file\n");
  567.                     flush();
  568.                 }
  569.             } else {
  570.                 phpDocumentor_out(" -- Unable to read file, not a file\n");
  571.                 flush();
  572.             }
  573.         } else {
  574.             phpDocumentor_out(" -- Unable to read file, file does not exist\n");
  575.             flush();
  576.            }
  577.     }
  578.  
  579.     /**
  580.      * Tell whether to ignore a file or a directory
  581.      * allows * and ? wildcards
  582.      *
  583.      * @author Greg Beaver <cellog@users.sourceforge.net>
  584.      * @param    string  $file    just the file name of the file or directory,
  585.      *                          in the case of directories this is the last dir
  586.      * @param    string  $path    the full path
  587.      * @param    array   $ignore
  588.      * @return   bool    true if $path should be ignored, false if it should not
  589.      */
  590.     function checkIgnore($file,$path,$ignore,$ignore_no_ext = true)
  591.     {
  592.         $path = realpath($path);
  593.         if (!count($ignore)) return false;
  594.         if ($ignore_no_ext && strtoupper($file) != 'README' && strtoupper($file) != 'INSTALL' && strtoupper($file) != 'CHANGELOG' && strtoupper($file) != 'FAQ' && strtoupper($file) != 'NEWS')
  595.         {
  596.             if (!is_numeric(strpos($file,'.'))) return true;
  597.         }
  598.         if (!isset($this->ignore) || !$this->ignore)
  599.         {
  600.             $this->_setupIgnore($ignore);
  601.             if (!$this->ignore)
  602.             {
  603.                 return false;
  604.             }
  605.         }
  606.         if (is_array($this->ignore))
  607.         {
  608.             foreach($this->ignore as $match)
  609.             {
  610.                 // match is an array if the ignore parameter was a /path/to/pattern
  611.                 if (is_array($match))
  612.                 {
  613.                     // check to see if the path matches with a path delimiter appended
  614.                     preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path) . PATH_DELIMITER,$find);
  615.                     if (!count($find))
  616.                     {
  617.                         // check to see if it matches without an appended path delimiter
  618.                         preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path), $find);
  619.                     }
  620.                     if (count($find))
  621.                     {
  622.                         // check to see if the file matches the file portion of the regex string
  623.                         preg_match('/^' . strtoupper($match[1]).'$/', strtoupper($file), $find);
  624.                         if (count($find))
  625.                         {
  626.                             return true;
  627.                         }
  628.                     }
  629.                     // check to see if the full path matches the regex
  630.                     preg_match('/^' . strtoupper($match[0]).'$/',
  631.                                strtoupper($path . DIRECTORY_SEPARATOR . $file), $find);
  632.                     if (count($find))
  633.                     {
  634.                         return true;
  635.                     }
  636.                 } else
  637.                 {
  638.                     // ignore parameter was just a pattern with no path delimiters
  639.                     // check it against the path
  640.                     preg_match('/^' . strtoupper($match).'$/', strtoupper($path), $find);
  641.                     if (count($find))
  642.                     {
  643.                         return true;
  644.                     }
  645.                     // check it against the file only
  646.                     preg_match('/^' . strtoupper($match).'$/', strtoupper($file), $find);
  647.                     if (count($find))
  648.                     {
  649.                         return true;
  650.                     }
  651.                 }
  652.             }
  653.         }
  654.         return false;
  655.     }
  656.     
  657.     /**
  658.      * Construct the {@link $ignore} array
  659.      * @author Greg Beaver <cellog@users.sourceforge.net>
  660.      * @param array strings of files/paths/wildcards to ignore
  661.      * @access protected
  662.      */
  663.     function _setupIgnore($ignore)
  664.     {
  665.         $ig = array();
  666.         if (is_array($ignore))
  667.         {
  668.             for($i=0; $i<count($ignore);$i++)
  669.             {
  670.                 $ignore[$i] = strtr($ignore[$i], "\\", "/");
  671.                 $ignore[$i] = str_replace('//','/',$ignore[$i]);
  672.  
  673.                 if (!empty($ignore[$i]))
  674.                 {
  675.                     if (!is_numeric(strpos($ignore[$i],PATH_DELIMITER)))
  676.                     {
  677.                         $ig[] = $this->getRegExpableSearchString($ignore[$i]);
  678.                     } else
  679.                     {
  680.                         if (basename($ignore[$i]) . PATH_DELIMITER == $ignore[$i])
  681.                         $ig[] = $this->getRegExpableSearchString($ignore[$i]);
  682.                         else
  683.                         $ig[] = array($this->getRegExpableSearchString($ignore[$i]),$this->getRegExpableSearchString(basename($ignore[$i])));
  684.                     }
  685.                 }
  686.             }
  687.             if (count($ig)) $this->ignore = $ig;
  688.         } else $this->ignore = false;
  689.     }
  690.     
  691.     /**
  692.      * Converts $s into a string that can be used with preg_match
  693.      * @param string $s string with wildcards ? and *
  694.      * @author Greg Beaver <cellog@users.sourceforge.net>
  695.      * @return string converts * to .*, ? to ., etc.
  696.      */
  697.     function getRegExpableSearchString($s)
  698.     {
  699.         $y = '\/';
  700.         if (DIRECTORY_SEPARATOR == '\\')
  701.         {
  702.             $y = '\\\\';
  703.         }
  704.         $s = str_replace('/', DIRECTORY_SEPARATOR, $s);
  705.         $x = strtr($s, array('?' => '.','*' => '.*','.' => '\\.','\\' => '\\\\','/' => '\\/',
  706.                                 '[' => '\\[',']' => '\\]','-' => '\\-'));
  707.         if (strpos($s, DIRECTORY_SEPARATOR) === strlen($s) - 1)
  708.         {
  709.             $x = "(?:.*$y$x?.*|$x.*)";
  710.         }
  711.         return $x;
  712.     }
  713.     
  714.     /**
  715.      * Removes files from the $dir array that do not match the search string in
  716.      * $match
  717.      * @param array $dir array of filenames (full path)
  718.      * @param string $match search string with wildcards
  719.      * @author Greg Beaver <cellog@users.sourceforge.net>
  720.      * @return string|array listing of every file in a directory that matches
  721.      *                      the search string
  722.      */
  723.     function removeNonMatches($dir, $match)
  724.     {
  725.         $match = $this->getRegExpableSearchString($match);
  726.         $nodir = false;
  727.         if (!is_array($dir))
  728.         {
  729.             $dir = array($dir);
  730.             $nodir = true;
  731.         }
  732.         foreach($dir as $i => $file)
  733.         {
  734.             preg_match('/^'.$match.'$/',basename($file),$find);
  735.             if (!count($find)) unset($dir[$i]);
  736.         }
  737.         if ($nodir) return $dir[0];
  738.         return $dir;
  739.     }
  740.     
  741.     /**
  742.      * Take a filename with wildcards and return all files that match the
  743.      * wildcards
  744.      * @param string $file a full path from the -f command-line parameter, with
  745.      * potential * and ? wildcards.
  746.      * @return mixed if $file contains wildcards, returns an array of matching
  747.      *               files, otherwise returns false
  748.      * @author Greg Beaver <cellog@users.sourceforge.net>
  749.      */
  750.     function getAllFiles($file)
  751.     {
  752.         $path = realpath(dirname($file));
  753.         $file = basename($file);
  754.         // any wildcards?
  755.         if (is_numeric(strpos($file,'?')) || is_numeric(strpos($file,'*')))
  756.         {
  757.             $files = $this->dirList($path);
  758.             $a = $this->removeNonMatches($files,$file);
  759.             return $a;
  760.         }
  761.         return false;
  762.     }
  763. }
  764.  
  765. /**#@+
  766.  * Sorting functions for the file list
  767.  * @param string
  768.  * @param string
  769.  */
  770. function Ioinc_sortfiles($a, $b)
  771. {
  772.     return strnatcasecmp($a['file'],$b['file']);
  773. }
  774.  
  775. function Ioinc_mystrucsort($a, $b)
  776. {
  777.     if (is_numeric($a) && is_string($b)) return 1;
  778.     if (is_numeric($b) && is_string($a)) return -1;
  779.     if (is_numeric($a) && is_numeric($b))
  780.     {
  781.         if ($a > $b) return 1;
  782.         if ($a < $b) return -1;
  783.         if ($a == $b) return 0;
  784.     }
  785.     return strnatcasecmp($a,$b);
  786. }
  787. /**#@-*/
  788.  
  789. /**
  790.  * Recursively add all the subdirectories of $contents to $dir without erasing anything in
  791.  * $dir
  792.  * @param array
  793.  * @param array
  794.  * @return array processed $dir
  795.  */
  796. function set_dir($dir,$contents)
  797. {
  798.     while(list($one,$two) = each($contents))
  799.     {
  800.         if (isset($dir[$one]))
  801.         {
  802.             $dir[$one] = set_dir($dir[$one],$contents[$one]);
  803.         } else $dir[$one] = $two;
  804.     }
  805.     return $dir;
  806. }
  807.  
  808. /**
  809.  * Recursively move contents of $struc into associative array
  810.  *
  811.  * The contents of $struc have many indexes like 'dir/subdir/subdir2'.
  812.  * This function converts them to
  813.  * array('dir' => array('subdir' => array('subdir2')))
  814.  * @param array struc is array('dir' => array of files in dir,'dir/subdir' => array of files in dir/subdir,...)
  815.  * @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')
  816.  * @return array same as struc but with array('dir' => array(file1,file2,'subdir' => array(file1,...)))
  817.  */
  818. function setup_dirs($struc,$dir,$contents)
  819. {
  820.     if (!count($dir))
  821.     {
  822.         foreach($contents as $dir => $files)
  823.         {
  824.             if (is_string($dir))
  825.             {
  826.                 if (strpos($dir,'/'))
  827.                 {
  828.                     $test = true;
  829.                     $a = $contents[$dir];
  830.                     unset($contents[$dir]);
  831.                     $b = explode('/',$dir);
  832.                     $c = array_shift($b);
  833.                     if (isset($contents[$c]))
  834.                     {
  835.                         $contents[$c] = set_dir($contents[$c],setup_dirs(array(),$b,$a));
  836.                     } else $contents[$c] = setup_dirs(array(),$b,$a);
  837.                 }
  838.             }
  839.         }
  840.         return $contents;
  841.     }
  842.     $me = array_shift($dir);
  843.     if (!isset($struc[$me])) $struc[$me] = array();
  844.     $struc[$me] = setup_dirs($struc[$me],$dir,$contents);
  845.     return $struc;
  846. }
  847.  
  848. if (!function_exists('get_include_path')) {
  849. function get_include_path()
  850. {
  851.     return ini_get('include_path');
  852. }
  853. }
  854. ?>
  855.