From owner-svn-src-stable-8@FreeBSD.ORG Thu Jun 13 21:06:18 2013 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 1747A70B; Thu, 13 Jun 2013 21:06:18 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id ED4C312DB; Thu, 13 Jun 2013 21:06:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5DL6H3m013290; Thu, 13 Jun 2013 21:06:17 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5DL6HS8013273; Thu, 13 Jun 2013 21:06:17 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201306132106.r5DL6HS8013273@svn.freebsd.org> From: Eitan Adler Date: Thu, 13 Jun 2013 21:06:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r251710 - stable/8/usr.bin/split X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jun 2013 21:06:18 -0000 Author: eadler Date: Thu Jun 13 21:06:17 2013 New Revision: 251710 URL: http://svnweb.freebsd.org/changeset/base/251710 Log: MFC r227183,r229905,r250432,r250451,r250882: - Add missing static keywords to split(1) - Fix warning when compiling with gcc46: error: variable 'defname' set but not use - Implement 'split -d' which allows a numeric suffix instead of an alphabetic one. - Bump .Dd for recent content change. Avoid signed overflow in error handling code. PR: bin/116209 Modified: stable/8/usr.bin/split/split.1 stable/8/usr.bin/split/split.c Directory Properties: stable/8/usr.bin/split/ (props changed) Modified: stable/8/usr.bin/split/split.1 ============================================================================== --- stable/8/usr.bin/split/split.1 Thu Jun 13 21:05:38 2013 (r251709) +++ stable/8/usr.bin/split/split.1 Thu Jun 13 21:06:17 2013 (r251710) @@ -32,7 +32,7 @@ .\" @(#)split.1 8.3 (Berkeley) 4/16/94 .\" $FreeBSD$ .\" -.Dd September 2, 2010 +.Dd May 9, 2013 .Dt SPLIT 1 .Os .Sh NAME @@ -40,10 +40,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 @@ -53,10 +55,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 @@ -112,6 +116,8 @@ or 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 Modified: stable/8/usr.bin/split/split.c ============================================================================== --- stable/8/usr.bin/split/split.c Thu Jun 13 21:05:38 2013 (r251709) +++ stable/8/usr.bin/split/split.c Thu Jun 13 21:06:17 2013 (r251710) @@ -55,6 +55,7 @@ static const char sccsid[] = "@(#)split. #include #include #include +#include #include #include #include @@ -65,16 +66,17 @@ static const char sccsid[] = "@(#)split. #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); @@ -92,7 +94,8 @@ main(int argc, char **argv) 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': @@ -135,6 +138,9 @@ main(int argc, char **argv) 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(); @@ -352,6 +358,8 @@ newfile(void) long i, maxfiles, tfnum; static long fnum; static char *fpnt; + char beg, end; + int pattlen; if (ofd == -1) { if (fname[0] == '\0') { @@ -363,10 +371,22 @@ newfile(void) 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"); @@ -375,8 +395,8 @@ newfile(void) 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';