/** * References a file. * Parses the files contents for symbols and creates references to the * files where these symbols are defined. * * @param Luxor_Driver $files An instance of a storage backend driver. * @param string $pathname The (relative) pathname of the file to * be referenced. * @param Luxor_Lang $lang The language object for $pathname. * * @return mixed A PEAR_Error if an error occured. */ function processRefs($files, $pathname, $lang) { global $index; /* Get the unique ID for this file. */ $fileId = $index->fileId($pathname); if ($fileId === false) { $fileId = $index->createFileId($pathname, '', $files->getFiletime($pathname)); } if (is_a($fileId, 'PEAR_Error')) { return $fileId; } /* Update the file's status. */ $result = $index->toReference($fileId); if ($result === false) { return PEAR::raiseError(sprintf(_("%s was already indexed."), $pathname)); } elseif (is_a($result, 'PEAR_Error')) { return $result; } /* Empty symbol cache. */ $index->clearCache(); /* Create references to symbol definitions. */ $path = $files->tmpFile($pathname); if (!$path) { return PEAR::raiseError(sprintf(_("Can't create copy of file %s."), $pathname)); } $result = $lang->referenceFile($path, $fileId); if (is_a($result, 'PEAR_Error')) { return $result; } }
/** * Attempts to determine a files programming language and returns * a parser instance for this language. * * @param Luxor_Files $files An instance of Luxor_Files to use for file * operations and path name resolution. * @param string $pathname The path name of the file to create a * parser for. * * @return mixed The created concrete Luxor_Lang instance, or false * on error. */ function builder($files, $pathname) { global $languages; $languages = Horde::loadConfiguration('languages.php', 'languages', 'luxor'); /* First, check the 'filetype' hash for a matching file extension. */ foreach ($languages['filetype'] as $type) { if (preg_match('/' . $type[1] . '/', $pathname)) { return Luxor_Lang::factory($type[2], $type); } } /* Next, try to detect the shebang line. */ $fh = $files->getFileHandle($pathname); if (!$fh || is_a($fh, 'PEAR_Error')) { return $fh; } $line = fgets($fh); if (!preg_match('/^\\#!\\s*(\\S+)/s', $line, $match)) { return false; } if (isset($languages['interpreters'][$match[1]])) { $lang = $languages['filetype'][$languages['interpreters'][$match[1]]]; return Luxor_Lang::factory($lang[2], $lang); } return false; }
/** */ 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>'; }