home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
CMDS
/
smallutils.t.Z
/
smallutils.t
/
fc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-19
|
2KB
|
92 lines
#include <stdio.h>
#include <strings.h>
main(argc,argv)
int argc;
char *argv[];
{
/* fc - floppy chopper - cuts files up into 350,000 byte segments
for easy storage on 360k floppies */
FILE *infile, *outfile;
static char filnam[40],filnam2[40];
int counter;
char c;
if (argc==1)
{
infile=stdin;
strcpy(filnam,"stdin\0");
}
else
if (argv[1][0]=='-')
{
if (argv[1][1]!='?')
{
fprintf(stderr,"Invalid argument %s!\n\n",argv[1]);
exit(1);
}
else
{ /* print help */
printf("Syntax: fc [<file>]\n");
printf("Function: Takes first 350,000 bytes of a file or stdin\n");
printf(" and puts in one file and puts remaining bytes\n");
printf(" in another file for easily putting large files\n");
printf(" on 360k media.\n");
printf("Options: none\n\n");
exit(0);
}
}
else
{
infile=fopen(argv[1],"r");
strcpy(filnam,argv[1]);
if (infile==NULL)
{
fprintf (stderr,"Error opening file %s!\n\n",argv[1]);
exit(1);
}
}
/* ok file is open lets start */
strcpy(filnam2,filnam);
strcat(filnam,"_1");
outfile=fopen(filnam,"w");
if (outfile==NULL)
{
fprintf(stderr,"Error creating output file %s !\n",filnam);
exit(1);
}
for (counter=350000;counter--;)
{
c=fgetc(infile);
if (c== EOF)
{
printf("Oops! File was already less than 350,000 bytes!\n");
printf("That's ok. Now you have two copies of the same\n");
printf("file. \n");
fclose(outfile);
if (argc>1)
fclose(infile);
exit(0);
}
fwrite(&c,1,1,outfile);
}
fclose (outfile);
strcat(filnam2,"_2");
outfile=fopen(filnam2,"w");
if (outfile==NULL)
{
fprintf(stderr,"Blarg! Can't open second file %s!\n",filnam2);
exit(1);
}
while (!(c=fgetc(infile)==EOF))
{
fwrite(&c,1,1,outfile);
}
fclose(outfile);
if (argc>1)
fclose(infile);
printf("All done! Files are %s and %s.\n\n",filnam,filnam2);
exit(0);
}