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 00148 unsigned int lineNumberDigits; 00149 00151 bool generateEntireDoc; 00152 00154 bool generateVersion; 00155 00157 bool canUseStdOut; 00158 00160 bool binaryOutput; 00161 00166 unsigned int tabSpaces; 00167 00172 void updateBufferedOutput(BufferedOutput *output); 00173 00174 public: 00178 SourceHighlight(const std::string &outputLang = "html.outlang"); 00179 ~SourceHighlight(); 00180 00186 void initialize(); 00187 00195 void highlight(const std::string &input, const std::string &output, 00196 const std::string &inputLang); 00197 00206 void 00207 highlight(std::istream &input, std::ostream &output, 00208 const std::string &inputLang, 00209 const std::string &inputFileName = ""); 00210 00218 void checkLangDef(const std::string &langFile); 00219 00227 void checkOutLangDef(const std::string &langFile); 00228 00237 void printHighlightState(const std::string &langFile, std::ostream &os); 00238 00247 void printLangElems(const std::string &langFile, std::ostream &os); 00248 00254 const std::string createOutputFileName(const std::string &inputFile); 00255 00256 void setDataDir(const std::string &_datadir) { 00257 dataDir = _datadir; 00258 } 00259 00260 void setStyleFile(const std::string &_styleFile) { 00261 styleFile = _styleFile; 00262 } 00263 00264 void setStyleCssFile(const std::string &_styleFile) { 00265 styleCssFile = _styleFile; 00266 } 00267 00268 void setStyleDefaultFile(const std::string &_styleDefaultFile) { 00269 styleDefaultFile = _styleDefaultFile; 00270 } 00271 00272 void setTitle(const std::string &_title) { 00273 title = _title; 00274 } 00275 00276 void setCss(const std::string &_css) { 00277 css = _css; 00278 } 00279 00280 void setHeaderFileName(const std::string &h) { 00281 headerFileName = h; 00282 } 00283 00284 void setFooterFileName(const std::string &f) { 00285 footerFileName = f; 00286 } 00287 00288 void setOutputDir(const std::string &_outputDir) { 00289 outputFileDir = _outputDir; 00290 } 00291 00292 const TextStyleFormatterCollection &getFormatterCollection() const { 00293 return formatterCollection; 00294 } 00295 00296 void setOptimize(bool b = true) { 00297 optimize = b; 00298 } 00299 00300 void setGenerateLineNumbers(bool b = true) { 00301 generateLineNumbers = b; 00302 } 00303 00304 void setGenerateLineNumberRefs(bool b = true) { 00305 generateLineNumberRefs = b; 00306 } 00307 00308 void setLineNumberPad(char c) { 00309 lineNumberPad = c; 00310 } 00311 00312 void setLineNumberAnchorPrefix(const std::string &_prefix) { 00313 lineNumberAnchorPrefix = _prefix; 00314 } 00315 00316 void setLineNumberDigits(unsigned int d) { 00317 lineNumberDigits = d; 00318 } 00319 00320 void setGenerateEntireDoc(bool b = true) { 00321 generateEntireDoc = b; 00322 } 00323 00324 void setGenerateVersion(bool b = true) { 00325 generateVersion = b; 00326 } 00327 00328 void setCanUseStdOut(bool b = true) { 00329 canUseStdOut = b; 00330 } 00331 00332 void setBinaryOutput(bool b = true) { 00333 binaryOutput = b; 00334 } 00335 00336 void setHighlightEventListener(HighlightEventListener *l) { 00337 highlightEventListener = l; 00338 } 00339 00340 void setRangeSeparator(const std::string &sep) { 00341 rangeSeparator = sep; 00342 } 00343 00344 DocGenerator *getDocGenerator() const { 00345 return docGenerator; 00346 } 00347 00348 DocGenerator *getNoDocGenerator() const { 00349 return noDocGenerator; 00350 } 00351 00352 LineRanges *getLineRanges() const { 00353 return lineRanges; 00354 } 00355 00356 void setLineRanges(LineRanges *lr) { 00357 lineRanges = lr; 00358 } 00359 00360 RegexRanges *getRegexRanges() const { 00361 return regexRanges; 00362 } 00363 00364 void setRegexRanges(RegexRanges *rr) { 00365 regexRanges = rr; 00366 } 00367 00368 void setCTagsManager(CTagsManager *m) { 00369 ctagsManager = m; 00370 } 00371 00372 void setTabSpaces(unsigned int i) { 00373 tabSpaces = i; 00374 } 00375 00381 const std::string &getOutputFileExtension() const { 00382 return outputFileExtension; 00383 } 00384 }; 00385 00386 } 00387 00388 #endif /*SOURCEHIGHLIGHT_H_*/