home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / misc / splitit.lha / SplitIt! / SplitIt!.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-13  |  2.9 KB  |  136 lines

  1. /*
  2.  
  3. Name
  4.     SplitIt.c
  5.  
  6. Project
  7.     SplitIt
  8.  
  9. Version
  10.  
  11.     1.00
  12.  
  13. Synopsis        
  14.     An ANSI-C file splitter. Used to split long files so that they
  15.     may be copied to MSDOS-disks, taking care of the MSDOS file-system.
  16.     It's a shame that even Amiga users have to use this fucking
  17.     MICROSOFT - SHIT ! Winners don't use PCs !
  18.  
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <fcntl.h>
  24.  
  25. #include <stat.h>        /* DeComment when compiling under Amiga OS */
  26.  
  27. #include <stdlib.h>
  28. #include <fcntl.h>
  29.  
  30.  
  31. int    main (int argc, char ** argv)
  32. {
  33. struct stat file;
  34. long    disksize=atoi(argv[2]);
  35. void    *memory;
  36. char    joinname[20];
  37. char    outname[20];
  38. char    croutname[20];
  39. char    tempname[20];
  40. FILE    *joinfile;
  41. int    readfile=0;
  42. int    outfile=0;
  43. int    namecount=0;
  44. int     readsize=0;
  45.  
  46. if ((argc == 4) || (argc == 3))
  47.     {
  48.     puts ("ANSI - C File splitter\nCopyright (c) 1995 Laserdance Productions\n");
  49.     puts ("Scanning file...");
  50.     if (!stat (argv [1],&file))
  51.         {
  52.         printf ("Found file : %s - Filesize is : %ld bytes.\n",argv[1],file.st_size);
  53.         printf ("This file requires %d disk(s) of size %ld.\n",file.st_size/disksize+1,disksize);
  54.         }
  55.     else
  56.         {
  57.         printf ("**Error : Could not open file : %s",argv[1]);
  58.         return (10);
  59.         }
  60.     puts ("Allocating buffers ...");
  61.     if (memory = malloc (disksize))
  62.         {
  63.         if (argc ==3)
  64.             strncpy (outname,argv[1],8);
  65.         else
  66.             strncpy (outname,argv[3],8);
  67.  
  68.         outname[8]=0;
  69.         strcpy (joinname,outname);
  70.         strcat (joinname,".JOI");
  71.  
  72.         printf ("Opening logfile : %s \n",joinname);
  73.  
  74.         if (joinfile = fopen (joinname,"w"))
  75.             {
  76.             if (readfile = open (argv[1],O_RDONLY,NULL))
  77.                 {
  78.                 fprintf (joinfile,"; Joinfile for Amiga-OS join command\n; Created by SplitIt!\n; (c) Laserdance Production 1995\n\njoin ");
  79.                 do
  80.                     {
  81.                     if ((readsize = read (readfile,memory,disksize))!=-1)
  82.                         {
  83.                         strcpy (croutname,outname);
  84.                         sprintf (tempname,".%d",namecount);
  85.                         strcat (croutname,tempname);
  86.                         namecount++;
  87.                         printf ("Opening output file : %s\n",croutname);
  88.                         if (outfile = open (croutname,O_CREAT|O_WRONLY,NULL))
  89.                             {
  90.                             write (outfile,memory,readsize);
  91.                             fprintf (joinfile,"%s ",croutname);
  92.                             close (outfile);
  93.                             chmod (croutname,S_IWRITE|S_IREAD|S_IDELETE);
  94.                             }
  95.                         else
  96.                             {
  97.                             puts ("**Error : Cannot open file to write to!");
  98.                             free (memory);
  99.                             close (readfile);
  100.                             fclose (joinfile);
  101.                             return (10);
  102.                             }
  103.                         }
  104.  
  105.                     }
  106.                 while (readsize==disksize);
  107.                 fprintf (joinfile,"AS %s\n",argv[1]);
  108.                 }
  109.             else
  110.                 {
  111.                 puts ("**Error : Cannot open file to read from");
  112.                 free (memory);
  113.                 fclose (joinfile);
  114.                 return (10);
  115.                 }
  116.             fclose (joinfile);
  117.             }
  118.         else
  119.             {
  120.             puts ("**Error : Cannot open join file");
  121.             free (memory);
  122.             return (10);
  123.             }
  124.         }
  125.     else
  126.         {
  127.         printf ("**Error : Insufficient resources. Failed to allocate memory block of %ld bytes",disksize);
  128.         return (10);
  129.         }
  130.     }
  131. else
  132.     {
  133.     printf ("Usage : %s FILENAME DISKSIZE [OUTPUTNAME]\n",argv[0]);
  134.     }
  135. }
  136.