"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/codegenerator.cpp" between
ansifilter-2.17.tar.bz2 and ansifilter-2.18.tar.bz2

About: Ansifilter parses common ANSI codes to remove them or to convert them to another colored text file format (HTML, TeX, LaTeX, RTF, Pango or BBCode).

codegenerator.cpp  (ansifilter-2.17.tar.bz2):codegenerator.cpp  (ansifilter-2.18.tar.bz2)
/*************************************************************************** /***************************************************************************
codegenerator.cpp - description codegenerator.cpp - description
------------------- -------------------
copyright : (C) 2007-2020 by Andre Simon copyright : (C) 2007-2021 by Andre Simon
email : a.simon@mailbox.org email : a.simon@mailbox.org
***************************************************************************/ ***************************************************************************/
/* /*
This file is part of ANSIFilter. This file is part of ANSIFilter.
ANSIFilter is free software: you can redistribute it and/or modify ANSIFilter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
skipping to change at line 125 skipping to change at line 125
curX(0), curX(0),
curY(0), curY(0),
memX(0), memX(0),
memY(0), memY(0),
maxY(0), maxY(0),
asciiArtWidth(80), asciiArtWidth(80),
asciiArtHeight(150), asciiArtHeight(150),
lineWrapLen(0) lineWrapLen(0)
{ {
elementStyle.setFgColour(rgb2html(workingPalette[0])); elementStyle.setFgColour(rgb2html(workingPalette[0]));
// first style: default coloring
//documentStyles.push_back(StyleInfo ( rgb2html(workingPalette[0]).substr(1)
, "", false, false, false, false, false));
} }
CodeGenerator::~CodeGenerator() CodeGenerator::~CodeGenerator()
{} {}
void CodeGenerator::setShowLineNumbers(bool flag) void CodeGenerator::setShowLineNumbers(bool flag)
{ {
showLineNumbers=flag; showLineNumbers=flag;
} }
skipping to change at line 1091 skipping to change at line 1089
if (parseCP437){ if (parseCP437){
allocateTermBuffer(); allocateTermBuffer();
} }
while (true) { while (true) {
bool eof=false; bool eof=false;
eof=!getline(*in, line); eof=!getline(*in, line);
if( !omitNewLine ) if( !omitNewLine )
++lineNumber; ++lineNumber;
numberCurrentLine = true; numberCurrentLine = true;
if (eof) { if (eof) {
// imitate tail bahaviour, continue to read after EOF // imitate tail bahaviour, continue to read after EOF
if (readAfterEOF) { if (readAfterEOF) {
out->flush(); out->flush();
in->clear(); in->clear();
#ifdef WIN32 #ifdef WIN32
Sleep(250); Sleep(250);
#else #else
sleep(1); sleep(1);
#endif #endif
} else { } else {
if (!parseCP437 && !omitTrailingCR) printNewLine(outputType!=TEXT); if (!parseCP437 && !omitTrailingCR)
printNewLine(outputType!=TEXT);
break; break;
} }
} else { } else {
if (!omitNewLine && !parseCP437 && lineNumber>1) printNewLine(); if (!omitNewLine && !parseCP437 && lineNumber>1)
printNewLine();
if (!omitNewLine )
insertLineNumber();
if (!omitNewLine ) insertLineNumber();
omitNewLine = false; omitNewLine = false;
i=0; i=0;
plainTxtCnt=0; plainTxtCnt=0;
size_t seqEnd=string::npos; size_t seqEnd=string::npos;
while (i <line.length() ) { while (i <line.length() ) {
// CSI ? // CSI ?
cur = line[i]&0xff; cur = line[i]&0xff;
skipping to change at line 1143 skipping to change at line 1147
&& (line[seqEnd]<0x40 || line[seqEnd]>0x7e )) { && (line[seqEnd]<0x40 || line[seqEnd]>0x7e )) {
++seqEnd; ++seqEnd;
} }
if ( line[seqEnd]=='m' ) { if ( line[seqEnd]=='m' ) {
parseSGRParameters(line, i, seqEnd); parseSGRParameters(line, i, seqEnd);
} else { } else {
parseCodePage437Seq(line, i, seqEnd); parseCodePage437Seq(line, i, seqEnd);
} }
i=seqEnd+1; i=seqEnd+1;
} else { }
else {
++i; ++i;
} }
} else if (cur==0x1a && line.length() - i > 6){ } else if (cur==0x1a && line.length() - i > 6){
// skip SAUCE info section // skip SAUCE info section
while (line[i]==0x1a || !line[i]) ++i; while (line[i]==0x1a || !line[i]) ++i;
if (line.substr(i, 5)=="SAUCE"){ if (line.substr(i, 5)=="SAUCE"){
break; break;
} }
} else { } else {
if (curX>=0 && curX<asciiArtWidth && curY>=0 && curY<asciiArtHeight) { if (curX>=0 && curX<asciiArtWidth && curY>=0 && curY<asciiArtHeight) {
skipping to change at line 1217 skipping to change at line 1222
// http://linuxcommand.org/lc3_adv_tput.php // http://linuxcommand.org/lc3_adv_tput.php
// http://ascii-table.com/ansi-escape-sequences-vt-100.php // http://ascii-table.com/ansi-escape-sequences-vt-100.php
if (next==0x28){ // ( -> maybe need to handle more codes here if (next==0x28){ // ( -> maybe need to handle more codes here
if (line[i+2]==0x42) { // B if (line[i+2]==0x42) { // B
elementStyle.setReset(false); elementStyle.setReset(false);
i+=2; i+=2;
} }
} }
// https://iterm2.com/documentation-escape-codes.html
if (next==0x5d) {
if (line[i+2]=='8') {
size_t uriBegin = line.find(';', i+4);
seqEnd = line.find("\x1b]8;;\x07", i);
size_t uriDelim = line.find(0x07, uriBegin+1);
if (uriBegin != string::npos && seqEnd != string::npos){
string uri = line.substr(uriBegin+1, uriDelim - uriBegin
- 1 );
string txt = line.substr(uriDelim+1, seqEnd - uriDelim -
1);
lineBuf << getHyperlink(uri, txt);
i=seqEnd+4;
}
}
++i;
}
if (i<line.size()) ++i; if (i<line.size()) ++i;
if (line[i-1]==0x5b || (line[i-1]&0xff)==0x9b){ if (line[i-1]==0x5b || (line[i-1]&0xff)==0x9b){
seqEnd=i; seqEnd=i;
//find sequence end //find sequence end
while ( seqEnd<line.length() while ( seqEnd<line.length()
&& (line[seqEnd]<0x40 || line[seqEnd]>0x7e )) { && (line[seqEnd]<0x40 || line[seqEnd]>0x7e )) {
++seqEnd; ++seqEnd;
} }
if ( line[seqEnd]=='m' && !ignoreFormatting ) { if ( line[seqEnd]=='m' && !ignoreFormatting ) {
if (!elementStyle.isReset()) { if (!elementStyle.isReset()) {
lineBuf <<getCloseTag(); lineBuf << getCloseTag();
tagOpen=false; tagOpen=false;
} }
parseSGRParameters(line, i, seqEnd); parseSGRParameters(line, i, seqEnd);
if (!elementStyle.isReset()) { if (!elementStyle.isReset()) {
lineBuf <<getOpenTag(); lineBuf << getOpenTag();
tagOpen=true; tagOpen=true;
} }
} }
// fix K sequences (iterm2/grep) // fix K sequences (iterm2/grep)
isKSeq = line[seqEnd]=='K' && !ignClearSeq ; isKSeq = line[seqEnd]=='K' && !ignClearSeq ;
isGrepOutput = isKSeq && isascii(line[seqEnd+1]) && line[seqEn d+1] !=13 && line[seqEnd+1] != 27; isGrepOutput = isKSeq && isascii(line[seqEnd+1]) && line[seqEn d+1] !=13 && line[seqEnd+1] != 27;
if ( line[seqEnd]=='s' || line[seqEnd]=='u' if ( line[seqEnd]=='s' || line[seqEnd]=='u'
|| (isKSeq && !isGrepOutput) ){ || (isKSeq && !isGrepOutput) ){
 End of changes. 11 change blocks. 
11 lines changed or deleted 36 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)