Make pretty printer keep track of line numbers as it prints.

This commit is contained in:
Jim Derry 2015-11-28 14:16:17 +08:00
parent dd4eb46bb3
commit 34d456aa80
2 changed files with 9 additions and 1 deletions

View file

@ -312,6 +312,7 @@ void TY_(InitPrintBuf)( TidyDocImpl* doc )
InitIndent( &doc->pprint.indent[0] ); InitIndent( &doc->pprint.indent[0] );
InitIndent( &doc->pprint.indent[1] ); InitIndent( &doc->pprint.indent[1] );
doc->pprint.allocator = doc->allocator; doc->pprint.allocator = doc->allocator;
doc->pprint.line = 0;
} }
void TY_(FreePrintBuf)( TidyDocImpl* doc ) void TY_(FreePrintBuf)( TidyDocImpl* doc )
@ -613,6 +614,7 @@ static void WrapLine( TidyDocImpl* doc )
TY_(WriteChar)( '\\', doc->docOut ); TY_(WriteChar)( '\\', doc->docOut );
TY_(WriteChar)( '\n', doc->docOut ); TY_(WriteChar)( '\n', doc->docOut );
pprint->line++;
ResetLineAfterWrap( pprint ); ResetLineAfterWrap( pprint );
} }
@ -666,6 +668,7 @@ static void WrapAttrVal( TidyDocImpl* doc )
TY_(WriteChar)( ' ', doc->docOut ); TY_(WriteChar)( ' ', doc->docOut );
TY_(WriteChar)( '\n', doc->docOut ); TY_(WriteChar)( '\n', doc->docOut );
pprint->line++;
ResetLineAfterWrap( pprint ); ResetLineAfterWrap( pprint );
} }
@ -686,7 +689,7 @@ static void PFlushLineImpl( TidyDocImpl* doc )
for ( i = 0; i < pprint->linelen; ++i ) for ( i = 0; i < pprint->linelen; ++i )
TY_(WriteChar)( pprint->linebuf[i], doc->docOut ); TY_(WriteChar)( pprint->linebuf[i], doc->docOut );
if ( IsInString(pprint) ) if ( IsInString(pprint) )
TY_(WriteChar)( '\\', doc->docOut ); TY_(WriteChar)( '\\', doc->docOut );
ResetLine( pprint ); ResetLine( pprint );
@ -701,6 +704,7 @@ void TY_(PFlushLine)( TidyDocImpl* doc, uint indent )
PFlushLineImpl( doc ); PFlushLineImpl( doc );
TY_(WriteChar)( '\n', doc->docOut ); TY_(WriteChar)( '\n', doc->docOut );
pprint->line++;
pprint->indent[ 0 ].spaces = indent; pprint->indent[ 0 ].spaces = indent;
} }
@ -713,6 +717,7 @@ static void PCondFlushLine( TidyDocImpl* doc, uint indent )
PFlushLineImpl( doc ); PFlushLineImpl( doc );
TY_(WriteChar)( '\n', doc->docOut ); TY_(WriteChar)( '\n', doc->docOut );
pprint->line++;
pprint->indent[ 0 ].spaces = indent; pprint->indent[ 0 ].spaces = indent;
} }
} }
@ -733,6 +738,7 @@ void TY_(PFlushLineSmart)( TidyDocImpl* doc, uint indent )
/* Issue #228 - cfgBool( doc, TidyVertSpace ); */ /* Issue #228 - cfgBool( doc, TidyVertSpace ); */
if(TidyAddVS) { if(TidyAddVS) {
TY_(WriteChar)( '\n', doc->docOut ); TY_(WriteChar)( '\n', doc->docOut );
pprint->line++;
} }
pprint->indent[ 0 ].spaces = indent; pprint->indent[ 0 ].spaces = indent;
@ -749,6 +755,7 @@ static void PCondFlushLineSmart( TidyDocImpl* doc, uint indent )
/* Issue #228 - cfgBool( doc, TidyVertSpace ); */ /* Issue #228 - cfgBool( doc, TidyVertSpace ); */
if(TidyAddVS) { if(TidyAddVS) {
TY_(WriteChar)( '\n', doc->docOut ); TY_(WriteChar)( '\n', doc->docOut );
pprint->line++;
} }
pprint->indent[ 0 ].spaces = indent; pprint->indent[ 0 ].spaces = indent;

View file

@ -53,6 +53,7 @@ typedef struct _TidyPrintImpl
uint lbufsize; uint lbufsize;
uint linelen; uint linelen;
uint wraphere; uint wraphere;
uint line;
uint ixInd; uint ixInd;
TidyIndent indent[2]; /* Two lines worth of indent state */ TidyIndent indent[2]; /* Two lines worth of indent state */