Reformat source code: doc
authorgggeek <giunta.gaetano@gmail.com>
Sat, 21 Feb 2015 18:58:18 +0000 (18:58 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 21 Feb 2015 18:58:18 +0000 (18:58 +0000)
doc/convert.php
doc/custom.fo.xsl
doc/custom.xsl
doc/highlight.php

index 4de3b44..a811c4e 100644 (file)
@@ -1,57 +1,56 @@
 <?php
 /**
- * Script used to convert docbook source to human readable docs
+ * Script used to convert docbook source to human readable docs.
  *
  * @copyright (c) 2007-2014 G. Giunta
  */
-
-if ($_SERVER['argc'] < 4)
+if ($_SERVER['argc'] < 4) {
     die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
-else
+} else {
     echo "Starting xsl conversion process...\n";
+}
 
 $doc = $_SERVER['argv'][1];
 $xss = $_SERVER['argv'][2];
 
-if (!file_exists($doc))
+if (!file_exists($doc)) {
     die("KO: file $doc cannot be found\n");
-if (!file_exists($xss))
+}
+if (!file_exists($xss)) {
     die("KO: file $xss cannot be found\n");
+}
 
 // Load the XML source
-$xml = new DOMDocument;
+$xml = new DOMDocument();
 $xml->load($doc);
-$xsl = new DOMDocument;
+$xsl = new DOMDocument();
 $xsl->load($xss);
 
 // Configure the transformer
-$proc = new XSLTProcessor;
-if (version_compare(PHP_VERSION,'5.4',"<"))
-{
-    if(defined('XSL_SECPREF_WRITE_FILE'))
+$proc = new XSLTProcessor();
+if (version_compare(PHP_VERSION, '5.4', "<")) {
+    if (defined('XSL_SECPREF_WRITE_FILE')) {
         ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
-}
-else
-{
+    }
+} else {
     $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
 }
 $proc->importStyleSheet($xsl); // attach the xsl rules
 
 //if ($_SERVER['argc'] >= 4)
 //{
-    if (is_dir($_SERVER['argv'][3]))
-    {
-        if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3])))
-            echo "setting param base.dir KO\n";
-    }
-    else
-    {
-        //echo "{$_SERVER['argv'][3]} is not a dir\n";
+if (is_dir($_SERVER['argv'][3])) {
+    if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3]))) {
+        echo "setting param base.dir KO\n";
     }
+} else {
+    //echo "{$_SERVER['argv'][3]} is not a dir\n";
+}
 //}
 
 $out = $proc->transformToXML($xml);
-if (!is_dir($_SERVER['argv'][3]))
+if (!is_dir($_SERVER['argv'][3])) {
     file_put_contents($_SERVER['argv'][3], $out);
+}
 
 echo "OK\n";
index f87d974..5459826 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version='1.0'?>\r
 <xsl:stylesheet\r
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"\r
-       xmlns:fo="http://www.w3.org/1999/XSL/Format">\r
+    xmlns:fo="http://www.w3.org/1999/XSL/Format">\r
 <!--\r
  Customization xsl stylesheet for docbook to pdf transform\r
  @author Gaetano Giunta\r
index d38d2c7..b362d42 100644 (file)
@@ -70,7 +70,7 @@
     </xsl:when>\r
     <xsl:otherwise>\r
       <code>\r
-       <xsl:apply-templates mode="ansi-nontabular"/>\r
+        <xsl:apply-templates mode="ansi-nontabular"/>\r
       </code>\r
     </xsl:otherwise>\r
   </xsl:choose>\r
index b8afda1..82afde5 100644 (file)
@@ -1,46 +1,43 @@
 <?php
 /**
- * takes a dir as arg, highlights all php code found in html files inside
+ * takes a dir as arg, highlights all php code found in html files inside.
  *
  * @author Gaetano Giunta
  * @copyright (c) 2007-2014 G. Giunta
  */
-
 function highlight($file)
 {
-  $starttag = '<pre class="programlisting">';
-  $endtag = '</pre>';
+    $starttag = '<pre class="programlisting">';
+    $endtag = '</pre>';
 
-  $content = file_get_contents($file);
-  $last = 0;
-  $out = '';
-  while(($start = strpos($content, $starttag, $last)) !== false)
-  {
-    $end = strpos($content, $endtag, $start);
-    $code = substr($content, $start+strlen($starttag), $end-$start-strlen($starttag));
-    if ($code[strlen($code)-1] == "\n") {
-        $code = substr($code, 0, -1);
-    }
+    $content = file_get_contents($file);
+    $last = 0;
+    $out = '';
+    while (($start = strpos($content, $starttag, $last)) !== false) {
+        $end = strpos($content, $endtag, $start);
+        $code = substr($content, $start + strlen($starttag), $end - $start - strlen($starttag));
+        if ($code[strlen($code) - 1] == "\n") {
+            $code = substr($code, 0, -1);
+        }
 //var_dump($code);
-    $code = str_replace(array('&gt;', '&lt;'), array('>', '<'), $code);
-    $code = highlight_string('<?php '.$code, true);
-    $code = str_replace('<span style="color: #0000BB">&lt;?php&nbsp;<br />', '<span style="color: #0000BB">', $code);
+        $code = str_replace(array('&gt;', '&lt;'), array('>', '<'), $code);
+        $code = highlight_string('<?php ' . $code, true);
+        $code = str_replace('<span style="color: #0000BB">&lt;?php&nbsp;<br />', '<span style="color: #0000BB">', $code);
 //echo($code);
-    $out = $out . substr($content, $last, $start+strlen($starttag)-$last) . $code . $endtag;
-    $last = $end+strlen($endtag);
-  }
-  $out .= substr($content, $last, strlen($content));
-  return $out;
+        $out = $out . substr($content, $last, $start + strlen($starttag) - $last) . $code . $endtag;
+        $last = $end + strlen($endtag);
+    }
+    $out .= substr($content, $last, strlen($content));
+
+    return $out;
 }
 
 $dir = $argv[1];
 
 $files = scandir($dir);
-foreach($files as $file)
-{
-    if (substr($file, -5, 5) == '.html')
-    {
-        $out = highlight($dir.'/'.$file);
-        file_put_contents($dir.'/'.$file, $out);
+foreach ($files as $file) {
+    if (substr($file, -5, 5) == '.html') {
+        $out = highlight($dir . '/' . $file);
+        file_put_contents($dir . '/' . $file, $out);
     }
 }