/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to CodeViewer/codeviewerfunctions.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-08 08:05:58 UTC
  • mfrom: (19.4.4 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130408080558-0o7itutyu7jrn48b
Note to self: "bzr resolve --all" works like magic.
Merged implementation group 1's branch.
20130408.

Show diffs side-by-side

added added

removed removed

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