betz (04/01/83)
/* separate.c - separate a combined file into individual files */
#include <stdio.h>
#define LINEMAX 500
/* main - the main routine */
main(argc,argv)
int argc; char *argv[];
{
FILE *ifp,*ofp = NULL;
char line[LINEMAX],ofname[100];
/* make sure there is a file to separate */
if (argc != 2) {
printf("incorrect number of arguments\n");
exit();
}
/* open the input file */
if ((ifp = fopen(argv[1],"r")) == NULL) {
printf("can't open: %s\n",argv[1]);
exit();
}
/* process each file */
while (fgets(line,LINEMAX,ifp) != NULL) {
/* look for a header line */
if (sscanf(line,"<<<<<<<<<< %s >>>>>>>>>>",ofname) == 1) {
/* close the current output file */
if (ofp != NULL)
fclose(ofp);
/* open the new output file */
if ((ofp = fopen(ofname,"w")) == NULL)
printf("can't create: %s\n",ofname);
else
printf("creating: %s\n",ofname);
}
/* output a line to the current output file */
else if (ofp != NULL)
fputs(line,ofp);
/* no current output file, print the line */
else
fputs(line,stdout);
}
/* close the last output file */
if (ofp != NULL)
fclose(ofp);
/* close the input file */
fclose(ifp);
}jim (04/01/83)
Once again I am prompted to post my "shell archiver". I didn't invent the idea, but I did write this particular version. This is a shell script which takes as input the names of a bunch of files. It produces as output a shell script, which when run extracts the original files. I have seen some much fancier versions, but this one works and it is still what I use. I find it to be a convenient way to bundle up a bunch of files for distribution, for example in net.sources, because it doesn't require any special software on the receiving end, just a standard Unix shell. Put this script in a file called shar, and use it by typing: shar ArchiveName file1 file2 ... Here it is: AR=$1 shift echo "# The rest of this file is a shell script which will extract:" >>$AR echo "# $*" >>$AR for i do echo a - $i echo "echo x - $i" >>$AR echo "cat >$i <<'!Funky!Stuff!'" >>$AR cat $i >>$AR echo "!Funky!Stuff!" >>$AR done