[Midnightbsd-cvs] src [11333] sync split with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Jul 4 21:29:29 EDT 2018
Revision: 11333
http://svnweb.midnightbsd.org/src/?rev=11333
Author: laffer1
Date: 2018-07-04 21:29:29 -0400 (Wed, 04 Jul 2018)
Log Message:
-----------
sync split with freebsd
Modified Paths:
--------------
trunk/usr.bin/split/split.1
trunk/usr.bin/split/split.c
Property Changed:
----------------
trunk/usr.bin/split/split.1
Modified: trunk/usr.bin/split/split.1
===================================================================
--- trunk/usr.bin/split/split.1 2018-07-05 00:58:20 UTC (rev 11332)
+++ trunk/usr.bin/split/split.1 2018-07-05 01:29:29 UTC (rev 11333)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1990, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -26,9 +27,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)split.1 8.3 (Berkeley) 4/16/94
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/split/split.1 250451 2013-05-10 12:49:16Z eadler $
.\"
-.Dd September 2, 2010
+.Dd May 9, 2013
.Dt SPLIT 1
.Os
.Sh NAME
@@ -36,10 +37,12 @@
.Nd split a file into pieces
.Sh SYNOPSIS
.Nm
+.Fl d
.Op Fl l Ar line_count
.Op Fl a Ar suffix_length
.Op Ar file Op Ar prefix
.Nm
+.Fl d
.Fl b Ar byte_count Ns
.Oo
.Sm off
@@ -49,10 +52,12 @@
.Op Fl a Ar suffix_length
.Op Ar file Op Ar prefix
.Nm
+.Fl d
.Fl n Ar chunk_count
.Op Fl a Ar suffix_length
.Op Ar file Op Ar prefix
.Nm
+.Fl d
.Fl p Ar pattern
.Op Fl a Ar suffix_length
.Op Ar file Op Ar prefix
@@ -108,6 +113,8 @@
is appended to the number, the file is split into
.Ar byte_count
gigabyte pieces.
+.It Fl d
+Use a numeric suffix instead of a alphabetic suffix.
.It Fl l Ar line_count
Create split files
.Ar line_count
Property changes on: trunk/usr.bin/split/split.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/split/split.c
===================================================================
--- trunk/usr.bin/split/split.c 2018-07-05 00:58:20 UTC (rev 11332)
+++ trunk/usr.bin/split/split.c 2018-07-05 01:29:29 UTC (rev 11333)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
@@ -28,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/split/split.c 250882 2013-05-21 19:56:03Z eadler $");
#ifndef lint
static const char copyright[] =
@@ -51,6 +52,7 @@
#include <inttypes.h>
#include <limits.h>
#include <locale.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -61,16 +63,17 @@
#define DEFLINE 1000 /* Default num lines per file. */
-off_t bytecnt; /* Byte count to split on. */
-off_t chunks = 0; /* Chunks count to split into. */
-long numlines; /* Line count to split on. */
-int file_open; /* If a file open. */
-int ifd = -1, ofd = -1; /* Input/output file descriptors. */
-char bfr[MAXBSIZE]; /* I/O buffer. */
-char fname[MAXPATHLEN]; /* File name prefix. */
-regex_t rgx;
-int pflag;
-long sufflen = 2; /* File name suffix length. */
+static off_t bytecnt; /* Byte count to split on. */
+static off_t chunks = 0; /* Chunks count to split into. */
+static long numlines; /* Line count to split on. */
+static int file_open; /* If a file open. */
+static int ifd = -1, ofd = -1; /* Input/output file descriptors. */
+static char bfr[MAXBSIZE]; /* I/O buffer. */
+static char fname[MAXPATHLEN]; /* File name prefix. */
+static regex_t rgx;
+static int pflag;
+static bool dflag;
+static long sufflen = 2; /* File name suffix length. */
static void newfile(void);
static void split1(void);
@@ -88,7 +91,8 @@
setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "0123456789a:b:l:n:p:")) != -1)
+ dflag = false;
+ while ((ch = getopt(argc, argv, "0123456789a:b:dl:n:p:")) != -1)
switch (ch) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
@@ -131,6 +135,9 @@
errx(EX_USAGE, "%s: offset too large", optarg);
bytecnt = (off_t)(bytecnti * scale);
break;
+ case 'd': /* Decimal suffix */
+ dflag = true;
+ break;
case 'l': /* Line count. */
if (numlines != 0)
usage();
@@ -348,6 +355,8 @@
long i, maxfiles, tfnum;
static long fnum;
static char *fpnt;
+ char beg, end;
+ int pattlen;
if (ofd == -1) {
if (fname[0] == '\0') {
@@ -359,10 +368,22 @@
ofd = fileno(stdout);
}
- /* maxfiles = 26^sufflen, but don't use libm. */
+ if (dflag) {
+ beg = '0';
+ end = '9';
+ }
+ else {
+ beg = 'a';
+ end = 'z';
+ }
+ pattlen = end - beg + 1;
+
+ /* maxfiles = pattlen^sufflen, but don't use libm. */
for (maxfiles = 1, i = 0; i < sufflen; i++)
- if ((maxfiles *= 26) <= 0)
+ if (LONG_MAX / pattlen < maxfiles)
errx(EX_USAGE, "suffix is too long (max %ld)", i);
+ else
+ maxfiles *= pattlen;
if (fnum == maxfiles)
errx(EX_DATAERR, "too many files");
@@ -371,8 +392,8 @@
tfnum = fnum;
i = sufflen - 1;
do {
- fpnt[i] = tfnum % 26 + 'a';
- tfnum /= 26;
+ fpnt[i] = tfnum % pattlen + beg;
+ tfnum /= pattlen;
} while (i-- > 0);
fpnt[sufflen] = '\0';
More information about the Midnightbsd-cvs
mailing list