summaryrefslogtreecommitdiff
path: root/usr.bin/split
diff options
context:
space:
mode:
authorbjh21 <bjh21@NetBSD.org>2003-07-10 20:43:40 +0000
committerbjh21 <bjh21@NetBSD.org>2003-07-10 20:43:40 +0000
commitb768f7ad6ab0c64756d31bd96760341c4102e2f7 (patch)
tree7a128a37145a472a525c70875cbf610dc020e803 /usr.bin/split
parent15a7538ed46b00eab34bd5243787cc094bbd69d3 (diff)
Remove the hack that varied the first character of the output filename if
a base name wasn't specified. It's not really necessary now that we've got -a, it's ugly, and POSIX doesn't permit it. Suggested on tech-userlevel a couple of weeks ago to a deafening silence.
Diffstat (limited to 'usr.bin/split')
-rw-r--r--usr.bin/split/split.132
-rw-r--r--usr.bin/split/split.c58
2 files changed, 36 insertions, 54 deletions
diff --git a/usr.bin/split/split.1 b/usr.bin/split/split.1
index 21ec6526925..3d8b2fed7b2 100644
--- a/usr.bin/split/split.1
+++ b/usr.bin/split/split.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: split.1,v 1.11 2003/06/27 17:19:54 bjh21 Exp $
+.\" $NetBSD: split.1,v 1.12 2003/07/10 20:43:40 bjh21 Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)split.1 8.3 (Berkeley) 4/16/94
.\"
-.Dd June 27, 2003
+.Dd July 10, 2003
.Dt SPLIT 1
.Os
.Sh NAME
@@ -100,26 +100,30 @@ is not specified, two letters are used as the suffix.
.Pp
If the
.Ar name
-argument is not specified, the file is split into lexically ordered
-files named with prefixes in the range of
-.Dq Li x-z
-and with suffixes as above.
+argument is not specified,
+.Ql x
+is used.
+.Sh STANDARDS
+The
+.Nm
+utility conforms to
+.St -p1003.1-2001 .
.Sh HISTORY
A
.Nm
command appeared in
.At v6 .
+.Pp
The
.Fl a
-option was introduce in
+option was introduced in
.Nx 2.0 .
-.Sh BUGS
-For historical reasons, if you specify
-.Ar name ,
+Before that, if
+.Ar name
+was not specified,
.Nm
-can only create 676 separate
-files.
-The default naming convention allows 2028 separate files.
+would vary the first letter of the filename
+to increase the number of possible output files.
The
.Fl a
-option can be used to work around this limitation.
+option makes this unnecessary.
diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c
index ed1f5ed5a3a..701d4e6b178 100644
--- a/usr.bin/split/split.c
+++ b/usr.bin/split/split.c
@@ -1,4 +1,4 @@
-/* $NetBSD: split.c,v 1.17 2003/06/29 22:57:23 bjh21 Exp $ */
+/* $NetBSD: split.c,v 1.18 2003/07/10 20:43:40 bjh21 Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)split.c 8.3 (Berkeley) 4/25/94";
#endif
-__RCSID("$NetBSD: split.c,v 1.17 2003/06/29 22:57:23 bjh21 Exp $");
+__RCSID("$NetBSD: split.c,v 1.18 2003/07/10 20:43:40 bjh21 Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -76,6 +76,7 @@ main(int argc, char *argv[])
{
int ch;
char *ep, *p;
+ char const *base;
off_t bytecnt = 0; /* Byte count to split on. */
off_t numlines = 0; /* Line count to split on. */
size_t namelen;
@@ -141,20 +142,14 @@ main(int argc, char *argv[])
if ((name_max = pathconf(".", _PC_NAME_MAX)) == -1 &&
errno != 0)
err(EXIT_FAILURE, "pathconf");
- if (*argv != NULL) {
- namelen = strlen(*argv) + sfxlen;
- if (name_max != -1 && namelen > name_max)
- errx(EXIT_FAILURE, "Output file name too long");
- if ((fname = malloc(namelen + 1)) == NULL)
- err(EXIT_FAILURE, NULL);
- (void)strcpy(fname, *argv++); /* File name prefix. */
- } else {
- if (name_max != -1 && 1 + sfxlen > name_max)
- errx(EXIT_FAILURE, "Output file name too long");
- if ((fname = malloc(sfxlen + 2)) == NULL)
- err(EXIT_FAILURE, NULL);
- fname[0] = '\0';
- }
+
+ base = (*argv != NULL) ? *argv++ : "x";
+ namelen = strlen(base) + sfxlen;
+ if (name_max != -1 && namelen > name_max)
+ errx(EXIT_FAILURE, "Output file name too long");
+ if ((fname = malloc(namelen + 1)) == NULL)
+ err(EXIT_FAILURE, NULL);
+ (void)strcpy(fname, base); /* File name prefix. */
if (*argv != NULL)
usage();
@@ -283,39 +278,22 @@ static void
newfile(void)
{
static int fnum;
- static int defname;
static char *fpnt;
int quot, i;
if (ofd == -1) {
- if (fname[0] == '\0') {
- fname[0] = 'x';
- fpnt = fname + 1;
- defname = 1;
- } else {
- fpnt = fname + strlen(fname);
- defname = 0;
- }
- } else {
- if (close(ofd) != 0)
- err(1, "%s", fname);
- }
- /*
- * Hack to increase max files; original code wandered through
- * magic characters. Maximum files is 3 * 26 * 26 == 2028
- */
- fpnt[sfxlen] = '\0';
+ fpnt = fname + strlen(fname);
+ fpnt[sfxlen] = '\0';
+ } else if (close(ofd) != 0)
+ err(1, "%s", fname);
+
quot = fnum;
for (i = sfxlen - 1; i >= 0; i--) {
fpnt[i] = quot % 26 + 'a';
quot = quot / 26;
}
- if (quot > 0) {
- if (!defname || fname[0] == 'z')
- errx(1, "too many files.");
- ++fname[0];
- fnum = 0;
- }
+ if (quot > 0)
+ errx(1, "too many files.");
++fnum;
if ((ofd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE)) < 0)
err(1, "%s", fname);