1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
<?php
/* function menulayout
* Takes 6 arguments and outputs a HTML navigation menu
* $forward = link to "next page", i.e. "nextPage.html"
* $backward = link to "previous page", i.e. "previousPage.html"
* $downloadlink = link to download source file, on download button, i.e. "sourceFile.txt"
* headinglink = link in heading, i.e. "sourceFile.txt"
* filecontent = file containing info in the left panel, i.e. "panelContent.txt"
*/
function menulayout($forward,$backward,$downloadlink,$heading,$headinglink,$filecontent) {
if($backward != ""){
$backwardButton = "<a href='".$backward."'><img src='../media/codeviewer/CodeViewerLeftbutton.png'></a>";
}else{
$backwardButton = "<img src='../media/codeviewer/CodeViewerLeftbuttonGrayed.png'>";
}
if($forward != ""){
$forwardButton = "<a href='".$forward."'><img src='../media/codeviewer/CodeViewerRightbutton.png'></a>";
}else{
$forwardButton = "<img src='../media/codeviewer/CodeViewerLeftbuttonGrayed.png'>";
}
if($downloadlink != ""){
$downloadButton = "<a href='".$downloadlink."'><img src='../media/codeviewer/CodeViewerDownloadbutton.png'></a>";
}else{
$downloadButton = "<img src='../media/codeviewer/CodeViewerLeftbuttonGrayed.png'>";
}
echo ' <body onload="resize();" onresize="resize();">
<div class="Topmenu">
<table style="width:100%;height:100%;border:solid 1px;">
<tr>
<td class="buttonstyle">
'. $backwardButton .'
</td>
<td class="buttonstyle">
'. $forwardButton .'
</td>
<td class="buttonstyle">
<a href="../Lindex.html"><img src="../media/codeviewer/CodeViewerRightbutton.png"></a>
</td>
<td class="verticalaligntext">
<a href="'. $headinglink .'" style="text-decoration: none">'. $heading .'</a>
</td>
<td class="buttonstyle">
'. $downloadButton .'
</td>
</tr>
</table>
</div>
<div id="bottom" class="restContainer">
<div style="float: left;">
<div id="panel" class="panel" onmousemove="resizepanel(event)" onmousedown="mdpanel(event)" onmouseup="mupanel(event)">';
include($filecontents);
echo ' </div>
</div>
<div class="codecontent">';
}
/* function menulayoutend
* Outputs ending tags in HTML
*/
function menulayoutend() {
echo '
</div>
</div>
<div style="clear: both;"></div>
</body>
';
}
/* function showfile
* Outputs html with syntax highlighting.
* Takes 4 arguments_
* interestingrows: array containing arrays, each with 3 set values -- start line number, end line number, comment
* keywords: array containing keywords
* highlight: array containing arrays, each with two values - string to highlight, and HTML class to apply to highlight */
function showfile($interestingrows,$keywords,$highlight,$filename) {
echo "<pre>";
$handle = @fopen($filename, "r");
if ($handle) {
$lineno = 1;
$commentkind = 0;
$commenton = 0;
while (($buffer = fgets($handle, 4096)) !== false) {
$buffer = str_replace("\n", "", $buffer);
$buffer = str_replace("\r", "", $buffer);
$buffer = str_pad($buffer, 150, " ", STR_PAD_RIGHT);
$buffer = str_replace("&", "&", $buffer);
$buffer = str_replace("<", "<", $buffer);
$buffer = str_replace(">", ">", $buffer);
$buffer = str_replace("\t", " ", $buffer);
$interesting = 0;
$startspan = 0;
foreach($interestingrows as $row){
if($lineno >= $row[0] && $lineno <= $row[1]){
$interesting = true;
}
}
foreach($keywords as $keyword){
if($interesting){
$buffer = str_replace($keyword,"<span class='keywordinteresting'>".$keyword."</span>", $buffer);
}else{
$buffer = str_replace($keyword,"<span class='keyword'>".$keyword."</span>", $buffer);
}
}
// Detect comments - 0 == No comment 1 == Line comment 2 == Start Comment 3 == End Comment
$commentkind = 0;
$commentpos = strpos($buffer,"/*");
if($commentpos >= 0){
$subby = substr($buffer,$commentpos+2,1);
}else{
$subby = "Foo";
}
if($commentpos && $subby != '"'){
$commentkind = 2;
$commenton = 1;
}
$commentpos = strpos($buffer,"*/");
if($commentpos){
$commentkind = 3;
$commenton = 0;
}
$commentpos=strpos($buffer,"//");
if($commentpos){
$commentkind = 1;
$commenton = 0;
}
foreach($highlight as $highlightkeyword){
$foundpos = strpos($buffer, $highlightkeyword[0]);
// If line comment and keyword before comment marker
if(($foundpos <= $commentpos && ($commentkind == 1 || $commentkind == 2)) || ($commentkind == 0) || ($foundpos > $commentpos && $commentkind == 3)) {
if(!($commentkind==0&&$commenton==1)) {
$buffer = str_replace($highlightkeyword[0],"<span class='".$highlightkeyword[1]."'>".$highlightkeyword[0]."</span>",$buffer);
}
}
}
// echo $commentkind.$commenton;
if($commentkind > 0){
if($commentkind == 1){
$buffer = str_replace("//","<span class='commented'>//",$buffer);
$buffer .= "</span>";
}
if($commentkind==2) {
$buffer=str_replace("/*","<span class='commented'>/*",$buffer);
}
if($commentkind==3) {
$buffer=str_replace("*/","*/</span>",$buffer);
}
}
$linenostr = $lineno;
$linenostr = str_pad($linenostr,3," ",STR_PAD_RIGHT);
if($interesting){
echo "<span class='interesting'>";
echo "<span class='linenointeresting'>".$linenostr."</span> ";
$startspan = 1;
} else {
echo "<span class='lineno'>".$linenostr."</span> ";
}
echo $buffer;
if($startspan) {
echo "</span>";
}
$lineno++;
echo "<br>";
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
echo "</pre>";
}
?>
|