/** */ function markupfile($pathname, $fileh, $ann = array()) { global $files, $conf; preg_match_all('|^(.*/)|', $pathname, $dir); $dir = $dir[0]; /* Determine the file's language and create a Luxor_Lang * instance. */ $lang =& Luxor_Lang::builder($files, $pathname); if (is_a($lang, 'PEAR_Error')) { return $lang; } $html = '<table cellspacing="0" width="100%" class="text">'; // A source code file. if (!$lang) { return false; } $parser = new Luxor_SimpleParse($fileh, 1, $lang->_langmap['spec']); $linenum = 1; list($btype, $frag) = $parser->nextFrag(); $ofrag = ''; while ($frag) { $frag = preg_replace('/([&<>])/', chr(0) . '$1', $frag); switch ($btype) { case 'comment': // Comment // Convert mail adresses to mailto: // &freetextmarkup($frag); // $lang->processComment(\$frag); $frag = Luxor::fixString($frag, '<span class="comment">', '</span>'); break; case 'string': $frag = Luxor::fixString($frag, '<span class="string">', '</span>'); break; case 'include': // Include directive $frag = $lang->processInclude($frag, $dir); break; case 'variable': if (!empty($conf['options']['use_show_var'])) { $pre = sprintf('<span class="variable"><span class="var_%s" onmouseover="show_var(\'var_%s\');" onmouseout="unshow_var(\'var_%s\');">', substr($frag, 1), substr($frag, 1), substr($frag, 1)); $frag = Luxor::fixString($frag, $pre, '</span></span>'); } else { $frag = Luxor::fixString($frag, '<span class="variable">', '</span>'); } break; default: // Code // somehow get $source['may_reference'] into the second parameter here. $frag = $lang->processCode($frag); } $frag = preg_replace('/\\0([&<>])/', '$1', $frag); $ofrag .= $frag; list($btype, $frag) = $parser->nextFrag(); } $lines = preg_split('(\\r\\n|\\n|\\r)', $ofrag); foreach ($lines as $line) { $html .= '<tr><td align="right" style="padding-left:10px; padding-right:10px;"><a id="l' . $linenum . '" class="fixed" style="color:black">' . $linenum++ . '</a></td><td width="100%" class="fixed">' . $line . "</td></tr>\n"; } return $html . '</table>'; }
/** * References a file. * * @param string $path The full path name of the file to reference. * @param int $fileId The file's unique ID. * * @return mixed A PEAR_Error on error. */ function referenceFile($path, $fileId) { global $conf, $index; $fp = @fopen($path, 'r'); if (!$fp) { return PEAR::raiseError(sprintf(_("Can't open file %s."), $path)); } /* Instantiate parser. */ $parser = new Luxor_SimpleParse($fp, 1, $this->_langmap['spec']); $linenum = 1; list($btype, $frag) = $parser->nextFrag(); while ($frag) { $lines = array(); if (preg_match_all('/(.*?\\n)/', $frag, $match)) { $lines = $match[1]; } if (preg_match('/([^\\n]*)$/', $frag, $match)) { $lines[] = $match[1]; } if ($btype) { /* Skip comments, strings and includes. */ if ($btype == 'comment' || $btype == 'string' || $btype == 'include') { $linenum += count($lines) - 1; } } else { foreach ($lines as $l) { /* Strip symbol name. */ preg_match_all('/(?:^|[^a-zA-Z_\\#])(\\~?_*[a-zA-Z][a-zA-Z0-9_]*)\\b/x', $l, $match); foreach ($match[1] as $string) { /* Create references only for known symbols and not reserved words. */ if (!in_array($string, $this->_langmap['reserved']) && $index->isSymbol($string)) { $result = $index->reference($string, $fileId, $linenum); if (is_a($result, 'PEAR_Error')) { return $result; } } } $linenum++; } $linenum--; } list($btype, $frag) = $parser->nextFrag(); } }