Changeset 228
- Timestamp:
- 08/02/06 12:19:44 (2 years ago)
- Files:
-
- trunk/build/mkdist.php (modified) (1 diff)
- trunk/build/preprocess.php (modified) (1 diff)
- trunk/build/preprocessor.lib.php (modified) (6 diffs)
- trunk/build/tests/ppdatas/result5_1.txt (modified) (1 diff)
- trunk/build/tests/ppdatas/result5_2.txt (modified) (1 diff)
- trunk/build/tests/ppdatas/result_define.txt (added)
- trunk/build/tests/ppdatas/result_define2.txt (added)
- trunk/build/tests/ppdatas/source5.txt (modified) (1 diff)
- trunk/build/tests/ppdatas/source_define.txt (added)
- trunk/build/tests/ppdatas/source_define2.txt (added)
- trunk/build/tests/testpreprocess.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/mkdist.php
r165 r228 98 98 99 99 $preproc->setVars($_SERVER); 100 $contents = $preproc-> run(file_get_contents($sourcedir.$currentsrcdir.$m[2]));100 $contents = $preproc->parseFile($sourcedir.$currentsrcdir.$m[2]); 101 101 if($contents===false){ 102 102 echo "$ficlist : line $nbline, cannot process file ".$m[2]." (error code=".$preproc->errorCode." line=".$preproc->errorLine.")\n"; trunk/build/preprocess.php
r165 r228 55 55 56 56 57 $source = file_get_contents($sourcefile);58 59 57 $proc = new jPreProcessor(); 60 58 $proc->setVars($_SERVER); 61 $dist = $proc-> run($source);59 $dist = $proc->parseFile($sourcefile); 62 60 63 61 trunk/build/preprocessor.lib.php
r82 r228 32 32 const ERR_SYNTAX = 1; 33 33 const ERR_IF_MISSING = 2; 34 const ERR_ENDIF_MISSING = 2; 34 35 35 36 … … 50 51 } 51 52 52 public function run($sourceContent){53 public function parseFile($filename){ 53 54 $this->errorCode=0; 54 55 $this->errorLine=0; 56 $this->_blockstack = array(); 57 58 // on sauve les variables pour les retrouver intact apr�le parsing 59 // de fa� �ouvoir r�ecuter plusieurs fois run sur des contenus diff�nts 55 60 $this->_savedVariables= $this->_variables; 56 $source =explode("\n",$sourceContent); 61 62 $source =explode("\n",file_get_contents($filename)); 57 63 58 64 $result=''; 65 // on parcours chaque ligne du source 59 66 foreach($source as $nb=>$line){ 60 if(preg_match('/^\#(ifdef|expand|define|ifndef|elifdef)\s+([^\s]*)\s*$/m',$line,$m)){ 67 $isOpen = !(end($this->_blockstack) & self::BLOCK_NO); 68 69 if(preg_match('/^\#(ifdef|define|ifndef|elifdef|undef)\s+(\w+)\s*$/m',$line,$m)){ 61 70 switch($m[1]){ 62 71 case 'ifdef': 63 $end = end($this->_blockstack); 64 if( $end & self::BLOCK_NO ){ 72 if( !$isOpen ){ 65 73 array_push($this->_blockstack, self::BLOCK_IF_NO); 66 74 }else{ … … 73 81 $source[$nb]=false; 74 82 break; 75 case 'define': 76 /*if(preg_match('/^(\w+)(?:\s+(\w+))?$/m',$m[2],$m2)){ 77 78 }else{ 79 80 81 }*/ 83 case 'define': // define avec un seul argument. 84 if($isOpen ){ 85 $this->_variables[$m[2]] = ''; 86 } 87 $source[$nb]=false; 88 break; 89 case 'undef': 90 if($isOpen ){ 91 unset($this->_variables[$m[2]]); 92 } 82 93 $source[$nb]=false; 83 94 break; 84 95 case 'ifndef': 85 if( end($this->_blockstack) & self::BLOCK_NO){96 if(!$isOpen){ 86 97 array_push($this->_blockstack, self::BLOCK_IF_NO); 87 98 }else{ … … 116 127 var_dump($this->_blockstack); 117 128 echo "\n";*/ 118 129 130 }elseif(preg_match('/^\#(define)\s+(\w+)\s+(.+)$/m',$line,$m)){ 131 // define avec deux arguments 132 if($isOpen){ 133 $this->_variables[$m[2]] = trim($m[3]); 134 } 135 $source[$nb]=false; 136 119 137 }elseif(preg_match('/^\#(expand)\s(.*)$/m',$line,$m)){ 120 if( ! (end($this->_blockstack) & self::BLOCK_NO)){138 if($isOpen){ 121 139 $source[$nb]=preg_replace('/\_\_(\w*)\_\_/e', '(isset($this->_variables["\\1"])?$this->_variables["\\1"]:"__\\1__")',$m[2]); 122 140 }else{ 123 141 $source[$nb]=false; 124 142 } 125 126 143 127 144 }elseif(preg_match('/^\#(endif|else)\s*$/m',$line,$m)){ … … 151 168 } 152 169 }else{ 153 if( end($this->_blockstack) & self::BLOCK_NO){170 if(!$isOpen){ 154 171 $source[$nb]=false; 155 172 } … … 163 180 } 164 181 182 if(count($this->_blockstack)) 183 return $this->doError($nb,self::ERR_ENDIF_MISSING); 184 165 185 $this->_variables = $this->_savedVariables; 166 186 167 187 return $result; 168 //return implode("\n",$source);169 188 } 170 189 trunk/build/tests/ppdatas/result5_1.txt
r82 r228 6 6 7 7 voici le contenu de FOO : "__FOO__" et celui de BAR : __BAR__ 8 8 toto 9 9 ffffff trunk/build/tests/ppdatas/result5_2.txt
r82 r228 6 6 7 7 voici le contenu de FOO : "une variable foo" et celui de BAR : le bar est ouvert 8 8 toto 9 9 ffffff trunk/build/tests/ppdatas/source5.txt
r82 r228 10 10 11 11 #expand voici le contenu de FOO : "__FOO__" et celui de BAR : __BAR__ 12 12 #expand toto 13 13 ffffff trunk/build/tests/testpreprocess.php
r82 r228 56 56 'result7_5.txt'=>array('BAZ'=>true, 'BAR'=>true), 57 57 ), 58 'source_define.txt'=>array( 59 'result_define.txt'=>array('FOO'=>true), 60 ), 61 'source_define2.txt'=>array( 62 'result_define2.txt'=>array('FOO'=>'ok'), 63 ), 58 64 ); 59 65 … … 72 78 $proc = new jPreProcessor(); 73 79 foreach($this->testcase as $source=>$datas){ 74 $contents = file_get_contents(PP_DATA_DIR.$source);75 80 foreach($datas as $result=>$vars){ 76 81 $proc->setVars($vars); 77 $res = $proc-> run($contents);82 $res = $proc->parseFile(PP_DATA_DIR.$source); 78 83 $this->assertEqual($res, file_get_contents(PP_DATA_DIR.$result)); 79 84 }
