diff --git a/include/tidy.h b/include/tidy.h index 2f3dabd..bca1463 100755 --- a/include/tidy.h +++ b/include/tidy.h @@ -631,6 +631,9 @@ TIDY_EXPORT Bool TIDY_CALL tidyInitSink( TidyOutputSink* sink, TIDY_EXPORT void TIDY_CALL tidyPutByte( TidyOutputSink* sink, uint byteValue ); +/**************** + Errors +****************/ /** Callback to filter messages by diagnostic level: ** info, warning, etc. Just set diagnostic output ** handler to redirect all diagnostics output. Return true @@ -656,6 +659,18 @@ TIDY_EXPORT int TIDY_CALL tidySetErrorBuffer( TidyDoc tdoc, TidyBuffer* errb /** Set error sink to given generic sink */ TIDY_EXPORT int TIDY_CALL tidySetErrorSink( TidyDoc tdoc, TidyOutputSink* sink ); + +/**************** + Printing +****************/ +/** Callback to track the progress of the pretting printing process. +** +*/ +typedef Bool (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine ); + +TIDY_EXPORT Bool TIDY_CALL tidySetPrettyPrinterCallback( TidyDoc tdoc, + TidyPPProgress callback ); + /** @} end IO group */ /* TODO: Catalog all messages for easy translation diff --git a/src/pprint.c b/src/pprint.c index 2411156..c42d2fc 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -2118,10 +2118,17 @@ void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node ) Node *content, *last; uint spaces = cfg( doc, TidyIndentSpaces ); Bool xhtml = cfgBool( doc, TidyXhtmlOut ); + uint lastline = 0; if ( node == NULL ) return; + if (doc->progressCallback) + { + if (doc->pprint.line > lastline) + doc->progressCallback( tidyImplToDoc(doc), node->line, node->column, doc->pprint.line ); + } + if (node->type == TextNode) { PPrintText( doc, mode, indent, node ); diff --git a/src/tidy-int.h b/src/tidy-int.h index f4a4703..51bcf3b 100755 --- a/src/tidy-int.h +++ b/src/tidy-int.h @@ -59,6 +59,7 @@ struct _TidyDocImpl TidyReportFilter mssgFilt; TidyReportFilter2 mssgFilt2; TidyOptCallback pOptCallback; + TidyPPProgress progressCallback; /* Parse + Repair Results */ uint optionErrors; diff --git a/src/tidylib.c b/src/tidylib.c index 0d7dc88..851a752 100755 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -752,6 +752,19 @@ int TIDY_CALL tidySetErrorSink( TidyDoc tdoc, TidyOutputSink* sink ) return -EINVAL; } +/* Use TidyPPProgress to monitor the progress of the pretty printer. + */ +Bool TIDY_CALL tidySetPrettyPrinterCallback(TidyDoc tdoc, TidyPPProgress callback) +{ + TidyDocImpl* impl = tidyDocToImpl( tdoc ); + if ( impl ) + { + impl->progressCallback = callback; + return yes; + } + return no; +} + /* Document info */ int TIDY_CALL tidyStatus( TidyDoc tdoc )