home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume34 / fsp / part04 / fput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-18  |  1.4 KB  |  59 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. static put_file(path)
  13.     char *path;
  14. {
  15.     struct stat sb;
  16.     char *name, *t2;
  17.     FILE *fp;
  18.  
  19.     if(stat(path,&sb) != 0) { perror(path); return; }
  20.     if(!(S_IFREG & sb.st_mode)) { fprintf(stderr,"%s: not a file\n",path);
  21.                 return; }
  22.  
  23.     for(name = t2 = path; *t2; t2++) if(*t2 == '/') name = t2 + 1;
  24.  
  25.     if(fp = fopen(path,"r"))
  26.     {
  27.     util_upload(name,fp);
  28.     fclose(fp);
  29.  
  30.     } else fprintf(stderr,"Cannot read %s\n",path);
  31. }
  32.  
  33. main(argc,argv,envp)
  34.     int argc;
  35.     char **argv,**envp;
  36. {
  37.     char n[1024];
  38.     int prompt;
  39.  
  40.     env_client();
  41.  
  42.     if(argc > 1) while(*++argv) put_file(*argv); else
  43.     {
  44.     prompt = isatty(0);
  45.  
  46.     while(1)
  47.     {
  48.         if(prompt) { fputs("fput: ",stdout); fflush(stdout); }
  49.         if(!gets(n)) break;
  50.         if(!*n) continue;
  51.         put_file(n);
  52.     }
  53.     }
  54.  
  55.     client_done();
  56.  
  57.     exit(0);
  58. }
  59.