Xref: utzoo comp.binaries.ibm.pc:960 comp.sys.ibm.pc:14663 Path: utzoo!mnetor!uunet!husc6!panda!teddy!jpn From: jpn@teddy.UUCP (John P. Nelson) Newsgroups: comp.binaries.ibm.pc,comp.sys.ibm.pc Subject: Re: SPLIT for DOS Message-ID: <4717@teddy.UUCP> Date: 20 Apr 88 16:09:09 GMT References: <57@dcs.UUCP> <1387@slvblc.UUCP> Reply-To: jpn@teddy.UUCP (John P. Nelson) Organization: GenRad, Inc., Concord, Mass. Lines: 94 Keywords: split, Turbo-C >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 #include /*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