source: trunk/tools/database/www/cvs.php3@ 3953

Last change on this file since 3953 was 3953, checked in by bird, 25 years ago

More coding done...
Directory listing works.
Syntax highlighting for .ASM and .MAK.
Using Apache icons.

File size: 67.1 KB
Line 
1<?php
2
3require "Odin32DBhelpers.php3";
4
5/*
6 * Configuration:
7 */
8$sCVSROOT = ".";
9$sCVSROOT = "d:/odin32/cvs/cvsroot";
10$sCVSROOT = "g:/cvsroot";
11
12
13/**
14 * Quick and dirty CVS file parser.
15 */
16class CVSFile
17{
18 var $fOk; /* Status of contructor. */
19 var $sError; /* Last error message. */
20 var $sFullName; /* Full path of the */
21 var $sDir; /* CVSROOT relative directory */
22 var $sName; /* Workfile filename. */
23 var $sExt; /* Workfile extention. */
24 var $aasKeys; /* base keys */
25 var $aasDeltas; /* the text values only */
26 var $aaasRevs; /* all types of revision info (but the text) */
27
28
29 /**
30 * Constructor.
31 * Opens a CVS repository file, reads it into memory and closes it.
32 */
33 function CVSFile($sFilename, $fNoDeltas)
34 {
35 global $sCVSROOT;
36
37
38 $this->fOk = 0;
39 /*
40 * TODO: Security: Check that the path and filename is valid!
41 * We can't allow relative paths (ie. "..")
42 */
43 if (strlen($sFilename) < 3 || substr($sFilename, strlen($sFilename)-2) != ",v")
44 {
45 $this->sError = "filename is invalid";
46 return 1;
47 }
48
49 /*
50 * Check filesize. Minimum size is 10 bytes!
51 */
52 $this->sFullname = $sCVSROOT."/".$sFilename;
53 $cbFile = filesize($this->sFullname);
54 if ($cbFile <= 10)
55 {
56 $this->sError = "too small file, " . $this->sFullname . ", ". $cbFile ."\n";
57 return 1;
58 }
59 if (!$fNoDeltas && $cbFile >= (2*1024*1024)) //currently max size of 2MB.
60 {
61 $this->sError = "\ntoo large file, ". $this->sFullname .", ". $cbFile ."\n";
62 return 1;
63 }
64
65
66 /*
67 * Seems ok. Let's, init object variables
68 */
69 $this->fOk = 0;
70 $this->sError = "";
71 $i = strrpos($sFilename, "\\");
72 $j = strrpos($sFilename, "/");
73 $i = ($i > $j) ? $i : $j;
74 $this->sName = substr($sFilename, $i > 0 ? $i + 1 : 0, strlen($sFilename)-2 - ($i > 0 ? $i + 1 : 0));
75 $this->sDir = substr($sFilename, 0, $i);
76 if (($i = strrpos($this->sName, '.')) > 0)
77 $this->sExt = substr($this->sName, $i+1);
78 else
79 $this->sExt = "";
80 $this->aasKeys = array();
81 $this->aasDeltas = array();
82 $this->aaasRevs = array();
83
84
85 /*
86 * Open the file
87 */
88 $hFile = fopen($this->sFullname, "rb");
89 if (!$hFile)
90 {
91 $this->sError = "\nfailed to open the file $this->sFullname\n";
92 fclose($hFile);
93 return 1;
94 }
95
96 /*
97 * Parse the file.
98 */
99 $Timer = Odin32DBTimerStart("CVS Parse");
100 $this->fOk = $this->ParseFile2($hFile, 0);// $fNoDeltas);
101 Odin32DBTimerStop($Timer);
102
103 fclose($hFile);
104
105 /*
106 * Return.
107 */
108
109 return 1;
110 }
111
112
113 /**
114 * Parses the file.
115 * (internal)
116 */
117 function ParseFile($hFile, $fNoDeltas)
118 {
119
120 /*
121 * Parse file.
122 */
123 $fAt = 0;
124 $fNewKey= 1;
125 $sKey = "";
126 $sRev = "";
127 $fDesc = 0;
128
129 $iLine = -1;
130 $sLine = "";
131 $fStop = 0;
132 while (($sLine != "" || !feof($hFile)) && !$fStop)
133 {
134 /*
135 * Left trim.
136 * If empty line, get next and iterate.
137 */
138 $sLine = ltrim($sLine);
139 if (!$sLine || $sLine == "" || $sLine == "\n" || $sLine == "\r")
140 {
141 $iLine++;
142 $sLine = fgets($hFile, 0x1000);
143 continue;
144 }
145
146 /*
147 * Are we looking for a new key word?
148 */
149 if ($fNewKey)
150 {
151 //$sKey = CopyWord($sLine);
152 $cch = strlen($sLine);
153 for ($i = 0; $i < $cch; $i++)
154 {
155 $c = $sLine[$i];
156 if (!(
157 ($c >= 'a' && $c <= 'z')
158 ||
159 ($c >= 'A' && $c <= 'Z')
160 ||
161 ($c >= '0' && $c <= '9')
162 ||
163 $c == '.'
164 ||
165 $c == '_'
166 )
167 )
168 break;
169 }
170 $sKey = substr($sLine, 0, $i);
171
172 $sLine = ltrim(SkipWord($sLine));
173 if ($sKey[0] >= "0" && $sKey[0] <= "9")
174 /* Revision number: delta or revision info */
175 $sRev = $sKey;
176 else
177 $fNewKey = 0;
178 continue;
179 }
180
181
182 /*
183 * Extract value
184 */
185 $fNoSemicolon = ($sKey == "desc" || $sKey == "log" || $sKey == "desc");
186 if ($fAt = ($sLine[0] == "@")) //check if the value is enclosed in '@'s
187 $sLine = substr($sLine, 1);
188 $asValue = array();
189 $fEnd = 0;
190 while (!$fEnd)
191 {
192 /* get new line? */
193 if (!$sLine || $sLine == "" || $sLine == "\n" || $sLine == "\r")
194 {
195 if (feof($hFile))
196 break;
197 /* Get next line and remove any EOF chars */
198 $iLine++;
199 $sLine = str_replace("\x1a", "", fgets($hFile, 0x1000));
200 continue;
201 }
202
203 //echo "debug line $iLine: $sLine";
204
205 /*
206 * Look for end char (either ; or @) and copy.
207 * If end of value then $sLine <- rest of line.
208 */
209 $fEnd = 0;
210 $cchLine = strlen($sLine);
211 if ($fAt)
212 { /* terminated with @ */
213 //$iAt = 0;
214 //for ($iAt; $iAt+1 < $cchLine; $iAt++)
215 // if ($sLine[$iAt] == '@' && ($fEnd = ($sLine[++$iAt] != '@')))
216 // break;
217 if ($sLine[0] == '@' && $sLine[1] != '@')
218 $fEnd = $iAt = 1;
219 else
220 {
221 $iAt = 0;
222 while ($iAt = strpos($sLine, "@", $iAt+1))
223 if ($fEnd = ($sLine[++$iAt] != '@'))
224 break;
225 }
226
227 if ($fEnd)
228 {
229 $asValue[] = str_replace("@@", "@", substr($sLine, 0, $iAt - 1));
230 /* if semicolon end, skip to it. ASSUMES: same line! */
231 if (!$fNoSemicolon && ($iAt = strpos($sLine, ";", $iAt)) >= 0)
232 $iAt++;
233 $sLine = (strlen($sLine) > $iAt && $iAt >= 0) ? substr($sLine, $iAt) : "";
234 }
235 else
236 {
237 $asValue[] = str_replace("@@", "@", $sLine);
238 $sLine = "";
239 }
240 }
241 else
242 { /* terminated with ';' */
243 $i = strpos($sLine, ';');
244 if ($fEnd = ($i > 0 || $sLine[0] == ';'))
245 {
246 //$asValue[] = str_replace("@@", "@", substr($sLine, 0, $i));
247 $asValue[] = substr($sLine, 0, $i);
248 $sLine = (strlen($sLine) > $i+1) ? substr($sLine, $i+1) : "";
249 }
250 else
251 {
252 //$asValue[] = str_replace("@@", "@", $sLine);
253 $asValue[] = $sLine;
254 $sLine = "";
255 }
256 }
257 }
258
259
260 /*
261 * Process the key.
262 */
263 switch ($sKey)
264 {
265 /*
266 * This is normally the keyword separating
267 * revision info from log+text info.
268 */
269 case "desc":
270 $fDesc = 1;
271 $sRev = "";
272 break;
273
274 /*
275 * Stop after the first log entry.
276 */
277 case "log":
278 $fStop = $fNoDeltas;
279 break;
280
281 /*
282 * Don'r read deltas for archives with the expand tag set
283 */
284 case "expand":
285 $fNoDeltas = 1;//= $asValue[0] != "";
286 break;
287 }
288
289 /*
290 * Save key and value in the appopriate place.
291 */
292 if ($sRev == "")
293 { /* Base keys */
294 if (sizeof($this->aasKeys) <= 0 //sanity check! head must come first and have a value!
295 && ($sKey != "head" || sizeof($asValue) <= 0 || $asValue[0] == ""))
296 {
297 $this->sError = "Invalid file format.";
298 fclose($hFile);
299 return 0;
300 }
301 $this->aasKeys[$sKey] = $asValue;
302 }
303 else if ($sKey != "text")
304 { /* Revision information keys */
305 if (!isset($this->aaasRevs[$sRev]))
306 $this->aaasRevs[$sRev] = array($sKey => $asValue);
307 else
308 $this->aaasRevs[$sRev][$sKey] = $asValue;
309 }
310 else
311 { /* Delta (ie. 'text') key */
312 $this->aasDeltas[$sRev] = $asValue;
313 }
314
315 /*
316 * Completed reading of this key, so next one.
317 */
318 $fNewKey = 1;
319
320 /* debug */
321 //echo "debug key: $sKey value(".sizeof($asValue)."):".$asValue[0]."\n";
322 }
323
324 return 1;
325 }
326
327
328 /**
329 * Parses the file.
330 * (internal)
331 */
332 function ParseFile2($hFile, $fNoDeltas)
333 {
334
335 /*
336 * Parse file.
337 */
338 $sKey = "";
339 $sRev = "";
340
341 $sLine = "";
342 $fStop = 0;
343 while (!$fStop)
344 {
345 /*
346 * Left trim.
347 * If empty line, get next and iterate.
348 */
349 $sLine = ltrim($sLine);
350 if ($sLine == "")
351 {
352 if (feof($hFile))
353 break;
354 $sLine = fgets($hFile, 0x1000);
355 continue;
356 }
357
358 /*
359 * Are we looking for a new key word?
360 */
361 if ($sKey == "")
362 {
363 $cch = strlen($sLine);
364 for ($i = 0; $i < $cch; $i++)
365 {
366 $c = $sLine[$i];
367 if (!( ($c >= 'a' && $c <= 'z')
368 || ($c >= 'A' && $c <= 'Z')
369 || ($c >= '0' && $c <= '9')
370 || $c == '.' || $c == '_'
371 )
372 )
373 break;
374 }
375 if ($sLine[0] >= "0" && $sLine[0] <= "9") // Revision number: delta or revision info
376 $sRev = substr($sLine, 0, $i);
377 else
378 $sKey = substr($sLine, 0, $i);
379 $sLine = ltrim(substr($sLine, $i));
380 continue;
381 }
382
383
384 /*
385 * Extract value
386 */
387 $fSemicolon = !($sKey == "desc" || $sKey == "log" || $sKey == "desc");
388 $asValue = array();
389 $fEnd = 0;
390 if ($sLine[0] == "@") //check if the value is enclosed in '@'s
391 {
392 $sLine = substr($sLine, 1);
393 for (;;)
394 {
395 /* get new line? */
396 if ($sLine == "")
397 {
398 if (feof($hFile))
399 break;
400 $sLine = fgets($hFile, 0x1000);
401 continue;
402 }
403
404 /*
405 * Look for end char ( @) and copy.
406 * If end of value then $sLine <- rest of line.
407 */
408 if ($sLine[0] != '@' || $sLine[1] == '@')
409 {
410 $iAt = 0;
411 while ($iAt = strpos($sLine, "@", $iAt+1))
412 if ($fEnd = ($sLine[++$iAt] != '@'))
413 {
414 $asValue[] = str_replace("@@", "@", substr($sLine, 0, $iAt - 1));
415 /* if semicolon end, skip to it. ASSUMES: same line! */
416 if ($fSemicolon && ($i = strpos($sLine, ";", $iAt)) > 0)
417 $iAt = $i + 1;
418 $sLine = substr($sLine, $iAt);
419 break;
420 }
421 if ($iAt > 0)
422 break;
423 }
424 else
425 {
426 /* if semicolon end, skip to it. ASSUMES: same line! */
427 if ($fSemicolon && ($iAt = strpos($sLine, ";", 1)) > 0)
428 $sLine = substr($sLine, $iAt+1);
429 else
430 $sLine = substr($sLine, 1);
431 break;
432 }
433
434 $asValue[] = str_replace("@@", "@", $sLine);
435 $sLine = fgets($hFile, 0x1000);
436 }
437 }
438 else
439 {
440 for (;;)
441 {
442 /* get new line? */
443 if ($sLine == "")
444 {
445 if (feof($hFile))
446 break;
447 $sLine = fgets($hFile, 0x1000);
448 continue;
449 }
450
451 /*
452 * Look for end char (either ; or @) and copy.
453 * If end of value then $sLine <- rest of line.
454 */
455 if (($i = strpos($sLine, ';')) <= 0 && $sLine[0] != ';')
456 { //terminator not found.
457 $asValue[] = $sLine;
458 $sLine = fgets($hFile, 0x1000);
459 }
460 else
461 { //terminator found
462 $asValue[] = substr($sLine, 0, $i);
463 $sLine = substr($sLine, $i+1);
464 break; // end
465 }
466 }
467 }
468
469
470 /*
471 * Process the key.
472 */
473 switch ($sKey)
474 {
475 /*
476 * This is normally the keyword separating
477 * revision info from log+text info.
478 */
479 case "desc":
480 $sRev = "";
481 break;
482
483 /*
484 * Stop after the first log entry.
485 */
486 case "log":
487 $fStop = $fNoDeltas;
488 break;
489
490 /*
491 * Don'r read deltas for archives with the expand tag set
492 */
493 case "expand":
494 $fNoDeltas = 1;//= $asValue[0] != "";
495 break;
496 }
497
498 /*
499 * Save key and value in the appopriate place.
500 */
501 if ($sRev == "")
502 { /* Base keys */
503 if (sizeof($this->aasKeys) <= 0 //sanity check! head must come first and have a value!
504 && ($sKey != "head" || sizeof($asValue) <= 0 || $asValue[0] == ""))
505 {
506 $this->sError = "Invalid file format.";
507 fclose($hFile);
508 return 0;
509 }
510 $this->aasKeys[$sKey] = $asValue;
511 }
512 else if ($sKey != "text")
513 { /* Revision information keys */
514 if (!isset($this->aaasRevs[$sRev]))
515 $this->aaasRevs[$sRev] = array($sKey => $asValue);
516 else
517 $this->aaasRevs[$sRev][$sKey] = $asValue;
518 }
519 else
520 { /* Delta (ie. 'text') key */
521 $this->aasDeltas[$sRev] = $asValue;
522 }
523
524 /*
525 * Completed reading of this key, so next one.
526 */
527 $sKey = "";
528 }
529
530 return 1;
531 }
532
533
534
535 /**
536 * Debug dump function.
537 */
538 function DumpInfo()
539 {
540 echo "\nDump:<br>\n";
541
542 while (list ($sKey, $asValue) = each ($this->aasKeys))
543 {
544 echo "* key: $sKey *<br>\n";
545 if (sizeof((array)$asValue) > 0)
546 {
547 while (list ($key, $s) = each ($asValue))
548 echo $s;
549 echo "<br>\n";
550 }
551 }
552
553 while (list ($sRev, $aasKeys) = each ($this->aaasRevs))
554 {
555 echo "* Revision: $sRev *<br>\n";
556 if (sizeof((array)$aasKeys) > 0)
557 {
558 while (list ($sKey, $asValue) = each ($aasKeys))
559 {
560 echo "* key: $sKey *<br>\n";
561 if (sizeof((array)$asValue) > 0)
562 {
563 while (list ($key, $s) = each ($asValue))
564 echo $s;
565 echo "<br>\n";
566 }
567 }
568 }
569 }
570
571 if (0)
572 {
573 while (list ($sKey, $asValue) = each ($this->aasDeltas))
574 {
575 echo "* delta for revision: $sKey *<br>\n";
576 if (sizeof((array)$asValue) > 0)
577 {
578 while (list ($key, $s) = each ($asValue))
579 echo $s."<br>";
580 echo "\n";
581 }
582 }
583 }
584 }
585
586
587 /**
588 * Prints the contents of the file to stdout.
589 *
590 * Color coding is enabled. (TODO)
591 *
592 * Currently only $sRevision == head revision is supported
593 * @returns Success indicator (true / false)
594 * @param $sRevision. Revision number. defaults to head revision.
595 *
596 */
597 function PrintRevision($sRevision)
598 {
599 /* defaults to head revision if empty */
600 if ($sRevision == "") $sRevision = $this->aasKeys["head"][0];
601 if (!isset($this->aasDeltas[$sRevision]))
602 {
603 $this->sError = "CVSFile::PrintRevision is called with an invalid revision number. ($sRevision)";
604 return 0;
605 }
606 /* to-be-removed - TODO - FIXME */
607 if ($sRevision != $this->aasKeys["head"][0])
608 {
609 $this->sError = "CVSFile::PrintRevision is called with an invalid revision number (not head).";
610 return 0;
611 }
612
613 /*
614 * Initiate the color encoder.
615 */
616 switch (strtolower($this->sExt))
617 {
618 case 'c':
619 case 'cpp':
620 case 'cxx':
621 case 'h':
622 case 'hpp':
623 C_ColorInit($aVariables);
624 $iColorEncoder = 1;
625 break;
626
627 case 'asm':
628 case 'inc':
629 case 's':
630 ASM_ColorInit($aVariables);
631 $iColorEncoder = 2;
632 break;
633
634 case 'mk':
635 case 'mak':
636 Make_ColorInit($aVariables);
637 $iColorEncoder = 3;
638 break;
639
640 default:
641 if (strtolower($this->sName) == "makefile");
642 {
643 Make_ColorInit($aVariables);
644 $iColorEncoder = 3;
645 break;
646 }
647 $iColorEncoder = 0;
648 }
649
650
651
652 /*
653 * Write it!
654 */
655 $Timer = Odin32DBTimerStart("Write timer");
656 echo "<table><tr><td bgcolor=#020286><pre><font size=-0 face=\"System VIO, System Monospaced\" color=#02FEFE>\n";
657
658 for ($cLines = sizeof($this->aasDeltas[$sRevision]), $iLine = 0;
659 ($iLine < $cLines);
660 $iLine++)
661 {
662 /*
663 * Preprocessing... Color coding
664 */
665 echo "<a name=$iLine>";
666 switch ($iColorEncoder)
667 {
668 case 1:
669 echo str_replace("\t", " ", C_ColorEncode(htmlspecialchars($this->aasDeltas[$sRevision][$iLine]), $aVariables));
670 break;
671 case 2:
672 echo str_replace("\t", " ", ASM_ColorEncode(htmlspecialchars($this->aasDeltas[$sRevision][$iLine]), $aVariables));
673 break;
674 case 3:
675 echo str_replace("\t", " ", Make_ColorEncode(htmlspecialchars($this->aasDeltas[$sRevision][$iLine]), $aVariables));
676 break;
677 default:
678 echo htmlspecialchars($this->aasDeltas[$sRevision][$iLine]);
679 }
680 echo "</a>";
681 }
682
683 echo " \n", //80-columns line
684 "</pre></td></tr></table>\n";
685 Odin32DBTimerStop($Timer);
686
687 return 1;
688 }
689
690
691 /**
692 * Gets the revision number of the head revision.
693 * @returns head revision number
694 */
695 function getHead()
696 {
697 return $this->aasKeys["head"][0];
698 }
699
700
701 /**
702 * Gets the log string for the given revision.
703 * @returns Array of strings in the log text.
704 * @param $sRev Revision number to get log text for.
705 */
706 function getLog($sRev)
707 {
708 return @$this->aaasRevs[$sRev]["log"];
709 }
710
711
712 /**
713 * Gets the author for a revision.
714 * @return Author name.
715 * @param $sRev Revision number to get author name for.
716 */
717 function getAuthor($sRev)
718 {
719 return @$this->aaasRevs[$sRev]["author"][0];
720 }
721
722 /**
723 * Get date+time stap on a revision.
724 * @returns date string for the given revision.
725 * @param $sRev Revision number to get date+time for.
726 */
727 function getDate($sRev)
728 {
729 return @$this->aaasRevs[$sRev]["date"][0];
730 }
731
732 /**
733 * Get the age of the given revision.
734 * @returns Age string. (human readable)
735 * @param $sRev Revision number to get age for.
736 */
737 function getAge($sRev)
738 {
739 if (!isset($this->aaasRevs[$sRev]["date"][0]))
740 return "<i>error</i>";
741
742 $sDate = $this->aaasRevs[$sRev]["date"][0];
743 $sCurDate = date("Y.m.d.H.i.s");
744 if ($sDate > $sCurDate)
745 return "0 seconds"; //fixme?
746
747 /* seconds */
748 $i1 = substr($sCurDate, 17, 2);
749 $i2 = substr($sDate, 17, 2);
750 if ($fBorrow = ($i1 < $i2))
751 $i1 += 60;
752 $iSeconds = $i1 - $i2;
753
754 /* minuttes */
755 $i1 = substr($sCurDate, 14, 2);
756 $i2 = substr($sDate, 14, 2);
757 if ($fBorrow)
758 $i1--;
759 if ($fBorrow = ($i1 < $i2))
760 $i1 += 60;
761 $iMinuttes = $i1 - $i2;
762
763 /* hours */
764 $i1 = substr($sCurDate, 11, 2);
765 $i2 = substr($sDate, 11, 2);
766 if ($fBorrow)
767 $i1--;
768 if ($fBorrow = ($i1 < $i2))
769 $i1 += 24;
770 $iHours = $i1 - $i2;
771
772 /* days */
773 $i1 = substr($sCurDate, 8, 2);
774 $i2 = substr($sDate, 8, 2);
775 if ($fBorrow)
776 $i1--;
777 if ($fBorrow = ($i1 < $i2))
778 {
779 $iM = substr($sCurDate, 5, 2);
780 $iY = substr($sCurDate, 0, 4);
781 if ($iM == 1 || $iM == 3 || $iM == 5 || $iM == 7 || $iM == 8 || $iM == 10 || $iM == 12)
782 $i1 += 31;
783 else if ($iM == 4 || $iM == 6 || $iM == 9 || $iM == 11)
784 $i1 += 30;
785 else if (($iY % 4) != 0 || (($iY % 100) == 0 && ($iY % 1000) != 0))
786 $i1 += 28;
787 else
788 $i1 += 29;
789 }
790 $iDays = $i1 - $i2;
791
792 /* months */
793 $i1 = substr($sCurDate, 5, 2);
794 $i2 = substr($sDate, 5, 2);
795 if ($fBorrow)
796 $i1--;
797 if ($fBorrow = ($i1 < $i2))
798 $i1 += 12;
799 $iMonths = $i1 - $i2;
800
801 /* years */
802 $i1 = substr($sCurDate, 0, 4);
803 $i2 = substr($sDate, 0, 4);
804 if ($fBorrow)
805 $i1--;
806 $iYears = $i1 - $i2;
807
808 //printf("<!-- $sCurDate - $sDate = %04d.%02d.%02d.%02d.%02d.%02d -->\n", $iYears, $iMonths, $iDays, $iHours, $iMinuttes, $iSeconds);
809
810 /* make output */
811 if ($iYears > 0)
812 return "$iYears year".($iYears > 1 ? "s" : "")." $iMonths month".($iMonths > 1 ? "s" : "");
813 if ($iMonths > 0)
814 return "$iMonths month".($iMonths > 1 ? "s" : "")." $iDays day".($iDays > 1 ? "s" : "");
815 if ($iDays > 0)
816 return "$iDays day".($iDays > 1 ? "s" : "")." $iHours hour".($iHours > 1 ? "s" : "");
817 if ($iHours > 0)
818 return "$iHours hour".($iHours > 1 ? "s" : "")." $iMinuttes min";
819 if ($iMinuttes > 0)
820 return "$iMinuttes min $iSeconds sec";
821 return "$iSeconds seconds";
822 }
823
824 /**
825 * Get the workfile extention.
826 * @returns The workfile extention (without '.').
827 */
828 function getWorkfileExt()
829 {
830 return $this->sExt;
831 }
832
833
834 /**
835 * Get the workfile extention.
836 * @returns The workfile name (with extention)
837 */
838 function getWorkfileName()
839 {
840 return $this->sName;
841 }
842
843 /**
844 * Is this a binary file? We'll simply check for the expand keyword.
845 * @returns True (1) if binary, false (0) if not.
846 */
847 function isBinary()
848 {
849 return isset($this->aasKeys["expand"]);
850 }
851}
852
853
854/**
855 * This function displayes the contents of an directory.
856 */
857function ListDirectory($sDir, $iSortColumn)
858{
859 global $sCVSROOT;
860 $timer = Odin32DBTimerStart("List Directory");
861
862 /*
863 * Validate and fixup $sDir.
864 * Note that relative .. is not allowed!
865 */
866 $sDir = str_replace("\\", "/", $sDir);
867 if ($sDir == "")
868 $sDir = ".";
869 if ($sDir[0] == '/')
870 $sDir = substr($sDir, 1);
871 if ($sDir[strlen($sDir)-1] == '/')
872 $sDir = substr($sDir, 0, strlen($sDir) - 1);
873 if ((strlen($sDir) == 2 && $sDir == "..")
874 ||
875 (substr($sDir, 0, 3) == "../")
876 ||
877 (substr($sDir, strlen($sDir)-3) == "/..")
878 ||
879 (strpos($sDir, "/../") > 0)
880 )
881 {
882 echo "<!-- Invalid parameter: \$sDir $sDir -->\n";
883 echo "<i>Invalid parameter: \$sDir $sDir </i>\n";
884 return 87;
885 }
886
887 /*
888 * Open the directory, read the contents into two arrays;
889 * one for files and one for directories. All files which
890 * don't end with ',v' are ignored.
891 */
892 $hDir = opendir($sCVSROOT.'/'.$sDir);
893 if (!$hDir)
894 {
895 echo "<!-- debug error opendir($sDir) failed -->\n";
896 echo "<i>debug error opendir($sDir) failed</i>\n";
897 return 5;
898 }
899
900 $asFiles = array();
901 $asSubDirs = array();
902 while ($sEntry = readdir($hDir))
903 {
904 if (is_dir($sCVSROOT.'/'.$sDir.'/'.$sEntry))
905 {
906 if ($sEntry != '..' && $sEntry != '.')
907 $asSubDirs[] = $sEntry;
908 }
909 else
910 {
911 $cchEntry = strlen($sEntry);
912 if ($cchEntry > 2 && substr($sEntry, $cchEntry - 2, 2) == ',v')
913 $asFiles[$sEntry] = $sEntry;
914 }
915 }
916 closedir($hDir);
917
918 /*
919 * Get CVS data.
920 */
921 $aExtIcons = array(
922 "c" => "c.gif",
923 "cpp" => "c.gif",
924 "cxx" => "c.gif",
925 "h" => "c.gif",
926 "hpp" => "c.gif",
927 "c" => "c.gif",
928 /* these are caught by the isBinary test.
929 "exe" => "binary.gif",
930 "dll" => "binary.gif",
931 "lib" => "binary.gif",
932 "obj" => "binary.gif",
933 "a" => "binary.gif",
934 */
935 "bmp" => "image1.gif",
936 "gif" => "image1.gif",
937 "ico" => "image1.gif",
938 "jpg" => "image1.gif",
939 "pal" => "image1.gif",
940 "png" => "image1.gif",
941 "asm" => "text.gif",
942 "def" => "text.gif",
943 "doc" => "text.gif",
944 "inc" => "text.gif",
945 "lib" => "text.gif",
946 "mak" => "text.gif",
947 "mk" => "text.gif",
948 "txt" => "text.gif",
949 "" => "text.gif",
950 "bat" => "script.gif",
951 "cmd" => "script.gif",
952 "perl" => "script.gif",
953 "sh" => "script.gif"
954 );
955 $cvstimer = Odin32DBTimerStart("Get CVS Data");
956 $asRev = array();
957 $asAge = array();
958 $asAuthor = array();
959 $asLog = array();
960 $asIcon = array();
961 for ($i = 0; list($sKey, $sFile) = each($asFiles); $i++)
962 {
963 $obj = new CVSFile($sDir.'/'.$sFile, 1);
964 if ($obj->fOk)
965 {
966 $asRev[$sFile] = $sRev = $obj->getHead();
967 $asAge[$sFile] = $obj->getAge($sRev);
968 $asAuthor[$sFile] = $obj->getAuthor($sRev);
969 $asTmpLog = $obj->getLog($sRev);
970 for ($sLog = "", $j = sizeof($asTmpLog) - 1; $j >= 0; $j--)
971 {
972 if ($sLog == "")
973 {
974 if (trim($asTmpLog[$j]) != "")
975 $sLog = $asTmpLog[$j];
976 continue;
977 }
978 $sLog = $asTmpLog[$j]."<br>".$sLog;
979 }
980 $asLog[$sFile] = $sLog;
981 $sLog = "";
982 $asIcon[$sFile] = isset($aExtIcons[strtolower($obj->getWorkfileExt())])
983 ? $aExtIcons[strtolower($obj->getWorkfileExt())] :
984 ($obj->isBinary() ? "binary.gif" : "unknown.gif");
985 }
986 else
987 $asLog[$sFile] = $obj->sError;
988 }
989 Odin32DBTimerStop($cvstimer);
990
991 /*
992 * Sort the stuff.
993 */
994 sort($asSubDirs);
995 switch ($iSortColumn)
996 {
997 case 0: $asSorted = $asFiles; break;
998 case 1: $asSorted = $asRev; break;
999 case 2: $asSorted = $asAge; break;
1000 case 3: $asSorted = $asAuthor; break;
1001 case 4: $asSorted = $asLog; break;
1002 default: $asSorted = $asFiles; break;
1003 }
1004 asort($asSorted);
1005
1006
1007 /*
1008 * Present data
1009 */
1010 $aColumnColors = array("#d0dce0","#d0dce0","#d0dce0","#d0dce0", "#d0dcff","#d0dce0","#d0dce0","#d0dce0","#d0dce0");
1011 echo "<table border=0 width=100% cellspacing=1 cellpadding=2>\n",
1012 " <hr NOSHADE>\n",
1013 " <th bgcolor=",$aColumnColors[4+0-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=0>Filename</a></b></font></th>\n",
1014 " <th bgcolor=",$aColumnColors[4+1-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=1>Rev</a></b></font></th>\n",
1015 " <th bgcolor=",$aColumnColors[4+2-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=2>Age</a></b></font></th>\n",
1016 " <th bgcolor=",$aColumnColors[4+3-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=3>Author</a></b></font></th>\n",
1017 " <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",
1018 " </hr>\n";
1019 $i = 0;
1020 /* directories */
1021 if ($sDir != "." && $sDir != "")
1022 {
1023 if (($j = strrpos($sDir, "/")) > 0)
1024 $sParentDir = substr($sDir, 0, $j);
1025 else
1026 $sParentDir = ".";
1027 $sBgColor = ($i++ % 2) ? "" : " bgcolor=#f0f0f0";
1028 echo "<tr>\n",
1029 " <td", $sBgColor , ">",
1030 "<font size=-1><a href=\"cvs.phtml?sDir=",$sParentDir,"\"><img src=\"/icons/back.gif\" border=0> Parent Directory</a></font></td>\n",
1031 " <td$sBgColor>&nbsp;</td>\n",
1032 " <td$sBgColor>&nbsp;</td>\n",
1033 " <td$sBgColor>&nbsp;</td>\n",
1034 " <td$sBgColor>&nbsp;</td>\n",
1035 "</tr>\n";
1036 }
1037 while (list($sKey, $sVal) = each($asSubDirs))
1038 {
1039 $sBgColor = ($i++ % 2) ? "" : " bgcolor=#f0f0f0";
1040 echo "<tr>\n",
1041 " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sDir=$sDir/$sVal\"><img src=\"/icons/dir.gif\" border=0> $sVal</a></font></td>\n",
1042 " <td$sBgColor>&nbsp;</td>\n",
1043 " <td$sBgColor>&nbsp;</td>\n",
1044 " <td$sBgColor>&nbsp;</td>\n",
1045 " <td$sBgColor>&nbsp;</td>\n",
1046 "</tr>\n";
1047 }
1048
1049 /* files */
1050 while (list($sKey, $sVal) = each($asSorted))
1051 {
1052 $sBgColor = ($i++ % 2) ? "" : " bgcolor=#f0f0f0";
1053 $sRev = isset($asRev[$sKey]) ? $asRev[$sKey] : "<i> error </i>";
1054 $sAge = isset($asAge[$sKey]) ? $asAge[$sKey] : "<i> error </i>";
1055 $sAuthor= isset($asAuthor[$sKey])?$asAuthor[$sKey] : "<i> error </i>";
1056 $sLog = isset($asLog[$sKey]) ? $asLog[$sKey] : "<i> error </i>";
1057 $sIcon = isset($asIcon[$sKey]) ? $asIcon[$sKey] : "<i> error </i>";
1058 echo "<tr>\n",
1059 " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey\"><img src=\"/icons/$sIcon\" border=0>",substr($sKey, 0, -2),"</a></font></td>\n",
1060 " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey?sRev=$sRev\">$sRev</a></font></td>\n",
1061 " <td$sBgColor><font size=-1>$sAge</font></td>\n",
1062 " <td$sBgColor><font size=-1>$sAuthor</font></td>\n",
1063 " <td$sBgColor><font size=-2>$sLog</font></td>\n",
1064 "</tr>\n";
1065 }
1066
1067 echo "</table>\n";
1068 Odin32DBTimerStop($timer);
1069
1070
1071 /*
1072 * Debug dump.
1073 *//*
1074 while (list ($sKey, $sVal) = each ($asSubDirs))
1075 echo "Dir: $sVal<br>\n";
1076 while (list ($sKey, $sVal) = each ($asFiles))
1077 echo "File: $sVal<br>\n";
1078 */
1079}
1080
1081
1082/**
1083 * Copies the first word.
1084 * A words is: [a-zA-Z0-9_.]
1085 *
1086 * tested ok
1087 * @returns Returns the word at the start of $s.
1088 */
1089function CopyWord($s)
1090{
1091 $cch = strlen($s);
1092 for ($i = 0; $i < $cch; $i++)
1093 {
1094 $c = $s[$i];
1095 if (!($c >= 'a' && $c <= 'z')
1096 &&
1097 !($c >= 'A' && $c <= 'Z')
1098 &&
1099 !($c >= '0' && $c <= '9')
1100 &&
1101 !($c == '.' || $c == '_')
1102 )
1103 break;
1104 }
1105 return substr($s, 0, $i);
1106}
1107
1108
1109/**
1110 * Skips the first word.
1111 * A words is: [a-zA-Z0-9_.]
1112 *
1113 * tested ok
1114 * @returns $s - first word.
1115 */
1116function SkipWord($s)
1117{
1118 $cch = strlen($s);
1119 for ($i = 0; $i < $cch; $i++)
1120 {
1121 $c = $s[$i];
1122 if (!($c >= 'a' && $c <= 'z')
1123 &&
1124 !($c >= 'A' && $c <= 'Z')
1125 &&
1126 !($c >= '0' && $c <= '9')
1127 &&
1128 !($c == '.' || $c == '_')
1129 )
1130 break;
1131 }
1132 return substr($s, $i);
1133}
1134
1135
1136
1137
1138/*
1139 * C color encoding.
1140 */
1141$aC_Keywords = array(
1142// "auto" => 1,
1143 "break" => 1,
1144 "case" => 1,
1145 "char" => 1,
1146 "const" => 1,
1147 "continue" => 1,
1148 "default" => 1,
1149// "defined" => 1,
1150 "do" => 1,
1151 "double" => 1,
1152 "else" => 1,
1153 "enum" => 1,
1154 "extern" => 1,
1155 "float" => 1,
1156 "for" => 1,
1157 "goto" => 1,
1158 "if" => 1,
1159 "int" => 1,
1160 "long" => 1,
1161 "register" => 1,
1162 "return" => 1,
1163 "short" => 1,
1164 "sizeof" => 1,
1165 "static" => 1,
1166 "struct" => 1,
1167 "switch" => 1,
1168 "typedef" => 1,
1169 "union" => 1,
1170 "unsigned" => 1,
1171 "void" => 1,
1172 "while" => 1,
1173 "class" => 1,
1174 "delete" => 1,
1175// "finally" => 1,
1176 "friend" => 1,
1177 "inline" => 1,
1178 "new" => 1,
1179 "operator" => 1,
1180 "overload" => 1,
1181 "private" => 1,
1182 "protected" => 1,
1183 "public" => 1,
1184 "this" => 1,
1185 "virtual" => 1,
1186// "bool" => 1,
1187// "true" => 1,
1188// "false" => 1,
1189 "explicit" => 1,
1190 "mutable" => 1,
1191 "typename" => 1,
1192// "static_cast" => 1,
1193// "const_cast" => 1,
1194// "reinterpret_cast" => 1,
1195// "dynamic_cast" => 1,
1196// "using" => 1,
1197 "typeid" => 1,
1198// "asm" => 1,
1199 "catch" => 1,
1200 "signed" => 1,
1201 "template" => 1,
1202 "throw" => 1,
1203 "try" => 1,
1204// "namespace" => 1,
1205 "volatile" => 1
1206
1207 );
1208
1209$aC_Symbols = array(
1210 "{" => 1,
1211 "}" => 1,
1212// "[" => 1,
1213// "]" => 1,
1214// "(" => 1,
1215// ")" => 1,
1216// "." => 1,
1217// "," => 1,
1218 "!" => 1,
1219 "%" => 1,
1220// "&" => 1,
1221 "&amp;" => 1,
1222 "*" => 1,
1223 "-" => 1,
1224 "=" => 1,
1225 "+" => 1,
1226 ":" => 1,
1227 ";" => 1,
1228// "<" => 1,
1229 "&lt;" => 1,
1230// ">" => 1,
1231 "&gt;" => 1,
1232 "?" => 1,
1233 "/" => 1,
1234 "|" => 1,
1235 "~" => 1,
1236 "^" => 1,
1237 "*" => 1);
1238
1239/**
1240 * Initiate the variable array used by the C Color encoder.
1241 * @param $aVaraibles Variable array. (output)
1242 */
1243function C_ColorInit(&$aVariables)
1244{
1245 global $aC_Keywords;
1246 global $aC_Symbols;
1247
1248 $aVariables["fComment"] = 0;
1249
1250 ksort($aC_Keywords);
1251 ksort($aC_Symbols);
1252}
1253
1254
1255/**
1256 * Encode a line of C code.
1257 * @param $sLine Line string to encode.
1258 * @param $aVariables Variable array.
1259 * @returns Color encoded line string.
1260 */
1261function C_ColorEncode($sLine, &$aVariables)
1262{
1263 global $aC_Keywords;
1264 global $aC_Symbols;
1265
1266 $sRet = "";
1267 $cchLine = strlen($sLine);
1268
1269 /*
1270 * If mulitline comment we'll only check if it ends at this line.
1271 * if it doesn't we'll do nothing.
1272 * if it does we'll skip to then end of it.
1273 */
1274 if ($aVariables["fComment"])
1275 {
1276 if (!(($i = strpos($sLine, "*/")) || ($cchLine >= 2 && $sLine[0] == '*' && $sLine[1] == '/')))
1277 return $sLine;
1278 $i += 2;
1279 $sRet = substr($sLine, 0, $i)."</font>";
1280 $aVariables["fComment"] = 0;
1281 }
1282 else
1283 $i = 0;
1284
1285 /*
1286 * Loop thru the (remainings) of the line.
1287 */
1288 $fFirstNonBlank = 1;
1289 while ($i < $cchLine)
1290 {
1291 $ch = $sLine[$i];
1292 /* comment check */
1293 if ($i+1 < $cchLine && $ch == '/')
1294 {
1295 if ($sLine[$i+1] == '/')
1296 { /* one-line comment */
1297 return $sRet . "<font color=#02FE02>" . substr($sLine, $i) . "</font>";
1298 }
1299
1300 if ($sLine[$i+1] == '*')
1301 { /* Start of multiline comment */
1302 if ($j = strpos($sLine, "*/", $i + 2))
1303 {
1304 $sRet .= "<font color=#02FE02>" . substr($sLine, $i, $j+2 - $i) . "</font>";
1305 $i = $j + 2;
1306 }
1307 else
1308 {
1309 $aVariables["fComment"] = 1;
1310 return $sRet . "<font color=#02FE02>" . substr($sLine, $i);
1311 }
1312 continue;
1313 }
1314 }
1315
1316 /*
1317 * Check for string.
1318 */
1319 if ((($fDbl = (/*$sLine[$i] == '"' ||*/ substr($sLine, $i, 6) == "&quot;")) || $sLine[$i] == "'")
1320 && ($i == 0 || $sLine[$i-1] != '\\'))
1321 { /* start of a string */
1322 $j = $i + 1;
1323 if ($fDbl)
1324 {
1325 /* if ($sLine[$i] == '"')
1326 while ($j < $cchLine && $sLine[$j] != '"')
1327 $j += ($sLine[$j] == '\\') ? 2 : 1;
1328 else */
1329 {
1330 while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != "&quot;"))
1331 $j += ($sLine[$j] == '\\') ? 2 : 1;
1332 if ($j < $cchLine)
1333 $j += 5;
1334 }
1335 }
1336 else
1337 while ($j < $cchLine && $sLine[$j] != "'")
1338 $j += ($sLine[$j] == '\\') ? 2 : 1;
1339 $j++;
1340 $sRet .= "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>";
1341 $i = $j;
1342 continue;
1343 }
1344
1345 /*
1346 * Check for preprocessor directive.
1347 */
1348 if ($fFirstNonBlank && $ch == "#")
1349 {
1350 $j = $i + 1;
1351 while ($j < $cchLine && ($sLine[$j] == " " || $sLine[$j] == "\t"))
1352 $j++;
1353 $j += C_WordLen($sLine, $cchLine, $j);
1354 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $j - $i) . "</font>";
1355 $i = $j;
1356 $fFirstNonBlank = 0;
1357 continue;
1358 }
1359
1360 /*
1361 * If non-blank, lets check if we're at the start of a word...
1362 */
1363 $fBlank = ($ch == " " || $ch == "\t" || $ch == "\n");
1364 if ($fFirstNonBlank) $fFirstNonBlank = $fBlank;
1365 $cchWord = !$fBlank ? C_WordLen($sLine, $cchLine, $i) : 0;
1366
1367 if ($cchWord > 0)
1368 {
1369 /*
1370 * Check for keyword or number.
1371 */
1372 if (isset($aC_Keywords[substr($sLine, $i, $cchWord)]) || ($ch >= '0' && $ch <= '9'))
1373 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
1374
1375 /*
1376 * Skip word.
1377 */
1378 else
1379 $sRet .= substr($sLine, $i, $cchWord);
1380 $i += $cchWord;
1381 continue;
1382 }
1383
1384
1385 /*
1386 * Prepare for symbol check. (we'll have to check for HTML stuff like &amp;).
1387 */
1388 $cchWord = 1;
1389 if ($ch == '&')
1390 {
1391 /*
1392 while ($cchWord < 8 && $sLine[$i+$cchWord] != ';' &&
1393 ( ($sLine[$i+$cchWord] >= 'a' && $sLine[$i+$cchWord] <= 'z')
1394 || ($sLine[$i+$cchWord] >= 'A' && $sLine[$i+$cchWord] <= 'Z')
1395 )
1396 )
1397 $cchWord++;
1398
1399 if ($sLine[$i + $cchWord++] != ';')
1400 $cchWord = 1;
1401 */
1402 if (substr($sLine, $i, 5) == "&amp;")
1403 $cchWord = 5;
1404 else if (substr($sLine, $i, 4) == "&gt;" || substr($sLine, $i, 4) == "&lt;")
1405 $cchWord = 4;
1406 }
1407
1408 /*
1409 * Check for Symbol.
1410 */
1411 if (isset($aC_Symbols[substr($sLine, $i, $cchWord)]))
1412 {
1413 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>";
1414 $i += $cchWord;
1415 continue;
1416 }
1417
1418
1419 /*
1420 * Copy char
1421 */
1422 $sRet .= $sLine[$i];
1423 $i++;
1424 }
1425
1426 return $sRet;
1427}
1428
1429
1430/**
1431 * Encode a line of C code.
1432 * @param $sLine Line string to encode.
1433 * @param $aVariables Variable array.
1434 * @returns Color encoded line string.
1435 */
1436function C_ColorEncode2($sLine, &$aVariables)
1437{
1438 global $aC_Keywords;
1439 global $aC_Symbols;
1440
1441 $cchLine = strlen($sLine);
1442
1443 /*
1444 * If mulitline comment we'll only check if it ends at this line.
1445 * if it doesn't we'll do nothing.
1446 * if it does we'll skip to then end of it.
1447 */
1448 if ($aVariables["fComment"])
1449 {
1450 if (!(($i = strpos($sLine, "*/")) || ($cchLine >= 2 && $sLine[0] == '*' && $sLine[1] == '/')))
1451 {
1452 echo $sLine;
1453 return;
1454 }
1455 $i += 2;
1456 echo substr($sLine, 0, $i)."</font>";
1457 $aVariables["fComment"] = 0;
1458 }
1459 else
1460 $i = 0;
1461
1462 /*
1463 * Loop thru the (remainings) of the line.
1464 */
1465 $fFirstNonBlank = 1;
1466 while ($i < $cchLine)
1467 {
1468 $ch = $sLine[$i];
1469 /* comment check */
1470 if ($i+1 < $cchLine && $ch == '/')
1471 {
1472 if ($sLine[$i+1] == '/')
1473 { /* one-line comment */
1474 echo "<font color=#02FE02>" . substr($sLine, $i) . "</font>";
1475 return;
1476 }
1477
1478 if ($sLine[$i+1] == '*')
1479 { /* Start of multiline comment */
1480 if ($j = strpos($sLine, "*/", $i + 2))
1481 {
1482 echo "<font color=#02FE02>" . substr($sLine, $i, $j+2 - $i) . "</font>";
1483 $i = $j + 2;
1484 }
1485 else
1486 {
1487 $aVariables["fComment"] = 1;
1488 echo "<font color=#02FE02>" . substr($sLine, $i);
1489 return;
1490 }
1491 continue;
1492 }
1493 }
1494
1495 /*
1496 * Check for string.
1497 */
1498 if ((($fDbl = (/*$sLine[$i] == '"' ||*/ substr($sLine, $i, 6) == "&quot;")) || $sLine[$i] == "'")
1499 && ($i == 0 || $sLine[$i-1] != '\\'))
1500 { /* start of a string */
1501 $j = $i + 1;
1502 if ($fDbl)
1503 {
1504 /* if ($sLine[$i] == '"')
1505 while ($j < $cchLine && $sLine[$j] != '"')
1506 $j += ($sLine[$j] == '\\') ? 2 : 1;
1507 else */
1508 {
1509 while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != "&quot;"))
1510 $j += ($sLine[$j] == '\\') ? 2 : 1;
1511 if ($j < $cchLine)
1512 $j += 5;
1513 }
1514 }
1515 else
1516 while ($j < $cchLine && $sLine[$j] != "'")
1517 $j += ($sLine[$j] == '\\') ? 2 : 1;
1518 $j++;
1519 echo "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>";
1520 $i = $j;
1521 continue;
1522 }
1523
1524 /*
1525 * Check for preprocessor directive.
1526 */
1527 if ($fFirstNonBlank && $ch == "#")
1528 {
1529 $j = $i + 1;
1530 while ($j < $cchLine && ($sLine[$j] == ' ' || $sLine[$j] == "\t"))
1531 $j++;
1532 $j += C_WordLen($sLine, $cchLine, $j);
1533 echo "<font color=#CECECE>" . substr($sLine, $i, $j - $i) . "</font>";
1534 $i = $j;
1535 $fFirstNonBlank = 0;
1536 continue;
1537 }
1538
1539 /*
1540 * If non-blank, lets check if we're at the start of a word...
1541 */
1542 $fBlank = ($ch == ' ' || $ch == "\t"); //TODO more "blanks"?
1543 if ($fFirstNonBlank) $fFirstNonBlank = $fBlank;
1544 $cchWord = !$fBlank ? C_WordLen($sLine, $cchLine, $i) : 0;
1545
1546 if ($cchWord > 0)
1547 {
1548 /*
1549 * Check for keyword or number.
1550 */
1551 if (isset($aC_Keywords[substr($sLine, $i, $cchWord)]) || ($ch >= '0' && $ch <= '9'))
1552 echo "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
1553
1554 /*
1555 * Skip word.
1556 */
1557 else
1558 echo substr($sLine, $i, $cchWord);
1559 $i += $cchWord;
1560 continue;
1561 }
1562
1563
1564 /*
1565 * Prepare for symbol check. (we'll have to check for HTML stuff like &amp;).
1566 */
1567 $cchWord = 1;
1568 if ($ch == '&')
1569 {
1570 if (substr($sLine, $i, 5) == "&amp;")
1571 $cchWord = 5;
1572 else if (substr($sLine, $i, 4) == "&gt;" || substr($sLine, $i, 4) == "&lt;")
1573 $cchWord = 4;
1574 }
1575
1576 /*
1577 * Check for Symbol.
1578 */
1579 if (isset($aC_Symbols[substr($sLine, $i, $cchWord)]))
1580 {
1581 echo "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>";
1582 $i += $cchWord;
1583 continue;
1584 }
1585
1586
1587 /*
1588 * Copy char
1589 */
1590 echo $ch;
1591 $i++;
1592 }
1593
1594 return;
1595}
1596
1597
1598/**
1599 * Calculates the lenght of the word which eventually starts at [$i].
1600 * @param $sLine Line.
1601 * @param $cchLine Line length.
1602 * @param $i Line index.
1603 * @returns Word length.
1604 */
1605function C_WordLen($sLine, $cchLine, $i)
1606{
1607
1608 /*
1609 * Check that previous letter wasen't a possible
1610 * word part.
1611 */
1612 if ($i > 0)
1613 {
1614 $ch = $sLine[$i - 1];
1615 if ( ($ch >= 'a' && $ch <= 'z')
1616 || ($ch >= 'A' && $ch <= 'Z')
1617 || ($ch >= '0' && $ch <= '9')
1618 || ($ch == '_')
1619 || ($ch == '$')
1620 )
1621 return 0;
1622 }
1623
1624 /*
1625 * Count letters in the word
1626 */
1627 $j = $i;
1628 $ch = $sLine[$i];
1629 while ($i < $cchLine &&
1630 ( ($ch >= 'a' && $ch <= 'z')
1631 || ($ch >= 'A' && $ch <= 'Z')
1632 || ($ch >= '0' && $ch <= '9')
1633 || ($ch == '_')
1634 || ($ch == '$')
1635 )
1636 )
1637 $ch = @$sLine[++$i];
1638 return $i - $j;
1639}
1640
1641
1642/*
1643 *
1644 */
1645
1646/*
1647 * ASM color encoding.
1648 */
1649$aASM_Keywords = array(
1650 "aaa" => 1,
1651 "aad" => 1,
1652 "aam" => 1,
1653 "aas" => 1,
1654 "adc" => 1,
1655 "add" => 1,
1656 "and" => 1,
1657 "arpl" => 1,
1658 "bound" => 1,
1659 "bsf" => 1,
1660 "bsr" => 1,
1661 "bswap" => 1,
1662 "bt" => 1,
1663 "btc" => 1,
1664 "btr" => 1,
1665 "bts" => 1,
1666 "call" => 1,
1667 "cbw" => 1,
1668 "cdq" => 1,
1669 "clc" => 1,
1670 "cld" => 1,
1671 "cli" => 1,
1672 "clts" => 1,
1673 "cmc" => 1,
1674 "cmp" => 1,
1675 "cmps" => 1,
1676 "cmpxchg" => 1,
1677 "cwd" => 1,
1678 "cwde" => 1,
1679 "daa" => 1,
1680 "das" => 1,
1681 "dec" => 1,
1682 "div" => 1,
1683 "enter" => 1,
1684 "hlt" => 1,
1685 "idiv" => 1,
1686 "imul" => 1,
1687 "in" => 1,
1688 "inc" => 1,
1689 "ins" => 1,
1690 "int" => 1,
1691 "into" => 1,
1692 "invd" => 1,
1693 "invlpg" => 1,
1694 "iret" => 1,
1695 "ja" => 1,
1696 "jae" => 1,
1697 "jb" => 1,
1698 "jbe" => 1,
1699 "jc" => 1,
1700 "jcxz" => 1,
1701 "jecxz" => 1,
1702 "je" => 1,
1703 "jg" => 1,
1704 "jge" => 1,
1705 "jl" => 1,
1706 "jle" => 1,
1707 "jna" => 1,
1708 "jnae" => 1,
1709 "jnb" => 1,
1710 "jnbe" => 1,
1711 "jnc" => 1,
1712 "jne" => 1,
1713 "jng" => 1,
1714 "jnge" => 1,
1715 "jnl" => 1,
1716 "jnle" => 1,
1717 "jno" => 1,
1718 "jnp" => 1,
1719 "jns" => 1,
1720 "jnz" => 1,
1721 "jo" => 1,
1722 "jp" => 1,
1723 "jpe" => 1,
1724 "jpo" => 1,
1725 "js" => 1,
1726 "jz" => 1,
1727 "jmp" => 1,
1728 "lahf" => 1,
1729 "lar" => 1,
1730 "lea" => 1,
1731 "leave" => 1,
1732 "lgdt" => 1,
1733 "lidt" => 1,
1734 "lldt" => 1,
1735 "lmsw" => 1,
1736 "lock" => 1,
1737 "lods" => 1,
1738 "loop" => 1,
1739 "loopz" => 1,
1740 "loopnz" => 1,
1741 "loope" => 1,
1742 "loopne" => 1,
1743 "lds" => 1,
1744 "les" => 1,
1745 "lfs" => 1,
1746 "lgs" => 1,
1747 "lss" => 1,
1748 "lsl" => 1,
1749 "ltr" => 1,
1750 "mov" => 1,
1751 "movs" => 1,
1752 "movsx" => 1,
1753 "movzx" => 1,
1754 "mul" => 1,
1755 "neg" => 1,
1756 "nop" => 1,
1757 "not" => 1,
1758 "or" => 1,
1759 "out" => 1,
1760 "outs" => 1,
1761 "pop" => 1,
1762 "popa" => 1,
1763 "popad" => 1,
1764 "popf" => 1,
1765 "popfd" => 1,
1766 "push" => 1,
1767 "pusha" => 1,
1768 "pushad" => 1,
1769 "pushf" => 1,
1770 "pushfd" => 1,
1771 "rcl" => 1,
1772 "rcr" => 1,
1773 "rep" => 1,
1774 "ret" => 1,
1775 "retf" => 1,
1776 "rol" => 1,
1777 "ror" => 1,
1778 "sahf" => 1,
1779 "sal" => 1,
1780 "sar" => 1,
1781 "sbb" => 1,
1782 "scas" => 1,
1783 "seta" => 1,
1784 "setae" => 1,
1785 "setb" => 1,
1786 "setbe" => 1,
1787 "setc" => 1,
1788 "sete" => 1,
1789 "setg" => 1,
1790 "setge" => 1,
1791 "setl" => 1,
1792 "setle" => 1,
1793 "setna" => 1,
1794 "setnae" => 1,
1795 "setnb" => 1,
1796 "setnbe" => 1,
1797 "setnc" => 1,
1798 "setne" => 1,
1799 "setng" => 1,
1800 "setnge" => 1,
1801 "setnl" => 1,
1802 "setnle" => 1,
1803 "setno" => 1,
1804 "setnp" => 1,
1805 "setns" => 1,
1806 "setnz" => 1,
1807 "seto" => 1,
1808 "setp" => 1,
1809 "setpe" => 1,
1810 "setpo" => 1,
1811 "sets" => 1,
1812 "setz" => 1,
1813 "sgdt" => 1,
1814 "shl" => 1,
1815 "shld" => 1,
1816 "shr" => 1,
1817 "shrd" => 1,
1818 "sidt" => 1,
1819 "sldt" => 1,
1820 "smsw" => 1,
1821 "stc" => 1,
1822 "std" => 1,
1823 "sti" => 1,
1824 "stos" => 1,
1825 "str" => 1,
1826 "sub" => 1,
1827 "test" => 1,
1828 "verr" => 1,
1829 "verw" => 1,
1830 "wait" => 1,
1831 "wbinvd" => 1,
1832 "xadd" => 1,
1833 "xchg" => 1,
1834 "xlatb" => 1,
1835 "xor" => 1,
1836 "fabs" => 1,
1837 "fadd" => 1,
1838 "fbld" => 1,
1839 "fbstp" => 1,
1840 "fchs" => 1,
1841 "fclex" => 1,
1842 "fcom" => 1,
1843 "fcos" => 1,
1844 "fdecstp" => 1,
1845 "fdiv" => 1,
1846 "fdivr" => 1,
1847 "ffree" => 1,
1848 "fiadd" => 1,
1849 "ficom" => 1,
1850 "fidiv" => 1,
1851 "fidivr" => 1,
1852 "fild" => 1,
1853 "fimul" => 1,
1854 "fincstp" => 1,
1855 "finit" => 1,
1856 "fist" => 1,
1857 "fisub" => 1,
1858 "fisubr" => 1,
1859 "fld" => 1,
1860 "fld1" => 1,
1861 "fldl2e" => 1,
1862 "fldl2t" => 1,
1863 "fldlg2" => 1,
1864 "fldln2" => 1,
1865 "fldpi" => 1,
1866 "fldz" => 1,
1867 "fldcw" => 1,
1868 "fldenv" => 1,
1869 "fmul" => 1,
1870 "fnop" => 1,
1871 "fpatan" => 1,
1872 "fprem" => 1,
1873 "fprem1" => 1,
1874 "fptan" => 1,
1875 "frndint" => 1,
1876 "frstor" => 1,
1877 "fsave" => 1,
1878 "fscale" => 1,
1879 "fsetpm" => 1,
1880 "fsin" => 1,
1881 "fsincos" => 1,
1882 "fsqrt" => 1,
1883 "fst" => 1,
1884 "fstcw" => 1,
1885 "fstenv" => 1,
1886 "fstsw" => 1,
1887 "fsub" => 1,
1888 "fsubr" => 1,
1889 "ftst" => 1,
1890 "fucom" => 1,
1891 "fwait" => 1,
1892 "fxam" => 1,
1893 "fxch" => 1,
1894 "fxtract" => 1,
1895 "fyl2x" => 1,
1896 "fyl2xp1" => 1,
1897 "f2xm1" => 1
1898 );
1899
1900$aASM_PPKeywords = array(
1901 ".align" => 1,
1902 ".alpha" => 1,
1903 "and" => 1,
1904 "assume" => 1,
1905 "byte" => 1,
1906 "code" => 1,
1907 ".code" => 1,
1908 "comm" => 1,
1909 "comment" => 1,
1910 ".const" => 1,
1911 ".cref" => 1,
1912 ".data" => 1,
1913 ".data?" => 1,
1914 "db" => 1,
1915 "dd" => 1,
1916 "df" => 1,
1917 "dosseg" => 1,
1918 "dq" => 1,
1919 "dt" => 1,
1920 "dw" => 1,
1921 "dword" => 1,
1922 "else" => 1,
1923 "end" => 1,
1924 "endif" => 1,
1925 "endm" => 1,
1926 "endp" => 1,
1927 "ends" => 1,
1928 "eq" => 1,
1929 "equ" => 1,
1930 ".err" => 1,
1931 ".err1" => 1,
1932 ".err2" => 1,
1933 ".errb" => 1,
1934 ".errdef" => 1,
1935 ".errdif" => 1,
1936 ".erre" => 1,
1937 ".erridn" => 1,
1938 ".errnb" => 1,
1939 ".errndef" => 1,
1940 ".errnz" => 1,
1941 "event" => 1,
1942 "exitm" => 1,
1943 "extrn" => 1,
1944 "far" => 1,
1945 ".fardata" => 1,
1946 ".fardata?" => 1,
1947 "fword" => 1,
1948 "ge" => 1,
1949 "group" => 1,
1950 "gt" => 1,
1951 "high" => 1,
1952 "if" => 1,
1953 "if1" => 1,
1954 "if2" => 1,
1955 "ifb" => 1,
1956 "ifdef" => 1,
1957 "ifdif" => 1,
1958 "ife" => 1,
1959 "ifidn" => 1,
1960 "ifnb" => 1,
1961 "ifndef" => 1,
1962 "include" => 1,
1963 "includelib" => 1,
1964 "irp" => 1,
1965 "irpc" => 1,
1966 "label" => 1,
1967 ".lall" => 1,
1968 "le" => 1,
1969 "length" => 1,
1970 ".lfcond" => 1,
1971 ".list" => 1,
1972 "local" => 1,
1973 "low" => 1,
1974 "lt" => 1,
1975 "macro" => 1,
1976 "mask" => 1,
1977 "mod" => 1,
1978 ".model" => 1,
1979 "name" => 1,
1980 "ne" => 1,
1981 "near" => 1,
1982 "not" => 1,
1983 "offset" => 1,
1984 "or" => 1,
1985 "org" => 1,
1986 "%out" => 1,
1987 "page" => 1,
1988 "proc" => 1,
1989 "ptr" => 1,
1990 "public" => 1,
1991 "purge" => 1,
1992 "qword" => 1,
1993 ".radix" => 1,
1994 "record" => 1,
1995 "rept" => 1,
1996 ".sall" => 1,
1997 "seg" => 1,
1998 "segment" => 1,
1999 ".seq" => 1,
2000 ".sfcond" => 1,
2001 "short" => 1,
2002 "size" => 1,
2003 ".stack" => 1,
2004 "struc" => 1,
2005 "subttl" => 1,
2006 "tbyte" => 1,
2007 ".tfcond" => 1,
2008 "this" => 1,
2009 "title" => 1,
2010 "type" => 1,
2011 ".type" => 1,
2012 "width" => 1,
2013 "word" => 1,
2014 ".xall" => 1,
2015 ".xcref" => 1,
2016 ".xlist" => 1,
2017 "xor" => 1
2018 );
2019
2020$aASM_Symbols = array(
2021 "{" => 1,
2022 "}" => 1,
2023 "!" => 1,
2024 "%" => 1,
2025 "&amp;" => 1,
2026 "*" => 1,
2027 "-" => 1,
2028 "=" => 1,
2029 "+" => 1,
2030 "&lt;" => 1,
2031 "&gt;" => 1,
2032 "/" => 1,
2033 "|" => 1,
2034 "~" => 1,
2035 "*" => 1);
2036
2037/**
2038 * Initiate the variable array used by the C Color encoder.
2039 * @param $aVaraibles Variable array. (output)
2040 */
2041function ASM_ColorInit(&$aVariables)
2042{
2043 global $aASM_Keywords;
2044 global $aASM_PPKeywords;
2045 global $aASM_Symbols;
2046
2047 ksort($aASM_Keywords);
2048 ksort($aASM_PPKeywords);
2049 ksort($aASM_Symbols);
2050}
2051
2052
2053/**
2054 * Encode a line of C code.
2055 * @param $sLine Line string to encode.
2056 * @param $aVariables Variable array.
2057 * @returns Color encoded line string.
2058 */
2059function ASM_ColorEncode($sLine, &$aVariables)
2060{
2061 global $aASM_Keywords;
2062 global $aASM_PPKeywords;
2063 global $aASM_Symbols;
2064
2065 $sRet = "";
2066 $cchLine = strlen($sLine);
2067 $i = 0;
2068 $fFirstNonBlank = 1;
2069
2070 /*
2071 * Loop thru the (remainings) of the line.
2072 */
2073 while ($i < $cchLine)
2074 {
2075 $ch = $sLine[$i];
2076
2077 /* comment check */
2078 if ($ch == ';')
2079 {
2080 return $sRet . "<font color=#02FE02>" . substr($sLine, $i) . "</font>";
2081 }
2082
2083 /*
2084 * Check for string.
2085 */
2086 if ((($fDbl = (substr($sLine, $i, 6) == "&quot;")) || $sLine[$i] == "'")
2087 && ($i == 0 || $sLine[$i-1] != '\\'))
2088 { /* start of a string */
2089
2090 $j = $i + 1;
2091 if ($fDbl)
2092 {
2093 while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != "&quot;"))
2094 $j += ($sLine[$j] == '\\') ? 2 : 1;
2095 if ($j < $cchLine)
2096 $j += 5;
2097 }
2098 else
2099 while ($j < $cchLine && $sLine[$j] != "'")
2100 $j += ($sLine[$j] == '\\') ? 2 : 1;
2101 $j++;
2102 $sRet .= "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>";
2103 $i = $j;
2104 $fFirstNonBlank = 0;
2105 continue;
2106 }
2107
2108 /*
2109 * If non-blank, lets check if we're at the start of a word...
2110 */
2111 $fBlank = ($ch == " " || $ch == "\t" || $ch == "\n");
2112 $cchWord = !$fBlank ? ASM_WordLen($sLine, $cchLine, $i) : 0;
2113
2114 if ($cchWord > 0)
2115 {
2116 $sWord = strtolower(substr($sLine, $i, $cchWord));
2117
2118 /*
2119 * Check for number.
2120 */
2121 if (($ch >= '0' && $ch <= '9'))
2122 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
2123 else
2124 {
2125 if ($fFirstNonBlank)
2126 {
2127 /*
2128 * Check for asm keyword.
2129 */
2130 if (isset($aASM_Keywords[$sWord]))
2131 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
2132 /*
2133 * Check for preprocessor directive.
2134 */
2135 else if (($f = isset($aASM_PPKeywords[$sWord]))
2136 ||
2137 ($i > 0 && $sLine[$i-1] == '.' && isset($aASM_PPKeywords[".".$sWord]))
2138 )
2139 {
2140 if ($f)
2141 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>";
2142 else
2143 $sRet = substr($sRet, 0, -1) . "<font color=#CECECE>." . substr($sLine, $i, $cchWord) . "</font>";
2144 }
2145 /*
2146 * Skip word.
2147 */
2148 else
2149 $sRet .= substr($sLine, $i, $cchWord);
2150 }
2151 else
2152 {
2153 /*
2154 * Check for preprocessor directive.
2155 */
2156 if (($f = isset($aASM_PPKeywords[$sWord]))
2157 ||
2158 ($i > 0 && $sLine[$i-1] == '.' && isset($aASM_PPKeywords[".".$sWord]))
2159 )
2160 {
2161 if ($f)
2162 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>";
2163 else
2164 $sRet = substr($sRet, 0, -1) . "<font color=#CECECE>." . substr($sLine, $i, $cchWord) . "</font>";
2165 }
2166 /*
2167 * Check for asm keyword.
2168 */
2169 else if (isset($aASM_Keywords[$sWord]))
2170 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
2171 /*
2172 * Skip word.
2173 */
2174 else
2175 $sRet .= substr($sLine, $i, $cchWord);
2176 }
2177 }
2178
2179 $i += $cchWord;
2180 $fFirstNonBlank = 0;
2181 continue;
2182 }
2183
2184 /*
2185 * Prepare for symbol check. (we'll have to check for HTML stuff like &amp;).
2186 */
2187 $cchWord = 1;
2188 if ($ch == '&')
2189 {
2190 if (substr($sLine, $i, 5) == "&amp;")
2191 $cchWord = 5;
2192 else if (substr($sLine, $i, 4) == "&gt;" || substr($sLine, $i, 4) == "&lt;")
2193 $cchWord = 4;
2194 }
2195
2196 /*
2197 * Check for Symbol.
2198 */
2199 if (isset($aASM_Symbols[substr($sLine, $i, $cchWord)]))
2200 {
2201 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>";
2202 $i += $cchWord;
2203 $fFirstNonBlank = 0;
2204 continue;
2205 }
2206
2207
2208 /*
2209 * Copy char
2210 */
2211 $sRet .= $sLine[$i];
2212 $i++;
2213 if ($fFirstNonBlank && !$fBlank)
2214 $fFirstNonBlank = 0;
2215 }
2216
2217 return $sRet;
2218}
2219
2220/**
2221 * Calculates the lenght of the word which eventually starts at [$i].
2222 * @param $sLine Line.
2223 * @param $cchLine Line length.
2224 * @param $i Line index.
2225 * @returns Word length.
2226 */
2227function ASM_WordLen($sLine, $cchLine, $i)
2228{
2229
2230 /*
2231 * Check that previous letter wasen't a possible
2232 * word part.
2233 */
2234 if ($i > 0)
2235 {
2236 $ch = $sLine[$i - 1];
2237 if ( ($ch >= 'a' && $ch <= 'z')
2238 || ($ch >= 'A' && $ch <= 'Z')
2239 || ($ch >= '0' && $ch <= '9')
2240 || ($ch == '_')
2241 || ($ch == '@')
2242 || ($ch == '?')
2243 || ($ch == '$')
2244 )
2245 return 0;
2246 }
2247
2248 /*
2249 * Count letters in the word
2250 */
2251 $j = $i;
2252 $ch = $sLine[$i];
2253 while ($i < $cchLine &&
2254 ( ($ch >= 'a' && $ch <= 'z')
2255 || ($ch >= 'A' && $ch <= 'Z')
2256 || ($ch >= '0' && $ch <= '9')
2257 || ($ch == '_')
2258 || ($ch == '@')
2259 || ($ch == '?')
2260 || ($ch == '$')
2261 )
2262 )
2263 $ch = @$sLine[++$i];
2264 return $i - $j;
2265}
2266
2267
2268
2269/*
2270 *
2271 */
2272/* hardcoded
2273$aMake_Keywords = array(
2274 "\$&amp;" => 1,
2275 "\$**" => 1,
2276 "\$*" => 1,
2277 "\$." => 1,
2278 "\$:" => 1,
2279 "\$&lt;" => 1,
2280 "\$?" => 1,
2281 "\$@" => 1,
2282 "\$d" => 1);
2283*/
2284$aMake_Symbols = array(
2285 "@" => 1,
2286 "(" => 1,
2287 ")" => 1,
2288 "." => 1,
2289 "=" => 1,
2290 "*" => 1,
2291 "+" => 1,
2292 "-" => 1,
2293 "/" => 1,
2294 "" => 1,
2295 "[" => 1,
2296 "]" => 1,
2297 "," => 1,
2298 "&lt;" => 1,
2299 "&gt;" => 1,
2300 ":" => 1,
2301 ";" => 1);
2302/**
2303 * Initiate the variable array used by the C Color encoder.
2304 * @param $aVaraibles Variable array. (output)
2305 */
2306function Make_ColorInit(&$aVariables)
2307{
2308 //global $aMake_Keywords;
2309 global $aMake_Symbols;
2310 //$aVariables = array("fInline" => 0)
2311 //ksort($aMake_Keywords);
2312 ksort($aMake_Symbols);
2313}
2314
2315
2316/**
2317 * Encode a line of C code.
2318 * @param $sLine Line string to encode.
2319 * @param $aVariables Variable array.
2320 * @returns Color encoded line string.
2321 */
2322function Make_ColorEncode($sLine, &$aVariables)
2323{
2324 global $aMake_Keywords;
2325 global $aMake_Symbols;
2326
2327 $sRet = "";
2328 $cchLine = strlen($sLine);
2329 $i = 0;
2330 $fFirstNonBlank = 1;
2331
2332 /*
2333 * Loop thru the (remainings) of the line.
2334 */
2335 while ($i < $cchLine)
2336 {
2337 $ch = $sLine[$i];
2338
2339 /* comment check */
2340 if ($ch == '#')
2341 {
2342 return $sRet . "<font color=#02FE02>" . substr($sLine, $i) . "</font>";
2343 }
2344
2345
2346 /*
2347 * Check for string.
2348 */
2349 if ((($fDbl = (substr($sLine, $i, 6) == "&quot;")) || $sLine[$i] == "'")
2350 && ($i == 0 || $sLine[$i-1] != '\\'))
2351 { /* start of a string */
2352
2353 $j = $i + 1;
2354 if ($fDbl)
2355 {
2356 while ($j < $cchLine && ($sLine[$j] != '&' || substr($sLine, $j, 6) != "&quot;"))
2357 $j += ($sLine[$j] == '\\') ? 2 : 1;
2358 if ($j < $cchLine)
2359 $j += 5;
2360 }
2361 else
2362 while ($j < $cchLine && $sLine[$j] != "'")
2363 $j += ($sLine[$j] == '\\') ? 2 : 1;
2364 $j++;
2365 $sRet .= "<font color=#FEFE02>".substr($sLine, $i, $j - $i)."</font>";
2366 $i = $j;
2367 $fFirstNonBlank = 0;
2368 continue;
2369 }
2370
2371 /*
2372 * Check for ! or % words
2373 */
2374 if (($fFirstNonBlank && ($ch == "#" || $ch == "!")))
2375 {
2376 $j = $i + 1;
2377 while ($j < $cchLine && ($sLine[$j] == ' ' || $sLine[$j] == "\t"))
2378 $j++;
2379 $j += Make_WordLen($sLine, $cchLine, $j);
2380 echo "<font color=#CECECE>" . substr($sLine, $i, $j - $i) . "</font>";
2381 $i = $j;
2382 $fFirstNonBlank = 0;
2383 continue;
2384 }
2385
2386 /*
2387 * Check for keyword
2388 */
2389 /* don't work
2390 if ($ch == "$" && $i + 1 < $cchLine)
2391 {
2392 $cch = 0;
2393 $sWord = substr($sLine, $i+1, 1);
2394 if ( $sWord == "*"
2395 || $sWord == "."
2396 || $sWord == ":"
2397 || $sWord == "?"
2398 || $sWord == "@"
2399 || $sWord == "d")
2400 $cch = 2;
2401 else if ($i + 2 < $cchLine && ($sWord = substr($sLine, $i+1, 2)) == "**")
2402 $cch = 3;
2403 else if ($i + 4 < $cchLine && ($sWord = substr($sLine, $i+1, 5)) == "&amp;")
2404 $cch = 6;
2405 else if ($i + 5 < $cchLine && ($sWord = substr($sLine, $i+1, 4)) == "&lt;")
2406 $cch = 5;
2407 if ($cch > 0)
2408 {
2409 echo "<font color=#CECECE>$" . $sWord . "</font>";
2410 $i += $cch;
2411 $fFirstNonBlank = 0;
2412 continue;
2413 }
2414 } */
2415
2416 /*
2417 * If non-blank, lets check if we're at the start of a word...
2418 */
2419 $fBlank = ($ch == " " || $ch == "\t" || $ch == "\n");
2420 $cchWord = !$fBlank ? Make_WordLen($sLine, $cchLine, $i) : 0;
2421
2422 if ($cchWord > 0)
2423 {
2424 $sWord = strtolower(substr($sLine, $i, $cchWord));
2425
2426 /*
2427 * Check for keywords.
2428 */
2429 if ($f = isset($aMake_Keywords[$sWord]))
2430 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
2431
2432 /*
2433 * Check for number.
2434 */
2435 else if (($ch >= '0' && $ch <= '9'))
2436 $sRet .= "<font color=#FF0202>" . substr($sLine, $i, $cchWord) . "</font>";
2437
2438 /*
2439 * Skip word.
2440 */
2441 else
2442 $sRet .= substr($sLine, $i, $cchWord);
2443
2444 $i += $cchWord;
2445 $fFirstNonBlank = 0;
2446 continue;
2447 }
2448
2449 /*
2450 * Prepare for symbol check. (we'll have to check for HTML stuff like &amp;).
2451 */
2452 $cchWord = 1;
2453 if ($ch == '&')
2454 {
2455 if (substr($sLine, $i, 5) == "&amp;")
2456 $cchWord = 5;
2457 else if (substr($sLine, $i, 4) == "&gt;" || substr($sLine, $i, 4) == "&lt;")
2458 $cchWord = 4;
2459 }
2460
2461 /*
2462 * Check for Symbol.
2463 */
2464 if (isset($aMake_Symbols[substr($sLine, $i, $cchWord)]))
2465 {
2466 $sRet .= "<font color=#CECECE>" . substr($sLine, $i, $cchWord) . "</font>";
2467 $i += $cchWord;
2468 $fFirstNonBlank = 0;
2469 continue;
2470 }
2471
2472
2473 /*
2474 * Copy char
2475 */
2476 $sRet .= $sLine[$i];
2477 $i++;
2478 if ($fFirstNonBlank && !$fBlank)
2479 $fFirstNonBlank = 0;
2480 }
2481
2482 return $sRet;
2483}
2484
2485/**
2486 * Calculates the lenght of the word which eventually starts at [$i].
2487 * @param $sLine Line.
2488 * @param $cchLine Line length.
2489 * @param $i Line index.
2490 * @returns Word length.
2491 */
2492function Make_WordLen($sLine, $cchLine, $i)
2493{
2494
2495 /*
2496 * Check that previous letter wasen't a possible
2497 * word part.
2498 */
2499 if ($i > 0)
2500 {
2501 $ch = $sLine[$i - 1];
2502 if ( ($ch >= 'a' && $ch <= 'z')
2503 || ($ch >= 'A' && $ch <= 'Z')
2504 || ($ch >= '0' && $ch <= '9')
2505 || ($ch == '_')
2506 )
2507 return 0;
2508 }
2509
2510 /*
2511 * Count letters in the word
2512 */
2513 $j = $i;
2514 $ch = $sLine[$i];
2515 while ($i < $cchLine &&
2516 ( ($ch >= 'a' && $ch <= 'z')
2517 || ($ch >= 'A' && $ch <= 'Z')
2518 || ($ch >= '0' && $ch <= '9')
2519 || ($ch == '_')
2520 )
2521 )
2522 $ch = @$sLine[++$i];
2523 return $i - $j;
2524}
2525
2526
2527?>
2528
Note: See TracBrowser for help on using the repository browser.