home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # This file was wrapped with "dummyshar". "sh" this file to extract.
- # Contents: bsplit.c
- echo extracting 'bsplit.c'
- if test -f 'bsplit.c' -a -z "$1"; then echo Not overwriting 'bsplit.c'; else
- sed 's/^X//' << \EOF > 'bsplit.c'
- X/*
- X * bsplit.c - split binary files in manageable pieces.
- X * usage is exactly like the split program.
- X *
- X * This program was written from scratch, without looking at the
- X * sources of split.
- X *
- X * Copyright (C) 1988 P. Knoppers
- X * Bilderdijkhof 59
- X * 2624 ZG Delft
- X * The Netherlands
- X */
- X
- Xchar copy0[] = "Copyright (C) 1988 P. Knoppers";
- Xchar copy1[] = "Permission to use and distribute copies of this";
- Xchar copy2[] = "program WITH SOURCE is granted to anyone, provided";
- Xchar copy3[] = "that it is NOT CHANGED in any way.";
- X
- X#include <stdio.h>
- X#define DEFSIZE 50000
- X#define DEFPREFIX "x"
- X#define MAXNAME 200
- X
- Xchar *malloc ();
- X
- Xmain (argc, argv) /* bsplit - split binary file */
- Xchar *argv[];
- X{
- X char *buf;
- X char *myname;
- X int bulksize = DEFSIZE;
- X int level;
- X int got;
- X int fno = 0;
- X char outfname[MAXNAME + 1];
- X char outbase[MAXNAME + 3];
- X int foundinname = 0;
- X FILE * infile = stdin;
- X FILE * outfile;
- X
- X myname = *argv;
- X strcpy (outbase, DEFPREFIX);
- X while (--argc > 0)
- X {
- X argv++;
- X if ((*argv)[0] == '-')
- X {
- X if ((*argv)[1] == '\0')
- X {
- X if (foundinname != 0)
- X {
- X fprintf (stderr,
- X "usage: %s [-size] [file [prefix]]\n",
- X myname);
- X exit (1);
- X }
- X foundinname++;
- X }
- X else
- X if (sscanf (*argv, "-%d", &bulksize) != 1)
- X {
- X fprintf (stderr,
- X "usage: %s [-size] [file [prefix]]\n",
- X myname);
- X exit (1);
- X }
- X }
- X else
- X if (foundinname != 0)
- X {
- X if (strlen (*argv) > MAXNAME)
- X {
- X fprintf (stderr, "%s: prefix too long\n",
- X myname);
- X exit (1);
- X }
- X strcpy (outbase, *argv);
- X }
- X else
- X {
- X if ((infile = fopen (*argv, "r")) == NULL)
- X {
- X fprintf (stderr, "%s: cannot open %s\n",
- X myname, *argv);
- X exit (1);
- X }
- X foundinname++;
- X }
- X }
- X
- X if ((buf = malloc (bulksize)) == NULL)
- X {
- X fprintf (stderr, "%s: malloc failed\n", myname);
- X exit (1);
- X }
- X level = 0;
- X while (1)
- X {
- X got = read (fileno (infile), &buf[level], bulksize - level);
- X level += got;
- X if ((level < bulksize) && (got > 0))
- X continue;
- X if ((level == bulksize) || ((got == 0) && (level > 0)))
- X {
- X sprintf (outfname, "%s%c%c", outbase, fno / 26 + 'a',
- X fno % 26 + 'a');
- X if ((outfile = fopen (outfname, "w")) == NULL)
- X {
- X fprintf (stderr, "%s: cannot create %s\n", myname,
- X outfname);
- X exit (1);
- X }
- X if (write (fileno (outfile), buf, level) != level)
- X {
- X fprintf (stderr, "%s: write failed\n", myname);
- X exit (1);
- X }
- X fclose (outfile);
- X level = 0;
- X fno++;
- X }
- X if (got == 0)
- X break;
- X }
- X}
- EOF
- chars=`wc -c < 'bsplit.c'`
- if test $chars != 2804; then echo 'bsplit.c' is $chars characters, should be 2804 characters!; fi
- fi
- exit 0
-
-
-