Source-highlight Library
/home/bettini/work/source-highlight/src-highlite/lib/srchilite/sourcehighlight.h
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 inputLang;
00069 
00071     std::string css;
00072 
00074     std::string headerFileName;
00075 
00077     std::string footerFileName;
00078 
00080     std::string outputFileExtension;
00081 
00083     std::string outputFileDir;
00084 
00086     FormatterManager *formatterManager;
00087 
00089     PreFormatter *preFormatter;
00090 
00092     TextStyleFormatterCollection formatterCollection;
00093 
00095     LangDefManager *langDefManager;
00096 
00098     LineNumGenerator *lineNumGenerator;
00099 
00103     DocGenerator *docGenerator;
00104 
00109     DocGenerator *noDocGenerator;
00110 
00114     HighlightEventListener *highlightEventListener;
00115 
00117     CTagsManager *ctagsManager;
00118 
00120     CTagsFormatter *ctagsFormatter;
00121 
00123     LineRanges *lineRanges;
00124 
00126     RegexRanges *regexRanges;
00127 
00132     bool optimize;
00133 
00135     bool generateLineNumbers;
00136 
00138     bool generateLineNumberRefs;
00139 
00141     std::string lineNumberAnchorPrefix;
00142 
00144     char lineNumberPad;
00145 
00151     unsigned int lineNumberDigits;
00152 
00154     bool generateEntireDoc;
00155 
00157     bool generateVersion;
00158 
00160     bool canUseStdOut;
00161 
00163     bool binaryOutput;
00164 
00169     unsigned int tabSpaces;
00170 
00175     void updateBufferedOutput(BufferedOutput *output);
00176 
00177 public:
00181     SourceHighlight(const std::string &outputLang = "html.outlang");
00182     ~SourceHighlight();
00183 
00189     void initialize();
00190 
00198     void highlight(const std::string &input, const std::string &output,
00199             const std::string &inputLang);
00200 
00209     void
00210             highlight(std::istream &input, std::ostream &output,
00211                     const std::string &inputLang,
00212                     const std::string &inputFileName = "");
00213 
00221     void checkLangDef(const std::string &langFile);
00222 
00230     void checkOutLangDef(const std::string &langFile);
00231 
00240     void printHighlightState(const std::string &langFile, std::ostream &os);
00241 
00250     void printLangElems(const std::string &langFile, std::ostream &os);
00251 
00257     const std::string createOutputFileName(const std::string &inputFile);
00258 
00259     void setDataDir(const std::string &_datadir) {
00260         dataDir = _datadir;
00261     }
00262 
00263     void setStyleFile(const std::string &_styleFile) {
00264         styleFile = _styleFile;
00265     }
00266 
00267     void setStyleCssFile(const std::string &_styleFile) {
00268         styleCssFile = _styleFile;
00269     }
00270 
00271     void setStyleDefaultFile(const std::string &_styleDefaultFile) {
00272         styleDefaultFile = _styleDefaultFile;
00273     }
00274 
00275     void setTitle(const std::string &_title) {
00276         title = _title;
00277     }
00278     
00279     void setInputLang(const std::string &_inputLang) {
00280         inputLang = _inputLang;
00281     }
00282 
00283     void setCss(const std::string &_css) {
00284         css = _css;
00285     }
00286 
00287     void setHeaderFileName(const std::string &h) {
00288         headerFileName = h;
00289     }
00290 
00291     void setFooterFileName(const std::string &f) {
00292         footerFileName = f;
00293     }
00294 
00295     void setOutputDir(const std::string &_outputDir) {
00296         outputFileDir = _outputDir;
00297     }
00298 
00299     const TextStyleFormatterCollection &getFormatterCollection() const {
00300         return formatterCollection;
00301     }
00302 
00303     void setOptimize(bool b = true) {
00304         optimize = b;
00305     }
00306 
00307     void setGenerateLineNumbers(bool b = true) {
00308         generateLineNumbers = b;
00309     }
00310 
00311     void setGenerateLineNumberRefs(bool b = true) {
00312         generateLineNumberRefs = b;
00313     }
00314 
00315     void setLineNumberPad(char c) {
00316         lineNumberPad = c;
00317     }
00318 
00319     void setLineNumberAnchorPrefix(const std::string &_prefix) {
00320         lineNumberAnchorPrefix = _prefix;
00321     }
00322 
00323     void setLineNumberDigits(unsigned int d) {
00324         lineNumberDigits = d;
00325     }
00326 
00327     void setGenerateEntireDoc(bool b = true) {
00328         generateEntireDoc = b;
00329     }
00330 
00331     void setGenerateVersion(bool b = true) {
00332         generateVersion = b;
00333     }
00334 
00335     void setCanUseStdOut(bool b = true) {
00336         canUseStdOut = b;
00337     }
00338 
00339     void setBinaryOutput(bool b = true) {
00340         binaryOutput = b;
00341     }
00342 
00343     void setHighlightEventListener(HighlightEventListener *l) {
00344         highlightEventListener = l;
00345     }
00346 
00347     void setRangeSeparator(const std::string &sep) {
00348         rangeSeparator = sep;
00349     }
00350 
00351     DocGenerator *getDocGenerator() const {
00352         return docGenerator;
00353     }
00354 
00355     DocGenerator *getNoDocGenerator() const {
00356         return noDocGenerator;
00357     }
00358 
00359     LineRanges *getLineRanges() const {
00360         return lineRanges;
00361     }
00362 
00363     void setLineRanges(LineRanges *lr) {
00364         lineRanges = lr;
00365     }
00366 
00367     RegexRanges *getRegexRanges() const {
00368         return regexRanges;
00369     }
00370 
00371     void setRegexRanges(RegexRanges *rr) {
00372         regexRanges = rr;
00373     }
00374 
00375     void setCTagsManager(CTagsManager *m) {
00376         ctagsManager = m;
00377     }
00378 
00379     void setTabSpaces(unsigned int i) {
00380         tabSpaces = i;
00381     }
00382 
00388     const std::string &getOutputFileExtension() const {
00389         return outputFileExtension;
00390     }
00391 };
00392 
00393 }
00394 
00395 #endif /*SOURCEHIGHLIGHT_H_*/