cvs: peardoc / colorize.php

From: Date: Sun, 13 Jan 2002 16:49:17 +0000
Subject: cvs: peardoc / colorize.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1922@lists.php.net to get a copy of this message
cox Sun Jan 13 11:49:17 2002 EDT Modified files: /peardoc colorize.php Log: - Fix for not processing all the files - Added the ability to process only one file Index: peardoc/colorize.php diff -u peardoc/colorize.php:1.2 peardoc/colorize.php:1.3 --- peardoc/colorize.php:1.2 Sat Dec 29 10:10:49 2001 +++ peardoc/colorize.php Sun Jan 13 11:49:16 2002 @@ -1,14 +1,20 @@ #!/usr/bin/php -Cq <?php error_reporting(E_ALL); -$HTML_PATH = @$argv[1]; -$FANCY_PATH = @$argv[2]; -if (empty($HTML_PATH)) { +$orig = @$argv[1]; +if (is_dir($orig)) { + $fancyFunc = 'generateFancyFiles'; + $dest = (isset($argv[2])) ? $argv[2] : $orig; +} elseif (is_file($orig)) { + $fancyFunc = 'generateFancyFile'; + $dest = (isset($argv[2])) ? $argv[2] : dirname($orig); +} else { die("Missing html sources\n"); } -if (empty($FANCY_PATH)) { - die("Missing destination directory\n"); + +if (!is_dir($dest)) { + mkdir($dest, 0555); } ini_set('highlight.string', '#007F00'); @@ -18,8 +24,8 @@ ini_set('highlight.default', '#0000BB'); ini_set('highlight.html', '#000000'); -$counter = generateFancyFiles($HTML_PATH, $FANCY_PATH); -echo "Highlight of $HTML_PATH files under $FANCY_PATH done\n"; +$counter = $fancyFunc($orig, $dest); +echo "Highlight of $orig in $dest done ($counter files processed)\n"; // Generate all the fancy files function generateFancyFiles($htmldir, $fancydir) @@ -27,16 +33,13 @@ // How many files were processed $counter = 0; - // Create directory, if absent - if (!@is_dir($fancydir)) { mkdir($fancydir, 0555); } - // Open the directory, and do the work on all HTML files if (!$handle = opendir($htmldir)) { die("Could not open dir '$htmldir'"); } while (false !== ($filename = readdir($handle))) { // Only process html or PHP files, skip r9045.html kind of files (no content) - if ((strpos($filename, ".php") || strpos($filename, ".php")) && !preg_match("!^r\\d+\\.html$!", $filename)) { + if ((ereg('.php$', $filename) || ereg('.html$', $filename)) && !preg_match("!^r\\d+\\.html$!", $filename)) { $counter++; newFace($htmldir, $fancydir, $filename); } @@ -45,6 +48,13 @@ return $counter; } // generateFancyFiles() function end +// Generate one fancy file in the dest dir +function generateFancyFile($orig, $dest) +{ + newFace(dirname($orig), $dest, basename($orig)); + return 1; +} + // Apply the new face to the given file function newFace ($htmldir, $fancydir, $filename) { @@ -64,6 +74,7 @@ fclose($fp); } // newFace() function end + // Change examples look function formatExample ()

« previous php.pear.cvs (#1922) next »