Annotation of libwww/Library/Examples/LoadToFile.c, revision 1.3
1.1 frystyk 1:
2: #include "WWWLib.h" /* Global Library Include file */
3: #include "WWWMIME.h" /* MIME parser/generator */
4: #include "WWWNews.h" /* News access module */
5: #include "WWWHTTP.h" /* HTTP access module */
6: #include "WWWFTP.h"
7: #include "WWWFile.h"
8: #include "WWWGophe.h"
9: #include "WWWInit.h"
10:
11: #define APP_NAME "GETTOOL"
12: #define APP_VERSION "1.0"
1.2 frystyk 13: #define DEFAULT_OUTPUT_FILE "get.out"
14:
15: /*
16: ** We get called here from the event loop when we are done
17: ** loading. Here we terminate the program as we have nothing
18: ** better to do.
19: */
20: int terminate_handler (HTRequest * request, HTResponse * response,
21: void * param, int status)
22: {
23: /* Delete our request again */
24: HTRequest_delete(request);
25:
26: /* Delete our profile */
27: HTProfile_delete();
28:
29: exit(status ? status : 0);
30: }
1.1 frystyk 31:
32: int main (int argc, char ** argv)
33: {
34: int status = 0;
35: int arg = 0;
1.2 frystyk 36: char * outputfile = NULL;
37: char * getme = NULL;
38: HTRequest * request = NULL;
39: HTChunk * chunk = NULL;
1.1 frystyk 40:
41: /* Initiate W3C Reference Library with a client profile */
42: HTProfile_newNoCacheClient(APP_NAME, APP_VERSION);
1.2 frystyk 43:
44: /* Add our own filter to terminate the application */
45: HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
46:
47: /* Turn off any interactions */
48: HTAlert_setInteractive(NO);
1.1 frystyk 49:
50: /* Scan command line for parameters */
51: for (arg=1; arg<argc; arg++) {
52: if (!strcmp(argv[arg], "-o")) {
53: outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
54: argv[++arg] : DEFAULT_OUTPUT_FILE;
55:
56: } else {
57: getme = argv[arg];
58: }
59: }
1.2 frystyk 60:
61: /* Make sure we have an output */
62: if (!outputfile) outputfile = DEFAULT_OUTPUT_FILE;
63:
64: if (getme && *getme) {
65: request = HTRequest_new();
66:
67: /* Start the load */
68: status = HTLoadToFile(getme, request, outputfile);
69:
70: /* Go into the event loop... */
71: HTEventList_loop(request);
72:
73: } else {
74:
75: /* Delete our profile if no load */
76: HTProfile_delete();
1.1 frystyk 77: }
78:
79: return 0;
80: }
Webmaster