Advertisement
jargon

Dungeon XAMPP-Builder 2021-0921-1940

Sep 21st, 2021
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.95 KB | None | 0 0
  1. <?php
  2.  
  3. $nen = array();
  4. include_once( 'nen.php' );
  5.  
  6. nen_ini();
  7.  
  8. include_once ( $nen[ 'root' ]. 'trk tok.php');
  9. include_once ( $nen[ 'root' ]. 'trk echo.php');
  10. include_once( $nen[ 'root' ]. 'fasttoc.php' );
  11.  
  12. //cycle_sourcefiles();
  13.  
  14. //cycle_pagedata();
  15. cfg_toc();
  16.  
  17. function fastcfg( $buffer = '' )
  18. {
  19.     global $nen;
  20.  
  21.     $lines = explode("\r\n", $buffer);
  22.    
  23.     $cfg = array();
  24.    
  25.     $index = 0;
  26.     while(true)
  27.     {
  28.         if( $index > count( $lines ) - 1 )
  29.         {
  30.             break;
  31.         }
  32.        
  33.         $temp = explode( ":", $lines[ $index ] );
  34.         $label[ $index ] = $temp[ 0 ];
  35.        
  36.         unset( $temp[ 0 ] );
  37.        
  38.         $value[ $index ] = implode( ":", $temp );
  39.        
  40.         $cfg[ $label[ $index ] ] = $value[ $index ];
  41.        
  42.         $index++;
  43.     }
  44.    
  45.     return $cfg;
  46.    
  47. }
  48.  
  49. function swapcfg()
  50. {
  51.     global $nen;
  52.    
  53.     $buffer = file_get_contents( $nen[ 'root' ]. 'pcre/dungeon-put.swap.pcre' );
  54.    
  55.     $cfg = fastcfg( $buffer );
  56.    
  57.     foreach( $cfg as $seek_k => $seek_v )
  58.     {
  59.         foreach( $cfg as $replace_k => $replace_v )
  60.         {
  61.             if( preg_match( '/swap\.([A-Z0-9]+)/', $replace_k, $replace_matches ) )
  62.             {
  63.                 if( preg_match( '/\{\{swap\.('. $replace_matches[ 1 ]. ')\}\}/', $seek_v, $seek_matches ) )
  64.                 {
  65.                     $cfg[ $seek_k ] = str_replace( '{{swap.'. $seek_matches[ 1 ]. '}}', $replace_v, $cfg[ $seek_k ] );
  66.                 }
  67.             }
  68.         }
  69.     }
  70.        
  71.     return $cfg;
  72. }
  73.  
  74. function cfg_slimmer()
  75. {
  76.     $cfg = swapcfg();
  77.  
  78.     foreach( $cfg as $swap_key => $swap_value )
  79.     {
  80.         if(preg_match('/swap.([0-9]+)/',$swap_key,$swap_matches))
  81.         {
  82.             unset( $cfg[ 'swap.'. $swap_matches[ 1 ] ] );
  83.         }
  84.     }
  85.    
  86.     trk_echo2( 'cfg', $cfg );
  87.  
  88.     return $cfg;
  89. }
  90.    
  91. function cfg_toc()
  92. {
  93.     global $nen;
  94.    
  95.     $toc_index = 0;
  96.     $toc_pattern = '/(DUN)([0-9]{3})(.BAS)/';
  97.    
  98.     $toc = fasttoc( 'miscdun/', array( '.bas', '.BAS' ) );
  99.  
  100.     $toc_result = '';
  101.    
  102.     $cfg = cfg_slimmer();
  103.    
  104.     $toc_lines=array();
  105.    
  106.     $result = '';
  107.    
  108.     while( preg_match( $toc_pattern, $toc[ $toc_index ], $toc_matches ) )
  109.     {
  110.         if( $toc_index > count( $toc ) - 1 )
  111.         {
  112.             break;
  113.         }
  114.  
  115.         $toc_lines[ $toc_index ] = explode( "\r\n", file_get_contents( $nen[ 'root' ] . 'miscdun/' . $toc[ $toc_index ] ) );
  116.        
  117.         $lines_index = 0;
  118.         while(true)
  119.         {          
  120.             if( $lines_index > count( $toc_lines[ $toc_index ] ) - 1 )
  121.             {
  122.                 break;
  123.             }
  124.            
  125.             foreach( $cfg as $cfg_key => $cfg_value )
  126.             {              
  127.                 if( $lines_index > count( $toc_lines[ $toc_index ] ) - 1 )
  128.                 {
  129.                     break;
  130.                 }
  131.                 $cfg_index = 0;
  132.                 while(
  133.                 !preg_match( '/'.
  134.                 $cfg_value. '/',
  135.                 $toc_lines[ $toc_index ][ $lines_index ],
  136.                 $cfg_matches ) )
  137.                 {
  138.                                                            
  139.                     if ( $cfg_index > count( $cfg ) - 1 )
  140.                     {
  141.                         unset(
  142.                         $toc_lines
  143.                         [ $toc_index ]
  144.                         [ $lines_index ]
  145.                         );
  146.                         $lines_index;
  147.                        
  148.                         $toc_lines[ $toc_index ] =
  149.                         explode( "\r\n",
  150.                             implode( "\r\n",
  151.                             $toc_lines
  152.                             [ $toc_index ]
  153.                         ) );
  154.                         $cfg_index = 0;
  155.                        
  156.                         break;
  157.                     }
  158.                    
  159.                     $cfg_index++;
  160.                 }
  161.             }      
  162.  
  163.             $lines_index++;
  164.         }
  165.        
  166.         file_put_contents( $nen[ 'root' ] . 'metaput/imap' . $toc_matches[ 2 ] . 'fb.dat', implode( "\r\n", $toc_lines[ $toc_index ] ) );
  167.        
  168.         $toc_index++;
  169.     }
  170.  
  171. }
  172.  
  173. function cycle_pagedata()
  174. {
  175.     global $nen;
  176.  
  177.     $toc = fasttoc( 'miscdun/', array( '.bas', '.BAS' ) );
  178.    
  179.     $cfg = cfg_slimmer();
  180.    
  181.     $index = 0;
  182.     $pattern = '/(DUN)([0-9]{3})(.BAS)/';
  183.                
  184.     while( preg_match( $pattern, $toc[ $index ], $matches ) )
  185.     {
  186.         if( $index > count( $toc ) - 1 )
  187.         {
  188.             break;
  189.         }
  190.                    
  191.         file_put_contents( $nen[ 'root' ] . 'metaput/imap' . $matches[ 2 ] . 'fb.dat', swapcfg( file_get_contents( $nen[ 'root' ] . 'miscdun/' . $toc[ $index ] ) ) );
  192.        
  193.         $index++;
  194.     }
  195.        
  196. }
  197.  
  198.  
  199. function cycle_sourcefiles()
  200. {
  201.     global $nen;
  202.  
  203.     $toc = fasttoc( 'miscdun/', array( '.bas', '.BAS' ) );
  204.    
  205.     $index = 0;
  206.     $pattern = '/(DUN)([0-9]{3})(.BAS)/';
  207.                
  208.     while( preg_match( $pattern, $toc[ $index ], $matches ) )
  209.     {
  210.         if( $index > count( $toc ) - 1 )
  211.         {
  212.             break;
  213.         }
  214.                    
  215.         file_put_contents( $nen[ 'root' ] . 'metaput/imap' . $matches[ 2 ] . 'fb.dat', perform_regex( 'miscdun/' . $toc[ $index ] ));
  216.        
  217.         $index++;
  218.     }
  219.        
  220. }
  221. function perform_regex( $sourcefile = 'miscdun/DUN030.BAS' )
  222. {  
  223.     global $nen;
  224.    
  225.     $sourcecode = file_get_contents( $nen[ 'root' ]. $sourcefile );
  226.    
  227.     $pattern = '/'. file_get_contents( $nen[ 'root' ]. 'pcre/mkput.pattern.pcre' ). '/';
  228.    
  229.     $mask = file_get_contents( $nen[ 'root' ]. 'pcre/mkput.mask.pcre' );
  230.    
  231.     $ret='';
  232.    
  233.     while( preg_match( $pattern, $sourcecode, $matches ) )
  234.     {
  235.         $meta = $mask;
  236.         $index = 1;
  237.        
  238.         while( true )
  239.         {
  240.             if( $index > count( $matches ) - 1 )
  241.             {
  242.                 break;
  243.             }
  244.            
  245.             $meta = str_replace( '{{'. $index. '}}', $matches[ $index ], $meta );
  246.            
  247.             $index++;
  248.         }
  249.        
  250.         if( !isset( $ret ) )
  251.         {
  252.             $ret = $meta;
  253.         }
  254.         elseif( strlen( $meta ) > 0 )
  255.         {
  256.             $ret .= "\r\n". $meta;
  257.         }
  258.         $sourcecode = str_replace( $matches[ 0 ], '', $sourcecode );
  259.     }
  260.  
  261.     if( !isset( $ret ) )
  262.     {
  263.         $ret = '';
  264.     }
  265.    
  266.     $ret = trim( $ret );
  267.    
  268.     return $ret;
  269. }
  270. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement