[comp.sys.ibm.pc] SPLIT for DOS

wnp@dcs.UUCP (Wolf N. Paul) (04/17/88)

Someone recently posted a request for a split program for DOS.

I found such a beast on the EXEC-PC BBS, and while it does not
follow the UNIX split(1) syntax, it provides the same functionality
and may even be more flexible.

I have posted a uuencoded ARC file (non-squashed) to comp.binaries.ibm.pc
and hope that folks find it helpful.
-- 
Wolf N. Paul * 3387 Sam Rayburn Run * Carrollton TX 75007 * (214) 306-9101
UUCP:  ihnp4!killer!dcs!wnp                    ESL: 62832882
INTERNET: wnp@EESDES.DAS.NET or wnp@dcs.UUCP   TLX: 910-280-0585 EES PLANO UD

dick@slvblc.UUCP (Dick Flanagan) (04/18/88)

In article <57@dcs.UUCP> wnp@dcs.UUCP (Wolf N. Paul) writes:
> Someone recently posted a request for a split program for DOS. While
> the attached does not exactly follow the syntax of UNIX split(1),
> it has the same functionality and is maybe even more flexible.

Nope!  I certainly appreciate the trouble Wolf went to to post this
program, but this particular "split" is a binary-mode byte-splitter,
not a text-mode line-splitter like its UNIX namesake.

If no one can come up with a true text-mode line split() for DOS, I
guess I'll just have to write one--then we'll all be in trouble!  *8-)

Dick

--
Dick Flanagan, W6OLD                         GEnie: FLANAGAN
UUCP: ...!ucbvax!ucscc!slvblc!dick           Voice: +1 408 336 3481
Internet: slvblc!dick@ucscc.UCSC.EDU         LORAN: N037 04.7 W122 04.6
USPS: PO Box 155, Ben Lomond, CA 95005

jpn@teddy.UUCP (John P. Nelson) (04/20/88)

>If no one can come up with a true text-mode line split() for DOS, I
>guess I'll just have to write one--then we'll all be in trouble!  *8-)

I wrote this in about 5 minutes, and sent it off to the person requesting
a public-domain split.  Since the discussion refuses to die by itself,
I am posting the source.  It works on unix, but is untested under DOS
(but should work, as long as your C library is sufficiently UNIX-like).
It could probably use some filename checks, especially with restrictive
DOS filenames.

No manpage.  See the UNIX manpage.


/* split.c	15-Apr-88 10:08 jpn Author
 *
 * (c) Copyright 1988 John P. Nelson
 *                All Rights Reserved.
 *
 *   This source code is freely distributable, and may be modified without
 *   permission, so long as this copyright notice remains intact.  Binary
 *   executables created from this source may be distributed freely, and
 *   used for any purpose whatsoever.
 *
 */

/*Inclusions*/
#include <stdio.h>
#include <ctype.h>

/*Definitions*/

/*External and global declarations */
char filename[128];
char prefix[128] = "x";
char suffix[] = "aa";
char *program;
int nlines = 1000;

FILE *input = stdin;
FILE *output = 0;


main(argc, argv)
int argc;
char **argv;
    {
    register int index = 0;
    char buffer[BUFSIZ];

    program = argv[0];
    if (argc > 1 && argv[1][0] == '-' && isdigit(argv[1][1]))
	{
	nlines = atoi(argv[1]+1);
	++argv;
	--argc;
	}
    if (argc > 3)
	{ fprintf(stderr, "%s: Too many arguments\n", program); exit(1); }
    if (argc > 1)
	if (strcmp(argv[1], "-"))
	    if ((input = fopen(argv[1], "r")) == 0)
		{ perror(argv[1]); exit(1); }
    if (argc > 2)
	strcpy(prefix, argv[2]);

    while (fgets(buffer, sizeof(buffer), input))
	{
	if (index == 0)
	    {
	    strcpy(filename, prefix);
	    strcat(filename, suffix);
	    if ((output = fopen(filename, "w")) == 0)
		{ perror(filename); exit(1); }
	    }
	if (fputs(buffer, output) == EOF)
	    { perror(filename); exit(1); }
	if (++index == nlines)
	    {
	    index = 0;
	    if (++suffix[1] > 'z')
		{
		++suffix[0];
		suffix[1] = 'a';
		}
	    if (fclose(output) == EOF)
		{ perror(filename); exit(1); }
	    }
	}
    }
-- 
     john nelson

UUCP:            {decvax,mit-eddie}!genrad!teddy!jpn
ARPA (sort of):  talcott.harvard.edu!panda!teddy!jpn