| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
class MiniTemplator { |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
var $subtemplateBasePath; |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
var $maxNestingLevel = 50; |
|---|
| 93 |
var $maxInclTemplateSize = 1000000; |
|---|
| 94 |
var $template; |
|---|
| 95 |
var $varTab; |
|---|
| 96 |
// Fields: |
|---|
| 97 |
// varName // variable name |
|---|
| 98 |
// varValue // variable value |
|---|
| 99 |
var $varTabCnt; |
|---|
| 100 |
var $varNameToNoMap; |
|---|
| 101 |
var $varRefTab; |
|---|
| 102 |
// Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
|---|
| 103 |
// Fields: |
|---|
| 104 |
// varNo // variable no |
|---|
| 105 |
// tPosBegin // template position of begin of variable reference |
|---|
| 106 |
// tPosEnd // template position of end of variable reference |
|---|
| 107 |
// blockNo // block no of the (innermost) block that contains this variable reference |
|---|
| 108 |
// blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
|---|
| 109 |
var $varRefTabCnt; |
|---|
| 110 |
var $blockTab; |
|---|
| 111 |
// Contains an entry for each block in the template. Ordered by TPosBegin. |
|---|
| 112 |
// Fields: |
|---|
| 113 |
// blockName // block name |
|---|
| 114 |
// nextWithSameName; // block no of next block with same name or -1 (blocks are backward linked in relation to template position) |
|---|
| 115 |
// tPosBegin // template position of begin of block |
|---|
| 116 |
// tPosContentsBegin // template pos of begin of block contents |
|---|
| 117 |
// tPosContentsEnd // template pos of end of block contents |
|---|
| 118 |
// tPosEnd // template position of end of block |
|---|
| 119 |
// nestingLevel // block nesting level |
|---|
| 120 |
// parentBlockNo // block no of parent block |
|---|
| 121 |
// definitionIsOpen // true while $BeginBlock processed but no $EndBlock |
|---|
| 122 |
// instances // number of instances of this block |
|---|
| 123 |
// firstBlockInstNo // block instance no of first instance of this block or -1 |
|---|
| 124 |
// lastBlockInstNo // block instance no of last instance of this block or -1 |
|---|
| 125 |
// currBlockInstNo // current block instance no, used during generation of output file |
|---|
| 126 |
// blockVarCnt // no of variables in block |
|---|
| 127 |
// blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
|---|
| 128 |
// firstVarRefNo // variable reference no of first variable of this block or -1 |
|---|
| 129 |
var $blockTabCnt; |
|---|
| 130 |
var $blockNameToNoMap; |
|---|
| 131 |
var $openBlocksTab; |
|---|
| 132 |
|
|---|
| 133 |
// Indexed by the block nesting level. |
|---|
| 134 |
var $blockInstTab; |
|---|
| 135 |
// This table contains an entry for each block instance that has been added. |
|---|
| 136 |
// Indexed by BlockInstNo. |
|---|
| 137 |
// Fields: |
|---|
| 138 |
// blockNo // block number |
|---|
| 139 |
// instanceLevel // instance level of this block |
|---|
| 140 |
// InstanceLevel is an instance counter per block. |
|---|
| 141 |
// (In contrast to blockInstNo, which is an instance counter over the instances of all blocks) |
|---|
| 142 |
// parentInstLevel // instance level of parent block |
|---|
| 143 |
// nextBlockInstNo // pointer to next instance of this block or -1 |
|---|
| 144 |
// Forward chain for instances of same block. |
|---|
| 145 |
// blockVarTab // block instance variables |
|---|
| 146 |
var $blockInstTabCnt; |
|---|
| 147 |
|
|---|
| 148 |
var $currentNestingLevel; |
|---|
| 149 |
var $templateValid; |
|---|
| 150 |
var $outputMode; |
|---|
| 151 |
var $outputFileHandle; |
|---|
| 152 |
var $outputError; |
|---|
| 153 |
var $outputString; |
|---|
| 154 |
|
|---|
| 155 |
/**#@-*/ |
|---|
| 156 |
|
|---|
| 157 |
//--- constructor --------------------------------------------------------------------------------------------------- |
|---|
| 158 |
|
|---|
| 159 |
/** |
|---|
| 160 |
* Constructs a MiniTemplator object. |
|---|
| 161 |
* @access public |
|---|
| 162 |
*/ |
|---|
| 163 |
function MiniTemplator() { |
|---|
| 164 |
$this->templateValid = false; } |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
function readTemplateFromFile ($fileName) { |
|---|
| 175 |
if (!$this->readFileIntoString($fileName,$s)) { |
|---|
| 176 |
$this->triggerError ("Error while reading template file " . $fileName . "."); |
|---|
| 177 |
return false; } |
|---|
| 178 |
if (!$this->setTemplateString($s)) return false; |
|---|
| 179 |
return true; } |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
function setTemplateString ($templateString) { |
|---|
| 188 |
$this->templateValid = false; |
|---|
| 189 |
$this->template = $templateString; |
|---|
| 190 |
if (!$this->parseTemplate()) return false; |
|---|
| 191 |
$this->reset(); |
|---|
| 192 |
$this->templateValid = true; |
|---|
| 193 |
return true; } |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
function loadSubtemplate ($subtemplateName, &$s) { |
|---|
| 201 |
$subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath,$subtemplateName); |
|---|
| 202 |
if (!$this->readFileIntoString($subtemplateFileName,$s)) { |
|---|
| 203 |
$this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . "."); |
|---|
| 204 |
return false; } |
|---|
| 205 |
return true; } |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
function parseTemplate() { |
|---|
| 215 |
$this->initParsing(); |
|---|
| 216 |
$this->beginMainBlock(); |
|---|
| 217 |
if (!$this->parseTemplateCommands()) return false; |
|---|
| 218 |
$this->endMainBlock(); |
|---|
| 219 |
if (!$this->checkBlockDefinitionsComplete()) return false; |
|---|
| 220 |
if (!$this->parseTemplateVariables()) return false; |
|---|
| 221 |
$this->associateVariablesWithBlocks(); |
|---|
| 222 |
return true; } |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
function initParsing() { |
|---|
| 228 |
$this->varTab = array(); |
|---|
| 229 |
$this->varTabCnt = 0; |
|---|
| 230 |
$this->varNameToNoMap = array(); |
|---|
| 231 |
$this->varRefTab = array(); |
|---|
| 232 |
$this->varRefTabCnt = 0; |
|---|
| 233 |
$this->blockTab = array(); |
|---|
| 234 |
$this->blockTabCnt = 0; |
|---|
| 235 |
$this->blockNameToNoMap = array(); |
|---|
| 236 |
$this->openBlocksTab = array(); } |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
function beginMainBlock() { |
|---|
| 244 |
$blockNo = 0; |
|---|
| 245 |
$this->registerBlock('@@InternalMainBlock@@', $blockNo); |
|---|
| 246 |
$bte =& $this->blockTab[$blockNo]; |
|---|
| 247 |
$bte['tPosBegin'] = 0; |
|---|
| 248 |
$bte['tPosContentsBegin'] = 0; |
|---|
| 249 |
$bte['nestingLevel'] = 0; |
|---|
| 250 |
$bte['parentBlockNo'] = -1; |
|---|
| 251 |
$bte['definitionIsOpen'] = true; |
|---|
| 252 |
$this->openBlocksTab[0] = $blockNo; |
|---|
| 253 |
$this->currentNestingLevel = 1; } |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
function endMainBlock() { |
|---|
| 260 |
$bte =& $this->blockTab[0]; |
|---|
| 261 |
$bte['tPosContentsEnd'] = strlen($this->template); |
|---|
| 262 |
$bte['tPosEnd'] = strlen($this->template); |
|---|
| 263 |
$bte['definitionIsOpen'] = false; |
|---|
| 264 |
$this->currentNestingLevel -= 1; } |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
function parseTemplateCommands() { |
|---|
| 272 |
$p = 0; |
|---|
| 273 |
while (true) { |
|---|
| 274 |
$p0 = strpos($this->template,'<!--',$p); |
|---|
| 275 |
if ($p0 === false) break; |
|---|
| 276 |
$p = strpos($this->template,'-->',$p0); |
|---|
| 277 |
if ($p === false) { |
|---|
| 278 |
$this->triggerError ("Invalid HTML comment in template at offset $p0."); |
|---|
| 279 |
return false; } |
|---|
| 280 |
$p += 3; |
|---|
| 281 |
$cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|---|
| 282 |
if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|---|
| 283 |
return false; |
|---|
| 284 |
if ($resumeFromStart) $p = $p0; } |
|---|
| 285 |
return true; } |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
function processTemplateCommand ($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) { |
|---|
| 292 |
$resumeFromStart = false; |
|---|
| 293 |
$p = 0; |
|---|
| 294 |
$cmd = ''; |
|---|
| 295 |
if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
|---|
| 296 |
$parms = substr($cmdL,$p); |
|---|
| 297 |
switch (strtoupper($cmd)) { |
|---|
| 298 |
case '$BEGINBLOCK': |
|---|
| 299 |
if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|---|
| 300 |
return false; |
|---|
| 301 |
break; |
|---|
| 302 |
case '$ENDBLOCK': |
|---|
| 303 |
if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|---|
| 304 |
return false; |
|---|
| 305 |
break; |
|---|
| 306 |
case '$INCLUDE': |
|---|
| 307 |
if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|---|
| 308 |
return false; |
|---|
| 309 |
$resumeFromStart = true; |
|---|
| 310 |
break; |
|---|
| 311 |
default: |
|---|
| 312 |
if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|---|
| 313 |
$this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|---|
| 314 |
return false; }} |
|---|
| 315 |
return true; } |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
function processBeginBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|---|
| 323 |
$p = 0; |
|---|
| 324 |
if (!$this->parseWord($parms,$p,$blockName)) { |
|---|
| 325 |
$this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|---|
| 326 |
return false; } |
|---|
| 327 |
if (trim(substr($parms,$p)) != '') { |
|---|
| 328 |
$this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|---|
| 329 |
return false; } |
|---|
| 330 |
$this->registerBlock ($blockName, $blockNo); |
|---|
| 331 |
$btr =& $this->blockTab[$blockNo]; |
|---|
| 332 |
$btr['tPosBegin'] = $cmdTPosBegin; |
|---|
| 333 |
$btr['tPosContentsBegin'] = $cmdTPosEnd; |
|---|
| 334 |
$btr['nestingLevel'] = $this->currentNestingLevel; |
|---|
| 335 |
$btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel-1]; |
|---|
| 336 |
$this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
|---|
| 337 |
$this->currentNestingLevel += 1; |
|---|
| 338 |
if ($this->currentNestingLevel > $this->maxNestingLevel) { |
|---|
| 339 |
$trhis->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin."); |
|---|
| 340 |
return false; } |
|---|
| 341 |
return true; } |
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
function processEndBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|---|
| 349 |
$p = 0; |
|---|
| 350 |
if (!$this->parseWord($parms,$p,$blockName)) { |
|---|
| 351 |
$this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|---|
| 352 |
return false; } |
|---|
| 353 |
if (trim(substr($parms,$p)) != '') { |
|---|
| 354 |
$this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|---|
| 355 |
return false; } |
|---|
| 356 |
if (!$this->lookupBlockName($blockName,$blockNo)) { |
|---|
| 357 |
$this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|---|
| 358 |
return false; } |
|---|
| 359 |
$this->currentNestingLevel -= 1; |
|---|
| 360 |
$btr =& $this->blockTab[$blockNo]; |
|---|
| 361 |
if (!$btr['definitionIsOpen']) { |
|---|
| 362 |
$this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|---|
| 363 |
return false; } |
|---|
| 364 |
if ($btr['nestingLevel'] != $this->currentNestingLevel) { |
|---|
| 365 |
$this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|---|
| 366 |
return false; } |
|---|
| 367 |
$btr['tPosContentsEnd'] = $cmdTPosBegin; |
|---|
| 368 |
$btr['tPosEnd'] = $cmdTPosEnd; |
|---|
| 369 |
$btr['definitionIsOpen'] = false; |
|---|
| 370 |
return true; } |
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
function registerBlock($blockName, &$blockNo) { |
|---|
| 376 |
$blockNo = $this->blockTabCnt++; |
|---|
| 377 |
$btr =& $this->blockTab[$blockNo]; |
|---|
| 378 |
$btr = array(); |
|---|
| 379 |
$btr['blockName'] = $blockName; |
|---|
| 380 |
if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
|---|
| 381 |
$btr['nextWithSameName'] = -1; |
|---|
| 382 |
$btr['definitionIsOpen'] = true; |
|---|
| 383 |
$btr['instances'] = 0; |
|---|
| 384 |
$btr['firstBlockInstNo'] = -1; |
|---|
| 385 |
$btr['lastBlockInstNo'] = -1; |
|---|
| 386 |
$btr['blockVarCnt'] = 0; |
|---|
| 387 |
$btr['firstVarRefNo'] = -1; |
|---|
| 388 |
$btr['blockVarNoToVarNoMap'] = array(); |
|---|
| 389 |
$this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; } |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
function checkBlockDefinitionsComplete() { |
|---|
| 397 |
for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|---|
| 398 |
$btr =& $this->blockTab[$blockNo]; |
|---|
| 399 |
if ($btr['definitionIsOpen']) { |
|---|
| 400 |
$this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . "."); |
|---|
| 401 |
return false; }} |
|---|
| 402 |
if ($this->currentNestingLevel != 0) { |
|---|
| 403 |
$this->triggerError ("Block nesting level error at end of template."); |
|---|
| 404 |
return false; } |
|---|
| 405 |
return true; } |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
function processIncludeCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|---|
| 413 |
$p = 0; |
|---|
| 414 |
if (!$this->parseWordOrQuotedString($parms,$p,$subtemplateName)) { |
|---|
| 415 |
$this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|---|
| 416 |
return false; } |
|---|
| 417 |
if (trim(substr($parms,$p)) != '') { |
|---|
| 418 |
$this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|---|
| 419 |
return false; } |
|---|
| 420 |
return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); } |
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
function insertSubtemplate ($subtemplateName, $tPos1, $tPos2) { |
|---|
| 428 |
if (strlen($this->template) > $this->maxInclTemplateSize) { |
|---|
| 429 |
$this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|---|
| 430 |
return false; } |
|---|
| 431 |
if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
|---|
| 432 |
|
|---|
| 433 |
// a table could be used that contains references to the string fragments.) |
|---|
| 434 |
$this->template = substr($this->template,0,$tPos1) . $subtemplate . substr($this->template,$tPos2); |
|---|
| 435 |
return true; } |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
function parseTemplateVariables() { |
|---|
| 443 |
$p = 0; |
|---|
| 444 |
while (true) { |
|---|
| 445 |
$p = strpos($this->template, '${', $p); |
|---|
| 446 |
if ($p === false) break; |
|---|
| 447 |
$p0 = $p; |
|---|
| 448 |
$p = strpos($this->template, '}', $p); |
|---|
| 449 |
if ($p === false) { |
|---|
| 450 |
$this->triggerError ("Invalid variable reference in template at offset $p0."); |
|---|
| 451 |
return false; } |
|---|
| 452 |
$p += 1; |
|---|
| 453 |
$varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|---|
| 454 |
if (strlen($varName) == 0) { |
|---|
| 455 |
$this->triggerError ("Empty variable name in template at offset $p0."); |
|---|
| 456 |
return false; } |
|---|
| 457 |
$this->registerVariableReference ($varName, $p0, $p); } |
|---|
| 458 |
return true; } |
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
function registerVariableReference ($varName, $tPosBegin, $tPosEnd) { |
|---|
| 464 |
if (!$this->lookupVariableName($varName,$varNo)) |
|---|
| 465 |
$this->registerVariable($varName,$varNo); |
|---|
| 466 |
$varRefNo = $this->varRefTabCnt++; |
|---|
| 467 |
$vrtr =& $this->varRefTab[$varRefNo]; |
|---|
| 468 |
$vrtr = array(); |
|---|
| 469 |
$vrtr['tPosBegin'] = $tPosBegin; |
|---|
| 470 |
$vrtr['tPosEnd'] = $tPosEnd; |
|---|
| 471 |
$vrtr['varNo'] = $varNo; } |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
function registerVariable ($varName, &$varNo) { |
|---|
| 477 |
$varNo = $this->varTabCnt++; |
|---|
| 478 |
$vtr =& $this->varTab[$varNo]; |
|---|
| 479 |
$vtr = array(); |
|---|
| 480 |
$vtr['varName'] = $varName; |
|---|
| 481 |
$vtr['varValue'] = ''; |
|---|
| 482 |
$this->varNameToNoMap[strtoupper($varName)] = $varNo; } |
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
function associateVariablesWithBlocks() { |
|---|
| 489 |
$varRefNo = 0; |
|---|
| 490 |
$activeBlockNo = 0; |
|---|
| 491 |
$nextBlockNo = 1; |
|---|
| 492 |
while ($varRefNo < $this->varRefTabCnt) { |
|---|
| 493 |
$vrtr =& $this->varRefTab[$varRefNo]; |
|---|
| 494 |
$varRefTPos = $vrtr['tPosBegin']; |
|---|
| 495 |
$varNo = $vrtr['varNo']; |
|---|
| 496 |
if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) { |
|---|
| 497 |
$activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|---|
| 498 |
continue; } |
|---|
| 499 |
if ($nextBlockNo < $this->blockTabCnt) { |
|---|
| 500 |
if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) { |
|---|
| 501 |
$activeBlockNo = $nextBlockNo; |
|---|
| 502 |
$nextBlockNo += 1; |
|---|
| 503 |
continue; }} |
|---|
| 504 |
$btr =& $this->blockTab[$activeBlockNo]; |
|---|
| 505 |
if ($varRefTPos < $btr['tPosBegin']) |
|---|
| 506 |
$this->programLogicError(1); |
|---|
| 507 |
$blockVarNo = $btr['blockVarCnt']++; |
|---|
| 508 |
$btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|---|
| 509 |
if ($btr['firstVarRefNo'] == -1) |
|---|
| 510 |
$btr['firstVarRefNo'] = $varRefNo; |
|---|
| 511 |
$vrtr['blockNo'] = $activeBlockNo; |
|---|
| 512 |
$vrtr['blockVarNo'] = $blockVarNo; |
|---|
| 513 |
$varRefNo += 1; }} |
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 52 |
|---|