home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume34 / fsp / part04 / fgetcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-18  |  1.5 KB  |  64 lines

  1.     /*********************************************************************\
  2.     *  Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu)   *
  3.     *                                                                     *
  4.     *  You may copy or modify this file in any manner you wish, provided  *
  5.     *  that this notice is always included, and that you hold the author  *
  6.     *  harmless for any loss or damage resulting from the installation or *
  7.     *  use of this software.                                              *
  8.     \*********************************************************************/
  9.  
  10. #include "client_def.h"
  11.  
  12. extern char **glob();
  13.  
  14. static get_file(path)
  15.     char *path;
  16. {
  17.     char *name, *t2;
  18.     FILE *fp;
  19.  
  20.     for(name = t2 = path; *t2; t2++) if(*t2 == '/') name = t2 + 1;
  21.  
  22.     if(fp = fopen(name,"w"))
  23.     {
  24.     if(util_download(path,fp) == -1) { fclose(fp); unlink(name); }
  25.                     else { fclose(fp);               }
  26.  
  27.     } else fprintf(stderr,"Cannot write %s\n",name);
  28. }
  29.  
  30. main(argc,argv,envp)
  31.     int argc;
  32.     char **argv,**envp;
  33. {
  34.     char **av, *av2[2], n[1024];
  35.     int prompt;
  36.  
  37.     env_client();
  38.  
  39.     if(argc > 1)
  40.     {
  41.     while(*++argv)
  42.     {
  43.         if(!(av = glob(*argv))) { av = av2; av2[0] = *argv; av2[1] = 0; }
  44.         while(*av) get_file(*av++);
  45.     }
  46.     } else
  47.     {
  48.     prompt = isatty(0);
  49.  
  50.     while(1)
  51.     {
  52.         if(prompt) { fputs("fget: ",stdout); fflush(stdout); }
  53.         if(!gets(n)) break;
  54.         if(!*n) continue;
  55.         if(!(av = glob(n))) { av = av2; av2[0] = n; av2[1] = 0; }
  56.         while(*av) get_file(*av++);
  57.     }
  58.     }
  59.  
  60.     client_done();
  61.  
  62.     exit(0);
  63. }
  64.