00001 // 00002 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008 00003 // 00004 // Copyright: See COPYING file that comes with this distribution 00005 // 00006 00007 #ifndef SOURCEHIGHLIGHT_H_ 00008 #define SOURCEHIGHLIGHT_H_ 00009 00010 #include <string> 00011 #include <istream> 00012 #include <ostream> 00013 00014 #include "textstyleformattercollection.h" 00015 00016 namespace srchilite { 00017 00018 class FormatterManager; 00019 class PreFormatter; 00020 class LangDefManager; 00021 class BufferedOutput; 00022 class LineNumGenerator; 00023 class DocGenerator; 00024 class CharTranslator; 00025 class HighlightEventListener; 00026 class CTagsManager; 00027 class CTagsFormatter; 00028 class LineRanges; 00029 class RegexRanges; 00030 00035 class SourceHighlight { 00037 std::string outputLang; 00038 00044 std::string dataDir; 00045 00047 std::string backgroundColor; 00048 00050 std::string styleFile; 00051 00053 std::string styleCssFile; 00054 00056 std::string styleDefaultFile; 00057 00059 std::string linePrefix; 00060 00062 std::string rangeSeparator; 00063 00065 std::string title; 00066 00068 std::string css; 00069 00071 std::string headerFileName; 00072 00074 std::string footerFileName; 00075 00077 std::string outputFileExtension; 00078 00080 std::string outputFileDir; 00081 00083 FormatterManager *formatterManager; 00084 00086 PreFormatter *preFormatter; 00087 00089 TextStyleFormatterCollection formatterCollection; 00090 00092 LangDefManager *langDefManager; 00093 00095 LineNumGenerator *lineNumGenerator; 00096 00100 DocGenerator *docGenerator; 00101 00106 DocGenerator *noDocGenerator; 00107 00111 HighlightEventListener *highlightEventListener; 00112 00114 CTagsManager *ctagsManager; 00115 00117 CTagsFormatter *ctagsFormatter; 00118 00120 LineRanges *lineRanges; 00121 00123 RegexRanges *regexRanges; 00124 00129 bool optimize; 00130 00132 bool generateLineNumbers; 00133 00135 bool generateLineNumberRefs; 00136 00138 std::string lineNumberAnchorPrefix; 00139 00141 char lineNumberPad; 00142 00144 bool generateEntireDoc; 00145 00147 bool generateVersion; 00148 00150 bool canUseStdOut; 00151 00153 bool binaryOutput; 00154 00159 unsigned int tabSpaces; 00160 00165 void updateBufferedOutput(BufferedOutput *output); 00166 00167 public: 00171 SourceHighlight(const std::string &outputLang = "html.lang"); 00172 ~SourceHighlight(); 00173 00179 void initialize(); 00180 00188 void highlight(const std::string &input, const std::string &output, 00189 const std::string &inputLang); 00190 00199 void 00200 highlight(std::istream &input, std::ostream &output, 00201 const std::string &inputLang, 00202 const std::string &inputFileName = ""); 00203 00211 void checkLangDef(const std::string &langFile); 00212 00220 void checkOutLangDef(const std::string &langFile); 00221 00230 void printHighlightState(const std::string &langFile, std::ostream &os); 00231 00240 void printLangElems(const std::string &langFile, std::ostream &os); 00241 00247 const std::string createOutputFileName(const std::string &inputFile); 00248 00249 void setDataDir(const std::string &_datadir) { 00250 dataDir = _datadir; 00251 } 00252 00253 void setStyleFile(const std::string &_styleFile) { 00254 styleFile = _styleFile; 00255 } 00256 00257 void setStyleCssFile(const std::string &_styleFile) { 00258 styleCssFile = _styleFile; 00259 } 00260 00261 void setStyleDefaultFile(const std::string &_styleDefaultFile) { 00262 styleDefaultFile = _styleDefaultFile; 00263 } 00264 00265 void setTitle(const std::string &_title) { 00266 title = _title; 00267 } 00268 00269 void setCss(const std::string &_css) { 00270 css = _css; 00271 } 00272 00273 void setHeaderFileName(const std::string &h) { 00274 headerFileName = h; 00275 } 00276 00277 void setFooterFileName(const std::string &f) { 00278 footerFileName = f; 00279 } 00280 00281 void setOutputDir(const std::string &_outputDir) { 00282 outputFileDir = _outputDir; 00283 } 00284 00285 const TextStyleFormatterCollection &getFormatterCollection() const { 00286 return formatterCollection; 00287 } 00288 00289 void setOptimize(bool b = true) { 00290 optimize = b; 00291 } 00292 00293 void setGenerateLineNumbers(bool b = true) { 00294 generateLineNumbers = b; 00295 } 00296 00297 void setGenerateLineNumberRefs(bool b = true) { 00298 generateLineNumberRefs = b; 00299 } 00300 00301 void setLineNumberPad(char c) { 00302 lineNumberPad = c; 00303 } 00304 00305 void setLineNumberAnchorPrefix(const std::string &_prefix) { 00306 lineNumberAnchorPrefix = _prefix; 00307 } 00308 00309 void setGenerateEntireDoc(bool b = true) { 00310 generateEntireDoc = b; 00311 } 00312 00313 void setGenerateVersion(bool b = true) { 00314 generateVersion = b; 00315 } 00316 00317 void setCanUseStdOut(bool b = true) { 00318 canUseStdOut = b; 00319 } 00320 00321 void setBinaryOutput(bool b = true) { 00322 binaryOutput = b; 00323 } 00324 00325 void setHighlightEventListener(HighlightEventListener *l) { 00326 highlightEventListener = l; 00327 } 00328 00329 void setRangeSeparator(const std::string &sep) { 00330 rangeSeparator = sep; 00331 } 00332 00333 DocGenerator *getDocGenerator() const { 00334 return docGenerator; 00335 } 00336 00337 DocGenerator *getNoDocGenerator() const { 00338 return noDocGenerator; 00339 } 00340 00341 LineRanges *getLineRanges() const { 00342 return lineRanges; 00343 } 00344 00345 void setLineRanges(LineRanges *lr) { 00346 lineRanges = lr; 00347 } 00348 00349 RegexRanges *getRegexRanges() const { 00350 return regexRanges; 00351 } 00352 00353 void setRegexRanges(RegexRanges *rr) { 00354 regexRanges = rr; 00355 } 00356 00357 void setCTagsManager(CTagsManager *m) { 00358 ctagsManager = m; 00359 } 00360 00361 void setTabSpaces(unsigned int i) { 00362 tabSpaces = i; 00363 } 00364 }; 00365 00366 } 00367 00368 #endif /*SOURCEHIGHLIGHT_H_*/