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