Annotation of libwww/Library/Examples/LoadToFile.c, revision 1.5

1.4       frystyk     1: /*
1.5     ! frystyk     2: **     @(#) $Id: LoadToFile.c,v 1.4 1999/01/25 23:27:34 frystyk Exp $
1.4       frystyk     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: 
1.5     ! frystyk    32: PRIVATE int printer (const char * fmt, va_list pArgs)
        !            33: {
        !            34:     return (vfprintf(stdout, fmt, pArgs));
        !            35: }
        !            36: 
        !            37: PRIVATE int tracer (const char * fmt, va_list pArgs)
        !            38: {
        !            39:     return (vfprintf(stderr, fmt, pArgs));
        !            40: }
        !            41: 
1.2       frystyk    42: /*
                     43: **  We get called here from the event loop when we are done
                     44: **  loading. Here we terminate the program as we have nothing
                     45: **  better to do.
                     46: */
                     47: int terminate_handler (HTRequest * request, HTResponse * response,
                     48:                       void * param, int status)
                     49: {
                     50:     /* Delete our request again */
                     51:     HTRequest_delete(request);
                     52: 
                     53:     /* Delete our profile */
                     54:     HTProfile_delete();
                     55: 
                     56:     exit(status ? status : 0);
                     57: }
1.1       frystyk    58: 
                     59: int main (int argc, char ** argv)
                     60: {
                     61:     int                        status = 0;     
                     62:     int                        arg = 0;
1.2       frystyk    63:     char *              outputfile = NULL;
                     64:     char *              getme = NULL;
                     65:     HTRequest *         request = NULL;
1.1       frystyk    66: 
                     67:     /* Initiate W3C Reference Library with a client profile */
                     68:     HTProfile_newNoCacheClient(APP_NAME, APP_VERSION);
1.2       frystyk    69: 
1.5     ! frystyk    70:     /* Need our own trace and print functions */
        !            71:     HTPrint_setCallback(printer);
        !            72:     HTTrace_setCallback(tracer);
        !            73: 
1.2       frystyk    74:     /* Add our own filter to terminate the application */
                     75:     HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
                     76: 
                     77:     /* Turn off any interactions */
                     78:     HTAlert_setInteractive(NO);
1.1       frystyk    79: 
1.4       frystyk    80:     /* Set the timeout for long we are going to wait for a response */
                     81:     HTHost_setEventTimeout(10000);
                     82: 
1.1       frystyk    83:     /* Scan command line for parameters */
                     84:     for (arg=1; arg<argc; arg++) {
                     85:         if (!strcmp(argv[arg], "-o")) { 
                     86:             outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
                     87:                 argv[++arg] : DEFAULT_OUTPUT_FILE;
                     88:             
                     89:         } else {
                     90:             getme = argv[arg];
                     91:         }
                     92:     }
1.2       frystyk    93: 
                     94:     /* Make sure we have an output */
                     95:     if (!outputfile) outputfile = DEFAULT_OUTPUT_FILE;
                     96: 
                     97:     if (getme && *getme) {
                     98:         request = HTRequest_new();
                     99: 
                    100:         /* Start the load */
                    101:         status = HTLoadToFile(getme, request, outputfile);
                    102: 
                    103:         /* Go into the event loop... */
                    104:         HTEventList_loop(request);
                    105: 
                    106:     } else {
1.5     ! frystyk   107:        HTPrint("Type the URI of document you want to load and the name of the local file.\n");
        !           108:        HTPrint("\t%s <address> -o <localfile>\n", argv[0]);
        !           109:        HTPrint("For example, %s http://www.w3.org -o w3chome.html\n", argv[0]);
1.2       frystyk   110: 
                    111:         /* Delete our profile if no load */
                    112:         HTProfile_delete();
1.1       frystyk   113:     }
                    114: 
                    115:     return 0;
                    116: }

Webmaster