diff options
Diffstat (limited to 'docs/examples/htmltidy.c')
-rw-r--r-- | docs/examples/htmltidy.c | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index a36e331b..687e3f34 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,13 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Download a document and use libtidy to parse the HTML. - * Written by Jeff Pohlmeyer - * +/* <DESC> + * Download a document and use libtidy to parse the HTML. + * </DESC> + */ +/* * LibTidy => http://tidy.sourceforge.net - * - * gcc -Wall -I/usr/local/include tidycurl.c -lcurl -ltidy -o tidycurl - * */ #include <stdio.h> @@ -38,29 +37,27 @@ uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out) { uint r; r = size * nmemb; - tidyBufAppend( out, in, r ); - return(r); + tidyBufAppend(out, in, r); + return r; } /* Traverse the document tree */ -void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) +void dumpNode(TidyDoc doc, TidyNode tnod, int indent) { TidyNode child; - for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) - { - ctmbstr name = tidyNodeGetName( child ); - if ( name ) - { + for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { + ctmbstr name = tidyNodeGetName(child); + if(name) { /* if it has a name, then it's an HTML tag ... */ TidyAttr attr; - printf( "%*.*s%s ", indent, indent, "<", name); + printf("%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ - for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { + for(attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { printf(tidyAttrName(attr)); tidyAttrValue(attr)?printf("=\"%s\" ", tidyAttrValue(attr)):printf(" "); } - printf( ">\n"); + printf(">\n"); } else { /* if it doesn't have a name, then it's probably text, cdata, etc... */ @@ -70,12 +67,12 @@ void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:""); tidyBufFree(&buf); } - dumpNode( doc, child, indent + 4 ); /* recursive */ + dumpNode(doc, child, indent + 4); /* recursive */ } } -int main(int argc, char **argv ) +int main(int argc, char **argv) { CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; @@ -83,7 +80,7 @@ int main(int argc, char **argv ) TidyBuffer docbuf = {0}; TidyBuffer tidy_errbuf = {0}; int err; - if ( argc == 2) { + if(argc == 2) { curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); @@ -94,19 +91,19 @@ int main(int argc, char **argv ) tdoc = tidyCreate(); tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */ tidyOptSetInt(tdoc, TidyWrapLen, 4096); - tidySetErrorBuffer( tdoc, &tidy_errbuf ); + tidySetErrorBuffer(tdoc, &tidy_errbuf); tidyBufInit(&docbuf); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf); err=curl_easy_perform(curl); - if ( !err ) { + if(!err) { err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */ - if ( err >= 0 ) { + if(err >= 0) { err = tidyCleanAndRepair(tdoc); /* fix any problems */ - if ( err >= 0 ) { + if(err >= 0) { err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */ - if ( err >= 0 ) { - dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */ + if(err >= 0) { + dumpNode(tdoc, tidyGetRoot(tdoc), 0); /* walk the tree */ fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */ } } @@ -120,11 +117,11 @@ int main(int argc, char **argv ) tidyBufFree(&docbuf); tidyBufFree(&tidy_errbuf); tidyRelease(tdoc); - return(err); + return err; } else - printf( "usage: %s <url>\n", argv[0] ); + printf("usage: %s <url>\n", argv[0]); - return(0); + return 0; } |