57 {
59 if (isset($contextstack) && is_array($contextstack)) {
60 $this->contextstack = $contextstack;
61 $this->context = array_pop($contextstack);
62 $this->context->inwhitespace = 0;
63 } else {
65 $this->context->from_language($this->highlightfile, $this->output_module);
66 $this->contextstack = array();
67 }
68 array_push($this->contextstack, $this->context);
69 $this->langstack = array();
70
71 if (isset($this->highlightfile->zones)) {
72
73
74 $this->starttags = array();
75 $this->endtags = array();
76 $this->starttaglengths = array();
77 foreach ($this->highlightfile->zones as $zone) {
78 $this->startmap[$zone[0]] = $zone[2];
79 array_push($this->starttags, $zone[0]);
80 if (!isset($this->endtags[$zone[0]])) {
81 $this->endtags[$zone[0]] = array();
82 }
83 array_push($this->endtags[$zone[0]], $zone[1]);
84 $this->starttaglengths[$zone[0]] = strlen($zone[0]);
85 }
86 $this->endtaglist = array();
87 $this->langcache = array();
88 }
89
90
91
92 $arr = preg_split(
"/\n/",
$text);
93 $aln = sizeof($arr);
94
95 if (isset($this->context->code_parts[0])) {
96 $out.= $this->context->code_parts[0];
97 }
98 for (
$i=0;
$i<$aln;
$i++) {
99 $this->context->prepro = 0;
101 if ($this->context->preprolength>0 && substr($line, 0, $this->context->preprolength)==$this->highlightfile->prepro) {
102 $out.= $this->context->prepro_parts[0];
103 $this->context->prepro = 1;
104 }
105
106
107 $this->context->inwhitespace = 1;
108
109
110 $this->context->incomment = 0;
111
112 if (isset($this->highlightfile->lineselect) && !$this->context->inselection && substr($line, 0, strlen($this->highlightfile->lineselect))==$this->highlightfile->lineselect) {
113 $out.= $this->context->select_parts[0];
114 $line = substr($line, strlen($this->highlightfile->lineselect));
115 $this->context->lineselect = 1;
116 }
117
118
119 if ($this->highlightfile->notrim==0) {
120 $line = trim($line);
121 }
122
123 $lineout = "";
124 $lineorig = $line;
125
126 $sw = $this->
_starts_with($lineorig, $this->highlightfile->unindent);
127 if ($lineorig != "") {
128 if ($this->context->ind>0 && $sw!="") {
129
130 $lineout = str_repeat("\t", ($this->context->ind-1));
131 } else {
132 $lineout = str_repeat("\t", $this->context->ind);
133 }
134 }
135 $ln = strlen($lineorig);
136 for ($j=0; $j<$ln; $j++) {
137 $currchar = $lineorig[$j];
138
139
140 if (isset($this->highlightfile->selecton) && !$this->context->inselection &&
141 !$this->context->inquote && !$this->context->inbcomment &&
142 substr($line, $j, strlen($this->highlightfile->selecton))==$this->highlightfile->selecton) {
143
144 $lineout = $this->
_munge($lineout) . $this->context->select_parts[0];
146 $lineout = "";
147 $this->context->inselection = 1;
148 $j+= strlen($this->highlightfile->selecton)-1;
149 continue;
150 }
151
152 if (isset($this->highlightfile->selectoff) && $this->context->inselection &&
153 substr($line, $j, strlen($this->highlightfile->selectoff))==$this->highlightfile->selectoff) {
154
155 $lineout.=$this->context->select_parts[1];
157 $lineout = "";
158 $this->context->inselection = 0;
159 $j+= strlen($this->highlightfile->selectoff);
160 continue;
161 }
162
163
164 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->incomment && !($this->highlightfile->perl && $j>0 && $line[$j-1]=="$")) {
165
166 $currmax = 0;
167 foreach ($this->highlightfile->linecommenton as
$l) {
168 if (
$l[0] != $currchar) {
169 continue;
170 }
171 $lln = $this->context->lcolengths[
$l];
172 if (substr($line, $j, $lln)==
$l) {
173 if ($lln > $currmax) {
175 $currmax = $lln;
176 }
177 }
178 }
179
180 if ($currmax != 0) {
181
182
183 $line = substr($line, $j);
184 $lineout = $this->
_munge($lineout);
185 $line = htmlentities($line);
187 if ($this->context->prepro) {
188 $out.= $this->context->prepro_parts[1];
189 $this->context->prepro = 0;
190 }
191 $out.= $this->context->linecomment_parts[0] . $line;
192 if (isset($this->statobj) && $this->statobj->harvest_comments) {
193 $this->statobj->comment_cache .= " " . substr($line, $lncl);
194 }
195 $lineout = "";
196 $this->context->incomment = 1;
197 $j = $ln + 1;
198 continue;
199 }
200 }
201
202
203
204 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->inbcomment && in_array($currchar, $this->context->startingbkonchars)) {
205
206 $currmax = 0;
207 foreach ($this->highlightfile->blockcommenton as $bo) {
208 if ($bo[0] != $currchar) {
209 continue;
210 }
211 $boln = $this->context->bcolengths[$bo];
212 if (substr($line, $j, $boln)==$bo) {
213 if ($boln > $currmax) {
214
215 $bkc = $bo;
216 $bkcl = $boln;
217 $currmax = $boln;
218 }
219 }
220 }
221
222 if ($currmax != 0) {
223
224 if ($this->prepro) {
225 $out.= $this->context->prepro_parts[1];
226 $this->prepro = 0;
227 }
228 $this->context->closingstrings = $this->context->bcomatches[$bkc];
229 $lineout = $this->
_munge($lineout);
230 $bkcout = str_replace(">", ">", $bkc);
231 $bkcout = str_replace("<", "<", $bkcout);
233 $out.= $this->context->blockcomment_parts[0] . $bkcout;
234 $lineout = "";
235 $this->context->inbcomment = 1;
236 $j += $bkcl-1;
237 continue;
238 }
239 }
240
241 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && $this->context->inbcomment) {
242
243 $currmax = 0;
244 foreach ($this->context->closingstrings as $bf) {
245 if ($bf[0] != $currchar) {
246 continue;
247 }
248 $bfln = $this->context->bcflengths[$bf];
249 if (substr($line, $j, $bfln)==$bf) {
250 if ($bfln > $currmax) {
251 $bku = $bf;
252 $bkul = $bfln;
253 $currmax = $bfln;
254 }
255 }
256 }
257
258 if ($currmax != 0) {
259
260 $bkuout = str_replace(">", ">", $bku);
261 $bkuout = str_replace("<", "<", $bkuout);
262 $lineout .= $bkuout . $this->context->blockcomment_parts[1];
263
265 $lineout = "";
266 $this->context->inbcomment = 0;
267 $j += $bkul-1;
268 continue;
269 }
270 }
271 if (isset($this->highlightfile->zones) && !$this->context->inbcomment && !$this->context->incomment && !$this->context->inquote) {
272
273 $startcurrmax = 0;
274 foreach ($this->starttags as $starttag) {
275 if ($starttag[0] != $currchar) {
276 continue;
277 }
278 $starttagln = $this->starttaglengths[$starttag];
279
280 if (substr($line, $j, $starttagln)==$starttag) {
281 if ($starttagln > $startcurrmax) {
282 $startcurrtag = $starttag;
283 $startcurrmax = $starttagln;
284 }
285 }
286 }
287 if ($startcurrmax != 0) {
288
289 $tagout = str_replace(">", ">", $startcurrtag);
290 $tagout = str_replace("<", "<", $tagout);
291 $out.= ltrim($lineout);
292 array_push($this->langstack, $this->highlightfile);
293 array_push($this->contextstack, $this->context);
295 require_once
$BEAUT_PATH .
"/HFile/" . $this->startmap[$startcurrtag] .
".php";
296 $this->endtaglist = $this->endtags[$startcurrtag];
297 if (isset($this->langcache[$startcurrtag])) {
298 $this->highlightfile = $this->langcache[$startcurrtag];
299 } else {
300 $this->highlightfile = new $this->startmap[$startcurrtag]();
301 $this->langcache[$startcurrtag] = $this->highlightfile;
302 }
303 $this->context =
new Context();
304 $this->context->from_language($this->highlightfile, $this->output_module);
305 $lineout = "";
306 $j += $startcurrmax-1;
307 continue;
308 }
309
310 $endcurrmax = 0;
311 foreach ($this->endtaglist as $endtag) {
312 if ($endtag[0] != $currchar) {
313 continue;
314 }
315 $endtagln = strlen($endtag);
316 if (substr($line, $j, $endtagln)==$endtag) {
317 if ($endtagln > $endcurrmax) {
318 $endcurrtag = $endtag;
319 $endcurrmax = $endtagln;
320 }
321 }
322 }
323 if ($endcurrmax!=0) {
324
325 $tagout = str_replace(">", ">", $endcurrtag);
326 $tagout = str_replace("<", "<", $tagout);
327
328 $lineout .= "$tagout";
330 $lineout = "";
331 $this->highlightfile = array_pop($this->langstack);
332 $this->context = array_pop($this->contextstack);
333 $this->endtaglist = array();
334 $j += $endcurrmax;
335 continue;
336 }
337 }
338
339
340 if ($this->context->incomment || $this->context->inbcomment) {
341 if ($this->context->inbcomment) {
342 if ($currchar == "<") {
343 $currchar = "<";
344 } elseif ($currchar == ">") {
345 $currchar = ">";
346 } elseif ($currchar == "&") {
347 $currchar = "&";
348 }
349 }
350
351 $lineout .= $currchar;
352 if ($this->context->newline) {
353 if (isset($this->statobj) && $this->statobj->harvest_comments) {
354 $this->statobj->comment_cache .= " ";
355 }
356 $this->context->newline = 0;
357 }
358 if (isset($this->statobj) && $this->statobj->harvest_comments) {
359 $this->statobj->comment_cache .= $currchar;
360 }
361 continue;
362 }
363
364
365 $delim = ($j==0 || in_array($currchar, $this->context->alldelims) || ($j>0 && in_array($lineorig[$j-1], $this->context->alldelims)));
366
367
368 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->escaping &&
369 ((in_array($currchar, (array) $this->highlightfile->stringchars) && $this->context->inquote && $currchar==$this->context->currquotechar) || (in_array($currchar, (array) $this->highlightfile->stringchars) && !$this->context->inquote))) {
370
371
372
373 if (!$this->context->escaping && isset($this->context->inquote) && !$this->context->inquote) {
374
375 $lineout = $this->
_munge($lineout);
377 $this->context->inquote = 1;
378 if (isset($this->statobj) && $this->statobj->harvest_strings) {
379 $this->string_cache.=" ";
380 }
381 if ($this->context->prepro) {
382 $lineout = $this->context->prepro_parts[1] . $currchar . $this->context->quote_parts[0];
383 } else {
384 $out.= $currchar . $this->context->quote_parts[0];
385 $lineout = "";
386 }
387 $this->context->currquotechar = $currchar;
388 }
389
390 elseif ($this->context->inquote && !$this->context->escaping && $currchar == $this->context->currquotechar) {
391
392 $this->context->inquote = 0;
393 if ($this->context->prepro) {
394 $lineout .= $this->context->quote_parts[1] . $this->context->prepro_parts[0] . $lineorig[$j];
395 } else {
396 $lineout .= $this->context->quote_parts[1] . $lineorig[$j];
397 }
399 $lineout = "";
400 $this->context->currquotechar = "";
401 }
402 }
403
404 elseif (!$this->context->inselection && $delim && !$this->context->inquote && ($stri=$this->_starts_with(substr($line, $j), $this->highlightfile->indent))!="") {
405
406 if (!$this->context->inwhitespace) {
407
408 $lineout .= str_repeat("\t", $this->context->ind);
409 }
410 $lineout .= $stri;
411 $this->context->ind++;
412 $j += strlen($stri)-1;
413 }
414
415 elseif (!$this->context->inselection && $delim && $this->context->ind>0 && !$this->context->inquote && ($stru=$this->_starts_with(substr($line, $j), $this->highlightfile->unindent))!="") {
416
417 $this->context->ind--;
418
419 if (!$this->context->inwhitespace) {
420
421 $lineout .= str_repeat("\t", $this->context->ind);
422 }
423 $lineout .= $stru;
424
425 $j += strlen($stru)-1;
426 }
427
428 elseif (!$this->context->inwhitespace || $currchar != " " || $currchar != "\t") {
429
430 if ($this->context->inquote && isset($this->statobj) && $this->statobj->harvest_strings) {
431 $this->statobj->string_cache .=$currchar;
432 }
433 $lineout .= htmlentities($currchar);
434 }
435 if ($this->context->inquote && $this->context->escaping) {
436
437 $this->context->escaping = 0;
438 } elseif ($this->context->inquote && $currchar == $this->highlightfile->escchar && !$this->context->escaping) {
439
440 $this->context->escaping = 1;
441 }
442 }
443 if ($currchar != " " && $currchar != "\t") {
444 $this->context->inwhitespace = 0;
445 }
446 if (!$this->context->incomment && !$this->context->inbcomment && !$this->context->inquote) {
447 $lineout = $this->
_munge($lineout);
448 }
450 if ($this->context->prepro) {
451 $lineout .= $this->context->prepro_parts[1];
452 }
453 }
454
455 if ($this->context->incomment) {
456 $out.= $this->context->linecomment_parts[1];
457 }
459 $lineout .="\n";
460 }
461 if ($this->context->lineselect) {
462 $lineout.= $this->context->select_parts[1];
463 }
465 $this->context->newline = 1;
466 $this->context->lineselect = 0;
467 }
468
469 if ($this->context->incomment) {
470 $out.= $this->context->linecomment_parts[1];
471 } elseif ($this->context->inbcomment) {
472 $out.= $this->context->blockcomment_parts[1];
473 } elseif ($this->context->inselection) {
474 $out.= $this->context->select_parts[1];
475 }
476 if (isset($this->context->code_parts[1])) {
477 $out.= $this->context->code_parts[1];
478 }
479
480 $pad = str_repeat(" ", $this->highlightfile->indent_depth);
481 $out = str_replace(
"\t", $pad,
$out);
482
484 }
_starts_with($text, $array)