PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/2.4/tags/tools/build_data.php

http://drawshield.googlecode.com/
PHP | 147 lines | 113 code | 6 blank | 28 comment | 29 complexity | 1b2a1a40e31cced458ad63cac757b542 MD5 | raw file
  1. <?php /* Copyright 2010 Karl R. Wilcox
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. */
  11. function draw_message($category,$message) { echo $message; }
  12. function get_mod ( $node, $name ) { return null; }
  13. include '../svg/colour.inc';
  14. function include_charge () {
  15. $node = null;
  16. $charge = array();
  17. include_once func_get_arg(0);
  18. return $charge;
  19. }
  20. function include_ordinary () {
  21. $node = null;
  22. $ordinary = array();
  23. include_once func_get_arg(0);
  24. return $ordinary;
  25. }
  26. $node = null;
  27. $charges = array();
  28. $chg_mods = array();
  29. $ordinaries = array();
  30. $ord_mods = array();
  31. $either = array();
  32. $flags = array();
  33. // Go through charges
  34. $dir = opendir('../charges');
  35. echo "Building charges...\n";
  36. while ( ($subdir = readdir($dir)) != false ) {
  37. if ( $subdir{0} != '.' and is_dir('../charges/' . $subdir) ) {
  38. $ddir = opendir('../charges/' . $subdir );
  39. while ( ($file = readdir($ddir)) != false ) {
  40. if ( ($file{0} != '_') and substr($file,-4) == '.inc' ) {
  41. $type = $subdir;
  42. $subtype = substr($file,0,strlen($file)-4);
  43. //echo "\r$subtype";
  44. $charge = include_charge ( '../charges/' . $subdir . '/' . $file );
  45. $def_col = array();
  46. // Add this to the either list, for disambiguation?
  47. if ( array_key_exists ( 'either', $charge ) ) {
  48. foreach ( $charge['patterns'] as $pattern )
  49. $either[] = array ( $subtype, $pattern, $type, 'charge');
  50. } else {
  51. foreach ( $charge['patterns'] as $pattern ) {
  52. $charges[] = array ( $subtype, $pattern, $type, 'charge');
  53. }
  54. }
  55. if ( array_key_exists( 'modifiers' , $charge ) )
  56. $modifiers['c:' . $subtype] = $charge['modifiers'];
  57. if ( array_key_exists( 'flags' , $charge ) )
  58. $flags['c:' . $subtype] = $charge['flags'];
  59. }
  60. }
  61. }
  62. }
  63. echo "\rcompleted\n";
  64. // Go through ordinaries
  65. echo "Building ordinaries...";
  66. $dir = opendir('../ordinaries');
  67. while ( ($subdir = readdir($dir)) != false ) {
  68. if ( $subdir{0} != '.' and is_dir('../ordinaries/' . $subdir) ) {
  69. $ddir = opendir('../ordinaries/' . $subdir );
  70. while ( ($file = readdir($ddir)) != false ) {
  71. if ( ($file{0} != '_') and substr($file,-4) == '.inc' ) {
  72. $type = $subdir;
  73. $subtype = substr($file,0,strlen($file)-4);
  74. //echo "\r$subtype";
  75. $ordinary = include_ordinary ( '../ordinaries/' . $subdir . '/' . $file );
  76. // Add this to the either list, for disambiguation?
  77. if ( array_key_exists ( 'either', $ordinary ) ) {
  78. foreach ( $ordinary['patterns'] as $pattern ) {
  79. $found = false;
  80. for ( $i = 0; $i < count($either); $i++ ) {
  81. if ( strcmp($either[$i][1], $pattern) === 0 ) {
  82. $either[$i][3] = 'either';
  83. $either[$i][0] .= ':' . $subtype;
  84. $either[$i][2] .= ':' . $type;
  85. $found = true;
  86. break;
  87. }
  88. }
  89. if ( !$found )
  90. $either[] = array ( $subtype, $pattern, $type, 'ordinary' );
  91. }
  92. } else {
  93. foreach ( $ordinary['patterns'] as $pattern ) {
  94. $ordinaries[] = array ( $subtype, $pattern, $type );
  95. }
  96. }
  97. if ( array_key_exists( 'modifiers' , $ordinary ) )
  98. $modifiers['o:' . $subtype] = $ordinary['modifiers'];
  99. if ( array_key_exists( 'flags' , $ordinary ) )
  100. $flags['o:' . $subtype] = $ordinary['flags'];
  101. }
  102. }
  103. }
  104. }
  105. echo "\ncompleted\n";
  106. // Write out the data files
  107. echo "Writing files...";
  108. $fp = fopen('../parser/data/charge_list.dat','w');
  109. fwrite ( $fp, serialize($charges) );
  110. fclose ( $fp );
  111. unset ( $charges );
  112. $fp = fopen('../parser/data/modifier_list.dat','w');
  113. fwrite ( $fp, serialize($modifiers) );
  114. fclose($fp);
  115. unset ( $modifiers );
  116. $fp = fopen('../parser/data/ordinary_list.dat','w');
  117. fwrite ( $fp, serialize($ordinaries) );
  118. fclose($fp);
  119. unset ( $ordinaries );
  120. $fp = fopen('../parser/data/either_list.dat','w');
  121. fwrite ( $fp, serialize($either) );
  122. fclose($fp);
  123. unset ( $either );
  124. $fp = fopen('../parser/data/flag_list.dat','w');
  125. fwrite ( $fp, serialize($flags) );
  126. fclose($fp);
  127. unset ( $flags );
  128. echo "completed\n";
  129. /* Fudge if web server can't write to folder, open in web browser
  130. header("Content-Transfer-Encoding: text");
  131. header('Content-Type: text/plain');
  132. echo "charge_list\n";
  133. echo serialize($charges) . "\n";
  134. echo "modifier_list\n";
  135. echo serialize($modifiers) . "\n";
  136. echo "either_list\n";
  137. echo serialize($either) . "\n"; */
  138. ?>