Ignore:
Timestamp:
Aug 4, 2000, 11:17:38 PM (25 years ago)
Author:
bird
Message:

More coding.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/database/www/cvs.php3

    r3947 r3950  
    11<?php
    22
    3 
     3require "../Odin32DBhelpers.php3";
     4
     5/*
     6 * Configuration:
     7 */
     8$sCVSROOT = ".";
    49$sCVSROOT = "d:/odin32/cvs/cvsroot";
    5 $sCVSROOT = ".";
     10
    611
    712/**
     
    2934        global $sCVSROOT;
    3035
     36        $timer = Odin32DBTimerStart("");
     37
    3138        $this->fOk = 0;
    3239        /*
     
    6572        $j = strrpos($sFilename, "/");
    6673        $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));
    6875        $this->sDir         = substr($sFilename, 0, $i);
    6976        if (($i = strrpos($this->sName, '.')) > 0)
     
    119126            if ($fNewKey)
    120127            {
    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
    122149                $sLine = ltrim(SkipWord($sLine));
    123150                if ($sKey[0] >= "0" && $sKey[0] <= "9")
     
    161188                if ($fAt)
    162189                {   /* 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
    167204                    if ($fEnd)
    168205                    {
     
    182219                {   /* terminated with ';' */
    183220                    $i = strpos($sLine, ';');
    184                     if ($fEnd = ($i >= 0))
     221                    if ($fEnd = ($i > 0 || $sLine[0] == ';'))
    185222                    {
    186                         $asValue[] = str_replace("@@", "@", substr($sLine, 0, $i));
     223                        //$asValue[] = str_replace("@@", "@", substr($sLine, 0, $i));
     224                        $asValue[] = substr($sLine, 0, $i);
    187225                        $sLine = (strlen($sLine) > $i+1) ? substr($sLine, $i+1) : "";
    188226                    }
    189227                    else
    190228                    {
    191                         $asValue[] = str_replace("@@", "@", $sLine);
     229                        //$asValue[] = str_replace("@@", "@", $sLine);
     230                        $asValue[] = $sLine;
    192231                        $sLine = "";
    193232                    }
     
    266305         */
    267306        $this->fOk = 1;
     307
     308        Odin32DBTimerStop($timer);
    268309        return 1;
    269310    }
     
    275316    function DumpInfo()
    276317    {
    277         echo "\nDump:\n";
     318        echo "\nDump:<br>\n";
     319
    278320        while (list ($sKey, $asValue) = each ($this->aasKeys))
    279321        {
    280             echo "* key: $sKey *\n";
     322            echo "* key: $sKey *<br>\n";
    281323            if (sizeof((array)$asValue) > 0)
    282324            {
    283325                while (list ($key, $s) = each ($asValue))
    284326                    echo $s;
    285                 echo "\n";
     327                echo "<br>\n";
    286328            }
    287329        }
     
    289331        while (list ($sRev, $aasKeys) = each ($this->aaasRevs))
    290332        {
    291             echo "* Revision: $sRev *\n";
     333            echo "* Revision: $sRev *<br>\n";
    292334            if (sizeof((array)$aasKeys) > 0)
    293335            {
    294336                while (list ($sKey, $asValue) = each ($aasKeys))
    295337                {
    296                     echo "* key: $sKey *\n";
     338                    echo "* key: $sKey *<br>\n";
    297339                    if (sizeof((array)$asValue) > 0)
    298340                    {
    299341                        while (list ($key, $s) = each ($asValue))
    300342                            echo $s;
    301                         echo "\n";
     343                        echo "<br>\n";
    302344                    }
    303345                }
     
    305347        }
    306348
    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))
    311352            {
    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        }
    318362    }
    319363
     
    364408         * Write it!
    365409         */
    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";
    367411
    368412        $fComment = 0;
     
    385429                case 'hpp':
    386430                    $sLine = C_ColorEncode($sLine, $aVariables);
     431                    //echo "<a name=$iLine>";
     432                    //C_ColorEncode2($sLine, $aVariables);
     433                    //echo "</a>";
    387434                    break;
     435
     436                default:
     437                    echo  "<a name=$iLine>$sLine</a>";
     438
    388439            }
    389440
     
    400451
    401452
     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
    402588}
    403589
     590
     591/**
     592 * This function displayes the contents of an directory.
     593 */
     594function 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>&nbsp;</td>\n",
     715             "    <td$sBgColor>&nbsp;</td>\n",
     716             "    <td$sBgColor>&nbsp;</td>\n",
     717             "    <td$sBgColor>&nbsp;</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>&nbsp;</td>\n",
     726             "    <td$sBgColor>&nbsp;</td>\n",
     727             "    <td$sBgColor>&nbsp;</td>\n",
     728             "    <td$sBgColor>&nbsp;</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}
    404770
    405771
     
    464830 */
    465831$aC_Keywords = array(
    466     "auto" => 1,
     832//    "auto" => 1,
    467833    "break" => 1,
    468834    "case" => 1,
     
    471837    "continue" => 1,
    472838    "default" => 1,
    473     "defined" => 1,
     839//    "defined" => 1,
    474840    "do" => 1,
    475841    "double" => 1,
     
    497863    "class" => 1,
    498864    "delete" => 1,
    499     "finally" => 1,
     865//    "finally" => 1,
    500866    "friend" => 1,
    501867    "inline" => 1,
     
    508874    "this" => 1,
    509875    "virtual" => 1,
    510     "bool" => 1,
    511     "true" => 1,
    512     "false" => 1,
     876//    "bool" => 1,
     877//    "true" => 1,
     878//    "false" => 1,
    513879    "explicit" => 1,
    514880    "mutable" => 1,
    515881    "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,
    521887    "typeid" => 1,
    522     "asm" => 1,
     888//    "asm" => 1,
    523889    "catch" => 1,
    524890    "signed" => 1,
     
    526892    "throw" => 1,
    527893    "try" => 1,
    528     "volatile" => 1,
    529     "namespace" => 1);
     894//    "namespace" => 1,
     895    "volatile" => 1
     896
     897    );
    530898
    531899$aC_Symbols = array(
     
    540908    "!" => 1,
    541909    "%" => 1,
    542     "&" => 1,
     910//    "&" => 1,
    543911    "&amp;" => 1,
    544912    "*" => 1,
     
    548916    ":" => 1,
    549917    ";" => 1,
    550     "<" => 1,
     918//    "<" => 1,
    551919    "&lt;" => 1,
    552     ">" => 1,
     920//    ">" => 1,
    553921    "&gt;" => 1,
    554922    "?" => 1,
     
    565933function C_ColorInit(&$aVariables)
    566934{
     935    global $aC_Keywords;
     936    global $aC_Symbols;
     937
    567938    $aVariables["fComment"] = 0;
     939
     940    ksort($aC_Keywords);
     941    ksort($aC_Symbols);
    568942}
    569943
     
    605979    while ($i < $cchLine)
    606980    {
     981        $ch = $sLine[$i];
    607982        /* comment check */
    608         if ($i+1 < $cchLine && $sLine[$i] == '/')
     983        if ($i+1 < $cchLine && $ch == '/')
    609984        {
    610985            if ($sLine[$i+1] == '/')
    611986            {   /* one-line comment */
    612                 return $sRet . "<font color=\"#02FE02\">" . substr($sLine, $i) . "</font>";
     987                return $sRet . "<font color=#02FE02>" . substr($sLine, $i) . "</font>";
    613988            }
    614989
     
    617992                if ($j = strpos($sLine, "*/", $i + 2))
    618993                {
    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>";
    620995                    $i = $j + 2;
    621996                }
     
    623998                {
    624999                    $aVariables["fComment"] = 1;
    625                     return $sRet . "<font color=\"#02FE02\">" . substr($sLine, $i);
     1000                    return $sRet . "<font color=#02FE02>" . substr($sLine, $i);
    6261001                }
    6271002                continue;
     
    6291004        }
    6301005
    631 
    6321006        /*
    6331007         * Check for string.
    6341008         */
    635         if ((($fDbl = ($sLine[$i] == '"' || substr($sLine, $i, 6) == "&quot;")) || $sLine[$i] == "'")
     1009        if ((($fDbl = (/*$sLine[$i] == '"' ||*/ substr($sLine, $i, 6) == "&quot;")) || $sLine[$i] == "'")
    6361010             && ($i == 0 || $sLine[$i-1] != '\\'))
    6371011        {   /* start of a string */
     
    6391013            if ($fDbl)
    6401014            {
    641                 if ($sLine[$i] == '"')
     1015               /* if ($sLine[$i] == '"')
    6421016                    while ($j < $cchLine && $sLine[$j] != '"')
    6431017                        $j += ($sLine[$j] == '\\') ? 2 : 1;
    644                 else
     1018                else */
    6451019                {
    6461020                    while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != "&quot;"))
     
    6541028                    $j += ($sLine[$j] == '\\') ? 2 : 1;
    6551029            $j++;
    656             $sRet .= "<font color=\"#FEFE02\">".substr($sLine, $i, $j - $i)."</font>";
     1030            $sRet .= "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>";
    6571031            $i = $j;
    6581032            continue;
    6591033        }
    6601034
    661 
    6621035        /*
    6631036         * Check for preprocessor directive.
    6641037         */
    665         if ($fFirstNonBlank && $sLine[$i] == "#")
     1038        if ($fFirstNonBlank && $ch == "#")
    6661039        {
    6671040            $j = $i + 1;
     
    6691042                $j++;
    6701043            $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>";
    6721045            $i = $j;
    6731046            $fFirstNonBlank = 0;
     
    6781051         * If non-blank, lets check if we're at the start of a word...
    6791052         */
    680         $fBlank = ($sLine[$i] == ' ' || $sLine[$i] == '\t'); //TODO more "blanks"?
     1053        $fBlank = ($ch == ' ' || $ch == '\t'); //TODO more "blanks"?
    6811054        if ($fFirstNonBlank)    $fFirstNonBlank = $fBlank;
    6821055        $cchWord = !$fBlank ? C_WordLen($sLine, $cchLine, $i) : 0;
     
    6851058        {
    6861059            /*
    687              * Check for keyword.
     1060             * Check for keyword or number.
    6881061             */
    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>";
    6971064
    6981065            /*
     
    7101077         */
    7111078        $cchWord = 1;
    712         if ($sLine[$i] == '&')
    713         {
     1079        if ($ch == '&')
     1080        {
     1081            /*
    7141082            while ($cchWord < 8 && $sLine[$i+$cchWord] != ';' &&
    7151083                    (   ($sLine[$i+$cchWord] >= 'a' && $sLine[$i+$cchWord] <= 'z')
     
    7181086                   )
    7191087                   $cchWord++;
     1088
    7201089            if ($sLine[$i + $cchWord++] != ';')
    7211090                $cchWord = 1;
     1091            */
     1092            if (substr($sLine, $i, 5) == "&amp;")
     1093                $cchWord = 5;
     1094            else if (substr($sLine, $i, 4) == "&gt;" || substr($sLine, $i, 4) == "&lt;")
     1095                $cchWord = 4;
    7221096        }
    7231097
     
    7251099         * Check for Symbol.
    7261100         */
    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>";
    7301104            $i += $cchWord;
    7311105            continue;
     
    7361110         * Copy char
    7371111         */
    738         $sRet = $sRet.$sLine[$i];
     1112        $sRet .= $sLine[$i];
    7391113        $i++;
    7401114    }
     
    7431117}
    7441118
     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 */
     1126function 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) == "&quot;")) || $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) != "&quot;"))
     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 &amp;).
     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) == "&amp;")
     1272                $cchWord = 5;
     1273            else if (substr($sLine, $i, 4) == "&gt;" || substr($sLine, $i, 4) == "&lt;")
     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}
    7451297
    7461298
     
    7591311     * word part.
    7601312     */
    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    }
    7711324
    7721325    /*
    7731326     * Count letters in the word
    7741327     */
    775     $cch = 0;
    776     $cchLine = strlen($sLine);
     1328    $j = $i;
     1329    $ch = $sLine[$i];
    7771330    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 == '$')
    7841336            )
    7851337           )
    786     {
    787         $i++;
    788         $cch++;
    789     }
    790     return $cch;
     1338        $ch = @$sLine[++$i];
     1339    return $i - $j;
    7911340}
    7921341
Note: See TracChangeset for help on using the changeset viewer.