File:  [Public] / libwww / Library / Examples / libapp_3.c
Revision 1.8: download - view: text, annotated - select for diffs
Wed Jan 6 15:38:47 1999 UTC (25 years, 5 months ago) by frystyk
Branches: MAIN
CVS tags: repeat-requests, candidate-5-4-1, before_webdav, Release-5-4-0, Release-5-3-1, Release-5-2-8, Release-5-2-6, HEAD, Before-New-Trace-Messages
A completely rewritten HText interface that makes it a lot easier to use the libwww HTML parser and also doesn't throw away tags or entities that are not defined in the libwww HTML DTD. The new interface is based on registering callbacks so that the application doesn't have to provide the old HText functions that it didn't use. The HTML parser itself has also improved as it now knows about several HTML 4.0 tags. Finally, there are three new sample applications called showtags, showtext, and showlinks which illustrate how to use the new HText interface. Currently the line mode browser hasn't been updated so it doesn't compile for the moment.

#include "WWWLib.h"
#include "WWWStream.h"
#include "WWWInit.h"

/*
**	Loads a URL and count the content length
*/
int main (int argc, char ** argv)
{
    HTRequest * request;
    HTProfile_newPreemptiveRobot("TestApp", "1.0");
    request = HTRequest_new();
    HTRequest_setOutputFormat(request, WWW_SOURCE);
    if (argc == 2) {
	char * url = argv[1];
	if (url && *url) {
	    HTParentAnchor * anchor=(HTParentAnchor*)HTAnchor_findAddress(url);
	    BOOL status =
		HTLoadToStream(url,
			       HTContentCounter(HTBlackHole(), request,0x2000),
			       request);
	    if (status)
		printf("Content length found to be %ld bytes\n",
		       HTAnchor_length(anchor));
	    else
		printf("Content length could not be found\n");
	} else
	    printf("Bad parameters - please try again\n");
    } else {
	printf("Type the URL to fetch\n");
    }
    HTRequest_delete(request);			/* Delete the request object */
    HTProfile_delete();
    return 0;
}

Webmaster