Annotation of libwww/Library/Examples/LoadToFile.c, revision 1.4
1.4 ! frystyk 1: /*
! 2: ** @(#) $Id: trace.c,v 1.2 1999/01/06 15:38:47 frystyk Exp $
! 3: **
! 4: ** More libwww samples can be found at "http://www.w3.org/Library/Examples/"
! 5: **
! 6: ** Copyright © 1995-1998 World Wide Web Consortium, (Massachusetts
! 7: ** Institute of Technology, Institut National de Recherche en
! 8: ** Informatique et en Automatique, Keio University). All Rights
! 9: ** Reserved. This program is distributed under the W3C's Software
! 10: ** Intellectual Property License. This program is distributed in the hope
! 11: ** that it will be useful, but WITHOUT ANY WARRANTY; without even the
! 12: ** implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
! 13: ** PURPOSE. See W3C License http://www.w3.org/Consortium/Legal/ for more
! 14: ** details.
! 15: **
! 16: ** Sample showing how to load a document and save it to local file
! 17: */
1.1 frystyk 18:
19: #include "WWWLib.h" /* Global Library Include file */
20: #include "WWWMIME.h" /* MIME parser/generator */
21: #include "WWWNews.h" /* News access module */
22: #include "WWWHTTP.h" /* HTTP access module */
23: #include "WWWFTP.h"
24: #include "WWWFile.h"
25: #include "WWWGophe.h"
26: #include "WWWInit.h"
27:
28: #define APP_NAME "GETTOOL"
29: #define APP_VERSION "1.0"
1.2 frystyk 30: #define DEFAULT_OUTPUT_FILE "get.out"
31:
32: /*
33: ** We get called here from the event loop when we are done
34: ** loading. Here we terminate the program as we have nothing
35: ** better to do.
36: */
37: int terminate_handler (HTRequest * request, HTResponse * response,
38: void * param, int status)
39: {
40: /* Delete our request again */
41: HTRequest_delete(request);
42:
43: /* Delete our profile */
44: HTProfile_delete();
45:
46: exit(status ? status : 0);
47: }
1.1 frystyk 48:
49: int main (int argc, char ** argv)
50: {
51: int status = 0;
52: int arg = 0;
1.2 frystyk 53: char * outputfile = NULL;
54: char * getme = NULL;
55: HTRequest * request = NULL;
1.1 frystyk 56:
57: /* Initiate W3C Reference Library with a client profile */
58: HTProfile_newNoCacheClient(APP_NAME, APP_VERSION);
1.2 frystyk 59:
60: /* Add our own filter to terminate the application */
61: HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
62:
63: /* Turn off any interactions */
64: HTAlert_setInteractive(NO);
1.1 frystyk 65:
1.4 ! frystyk 66: /* Set the timeout for long we are going to wait for a response */
! 67: HTHost_setEventTimeout(10000);
! 68:
1.1 frystyk 69: /* Scan command line for parameters */
70: for (arg=1; arg<argc; arg++) {
71: if (!strcmp(argv[arg], "-o")) {
72: outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
73: argv[++arg] : DEFAULT_OUTPUT_FILE;
74:
75: } else {
76: getme = argv[arg];
77: }
78: }
1.2 frystyk 79:
80: /* Make sure we have an output */
81: if (!outputfile) outputfile = DEFAULT_OUTPUT_FILE;
82:
83: if (getme && *getme) {
84: request = HTRequest_new();
85:
86: /* Start the load */
87: status = HTLoadToFile(getme, request, outputfile);
88:
89: /* Go into the event loop... */
90: HTEventList_loop(request);
91:
92: } else {
1.4 ! frystyk 93: printf("Type the URI of document you want to load and the name of the local file.\n");
! 94: printf("\t%s <address> -o <localfile>\n", argv[0]);
! 95: printf("For example, %s http://www.w3.org -o w3chome.html\n", argv[0]);
1.2 frystyk 96:
97: /* Delete our profile if no load */
98: HTProfile_delete();
1.1 frystyk 99: }
100:
101: return 0;
102: }
Webmaster