Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $nen = array();
- include_once( 'nen.php' );
- nen_ini();
- include_once ( $nen[ 'root' ]. 'trk tok.php');
- include_once ( $nen[ 'root' ]. 'trk echo.php');
- include_once( $nen[ 'root' ]. 'fasttoc.php' );
- //cycle_sourcefiles();
- //cycle_pagedata();
- cfg_toc();
- function fastcfg( $buffer = '' )
- {
- global $nen;
- $lines = explode("\r\n", $buffer);
- $cfg = array();
- $index = 0;
- while(true)
- {
- if( $index > count( $lines ) - 1 )
- {
- break;
- }
- $temp = explode( ":", $lines[ $index ] );
- $label[ $index ] = $temp[ 0 ];
- unset( $temp[ 0 ] );
- $value[ $index ] = implode( ":", $temp );
- $cfg[ $label[ $index ] ] = $value[ $index ];
- $index++;
- }
- return $cfg;
- }
- function swapcfg()
- {
- global $nen;
- $buffer = file_get_contents( $nen[ 'root' ]. 'pcre/dungeon-put.swap.pcre' );
- $cfg = fastcfg( $buffer );
- foreach( $cfg as $seek_k => $seek_v )
- {
- foreach( $cfg as $replace_k => $replace_v )
- {
- if( preg_match( '/swap\.([A-Z0-9]+)/', $replace_k, $replace_matches ) )
- {
- if( preg_match( '/\{\{swap\.('. $replace_matches[ 1 ]. ')\}\}/', $seek_v, $seek_matches ) )
- {
- $cfg[ $seek_k ] = str_replace( '{{swap.'. $seek_matches[ 1 ]. '}}', $replace_v, $cfg[ $seek_k ] );
- }
- }
- }
- }
- return $cfg;
- }
- function cfg_slimmer()
- {
- $cfg = swapcfg();
- foreach( $cfg as $swap_key => $swap_value )
- {
- if(preg_match('/swap.([0-9]+)/',$swap_key,$swap_matches))
- {
- unset( $cfg[ 'swap.'. $swap_matches[ 1 ] ] );
- }
- }
- trk_echo2( 'cfg', $cfg );
- return $cfg;
- }
- function cfg_toc()
- {
- global $nen;
- $toc_index = 0;
- $toc_pattern = '/(DUN)([0-9]{3})(.BAS)/';
- $toc = fasttoc( 'miscdun/', array( '.bas', '.BAS' ) );
- $toc_result = '';
- $cfg = cfg_slimmer();
- $toc_lines=array();
- $result = '';
- while( preg_match( $toc_pattern, $toc[ $toc_index ], $toc_matches ) )
- {
- if( $toc_index > count( $toc ) - 1 )
- {
- break;
- }
- $toc_lines[ $toc_index ] = explode( "\r\n", file_get_contents( $nen[ 'root' ] . 'miscdun/' . $toc[ $toc_index ] ) );
- $lines_index = 0;
- while(true)
- {
- if( $lines_index > count( $toc_lines[ $toc_index ] ) - 1 )
- {
- break;
- }
- foreach( $cfg as $cfg_key => $cfg_value )
- {
- if( $lines_index > count( $toc_lines[ $toc_index ] ) - 1 )
- {
- break;
- }
- $cfg_index = 0;
- while(
- !preg_match( '/'.
- $cfg_value. '/',
- $toc_lines[ $toc_index ][ $lines_index ],
- $cfg_matches ) )
- {
- if ( $cfg_index > count( $cfg ) - 1 )
- {
- unset(
- $toc_lines
- [ $toc_index ]
- [ $lines_index ]
- );
- $lines_index;
- $toc_lines[ $toc_index ] =
- explode( "\r\n",
- implode( "\r\n",
- $toc_lines
- [ $toc_index ]
- ) );
- $cfg_index = 0;
- break;
- }
- $cfg_index++;
- }
- }
- $lines_index++;
- }
- file_put_contents( $nen[ 'root' ] . 'metaput/imap' . $toc_matches[ 2 ] . 'fb.dat', implode( "\r\n", $toc_lines[ $toc_index ] ) );
- $toc_index++;
- }
- }
- function cycle_pagedata()
- {
- global $nen;
- $toc = fasttoc( 'miscdun/', array( '.bas', '.BAS' ) );
- $cfg = cfg_slimmer();
- $index = 0;
- $pattern = '/(DUN)([0-9]{3})(.BAS)/';
- while( preg_match( $pattern, $toc[ $index ], $matches ) )
- {
- if( $index > count( $toc ) - 1 )
- {
- break;
- }
- file_put_contents( $nen[ 'root' ] . 'metaput/imap' . $matches[ 2 ] . 'fb.dat', swapcfg( file_get_contents( $nen[ 'root' ] . 'miscdun/' . $toc[ $index ] ) ) );
- $index++;
- }
- }
- function cycle_sourcefiles()
- {
- global $nen;
- $toc = fasttoc( 'miscdun/', array( '.bas', '.BAS' ) );
- $index = 0;
- $pattern = '/(DUN)([0-9]{3})(.BAS)/';
- while( preg_match( $pattern, $toc[ $index ], $matches ) )
- {
- if( $index > count( $toc ) - 1 )
- {
- break;
- }
- file_put_contents( $nen[ 'root' ] . 'metaput/imap' . $matches[ 2 ] . 'fb.dat', perform_regex( 'miscdun/' . $toc[ $index ] ));
- $index++;
- }
- }
- function perform_regex( $sourcefile = 'miscdun/DUN030.BAS' )
- {
- global $nen;
- $sourcecode = file_get_contents( $nen[ 'root' ]. $sourcefile );
- $pattern = '/'. file_get_contents( $nen[ 'root' ]. 'pcre/mkput.pattern.pcre' ). '/';
- $mask = file_get_contents( $nen[ 'root' ]. 'pcre/mkput.mask.pcre' );
- $ret='';
- while( preg_match( $pattern, $sourcecode, $matches ) )
- {
- $meta = $mask;
- $index = 1;
- while( true )
- {
- if( $index > count( $matches ) - 1 )
- {
- break;
- }
- $meta = str_replace( '{{'. $index. '}}', $matches[ $index ], $meta );
- $index++;
- }
- if( !isset( $ret ) )
- {
- $ret = $meta;
- }
- elseif( strlen( $meta ) > 0 )
- {
- $ret .= "\r\n". $meta;
- }
- $sourcecode = str_replace( $matches[ 0 ], '', $sourcecode );
- }
- if( !isset( $ret ) )
- {
- $ret = '';
- }
- $ret = trim( $ret );
- return $ret;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement