extract example.c into its own file and include
This commit is contained in:
parent
81187629c3
commit
04beaeed02
49
build/documentation/example.1.c
Normal file
49
build/documentation/example.1.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
|
||||||
|
#include <tidy.h>;
|
||||||
|
#include <buffio.h>;
|
||||||
|
#include <stdio.h>;
|
||||||
|
#include <errno.h>;
|
||||||
|
|
||||||
|
int main(int argc, char **argv )
|
||||||
|
{
|
||||||
|
const char* input = "<title>Hello</title><p>World!";
|
||||||
|
TidyBuffer output = {0};
|
||||||
|
TidyBuffer errbuf = {0};
|
||||||
|
int rc = -1;
|
||||||
|
Bool ok;
|
||||||
|
|
||||||
|
// Initialize "document"
|
||||||
|
TidyDoc tdoc = tidyCreate();
|
||||||
|
printf( "Tidying:\t%s\n", input );
|
||||||
|
|
||||||
|
// Convert to XHTML
|
||||||
|
ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );
|
||||||
|
if ( ok )
|
||||||
|
rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics
|
||||||
|
if ( rc >= 0 )
|
||||||
|
rc = tidyParseString( tdoc, input ); // Parse the input
|
||||||
|
if ( rc >= 0 )
|
||||||
|
rc = tidyCleanAndRepair( tdoc ); // Tidy it up!
|
||||||
|
if ( rc >= 0 )
|
||||||
|
rc = tidyRunDiagnostics( tdoc ); // Kvetch
|
||||||
|
if ( rc > 1 ) // If error, force output.
|
||||||
|
rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
|
||||||
|
if ( rc >= 0 )
|
||||||
|
rc = tidySaveBuffer( tdoc, &output ); // Pretty Print
|
||||||
|
|
||||||
|
if ( rc >= 0 )
|
||||||
|
{
|
||||||
|
if ( rc > 0 )
|
||||||
|
printf( "\nDiagnostics:\n\n%s", errbuf.bp );
|
||||||
|
printf( "\nAnd here is the result:\n\n%s", output.bp );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf( "A severe error (%d) occurred.\n", rc );
|
||||||
|
|
||||||
|
tidyBufFree( &output );
|
||||||
|
tidyBufFree( &errbuf );
|
||||||
|
tidyRelease( tdoc );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
|
@ -43,52 +43,8 @@
|
||||||
- \b TidyLib - uses adaptable I/O. As part of the larger integration strategy it was decided to fully abstract all I/O. This means a (relatively) clean separation between character encoding processing and shovelling bytes back and forth. Internally, the library reads from sources and writes to sinks. This abstraction is used for both markup and configuration “files”. Concrete implementations are provided for file and memory I/O, and new sources and sinks may be provided via the public interface.
|
- \b TidyLib - uses adaptable I/O. As part of the larger integration strategy it was decided to fully abstract all I/O. This means a (relatively) clean separation between character encoding processing and shovelling bytes back and forth. Internally, the library reads from sources and writes to sinks. This abstraction is used for both markup and configuration “files”. Concrete implementations are provided for file and memory I/O, and new sources and sinks may be provided via the public interface.
|
||||||
|
|
||||||
\section example_hello Example
|
\section example_hello Example
|
||||||
\code{.c}
|
|
||||||
#include <tidy.h>;
|
|
||||||
#include <buffio.h>;
|
|
||||||
#include <stdio.h>;
|
|
||||||
#include <errno.h>;
|
|
||||||
|
|
||||||
int main(int argc, char **argv )
|
\include example.1.c
|
||||||
{
|
|
||||||
const char* input = "<title>Hello</title><p>World!";
|
|
||||||
TidyBuffer output = {0};
|
|
||||||
TidyBuffer errbuf = {0};
|
|
||||||
int rc = -1;
|
|
||||||
Bool ok;
|
|
||||||
|
|
||||||
TidyDoc tdoc = tidyCreate(); // Initialize "document"
|
|
||||||
printf( "Tidying:\t%s\n", input );
|
|
||||||
|
|
||||||
ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); // Convert to XHTML
|
|
||||||
if ( ok )
|
|
||||||
rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics
|
|
||||||
if ( rc >= 0 )
|
|
||||||
rc = tidyParseString( tdoc, input ); // Parse the input
|
|
||||||
if ( rc >= 0 )
|
|
||||||
rc = tidyCleanAndRepair( tdoc ); // Tidy it up!
|
|
||||||
if ( rc >= 0 )
|
|
||||||
rc = tidyRunDiagnostics( tdoc ); // Kvetch
|
|
||||||
if ( rc > 1 ) // If error, force output.
|
|
||||||
rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
|
|
||||||
if ( rc >= 0 )
|
|
||||||
rc = tidySaveBuffer( tdoc, &output ); // Pretty Print
|
|
||||||
|
|
||||||
if ( rc >= 0 )
|
|
||||||
{
|
|
||||||
if ( rc > 0 )
|
|
||||||
printf( "\nDiagnostics:\n\n%s", errbuf.bp );
|
|
||||||
printf( "\nAnd here is the result:\n\n%s", output.bp );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printf( "A severe error (%d) occurred.\n", rc );
|
|
||||||
|
|
||||||
tidyBufFree( &output );
|
|
||||||
tidyBufFree( &errbuf );
|
|
||||||
tidyRelease( tdoc );
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
\endcode
|
|
||||||
|
|
||||||
|
|
||||||
\page building_tidy Building Tidy
|
\page building_tidy Building Tidy
|
||||||
|
|
Loading…
Reference in a new issue