Pelzini

This is the code documentation for the Pelzini project

source of /processor/main.php

This is the main processor engine. It does all of the grunt-work of the processor
  1. <?php
  2. /*
  3. Copyright 2008 Josh Heidenreich
  4.  
  5. This file is part of Pelzini.
  6.  
  7. Pelzini is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. Pelzini is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Pelzini. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21.  
  22. /**
  23.  * This is the main processor engine. It does all of the grunt-work of the processor
  24.  *
  25.  * @package Processor
  26.  * @author Josh
  27.  * @since 0.1
  28.  **/
  29.  
  30. ini_set('memory_limit', '-1');
  31.  
  32. require_once 'functions.php';
  33. require_once 'constants.php';
  34.  
  35. output_status ('This is the Pelzini processor, Pelzini version ' . PELZINI_VERSION);
  36. output_status ('Pelzini is Copyright 2008 Josh Heidenreich, licenced under GPL 3');
  37. output_status ('For more information, see <a href="https://github.com/Karmabunny/pelzini">https://github.com/Karmabunny/pelzini</a>');
  38.  
  39. // Initialise each parser
  40. output_status ('');
  41. $parsers = array();
  42. $parsers['php'] = new PhpParser();
  43. output_status("Initialised the PHP parser.");
  44.  
  45. $parsers['js'] = new JavascriptParser();
  46. output_status("Initialised the Javascript parser.");
  47.  
  48. //$parsers['c'] = new CParser();
  49. //output_status("Initialised the (expermiental) C parser.");
  50.  
  51. foreach ($_SERVER['argv'] as $idx => $argument) {
  52. if ($idx == 0) continue;
  53. if ($argument == '--help') continue;
  54. if ($argument == '--config') continue;
  55.  
  56. $config = new Config();
  57. $result = $config->load($argument);
  58. if (! $result) continue;
  59.  
  60. $parser_model = array();
  61.  
  62. // Sync output database layout
  63. output_status ('');
  64. foreach ($config->getOutputters() as $outputter) {
  65. $outputter->check_layout(dirname(__FILE__) . '/database.layout');
  66. }
  67.  
  68. // Determine the file names
  69. output_status ('');
  70. output_status ("Getting filenames for parsing.");
  71. $file_names = get_filenames($config->getBaseDirectory(), '', $config->getExcludeDirectories());
  72. output_status ("Found " . count($file_names) . " files.");
  73.  
  74. // Process each file using its parser to build a code tree.
  75. output_status ('');
  76. output_status ('Processing files.');
  77. $success = 0;
  78. $failure = 0;
  79. foreach ($file_names as $file) {
  80. $parts = explode('.', $file);
  81. $ext = array_pop($parts);
  82.  
  83. if (isset($parsers[$ext]) and in_array($ext, $config->languages)) {
  84. output_status ("Processing file {$file}");
  85. $result = $parsers[$ext]->parseFile($config->getBaseDirectory(), $file);
  86.  
  87. if ($result != null) {
  88. $parser_model[] = $result;
  89. $success++;
  90. } else {
  91. output_status("ERROR: Processing of file {$file} failed!");
  92. $failure++;
  93. }
  94. }
  95. }
  96.  
  97. // Give a status output for the parsed files
  98. $total = $success + $failure;
  99. $noop = $total - count($file_names);
  100. output_status ('');
  101. output_status ("Processed {$total} file(s):");
  102. output_status (" {$success} file(s) were parsed successfully");
  103. output_status (" {$failure} file(s) failed to be parsed");
  104.  
  105. // Does processing of Javadoc tags
  106. // Ths should be hidden away somewhere, but meh
  107. foreach ($parser_model as $item) {
  108. if ($item instanceof ParserFile) {
  109. $item->treeWalk('process_javadoc_tags');
  110. }
  111. }
  112.  
  113. if ($config->getDocsDirectory() != '') {
  114. // Determine the file names for project documents
  115. output_status ('');
  116. output_status ("Getting filenames for project documents.");
  117. $file_names = get_filenames($config->getDocsDirectory(), '', array());
  118. output_status ("Found " . count($file_names) . " files.");
  119.  
  120. // Process each document, and add a ParserDocument
  121. output_status ('');
  122. output_status ('Processing files.');
  123. $success = 0;
  124. $failure = 0;
  125. foreach ($file_names as $file) {
  126. $file_parts = explode('.', basename($file));
  127. $ext = array_pop($file_parts);
  128. if ($ext != 'txt') continue;
  129. $content = file_get_contents($config->getDocsDirectory() . $file);
  130. if ($content == '') continue;
  131.  
  132. $doc = new ParserDocument ();
  133. $doc->name = implode('.', $file_parts);
  134. $doc->description = htmlify_text ($content);
  135. $parser_model[] = $doc;
  136. }
  137. }
  138.  
  139. // Transform the data model
  140. output_status ('');
  141. foreach ($config->getTransformers() as $transformer) {
  142. output_status ('Running ' . get_class($transformer));
  143.  
  144. $result = $transformer->transform($parser_model);
  145.  
  146. if ($result) {
  147. output_status ('Processed transformer ' . get_class($transformer) . ' successfully');
  148. $parser_model = $result;
  149. }
  150. }
  151.  
  152. // Output the generated tree to the specified outputters
  153. output_status ('');
  154. foreach ($config->getOutputters() as $outputter) {
  155. output_status ('Running ' . get_class($outputter));
  156.  
  157. $result = $outputter->output($parser_model, $config);
  158.  
  159. if ($result) {
  160. output_status ('Processed outputter ' . get_class($outputter) . ' successfully');
  161. }
  162. }
  163. }
  164.