Skip to content
This repository has been archived by the owner on Jul 21, 2018. It is now read-only.

Commit

Permalink
added "omit version info" checkbox in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-simon committed Nov 21, 2017
1 parent f246625 commit 0f146df
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 342 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Ansifilter ChangeLog

ansifilter 2.9

-fixed parsing of (B reset sequence (https://github.com/andre-simon/ansifilter/issues/10)
-fixed parsing of "(B" reset sequence (https://github.com/andre-simon/ansifilter/issues/10)
-CLI: added --no-version-info option

---

Expand Down
10 changes: 8 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-------------------------------------------------------------------------------
--- ANSIFILTER MANUAL - Version 2.8 ------------------------- AUGUST 2017 ---
--- ANSIFILTER MANUAL - Version 2.9 ---------------------- NOVEMBER 2017 ---
-------------------------------------------------------------------------------

OSI Certified Open Source Software
Expand Down Expand Up @@ -57,6 +57,7 @@ Format options:
-p, --plain Ignore ANSI formatting information
-w, --wrap=<len> Wrap long lines
--no-trailing-nl Omit trailing newline
--no-version-info Omit version info comment
--wrap-no-numbers Omit line numbers of wrapped lines (assumes -l)

ANSI art options:
Expand Down Expand Up @@ -157,4 +158,9 @@ Example file content:
Andre Simon
andre.simon1@gmx.de
http://www.andre-simon.de/
http://wiki.andre-simon.de/

sf.net project with SVN repository, download mirror, bug tracker, help forum:
http://sourceforge.net/projects/ansifilter/

Github project with Git repository, bug tracker:
https://github.com/andre-simon/ansifilter
Empty file modified ansifilter.desktop
100644 → 100755
Empty file.
Binary file modified man/ansifilter.1.gz
Binary file not shown.
95 changes: 50 additions & 45 deletions src/cmdlineoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cmdlineoptions.cpp - description
-------------------
begin : Sun Oct 13 2007
copyright : (C) 2007-2011 by Andre Simon
copyright : (C) 2007-2017 by Andre Simon
email : andre.simon1@gmx.de
***************************************************************************/

Expand Down Expand Up @@ -33,46 +33,45 @@ along with ANSIFilter. If not, see <http://www.gnu.org/licenses/>.
#include "platform_fs.h"
#include "stringtools.h"

using namespace std;


using namespace std;

const Arg_parser::Option options[] = {
{ 'a', "anchors", Arg_parser::no },
{ 'd', "doc-title", Arg_parser::yes },
{ 'e', "encoding", Arg_parser::yes },
{ 'f', "fragment", Arg_parser::no },
{ 'F', "font", Arg_parser::yes },
{ 'h', "help", Arg_parser::no },
{ 'H', "html", Arg_parser::no },
{ 'M', "pango", Arg_parser::no },
{ 'i', "input", Arg_parser::yes },
{ 'l', "line-numbers", Arg_parser::no },
{ 'L', "latex", Arg_parser::no },
{ 'P', "tex", Arg_parser::no },
{ 'B', "bbcode", Arg_parser::no },
{ 'o', "output", Arg_parser::yes },
{ 'O', "outdir", Arg_parser::yes },
{ 'p', "plain", Arg_parser::no },
{ 'r', "style-ref", Arg_parser::yes },
{ 'R', "rtf", Arg_parser::no },
{ 's', "font-size", Arg_parser::yes },
{ 't', "tail", Arg_parser::no },
{ 'T', "text", Arg_parser::no },
{ 'w', "wrap", Arg_parser::yes },
{ 'v', "version", Arg_parser::no },
{ 'V', "version", Arg_parser::no },
{ 'W', "wrap-no-numbers", Arg_parser::no },
{ 'X', "art-cp437", Arg_parser::no },
{ 'U', "art-bin", Arg_parser::no },
{ 'D', "art-tundra", Arg_parser::no },
{ 'Y', "art-width", Arg_parser::yes },
{ 'Z', "art-height", Arg_parser::yes },
{ 'm', "map", Arg_parser::yes },
{ 'N', "no-trailing-nl", Arg_parser::no },
{ 0, 0, Arg_parser::no }
};

const Arg_parser::Option options[] = {
{ 'a', "anchors", Arg_parser::no },
{ 'd', "doc-title", Arg_parser::yes },
{ 'e', "encoding", Arg_parser::yes },
{ 'f', "fragment", Arg_parser::no },
{ 'F', "font", Arg_parser::yes },
{ 'h', "help", Arg_parser::no },
{ 'H', "html", Arg_parser::no },
{ 'M', "pango", Arg_parser::no },
{ 'i', "input", Arg_parser::yes },
{ 'l', "line-numbers", Arg_parser::no },
{ 'L', "latex", Arg_parser::no },
{ 'P', "tex", Arg_parser::no },
{ 'B', "bbcode", Arg_parser::no },
{ 'o', "output", Arg_parser::yes },
{ 'O', "outdir", Arg_parser::yes },
{ 'p', "plain", Arg_parser::no },
{ 'r', "style-ref", Arg_parser::yes },
{ 'R', "rtf", Arg_parser::no },
{ 's', "font-size", Arg_parser::yes },
{ 't', "tail", Arg_parser::no },
{ 'T', "text", Arg_parser::no },
{ 'w', "wrap", Arg_parser::yes },
{ 'v', "version", Arg_parser::no },
{ 'V', "version", Arg_parser::no },
{ 'W', "wrap-no-numbers", Arg_parser::no },
{ 'X', "art-cp437", Arg_parser::no },
{ 'U', "art-bin", Arg_parser::no },
{ 'D', "art-tundra", Arg_parser::no },
{ 'Y', "art-width", Arg_parser::yes },
{ 'Z', "art-height", Arg_parser::yes },
{ 'm', "map", Arg_parser::yes },
{ 'N', "no-trailing-nl", Arg_parser::no },
{ 'C', "no-version-info", Arg_parser::no },

{ 0, 0, Arg_parser::no }
};

CmdLineOptions::CmdLineOptions( const int argc, const char *argv[] ):
outputType (ansifilter::TEXT),
Expand All @@ -88,14 +87,14 @@ CmdLineOptions::CmdLineOptions( const int argc, const char *argv[] ):
opt_asciiBin(false),
opt_asciiTundra(false),
opt_omit_trailing_cr(false),
opt_omit_version_info(false),
encodingName("ISO-8859-1"),
font("Courier New"),
fontSize("10pt"),
wrapLineLen(0),
asciiArtWidth(80),
asciiArtHeight(100)
{

char* hlEnvOptions=getenv("ANSIFILTER_OPTIONS");
if (hlEnvOptions!=NULL) {
std::ostringstream envos;
Expand Down Expand Up @@ -188,9 +187,9 @@ void CmdLineOptions::parseRuntimeOptions( const int argc, const char *argv[], bo
case 'L':
outputType = ansifilter::LATEX;
break;
case 'm':
colorMapPath = arg;
break;
case 'm':
colorMapPath = arg;
break;
case 'M':
outputType = ansifilter::PANGO;
break;
Expand Down Expand Up @@ -249,6 +248,9 @@ void CmdLineOptions::parseRuntimeOptions( const int argc, const char *argv[], bo
case 'N':
opt_omit_trailing_cr=true;
break;
case 'C':
opt_omit_version_info=true;
break;
default:
cerr << "ansifilter: option parsing failed" << endl;
}
Expand Down Expand Up @@ -413,7 +415,10 @@ bool CmdLineOptions::omitTrailingCR() const
{
return opt_omit_trailing_cr;
}

bool CmdLineOptions::omitVersionInfo() const
{
return opt_omit_version_info;
}
string CmdLineOptions::getDocumentTitle() const
{
return docTitle;
Expand Down
6 changes: 5 additions & 1 deletion src/cmdlineoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cmdlineoptions.h - description
-------------------
begin : Sun Oct 13 2007
copyright : (C) 2007 by Andre Simon
copyright : (C) 2007-2017 by Andre Simon
email : andre.simon1@gmx.de
***************************************************************************/

Expand Down Expand Up @@ -114,6 +114,9 @@ class CmdLineOptions

/** \return True if output should not be terminated with carriage return */
bool omitTrailingCR() const;

/** \return True if output should not contain a version info comment */
bool omitVersionInfo() const;

/** \return Document title */
string getDocumentTitle() const ;
Expand Down Expand Up @@ -145,6 +148,7 @@ class CmdLineOptions
bool opt_asciiTundra;

bool opt_omit_trailing_cr;
bool opt_omit_version_info;

// name of single output file
string outFilename;
Expand Down
20 changes: 6 additions & 14 deletions src/codegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ CodeGenerator::CodeGenerator(ansifilter::OutputType type)
numberWrappedLines ( true ), //TODO add option
numberCurrentLine(false),
addAnchors(false),
omitVersionInfo(false),
parseCP437(false),
parseAsciiBin(false),
parseAsciiTundra(false),

outputType(type),
ignoreFormatting(false),
readAfterEOF(false),
omitTrailingCR(false),
termBuffer(NULL),
curX(0),
curY(0),
Expand Down Expand Up @@ -544,7 +546,6 @@ bool CodeGenerator::parseSGRParameters(const string& line, size_t begin, size_t
case 107:
elementStyle.setBgColour(rgb2html(workingPalette[ansiCode-100+8]));
break;

}

// Set RTF color index
Expand Down Expand Up @@ -787,7 +788,6 @@ void CodeGenerator::parseXBinFile(){

// decode image
if( (flags & 4) == 4) {
// std::cerr<<"DECODE--- starting at "<<in->tellg()<<"\n";
int c=0;
while( in && curY < asciiArtHeight)
{
Expand Down Expand Up @@ -857,7 +857,7 @@ void CodeGenerator::parseXBinFile(){
}
}
} else {
// std::cerr<<"FLAT--- starting at "<<in->tellg()<<"\n";
//flat BIN
parseBinFile();
}
}
Expand Down Expand Up @@ -931,7 +931,6 @@ void CodeGenerator::parseTundraFile(){
bg_blue=buffer[8];

cur = buffer[0];

}

if (cur !=1 && cur !=2 && cur !=4 && cur !=6)
Expand Down Expand Up @@ -1142,12 +1141,6 @@ void CodeGenerator::processInput()
curX=0;
if (line[i]=='\r') i=line.length();
}

/*if (line[i]=='\t'){
curX += 8;
std::cerr<<"tab\n";
}*/

++i;
}
} else {
Expand All @@ -1172,8 +1165,8 @@ void CodeGenerator::processInput()
}
}

++i;

if (i<line.size()) ++i;
if (line[i-1]==0x5b || (line[i-1]&0xff)==0x9b){
seqEnd=i;
//find sequence end
Expand All @@ -1200,8 +1193,7 @@ void CodeGenerator::processInput()
|| (line[seqEnd]=='K' && !isGrepOutput) )
i=line.length();
else
i = // ((line[seqEnd]=='m' || line[seqEnd]=='C'|| isGrepOutput) ? 1 : 0 )
1 + ((seqEnd!=line.length())?seqEnd:i);
i = 1 + ((seqEnd!=line.length())?seqEnd:i);
} else {
cur= line[i-1]&0xff;
next = line[i]&0xff;
Expand Down
12 changes: 10 additions & 2 deletions src/codegenerator.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************
codegenerator.h - description
-------------------
copyright : (C) 2007-2016 by Andre Simon
copyright : (C) 2007-2017 by Andre Simon
email : andre.simon1@gmx.de
***************************************************************************/

Expand Down Expand Up @@ -186,6 +186,12 @@ class CodeGenerator
omitTrailingCR=b;
}

/** \param b set to true if the output should not contain a version info comment*/
void setOmitVersionInfo(bool b)
{
omitVersionInfo=b;
}

/** \return plain outputting flag */
bool getPlainOutput()
{
Expand Down Expand Up @@ -279,7 +285,8 @@ class CodeGenerator
numberWrappedLines, ///< also show number of wrapped lines
numberCurrentLine, ///< output number of current line
addAnchors; ///< add HTML anchor to line number


bool omitVersionInfo; ///< do not print version info comment
bool parseCP437; ///< treat input as CP437 file
bool parseAsciiBin; ///< treat input as BIN or XBIN file
bool parseAsciiTundra; ///< treat input as Tundra file
Expand Down Expand Up @@ -360,6 +367,7 @@ class CodeGenerator
bool ignoreFormatting; ///< ignore color and font face information
bool readAfterEOF; ///< continue reading after EOF occoured
bool omitTrailingCR; ///< do not print EOL at the end of output


TDChar* termBuffer;
int curX, curY, memX, memY, maxY; ///< cursor position for Codepage 437 sequences
Expand Down
10 changes: 7 additions & 3 deletions src/htmlgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ string HtmlGenerator::getCloseTag()

string HtmlGenerator::getGeneratorComment()
{
ostringstream s;
s <<"\n</body>\n</html>\n<!--HTML generated by ansifilter "
ostringstream s;
s << "<!--HTML generated by ansifilter "
<< ANSIFILTER_VERSION << ", " << ANSIFILTER_URL <<"-->\n";

return s.str();
Expand Down Expand Up @@ -145,7 +145,11 @@ string HtmlGenerator::getFooter()
{
string footer;
footer += getCloseTag();
footer += "</pre>" + getGeneratorComment();
footer += "</pre>\n</body>\n</html>\n";

if (!omitVersionInfo)
footer += getGeneratorComment();

return footer;
}

Expand Down
6 changes: 5 additions & 1 deletion src/latexgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ string LaTeXGenerator::getHeader()
string LaTeXGenerator::getFooter()
{
string footer;
footer = "\\end{document}" + getGeneratorComment();
footer = "\\end{document}\n";

if (!omitVersionInfo)
footer += getGeneratorComment();

return footer;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
main.cpp - description
-------------------
copyright : (C) 2007-2016 by Andre Simon
copyright : (C) 2007-2017 by Andre Simon
email : andre.simon1@gmx.de
Highlight is a universal source code to HTML converter. Syntax highlighting
Expand Down Expand Up @@ -78,6 +78,7 @@ void ANSIFilterApp::printHelp()
cout << " -p, --plain Ignore ANSI formatting information\n";
cout << " -w, --wrap=<len> Wrap long lines\n";
cout << " --no-trailing-nl Omit trailing newline\n";
cout << " --no-version-info Omit version info comment\n";
cout << " --wrap-no-numbers Omit line numbers of wrapped lines (assumes -l)\n";

cout << "\nANSI art options:\n";
Expand Down Expand Up @@ -164,6 +165,7 @@ int ANSIFilterApp::run( const int argc, const char *argv[] )

generator->setAsciiArtSize(options.getAsciiArtWidth(), options.getAsciiArtHeight());
generator->setOmitTrailingCR(options.omitTrailingCR());
generator->setOmitVersionInfo(options.omitVersionInfo());

ansifilter::ParseError error = generator->generateFile(inFileList[i], outFilePath);

Expand Down
Loading

0 comments on commit 0f146df

Please sign in to comment.