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