From owner-svn-src-all@FreeBSD.ORG Fri May 10 04:23:04 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 877FE831; Fri, 10 May 2013 04:23:04 +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 79753B36; Fri, 10 May 2013 04:23:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4A4N4Gv094728; Fri, 10 May 2013 04:23:04 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4A4N44u094726; Fri, 10 May 2013 04:23:04 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201305100423.r4A4N44u094726@svn.freebsd.org> From: Eitan Adler Date: Fri, 10 May 2013 04:23:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250432 - head/usr.bin/split X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 May 2013 04:23:04 -0000 Author: eadler Date: Fri May 10 04:23:03 2013 New Revision: 250432 URL: http://svnweb.freebsd.org/changeset/base/250432 Log: Implement 'split -d' which allows a numeric suffix instead of an alphabetic one. PR: bin/116209 Submitted by: Marcin Gryszkalis (adapted from) Reviewed by: will MFC after: 1 week Modified: head/usr.bin/split/split.1 head/usr.bin/split/split.c Modified: head/usr.bin/split/split.1 ============================================================================== --- head/usr.bin/split/split.1 Fri May 10 03:49:05 2013 (r250431) +++ head/usr.bin/split/split.1 Fri May 10 04:23:03 2013 (r250432) @@ -36,10 +36,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 +51,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 +112,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: head/usr.bin/split/split.c ============================================================================== --- head/usr.bin/split/split.c Fri May 10 03:49:05 2013 (r250431) +++ head/usr.bin/split/split.c Fri May 10 04:23:03 2013 (r250432) @@ -51,6 +51,7 @@ static const char sccsid[] = "@(#)split. #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ static char bfr[MAXBSIZE]; /* I/O buff 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); @@ -88,7 +90,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': @@ -131,6 +134,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(); @@ -348,6 +354,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') { @@ -359,9 +367,19 @@ 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 ((maxfiles *= pattlen) <= 0) errx(EX_USAGE, "suffix is too long (max %ld)", i); if (fnum == maxfiles) @@ -371,8 +389,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';