jeroen          Sat Jul  7 17:19:49 2001 EDT

  Added files:                 
    /phpdoc/scripts     README process.php tfn.php 
  Log:
  Added a scripts directory with some phpdoc-scripts.
  
  Maybe move the scripts in the root op phpdoc here too?
  
  

Index: phpdoc/scripts/process.php
+++ phpdoc/scripts/process.php
#!/usr/bin/php -q
<?php

if ($argc < 2 || $argc > 3)
{       ?>
Process the manual to do some replacements.

  Usage:
  <?=$argv[0]?> <apply-script> [<startdir>]

  <apply-script> must contain the function apply($input),
  which recieves a whole xml-file, and should output
  return the new file.

  With <startdir> you can specify in which dir
  to start looking recursively for xml files.

  Written by [EMAIL PROTECTED]

  <?php
  exit;
}

echo "Starting with manual-process\n";
echo "Including $argv[1]...";
include("$argv[1]");
echo " done\n";
if (!function_exists('apply'))
{
        ?>


### FATAL ERROR ###

In <?=$argv[1]?> you should define a function:
  string apply(string $string)

        <?php
        exit;
}

$startdir = isset($argv[2]) ? $argv[2] : '.';
        

echo "Constructing list of all xml-files (may take a while)...";
$files = all_xml_files($startdir);
echo " done (".count($files)." xml files found)\n";

foreach ($files as $file)
{
        echo "[Processing $file]\n";
        $fp = fopen($file,'r');
        $old = fread($fp,filesize($file));
        fclose($fp);
        if (!$old)
        {
                echo "WARNING: problem reading $file, skipping\n";
                continue;
        }
        $new = apply($old);
        $fp = fopen($file,'w');
        $res = fwrite($fp,$new);
        fclose($fp);
        if (!$res)
        {
                echo "WARNING: problem writing $file, file might be damaged\n";
                continue;
        }
}

        
/* Utility functions: */

function all_xml_files($startdir)
{
        $startdir = ereg_replace('/+$','',$startdir);
        //echo "\$startdir = $startdir\n";
        $entries = array();

        $handle=opendir($startdir);
        while ($file = readdir($handle))
        {
                $ffile = "$startdir/$file"; // full file(path)
                //echo "$file\n";
                if (ereg('\.xml$',$file))
                        $entries[] = $ffile;
                if ($file{0} != '.' && is_dir($ffile))
                        $entries = array_merge($entries,all_xml_files($ffile));
        }
        closedir($handle);

        return $entries;
}
        


Index: phpdoc/scripts/tfn.php
+++ phpdoc/scripts/tfn.php
<?php

// For use in process.php

// true,false,null -> entities

function apply($input)
{
        $from = '/([^a-zA-Z$._-])(true|false|null)([^a-zA-Z$_-])/i';
        $to = "\\1&\\2;\\3";

        $lines = explode("\n",$input);

        $active = TRUE;

        foreach ($lines as $nr => $line)
        {
                $active = $active && !ereg('<programlisting',$line);
                $active = $active ||  ereg('</programlisting',$line);
                if ($active)
                        $lines[$nr] = preg_replace( $from , $to , $line );
                
        }

        $output = implode("\n",$lines);

        // lowercase the entities:
        $output = eregi_replace('&true;','&true;',$output);
        $output = eregi_replace('&false;','&false;',$output);
        $output = eregi_replace('&null;','&null;',$output);

        $from = 
'/(<constant>)?(<literal>)?&(true|false|null);(<\/constant>)?(<\/literal>)?/';
        $to = "&\\3;";
        

        $output = preg_replace($from,$to,$output);


        $output = ereg_replace('<type>&null;</type>','<type>null</type>',$output);

        return $output;

}


Reply via email to