Changeset 3950 for trunk/tools/database/www/cvs.php3
- Timestamp:
- Aug 4, 2000, 11:17:38 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/www/cvs.php3
r3947 r3950 1 1 <?php 2 2 3 3 require "../Odin32DBhelpers.php3"; 4 5 /* 6 * Configuration: 7 */ 8 $sCVSROOT = "."; 4 9 $sCVSROOT = "d:/odin32/cvs/cvsroot"; 5 $sCVSROOT = "."; 10 6 11 7 12 /** … … 29 34 global $sCVSROOT; 30 35 36 $timer = Odin32DBTimerStart(""); 37 31 38 $this->fOk = 0; 32 39 /* … … 65 72 $j = strrpos($sFilename, "/"); 66 73 $i = ($i > $j) ? $i : $j; 67 $this->sName = substr($sFilename, $i > 0 ? $i + 1 : 0, strlen($sFilename)-2 );74 $this->sName = substr($sFilename, $i > 0 ? $i + 1 : 0, strlen($sFilename)-2 - ($i > 0 ? $i + 1 : 0)); 68 75 $this->sDir = substr($sFilename, 0, $i); 69 76 if (($i = strrpos($this->sName, '.')) > 0) … … 119 126 if ($fNewKey) 120 127 { 121 $sKey = CopyWord($sLine); 128 //$sKey = CopyWord($sLine); 129 $cch = strlen($sLine); 130 for ($i = 0; $i < $cch; $i++) 131 { 132 $c = $sLine[$i]; 133 if (!( 134 ($c >= 'a' && $c <= 'z') 135 || 136 ($c >= 'A' && $c <= 'Z') 137 || 138 ($c >= '0' && $c <= '9') 139 || 140 $c == '.' 141 || 142 $c == '_' 143 ) 144 ) 145 break; 146 } 147 $sKey = substr($sLine, 0, $i); 148 122 149 $sLine = ltrim(SkipWord($sLine)); 123 150 if ($sKey[0] >= "0" && $sKey[0] <= "9") … … 161 188 if ($fAt) 162 189 { /* terminated with @ */ 163 $iAt = 0; 164 for ($iAt; $iAt+1 < $cchLine; $iAt++) 165 if ($sLine[$iAt] == '@' && ($fEnd = ($sLine[++$iAt] != '@'))) 166 break; 190 //$iAt = 0; 191 //for ($iAt; $iAt+1 < $cchLine; $iAt++) 192 // if ($sLine[$iAt] == '@' && ($fEnd = ($sLine[++$iAt] != '@'))) 193 // break; 194 if ($sLine[0] == '@' && $sLine[1] != '@') 195 $fEnd = $iAt = 1; 196 else 197 { 198 $iAt = 0; 199 while ($iAt = strpos($sLine, "@", $iAt+1)) 200 if ($fEnd = ($sLine[++$iAt] != '@')) 201 break; 202 } 203 167 204 if ($fEnd) 168 205 { … … 182 219 { /* terminated with ';' */ 183 220 $i = strpos($sLine, ';'); 184 if ($fEnd = ($i > = 0))221 if ($fEnd = ($i > 0 || $sLine[0] == ';')) 185 222 { 186 $asValue[] = str_replace("@@", "@", substr($sLine, 0, $i)); 223 //$asValue[] = str_replace("@@", "@", substr($sLine, 0, $i)); 224 $asValue[] = substr($sLine, 0, $i); 187 225 $sLine = (strlen($sLine) > $i+1) ? substr($sLine, $i+1) : ""; 188 226 } 189 227 else 190 228 { 191 $asValue[] = str_replace("@@", "@", $sLine); 229 //$asValue[] = str_replace("@@", "@", $sLine); 230 $asValue[] = $sLine; 192 231 $sLine = ""; 193 232 } … … 266 305 */ 267 306 $this->fOk = 1; 307 308 Odin32DBTimerStop($timer); 268 309 return 1; 269 310 } … … 275 316 function DumpInfo() 276 317 { 277 echo "\nDump:\n"; 318 echo "\nDump:<br>\n"; 319 278 320 while (list ($sKey, $asValue) = each ($this->aasKeys)) 279 321 { 280 echo "* key: $sKey * \n";322 echo "* key: $sKey *<br>\n"; 281 323 if (sizeof((array)$asValue) > 0) 282 324 { 283 325 while (list ($key, $s) = each ($asValue)) 284 326 echo $s; 285 echo " \n";327 echo "<br>\n"; 286 328 } 287 329 } … … 289 331 while (list ($sRev, $aasKeys) = each ($this->aaasRevs)) 290 332 { 291 echo "* Revision: $sRev * \n";333 echo "* Revision: $sRev *<br>\n"; 292 334 if (sizeof((array)$aasKeys) > 0) 293 335 { 294 336 while (list ($sKey, $asValue) = each ($aasKeys)) 295 337 { 296 echo "* key: $sKey * \n";338 echo "* key: $sKey *<br>\n"; 297 339 if (sizeof((array)$asValue) > 0) 298 340 { 299 341 while (list ($key, $s) = each ($asValue)) 300 342 echo $s; 301 echo " \n";343 echo "<br>\n"; 302 344 } 303 345 } … … 305 347 } 306 348 307 while (list ($sKey, $asValue) = each ($this->aasDeltas)) 308 { 309 echo "* delta for revision: $sKey *\n"; 310 if (sizeof((array)$asValue) > 0) 349 if (0) 350 { 351 while (list ($sKey, $asValue) = each ($this->aasDeltas)) 311 352 { 312 while (list ($key, $s) = each ($asValue)) 313 echo $s; 314 echo "\n"; 315 } 316 } 317 353 echo "* delta for revision: $sKey *<br>\n"; 354 if (sizeof((array)$asValue) > 0) 355 { 356 while (list ($key, $s) = each ($asValue)) 357 echo $s."<br>"; 358 echo "\n"; 359 } 360 } 361 } 318 362 } 319 363 … … 364 408 * Write it! 365 409 */ 366 echo "<table><tr><td bgcolor= \"#020286\"><pre><font size=-0 face=\"System VIO, System Monospaced\" color=\"#02FEFE\">\n";410 echo "<table><tr><td bgcolor=#020286><pre><font size=-0 face=\"System VIO, System Monospaced\" color=#02FEFE>\n"; 367 411 368 412 $fComment = 0; … … 385 429 case 'hpp': 386 430 $sLine = C_ColorEncode($sLine, $aVariables); 431 //echo "<a name=$iLine>"; 432 //C_ColorEncode2($sLine, $aVariables); 433 //echo "</a>"; 387 434 break; 435 436 default: 437 echo "<a name=$iLine>$sLine</a>"; 438 388 439 } 389 440 … … 400 451 401 452 453 /** 454 * Gets the revision number of the head revision. 455 * @returns head revision number 456 */ 457 function getHead() 458 { 459 return $this->aasKeys["head"][0]; 460 } 461 462 463 /** 464 * Gets the log string for the given revision. 465 * @returns Array of strings in the log text. 466 * @param $sRev Revision number to get log text for. 467 */ 468 function getLog($sRev) 469 { 470 return @$this->aaasRevs[$sRev]["log"]; 471 } 472 473 474 /** 475 * Gets the author for a revision. 476 * @return Author name. 477 * @param $sRev Revision number to get author name for. 478 */ 479 function getAuthor($sRev) 480 { 481 return @$this->aaasRevs[$sRev]["author"][0]; 482 } 483 484 /** 485 * Get date+time stap on a revision. 486 * @returns date string for the given revision. 487 * @param $sRev Revision number to get date+time for. 488 */ 489 function getDate($sRev) 490 { 491 return @$this->aaasRevs[$sRev]["date"][0]; 492 } 493 494 /** 495 * Get the age of the given revision. 496 * @returns Age string. (human readable) 497 * @param $sRev Revision number to get age for. 498 */ 499 function getAge($sRev) 500 { 501 if (!isset($this->aaasRevs[$sRev]["date"][0])) 502 return "<i>error</i>"; 503 504 $sDate = $this->aaasRevs[$sRev]["date"][0]; 505 $sCurDate = date("Y.m.d.H.i.s"); 506 if ($sDate > $sCurDate) 507 { 508 return "0 seconds"; //fixme? 509 } 510 511 /* seconds */ 512 $i1 = substr($sCurDate, 17, 2); 513 $i2 = substr($sDate, 17, 2); 514 if ($fBorrow = ($i1 < $i2)) 515 $i1 += 60; 516 $iSeconds = $i1 - $i2; 517 518 /* minuttes */ 519 $i1 = substr($sCurDate, 14, 2); 520 $i2 = substr($sDate, 14, 2); 521 if ($fBorrow) 522 $i1--; 523 if ($fBorrow = ($i1 < $i2)) 524 $i1 += 60; 525 $iMinuttes = $i1 - $i2; 526 527 /* hours */ 528 $i1 = substr($sCurDate, 11, 2); 529 $i2 = substr($sDate, 11, 2); 530 if ($fBorrow) 531 $i1--; 532 if ($fBorrow = ($i1 < $i2)) 533 $i1 += 24; 534 $iHours = $i1 - $i2; 535 536 /* days */ 537 $i1 = substr($sCurDate, 8, 2); 538 $i2 = substr($sDate, 8, 2); 539 if ($fBorrow) 540 $i1--; 541 if ($fBorrow = ($i1 < $i2)) 542 { 543 $iM = substr($sCurDate, 5, 2); 544 $iY = substr($sCurDate, 0, 4); 545 if ($iM == 1 || $iM == 3 || $iM == 5 || $iM == 7 || $iM == 8 || $iM == 10 || $iM == 12) 546 $i1 += 31; 547 else if ($iM == 4 || $iM == 6 || $iM == 9 || $iM == 11) 548 $i1 += 30; 549 else if (($iY % 4) != 0 || (($iY % 100) == 0 && ($iY % 1000) != 0)) 550 $i1 += 28; 551 else 552 $i1 += 29; 553 } 554 $iDays = $i1 - $i2; 555 556 /* months */ 557 $i1 = substr($sCurDate, 5, 2); 558 $i2 = substr($sDate, 5, 2); 559 if ($fBorrow) 560 $i1--; 561 if ($fBorrow = ($i1 < $i2)) 562 $i1 += 12; 563 $iMonths = $i1 - $i2; 564 565 /* years */ 566 $i1 = substr($sCurDate, 0, 4); 567 $i2 = substr($sDate, 0, 4); 568 if ($fBorrow) 569 $i1--; 570 $iYears = $i1 - $i2; 571 572 //printf("<!-- $sCurDate - $sDate = %04d.%02d.%02d.%02d.%02d.%02d -->\n", $iYears, $iMonths, $iDays, $iHours, $iMinuttes, $iSeconds); 573 574 /* make output */ 575 if ($iYears > 0) 576 return "$iYears year".($iYears > 1 ? "s" : "")." $iMonths month".($iMonths > 1 ? "s" : ""); 577 if ($iMonths > 0) 578 return "$iMonths month".($iMonths > 1 ? "s" : "")." $iDays day".($iDays > 1 ? "s" : ""); 579 if ($iDays > 0) 580 return "$iDays day".($iDays > 1 ? "s" : "")." $iHours hour".($iHours > 1 ? "s" : ""); 581 if ($iHours > 0) 582 return "$iHours hour".($iHours > 1 ? "s" : "")." $iMinuttes min"; 583 if ($iMinuttes > 0) 584 return "$iMinuttes min $iSeconds sec"; 585 return "$iSeconds seconds"; 586 } 587 402 588 } 403 589 590 591 /** 592 * This function displayes the contents of an directory. 593 */ 594 function ListDirectory($sDir, $iSortColumn) 595 { 596 global $sCVSROOT; 597 598 /* 599 * Validate and fixup $sDir. 600 * Note that relative .. is not allowed! 601 */ 602 $sDir = str_replace("\\", "/", $sDir); 603 if ($sDir == "") 604 $sDir = "."; 605 if ($sDir[0] == '/') 606 $sDir = substr($sDir, 1); 607 if ($sDir[strlen($sDir)-1] == '/') 608 $sDir = substr($sDir, 0, strlen($sDir) - 1); 609 if ((strlen($sDir) == 2 && $sDir == "..") 610 || 611 (substr($sDir, 0, 3) == "../") 612 || 613 (substr($sDir, strlen($sDir)-3) == "/..") 614 || 615 (strpos($sDir, "/../") > 0) 616 ) 617 { 618 echo "<!-- Invalid parameter: \$sDir $sDir -->\n"; 619 echo "<i>Invalid parameter: \$sDir $sDir </i>\n"; 620 return 87; 621 } 622 623 /* 624 * Open the directory, read the contents into two arrays; 625 * one for files and one for directories. All files which 626 * don't end with ',v' are ignored. 627 */ 628 $hDir = opendir($sCVSROOT.'/'.$sDir); 629 if (!$hDir) 630 { 631 echo "<!-- debug error opendir($sDir) failed -->\n"; 632 echo "<i>debug error opendir($sDir) failed</i>\n"; 633 return 5; 634 } 635 636 $asFiles = array(); 637 $asSubDirs = array(); 638 while ($sEntry = readdir($hDir)) 639 { 640 if (is_dir($sCVSROOT.'/'.$sDir.'/'.$sEntry)) 641 { 642 if ($sEntry != '..' && $sEntry != '.') 643 $asSubDirs[] = $sEntry; 644 } 645 else 646 { 647 $cchEntry = strlen($sEntry); 648 if ($cchEntry > 2 && substr($sEntry, $cchEntry - 2, 2) == ',v') 649 $asFiles[$sEntry] = $sEntry; 650 } 651 } 652 closedir($hDir); 653 654 /* 655 * Get CVS data. 656 */ 657 $asRev = array(); 658 $asAge = array(); 659 $asAuthor = array(); 660 $asLog = array(); 661 for ($i = 0; list($sKey, $sFile) = each($asFiles); $i++) 662 { 663 $obj = new CVSFile($sDir.'/'.$sFile, 1); 664 if ($obj->fOk) 665 { 666 $asRev[$sFile] = $sRev = $obj->getHead(); 667 $asAge[$sFile] = $obj->getAge($sRev); 668 $asAuthor[$sFile] = $obj->getAuthor($sRev); 669 $asLog[$sFile] = $obj->getLog($sRev); 670 } 671 else 672 $asLog[$sFile] = $obj->sError; 673 } 674 675 /* 676 * Sort the stuff. 677 */ 678 sort($asSubDirs); 679 switch ($iSortColumn) 680 { 681 case 0: $asSorted = $asFiles; break; 682 case 1: $asSorted = $asRev; break; 683 case 2: $asSorted = $asAge; break; 684 case 3: $asSorted = $asAuthor; break; 685 case 4: $asSorted = $asLog; break; 686 default: $asSorted = $asFiles; break; 687 } 688 asort($asSorted); 689 690 /* 691 * Present data 692 */ 693 $aColumnColors = array("#cccccc","#cccccc","#cccccc","#cccccc", "#88ff88","#cccccc","#cccccc","#cccccc","#cccccc"); 694 echo "<table border=0 width=100% cellspacing=1 cellpadding=2>\n", 695 " <hr NOSHADE>\n", 696 " <th bgcolor=#".$aColumnColors[4+0-$iSortColumn]."><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=0>Filename</a></b></th>\n", 697 " <th bgcolor=#".$aColumnColors[4+1-$iSortColumn]."><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=1>Rev</a></b></th>\n", 698 " <th bgcolor=#".$aColumnColors[4+2-$iSortColumn]."><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=2>Age</a></b></th>\n", 699 " <th bgcolor=#".$aColumnColors[4+3-$iSortColumn]."><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=3>Author</a></b></th>\n", 700 " <th bgcolor=#".$aColumnColors[4+4-$iSortColumn]."><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=4>Last Log Entry</a></b></th>\n", 701 " </hr>\n"; 702 $i = 0; 703 /* directories */ 704 if ($sDir != "." && $sDir != "") 705 { 706 if (($j = strrpos($sDir, '/')) > 0) 707 $sParentDir = substr($sDir, 0, $j - 1); 708 else 709 $sParentDir = ""; 710 $sBgColor = ($i++ % 2) ? "" : " bgcolor=#ccccee"; 711 echo " <tr>\n", 712 " <td", $sBgColor , ">", 713 "<font size=-1><a href=\"cvs.phtml?sDir=$sParentDir\">Parent Directory</a></font></td>\n", 714 " <td$sBgColor> </td>\n", 715 " <td$sBgColor> </td>\n", 716 " <td$sBgColor> </td>\n", 717 " <td$sBgColor> </td>\n", 718 " </tr>\n"; 719 } 720 while (list($sKey, $sVal) = each($asSubDirs)) 721 { 722 $sBgColor = ($i++ % 2) ? "" : " bgcolor=#ccccee"; 723 echo " <tr>\n", 724 " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sDir=$sDir/$sVal\">$sVal</a></font></td>\n", 725 " <td$sBgColor> </td>\n", 726 " <td$sBgColor> </td>\n", 727 " <td$sBgColor> </td>\n", 728 " <td$sBgColor> </td>\n", 729 " </tr>\n"; 730 } 731 732 /* files */ 733 while (list($sKey, $sVal) = each($asSorted)) 734 { 735 $sBgColor = ($i++ % 2) ? "" : " bgcolor=#ccccee"; 736 $sRev = isset($asRev[$sKey]) ? $asRev[$sKey] : "<i> error </i>"; 737 $sAge = isset($asAge[$sKey]) ? $asAge[$sKey] : "<i> error </i>"; 738 $sAuthor= isset($asAuthor[$sKey])?$asAuthor[$sKey] : "<i> error </i>"; 739 for ($sLog = "", $j = sizeof($asLog[$sKey]) - 1; $j >= 0; $j--) 740 { 741 if ($sLog == "") 742 { 743 if (trim($asLog[$sKey][$j]) != "") 744 $sLog = $asLog[$sKey][$j]; 745 continue; 746 } 747 $sLog = $asLog[$sKey][$j]."<br>".$sLog; 748 } 749 echo " <tr>\n", 750 " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey\">$sKey</a></font></td>\n", 751 " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey?sRev=$sRev\">$sRev</a></font></td>\n", 752 " <td$sBgColor><font size=-1>$sAge</font></td>\n", 753 " <td$sBgColor><font size=-1>$sAuthor</font></td>\n", 754 " <td$sBgColor><font size=-1>$sLog</font></td>\n", 755 " </tr>\n"; 756 } 757 758 echo "</table>\n"; 759 760 761 /* 762 * Debug dump. 763 *//* 764 while (list ($sKey, $sVal) = each ($asSubDirs)) 765 echo "Dir: $sVal<br>\n"; 766 while (list ($sKey, $sVal) = each ($asFiles)) 767 echo "File: $sVal<br>\n"; 768 */ 769 } 404 770 405 771 … … 464 830 */ 465 831 $aC_Keywords = array( 466 "auto" => 1,832 // "auto" => 1, 467 833 "break" => 1, 468 834 "case" => 1, … … 471 837 "continue" => 1, 472 838 "default" => 1, 473 "defined" => 1,839 // "defined" => 1, 474 840 "do" => 1, 475 841 "double" => 1, … … 497 863 "class" => 1, 498 864 "delete" => 1, 499 "finally" => 1,865 // "finally" => 1, 500 866 "friend" => 1, 501 867 "inline" => 1, … … 508 874 "this" => 1, 509 875 "virtual" => 1, 510 "bool" => 1,511 "true" => 1,512 "false" => 1,876 // "bool" => 1, 877 // "true" => 1, 878 // "false" => 1, 513 879 "explicit" => 1, 514 880 "mutable" => 1, 515 881 "typename" => 1, 516 "static_cast" => 1,517 "const_cast" => 1,518 "reinterpret_cast" => 1,519 "dynamic_cast" => 1,520 "using" => 1,882 // "static_cast" => 1, 883 // "const_cast" => 1, 884 // "reinterpret_cast" => 1, 885 // "dynamic_cast" => 1, 886 // "using" => 1, 521 887 "typeid" => 1, 522 "asm" => 1,888 // "asm" => 1, 523 889 "catch" => 1, 524 890 "signed" => 1, … … 526 892 "throw" => 1, 527 893 "try" => 1, 528 "volatile" => 1, 529 "namespace" => 1); 894 // "namespace" => 1, 895 "volatile" => 1 896 897 ); 530 898 531 899 $aC_Symbols = array( … … 540 908 "!" => 1, 541 909 "%" => 1, 542 "&" => 1,910 // "&" => 1, 543 911 "&" => 1, 544 912 "*" => 1, … … 548 916 ":" => 1, 549 917 ";" => 1, 550 "<" => 1,918 // "<" => 1, 551 919 "<" => 1, 552 ">" => 1,920 // ">" => 1, 553 921 ">" => 1, 554 922 "?" => 1, … … 565 933 function C_ColorInit(&$aVariables) 566 934 { 935 global $aC_Keywords; 936 global $aC_Symbols; 937 567 938 $aVariables["fComment"] = 0; 939 940 ksort($aC_Keywords); 941 ksort($aC_Symbols); 568 942 } 569 943 … … 605 979 while ($i < $cchLine) 606 980 { 981 $ch = $sLine[$i]; 607 982 /* comment check */ 608 if ($i+1 < $cchLine && $ sLine[$i]== '/')983 if ($i+1 < $cchLine && $ch == '/') 609 984 { 610 985 if ($sLine[$i+1] == '/') 611 986 { /* one-line comment */ 612 return $sRet . "<font color= \"#02FE02\">" . substr($sLine, $i) . "</font>";987 return $sRet . "<font color=#02FE02>" . substr($sLine, $i) . "</font>"; 613 988 } 614 989 … … 617 992 if ($j = strpos($sLine, "*/", $i + 2)) 618 993 { 619 $sRet = $sRet . "<font color=\"#02FE02\">" . substr($sLine, $i, $j+2 - $i) . "</font>";994 $sRet .= "<font color=#02FE02>" . substr($sLine, $i, $j+2 - $i) . "</font>"; 620 995 $i = $j + 2; 621 996 } … … 623 998 { 624 999 $aVariables["fComment"] = 1; 625 return $sRet . "<font color= \"#02FE02\">" . substr($sLine, $i);1000 return $sRet . "<font color=#02FE02>" . substr($sLine, $i); 626 1001 } 627 1002 continue; … … 629 1004 } 630 1005 631 632 1006 /* 633 1007 * Check for string. 634 1008 */ 635 if ((($fDbl = ( $sLine[$i] == '"' ||substr($sLine, $i, 6) == """)) || $sLine[$i] == "'")1009 if ((($fDbl = (/*$sLine[$i] == '"' ||*/ substr($sLine, $i, 6) == """)) || $sLine[$i] == "'") 636 1010 && ($i == 0 || $sLine[$i-1] != '\\')) 637 1011 { /* start of a string */ … … 639 1013 if ($fDbl) 640 1014 { 641 if ($sLine[$i] == '"')1015 /* if ($sLine[$i] == '"') 642 1016 while ($j < $cchLine && $sLine[$j] != '"') 643 1017 $j += ($sLine[$j] == '\\') ? 2 : 1; 644 else 1018 else */ 645 1019 { 646 1020 while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != """)) … … 654 1028 $j += ($sLine[$j] == '\\') ? 2 : 1; 655 1029 $j++; 656 $sRet .= "<font color= \"#FEFE02\">".substr($sLine, $i, $j - $i)."</font>";1030 $sRet .= "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>"; 657 1031 $i = $j; 658 1032 continue; 659 1033 } 660 1034 661 662 1035 /* 663 1036 * Check for preprocessor directive. 664 1037 */ 665 if ($fFirstNonBlank && $ sLine[$i]== "#")1038 if ($fFirstNonBlank && $ch == "#") 666 1039 { 667 1040 $j = $i + 1; … … 669 1042 $j++; 670 1043 $j += C_WordLen($sLine, $cchLine, $j); 671 $sRet .= "<font color= \"#CECECE\">" . substr($sLine, $i, $j - $i) . "</font>";1044 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $j - $i) . "</font>"; 672 1045 $i = $j; 673 1046 $fFirstNonBlank = 0; … … 678 1051 * If non-blank, lets check if we're at the start of a word... 679 1052 */ 680 $fBlank = ($ sLine[$i] == ' ' || $sLine[$i]== '\t'); //TODO more "blanks"?1053 $fBlank = ($ch == ' ' || $ch == '\t'); //TODO more "blanks"? 681 1054 if ($fFirstNonBlank) $fFirstNonBlank = $fBlank; 682 1055 $cchWord = !$fBlank ? C_WordLen($sLine, $cchLine, $i) : 0; … … 685 1058 { 686 1059 /* 687 * Check for keyword .1060 * Check for keyword or number. 688 1061 */ 689 if ($cchWord > 0 && isset($aC_Keywords[substr($sLine, $i, $cchWord)])) 690 $sRet .= "<font color=\"#FF0202\">" . substr($sLine, $i, $cchWord) . "</font>"; 691 692 /* 693 * Check for number 694 */ 695 else if ($sLine[$i] >= '0' && $sLine[$i] <= '9') 696 $sRet .= "<font color=\"#FE0202\">" . substr($sLine, $i, $cchWord) . "</font>"; 1062 if ($cchWord > 0 && (isset($aC_Keywords[substr($sLine, $i, $cchWord)]) || ($ch >= '0' && $ch <= '9'))) 1063 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>"; 697 1064 698 1065 /* … … 710 1077 */ 711 1078 $cchWord = 1; 712 if ($sLine[$i] == '&') 713 { 1079 if ($ch == '&') 1080 { 1081 /* 714 1082 while ($cchWord < 8 && $sLine[$i+$cchWord] != ';' && 715 1083 ( ($sLine[$i+$cchWord] >= 'a' && $sLine[$i+$cchWord] <= 'z') … … 718 1086 ) 719 1087 $cchWord++; 1088 720 1089 if ($sLine[$i + $cchWord++] != ';') 721 1090 $cchWord = 1; 1091 */ 1092 if (substr($sLine, $i, 5) == "&") 1093 $cchWord = 5; 1094 else if (substr($sLine, $i, 4) == ">" || substr($sLine, $i, 4) == "<") 1095 $cchWord = 4; 722 1096 } 723 1097 … … 725 1099 * Check for Symbol. 726 1100 */ 727 if (isset($aC_Symbols[substr($sLine, $i, 1)]))728 { 729 $sRet .= "<font color= \"#CECECE\">" . substr($sLine, $i, $cchWord) . "</font>";1101 if (isset($aC_Symbols[substr($sLine, $i, $cchWord)])) 1102 { 1103 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>"; 730 1104 $i += $cchWord; 731 1105 continue; … … 736 1110 * Copy char 737 1111 */ 738 $sRet = $sRet.$sLine[$i];1112 $sRet .= $sLine[$i]; 739 1113 $i++; 740 1114 } … … 743 1117 } 744 1118 1119 1120 /** 1121 * Encode a line of C code. 1122 * @param $sLine Line string to encode. 1123 * @param $aVariables Variable array. 1124 * @returns Color encoded line string. 1125 */ 1126 function C_ColorEncode2($sLine, &$aVariables) 1127 { 1128 global $aC_Keywords; 1129 global $aC_Symbols; 1130 1131 $cchLine = strlen($sLine); 1132 1133 /* 1134 * If mulitline comment we'll only check if it ends at this line. 1135 * if it doesn't we'll do nothing. 1136 * if it does we'll skip to then end of it. 1137 */ 1138 if ($aVariables["fComment"]) 1139 { 1140 if (!(($i = strpos($sLine, "*/")) || ($cchLine >= 2 && $sLine[0] == '*' && $sLine[1] == '/'))) 1141 { 1142 echo $sLine; 1143 return; 1144 } 1145 $i += 2; 1146 echo substr($sLine, 0, $i)."</font>"; 1147 $aVariables["fComment"] = 0; 1148 } 1149 else 1150 $i = 0; 1151 1152 /* 1153 * Loop thru the (remainings) of the line. 1154 */ 1155 $fFirstNonBlank = 1; 1156 while ($i < $cchLine) 1157 { 1158 $ch = $sLine[$i]; 1159 /* comment check */ 1160 if ($i+1 < $cchLine && $ch == '/') 1161 { 1162 if ($sLine[$i+1] == '/') 1163 { /* one-line comment */ 1164 echo "<font color=#02FE02>" . substr($sLine, $i) . "</font>"; 1165 return; 1166 } 1167 1168 if ($sLine[$i+1] == '*') 1169 { /* Start of multiline comment */ 1170 if ($j = strpos($sLine, "*/", $i + 2)) 1171 { 1172 echo "<font color=#02FE02>" . substr($sLine, $i, $j+2 - $i) . "</font>"; 1173 $i = $j + 2; 1174 } 1175 else 1176 { 1177 $aVariables["fComment"] = 1; 1178 echo "<font color=#02FE02>" . substr($sLine, $i); 1179 return; 1180 } 1181 continue; 1182 } 1183 } 1184 1185 /* 1186 * Check for string. 1187 */ 1188 if ((($fDbl = (/*$sLine[$i] == '"' ||*/ substr($sLine, $i, 6) == """)) || $sLine[$i] == "'") 1189 && ($i == 0 || $sLine[$i-1] != '\\')) 1190 { /* start of a string */ 1191 $j = $i + 1; 1192 if ($fDbl) 1193 { 1194 /* if ($sLine[$i] == '"') 1195 while ($j < $cchLine && $sLine[$j] != '"') 1196 $j += ($sLine[$j] == '\\') ? 2 : 1; 1197 else */ 1198 { 1199 while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != """)) 1200 $j += ($sLine[$j] == '\\') ? 2 : 1; 1201 if ($j < $cchLine) 1202 $j += 5; 1203 } 1204 } 1205 else 1206 while ($j < $cchLine && $sLine[$j] != "'") 1207 $j += ($sLine[$j] == '\\') ? 2 : 1; 1208 $j++; 1209 echo "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>"; 1210 $i = $j; 1211 continue; 1212 } 1213 1214 /* 1215 * Check for preprocessor directive. 1216 */ 1217 if ($fFirstNonBlank && $ch == "#") 1218 { 1219 $j = $i + 1; 1220 while ($j < $cchLine && ($sLine[$j] == ' ' || $sLine[$j] == '\t')) 1221 $j++; 1222 $j += C_WordLen($sLine, $cchLine, $j); 1223 echo "<font color=#CECECE>" . substr($sLine, $i, $j - $i) . "</font>"; 1224 $i = $j; 1225 $fFirstNonBlank = 0; 1226 continue; 1227 } 1228 1229 /* 1230 * If non-blank, lets check if we're at the start of a word... 1231 */ 1232 $fBlank = ($ch == ' ' || $ch == '\t'); //TODO more "blanks"? 1233 if ($fFirstNonBlank) $fFirstNonBlank = $fBlank; 1234 $cchWord = !$fBlank ? C_WordLen($sLine, $cchLine, $i) : 0; 1235 1236 if ($cchWord > 0) 1237 { 1238 /* 1239 * Check for keyword or number. 1240 */ 1241 if ($cchWord > 0 && (isset($aC_Keywords[substr($sLine, $i, $cchWord)]) || ($ch >= '0' && $ch <= '9'))) 1242 echo "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>"; 1243 1244 /* 1245 * Skip word. 1246 */ 1247 else 1248 echo substr($sLine, $i, $cchWord); 1249 $i += $cchWord; 1250 continue; 1251 } 1252 1253 1254 /* 1255 * Prepare for symbol check. (we'll have to check for HTML stuff like &). 1256 */ 1257 $cchWord = 1; 1258 if ($ch == '&') 1259 { 1260 /* 1261 while ($cchWord < 8 && $sLine[$i+$cchWord] != ';' && 1262 ( ($sLine[$i+$cchWord] >= 'a' && $sLine[$i+$cchWord] <= 'z') 1263 || ($sLine[$i+$cchWord] >= 'A' && $sLine[$i+$cchWord] <= 'Z') 1264 ) 1265 ) 1266 $cchWord++; 1267 1268 if ($sLine[$i + $cchWord++] != ';') 1269 $cchWord = 1; 1270 */ 1271 if (substr($sLine, $i, 5) == "&") 1272 $cchWord = 5; 1273 else if (substr($sLine, $i, 4) == ">" || substr($sLine, $i, 4) == "<") 1274 $cchWord = 4; 1275 } 1276 1277 /* 1278 * Check for Symbol. 1279 */ 1280 if (isset($aC_Symbols[substr($sLine, $i, $cchWord)])) 1281 { 1282 echo "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>"; 1283 $i += $cchWord; 1284 continue; 1285 } 1286 1287 1288 /* 1289 * Copy char 1290 */ 1291 echo $ch; 1292 $i++; 1293 } 1294 1295 return; 1296 } 745 1297 746 1298 … … 759 1311 * word part. 760 1312 */ 761 if ($i > 0 && 762 ( 763 ($sLine[$i-1] >= 'a' && $sLine[$i-1] <= 'z') 764 || ($sLine[$i-1] >= 'A' && $sLine[$i-1] <= 'Z') 765 || ($sLine[$i-1] >= '0' && $sLine[$i-1] <= '9') 766 || ($sLine[$i-1] == '_') 767 || ($sLine[$i-1] == '$') 768 ) 769 ) 770 return 0; 1313 if ($i > 0) 1314 { 1315 $ch = $sLine[$i - 1]; 1316 if ( ($ch >= 'a' && $ch <= 'z') 1317 || ($ch >= 'A' && $ch <= 'Z') 1318 || ($ch >= '0' && $ch <= '9') 1319 || ($ch == '_') 1320 || ($ch == '$') 1321 ) 1322 return 0; 1323 } 771 1324 772 1325 /* 773 1326 * Count letters in the word 774 1327 */ 775 $ cch = 0;776 $c chLine = strlen($sLine);1328 $j = $i; 1329 $ch = $sLine[$i]; 777 1330 while ($i < $cchLine && 778 ( 779 ($sLine[$i] >= 'a' && $sLine[$i] <= 'z') 780 || ($sLine[$i] >= 'A' && $sLine[$i] <= 'Z') 781 || ($sLine[$i] >= '0' && $sLine[$i] <= '9') 782 || ($sLine[$i] == '_') 783 || ($sLine[$i] == '$') 1331 ( ($ch >= 'a' && $ch <= 'z') 1332 || ($ch >= 'A' && $ch <= 'Z') 1333 || ($ch >= '0' && $ch <= '9') 1334 || ($ch == '_') 1335 || ($ch == '$') 784 1336 ) 785 1337 ) 786 { 787 $i++; 788 $cch++; 789 } 790 return $cch; 1338 $ch = @$sLine[++$i]; 1339 return $i - $j; 791 1340 } 792 1341
Note:
See TracChangeset
for help on using the changeset viewer.