Ignore:
Timestamp:
Aug 5, 2000, 11:24:00 PM (25 years ago)
Author:
bird
Message:

More coding...

File:
1 edited

Legend:

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

    r3950 r3952  
    11<?php
    22
    3 require "../Odin32DBhelpers.php3";
     3require "Odin32DBhelpers.php3";
    44
    55/*
     
    3434        global $sCVSROOT;
    3535
    36         $timer = Odin32DBTimerStart("");
    3736
    3837        $this->fOk = 0;
     
    9493        }
    9594
     95        /*
     96         * Parse the file.
     97         */
     98        $this->fOk = $this->ParseFile2($hFile, 0);// $fNoDeltas);
     99
     100        fclose($hFile);
     101
     102        /*
     103         * Return.
     104         */
     105
     106        return 1;
     107    }
     108
     109
     110    /**
     111     * Parses the file.
     112     * (internal)
     113     */
     114    function ParseFile($hFile, $fNoDeltas)
     115    {
    96116
    97117        /*
     
    274294                    $this->sError = "Invalid file format.";
    275295                    fclose($hFile);
    276                     return 1;
     296                    return 0;
    277297                }
    278298                $this->aasKeys[$sKey] = $asValue;
     
    299319        }
    300320
    301         fclose($hFile);
    302 
    303         /*
    304          * Return successfully.
    305          */
    306         $this->fOk = 1;
    307 
    308         Odin32DBTimerStop($timer);
    309321        return 1;
    310322    }
     323
     324
     325    /**
     326     * Parses the file.
     327     * (internal)
     328     */
     329    function ParseFile2($hFile, $fNoDeltas)
     330    {
     331
     332        /*
     333         * Parse file.
     334         */
     335        $sKey   = "";
     336        $sRev   = "";
     337
     338        $sLine  = "";
     339        $fStop  = 0;
     340        while (!$fStop)
     341        {
     342            /*
     343             * Left trim.
     344             * If empty line, get next and iterate.
     345             */
     346            $sLine = ltrim($sLine);
     347            if ($sLine == "")
     348            {
     349                if (feof($hFile))
     350                    break;
     351                $sLine = fgets($hFile, 0x1000);
     352                continue;
     353            }
     354
     355            /*
     356             * Are we looking for a new key word?
     357             */
     358            if ($sKey == "")
     359            {
     360                $cch = strlen($sLine);
     361                for ($i = 0; $i < $cch; $i++)
     362                {
     363                    $c = $sLine[$i];
     364                    if (!(   ($c >= 'a' && $c <= 'z')
     365                          || ($c >= 'A' && $c <= 'Z')
     366                          || ($c >= '0' && $c <= '9')
     367                          || $c == '.'  || $c == '_'
     368                          )
     369                        )
     370                        break;
     371                }
     372                if ($sLine[0] >= "0" && $sLine[0] <= "9") // Revision number: delta or revision info
     373                    $sRev = substr($sLine, 0, $i);
     374                else
     375                    $sKey = substr($sLine, 0, $i);
     376                $sLine = ltrim(substr($sLine, $i));
     377                continue;
     378            }
     379
     380
     381            /*
     382             * Extract value
     383             */
     384            $fSemicolon = !($sKey == "desc" || $sKey == "log" || $sKey == "desc");
     385            $asValue = array();
     386            $fEnd = 0;
     387            if ($sLine[0] == "@") //check if the value is enclosed in '@'s
     388            {
     389                $sLine = substr($sLine, 1);
     390                for (;;)
     391                {
     392                    /* get new line? */
     393                    if ($sLine == "")
     394                    {
     395                        if (feof($hFile))
     396                            break;
     397                        $sLine = fgets($hFile, 0x1000);
     398                        continue;
     399                    }
     400
     401                    /*
     402                     * Look for end char ( @) and copy.
     403                     * If end of value then $sLine <- rest of line.
     404                     */
     405                    if ($sLine[0] != '@' || $sLine[1] == '@')
     406                    {
     407                        $iAt = 0;
     408                        while ($iAt = strpos($sLine, "@", $iAt+1))
     409                            if ($fEnd = ($sLine[++$iAt] != '@'))
     410                            {
     411                                $asValue[] = str_replace("@@", "@", substr($sLine, 0, $iAt - 1));
     412                                /* if semicolon end, skip to it. ASSUMES: same line! */
     413                                if ($fSemicolon && ($i = strpos($sLine, ";", $iAt)) > 0)
     414                                    $iAt = $i + 1;
     415                                $sLine = substr($sLine, $iAt);
     416                                break;
     417                            }
     418                        if ($iAt > 0)
     419                            break;
     420                    }
     421                    else
     422                    {
     423                        /* if semicolon end, skip to it. ASSUMES: same line! */
     424                        if ($fSemicolon && ($iAt = strpos($sLine, ";", 1)) > 0)
     425                            $sLine = substr($sLine, $iAt+1);
     426                        else
     427                            $sLine = substr($sLine, 1);
     428                        break;
     429                    }
     430
     431                    $asValue[] = str_replace("@@", "@", $sLine);
     432                    $sLine = fgets($hFile, 0x1000);
     433                }
     434            }
     435            else
     436            {
     437                for (;;)
     438                {
     439                    /* get new line? */
     440                    if ($sLine == "")
     441                    {
     442                        if (feof($hFile))
     443                            break;
     444                        $sLine = fgets($hFile, 0x1000);
     445                        continue;
     446                    }
     447
     448                    /*
     449                     * Look for end char (either ; or @) and copy.
     450                     * If end of value then $sLine <- rest of line.
     451                     */
     452                    if (($i = strpos($sLine, ';')) <= 0 && $sLine[0] != ';')
     453                    {   //terminator not found.
     454                        $asValue[] = $sLine;
     455                        $sLine = fgets($hFile, 0x1000);
     456                    }
     457                    else
     458                    {   //terminator found
     459                        $asValue[] = substr($sLine, 0, $i);
     460                        $sLine = substr($sLine, $i+1);
     461                        break; // end
     462                    }
     463                }
     464            }
     465
     466
     467            /*
     468             * Process the key.
     469             */
     470            switch ($sKey)
     471            {
     472                /*
     473                 * This is normally the keyword separating
     474                 * revision info from log+text info.
     475                 */
     476                case "desc":
     477                    $sRev = "";
     478                    break;
     479
     480                /*
     481                 * Stop after the first log entry.
     482                 */
     483                case "log":
     484                    $fStop = $fNoDeltas;
     485                    break;
     486
     487                /*
     488                 * Don'r read deltas for archives with the expand tag set
     489                 */
     490                case "expand":
     491                    $fNoDeltas = 1;//= $asValue[0] != "";
     492                    break;
     493            }
     494
     495            /*
     496             * Save key and value in the appopriate place.
     497             */
     498            if ($sRev == "")
     499            {   /* Base keys */
     500                if (sizeof($this->aaKeys) <= 0 //sanity check! head must come first and have a value!
     501                    && ($sKey != "head" || sizeof($asValue) <= 0 || $asValue[0] == ""))
     502                {
     503                    $this->sError = "Invalid file format.";
     504                    fclose($hFile);
     505                    return 1;
     506                }
     507                $this->aasKeys[$sKey] = $asValue;
     508            }
     509            else if ($sKey != "text")
     510            {   /* Revision information keys  */
     511                if (!isset($this->aaasRevs[$sRev]))
     512                    $this->aaasRevs[$sRev] = array($sKey => $asValue);
     513                else
     514                    $this->aaasRevs[$sRev][$sKey] = $asValue;
     515            }
     516            else
     517            {   /* Delta (ie. 'text') key */
     518                $this->aasDeltas[$sRev] = $asValue;
     519            }
     520
     521            /*
     522             * Completed reading of this key, so next one.
     523             */
     524            $sKey = "";
     525        }
     526
     527        return 1;
     528    }
     529
    311530
    312531
     
    400619            case 'hpp':
    401620                C_ColorInit($aVariables);
     621                $iColorEncoder = 1;
    402622                break;
     623            default:
     624                $iColorEncoder = 0;
    403625        }
    404626
     
    410632        echo "<table><tr><td bgcolor=#020286><pre><font size=-0 face=\"System VIO, System Monospaced\" color=#02FEFE>\n";
    411633
    412         $fComment = 0;
    413         $iLine = 0;
    414         $cLines = sizeof($this->aasDeltas[$sRevision]);
    415         //echo "<!-- debug $this->sExt -->\n";
    416         while ($iLine < $cLines)
    417         {
    418             $sLine = htmlspecialchars($this->aasDeltas[$sRevision][$iLine++]);
    419 
     634        for ($cLines = sizeof($this->aasDeltas[$sRevision]), $iLine = 0;
     635             ($iLine < $cLines);
     636             $iLine++)
     637        {
    420638            /*
    421639             * Preprocessing... Color coding
    422640             */
    423             switch ($this->sExt)
     641            switch ($iColorEncoder)
    424642            {
    425                 case 'c':
    426                 case 'cpp':
    427                 case 'cxx':
    428                 case 'h':
    429                 case 'hpp':
    430                     $sLine = C_ColorEncode($sLine, $aVariables);
    431                     //echo "<a name=$iLine>";
    432                     //C_ColorEncode2($sLine, $aVariables);
    433                     //echo "</a>";
     643                case 1:
     644                    echo "<a name=$iLine>";
     645                    echo  C_ColorEncode(htmlspecialchars($this->aasDeltas[$sRevision][$iLine]), $aVariables);
     646                    //C_ColorEncode2(htmlspecialchars($this->aasDeltas[$sRevision][$iLine]), $aVariables);
     647                    echo "</a>";
    434648                    break;
    435649
    436650                default:
    437                     echo  "<a name=$iLine>$sLine</a>";
    438 
    439             }
    440 
    441             /*
    442              * Finished processing of the line. So, write it.
    443              */
    444             echo  "<a name=$iLine>$sLine</a>";
     651                    echo  "<a name=$iLine>",htmlspecialchars($this->aasDeltas[$sRevision][$iLine]),"</a>";
     652            }
    445653        }
    446654
     
    505713        $sCurDate = date("Y.m.d.H.i.s");
    506714        if ($sDate > $sCurDate)
    507         {
    508715            return "0 seconds"; //fixme?
    509         }
    510716
    511717        /* seconds */
     
    595801{
    596802    global $sCVSROOT;
     803    $timer = Odin32DBTimerStart("List Directory");
    597804
    598805    /*
     
    655862     * Get CVS data.
    656863     */
     864    $cvstimer = Odin32DBTimerStart("Get CVS Data");
    657865    $asRev      = array();
    658866    $asAge      = array();
     
    667875            $asAge[$sFile]    = $obj->getAge($sRev);
    668876            $asAuthor[$sFile] = $obj->getAuthor($sRev);
    669             $asLog[$sFile]    = $obj->getLog($sRev);
     877            $asTmpLog         = $obj->getLog($sRev);
     878            for ($sLog = "", $j = sizeof($asTmpLog) - 1; $j >= 0; $j--)
     879            {
     880                if ($sLog == "")
     881                {
     882                    if (trim($asTmpLog[$j]) != "")
     883                        $sLog = $asTmpLog[$j];
     884                    continue;
     885                }
     886                $sLog = $asTmpLog[$j]."<br>".$sLog;
     887            }
     888            $asLog[$sFile] = $sLog;
     889            $sLog = "";
    670890        }
    671891        else
    672             $asLog[$sFile] = $obj->sError;
    673     }
     892            $asLog[$sFile]    = $obj->sError;
     893    }
     894    Odin32DBTimerStop($cvstimer);
    674895
    675896    /*
     
    688909    asort($asSorted);
    689910
     911
    690912    /*
    691913     * Present data
     
    694916    echo "<table border=0 width=100% cellspacing=1 cellpadding=2>\n",
    695917         "  <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",
     918         "    <th bgcolor=",$aColumnColors[4+0-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=0>Filename</a></b></font></th>\n",
     919         "    <th bgcolor=",$aColumnColors[4+1-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=1>Rev</a></b></font></th>\n",
     920         "    <th bgcolor=",$aColumnColors[4+2-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=2>Age</a></b></font></th>\n",
     921         "    <th bgcolor=",$aColumnColors[4+3-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=3>Author</a></b></font></th>\n",
     922         "    <th bgcolor=",$aColumnColors[4+4-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=4>Last Log Entry</a></b></font></th>\n",
    701923         "  </hr>\n";
    702924    $i = 0;
     
    709931            $sParentDir = "";
    710932        $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";
     933        echo "<tr>\n",
     934             " <td", $sBgColor , ">",
     935               "<font size=-1><a href=\"cvs.phtml?sDir=",$sParentDir,"\"><img src=\"cvsicons/parent.gif\" border=0> Parent Directory</a></font></td>\n",
     936             " <td$sBgColor>&nbsp;</td>\n",
     937             " <td$sBgColor>&nbsp;</td>\n",
     938             " <td$sBgColor>&nbsp;</td>\n",
     939             " <td$sBgColor>&nbsp;</td>\n",
     940             "</tr>\n";
    719941    }
    720942    while (list($sKey, $sVal) = each($asSubDirs))
    721943    {
    722944        $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";
     945        echo "<tr>\n",
     946             " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sDir=$sDir/$sVal\"><img src=\"cvsicons/dir.gif\" border=0> $sVal</a></font></td>\n",
     947             " <td$sBgColor>&nbsp;</td>\n",
     948             " <td$sBgColor>&nbsp;</td>\n",
     949             " <td$sBgColor>&nbsp;</td>\n",
     950             " <td$sBgColor>&nbsp;</td>\n",
     951             "</tr>\n";
    730952    }
    731953
     
    737959        $sAge   = isset($asAge[$sKey])  ? $asAge[$sKey]     : "<i> error </i>";
    738960        $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";
     961        $sLog   = isset($asLog[$sKey])  ?$asLog[$sKey]      : "<i> error </i>";
     962        echo "<tr>\n",
     963             " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey\"><img src=\"cvsicons/file.gif\" border=0>",substr($sKey, 0, -2),"</a></font></td>\n",
     964             " <td$sBgColor><font size=-2><a href=\"cvs.phtml?sFile=$sDir/$sKey?sRev=$sRev\">$sRev</a></font></td>\n",
     965             " <td$sBgColor><font size=-2>$sAge</font></td>\n",
     966             " <td$sBgColor><font size=-2>$sAuthor</font></td>\n",
     967             " <td$sBgColor><font size=-2>$sLog</font></td>\n",
     968             "</tr>\n";
    756969    }
    757970
    758971    echo "</table>\n";
     972    Odin32DBTimerStop($timer);
    759973
    760974
Note: See TracChangeset for help on using the changeset viewer.