home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / LSFileCut.lha / LSFileCut.readme < prev    next >
Encoding:
Text File  |  1999-07-19  |  2.1 KB  |  102 lines

  1. Short:    Cut data from FILE with position, and length (with source)
  2. Author:   LouiSe
  3. Uploader: LouiSe <louise@mail.ahiv.hu>
  4. Type:     util/file
  5.  
  6. Simple file cutter by LouiSe
  7.  
  8. Usage:  LSFileCut <sourcefile> <targetfile> <position> <bytes>
  9.  
  10. ---------------------------------------------------------
  11.  
  12. check out our projects @
  13. - http://AMIGAonly.ahol.com               AMIGAonly, the hungarian Amiga magazin
  14. - http://AMIGAonly.ahol.com/louise/        LouiSe's home
  15. - http://AMIGAonly.ahol.com/amilinux/    Amiga Linux page
  16.  
  17. --- CUT HERE for THE SOURCE ! ---------------------------
  18.  
  19. #include    <stdio.h>
  20. #include    <string.h>
  21. #include    <stdlib.h>
  22. #include    <clib/dos_protos.h>
  23.  
  24. #define    BUFFSIZE 200000UL
  25.  
  26. void    main(int argc, char *argv[])
  27. {
  28.     BPTR    fhi, fho;
  29.     long    pos,bytes;
  30.     char    buffer[BUFFSIZE];
  31.     long    allbytes=0;
  32.     long    fr=0;
  33.     
  34.     if(argc<5)
  35.     {
  36.         printf("usage:\n");
  37.         printf("      LSFileCut <source filename> <target filename> <position> <bytes>\n");
  38.         exit(0);
  39.     }
  40.     
  41.  
  42.     if(strchr(argv[3],'x')!=NULL) sscanf(argv[3],"%x",&pos);
  43.     else                              pos=atol(argv[3]);
  44.     if(strchr(argv[4],'x')!=NULL) sscanf(argv[4],"%x",&bytes);
  45.     else                              bytes=atol(argv[4]);
  46.  
  47.     printf("FileCut v1.05 by LouiSe 1999\n\n");
  48.     printf("Input file   : %s\n",argv[1]);
  49.     printf("Output file  : %s\n",argv[2]);
  50.     printf("Cut position : %lu\n",pos);
  51.     printf("Bytes to Cut : %lu\n",bytes);
  52.  
  53.     if((fhi=Open(argv[1],MODE_OLDFILE))==NULL)
  54.     {
  55.         printf("*** couldn't open input file: []\n",argv[1]);
  56.         exit(-1);
  57.     }
  58.     else
  59.         {
  60.             if((fho=Open(argv[2],MODE_NEWFILE))==NULL)
  61.             {
  62.                 printf("*** couldn't open output file: []\n",argv[2]);
  63.                 exit(-2);
  64.             }
  65.             else
  66.                 {
  67.                     allbytes=0;
  68.                     Seek(fhi,pos,OFFSET_BEGINNING);
  69.                     while(1)
  70.                     {
  71.                         fr=Read(fhi,buffer,sizeof(buffer));
  72.                         if(fr<=0) break;
  73.                         allbytes=allbytes+fr;
  74.                         // printf("fr=%lu, allbytes=%lu\n",fr,allbytes);
  75.  
  76.                         if(allbytes<bytes)
  77.                         {
  78.                             Write(fho,buffer,fr);
  79.                         }
  80.                         else
  81.                             {
  82.                                 if(fr>bytes)
  83.                                 {
  84.                                     Write(fho,buffer,bytes);
  85.                                 }
  86.                                 else
  87.                                     {
  88.                                         Write(fho,buffer,allbytes-bytes);
  89.                                     }
  90.                                     break;
  91.                             }
  92.                     }
  93.                     
  94.                     Close(fhi);
  95.                     Close(fho);
  96.                 }
  97.     
  98.         }
  99.  
  100. }
  101.  
  102.