OSDN Git Service

Initial commit
[wordring-tm/wordring-tm.git] / third_party / tidy-html5-master / build / documentation / examples / example.1.c
1
2
3 #include <tidy.h>;
4 #include <buffio.h>;
5 #include <stdio.h>;
6 #include <errno.h>;
7
8 int main(int argc, char **argv )
9 {
10     const char* input = "<title>Hello</title><p>World!";
11     TidyBuffer output = {0};
12     TidyBuffer errbuf = {0};
13     int rc = -1;
14     Bool ok;
15
16     // Initialize "document"
17     TidyDoc tdoc = tidyCreate();
18     printf( "Tidying:\t%s\n", input );
19
20     // Convert to XHTML
21     ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  
22     if ( ok )
23         rc = tidySetErrorBuffer( tdoc, &errbuf );    // Capture diagnostics
24     if ( rc >= 0 )
25         rc = tidyParseString( tdoc, input );         // Parse the input
26     if ( rc >= 0 )
27         rc = tidyCleanAndRepair( tdoc );             // Tidy it up!
28     if ( rc >= 0 )
29         rc = tidyRunDiagnostics( tdoc );             // Kvetch
30     if ( rc > 1 )                                    // If error, force output.
31         rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
32     if ( rc >= 0 )
33         rc = tidySaveBuffer( tdoc, &output );        // Pretty Print
34
35     if ( rc >= 0 )
36     {
37     if ( rc > 0 )
38         printf( "\nDiagnostics:\n\n%s", errbuf.bp );
39     printf( "\nAnd here is the result:\n\n%s", output.bp );
40     }
41     else
42         printf( "A severe error (%d) occurred.\n", rc );
43
44     tidyBufFree( &output );
45     tidyBufFree( &errbuf );
46     tidyRelease( tdoc );
47     return rc;
48 }
49