Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Sep 2007 23:29:13 GMT
From:      Marcin Gryszkalis <mg@fork.pl>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/116209: [patch] decimal suffix in split
Message-ID:  <200709082329.l88NTDFF049763@www.freebsd.org>
Resent-Message-ID: <200709082330.l88NU1BB081412@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         116209
>Category:       bin
>Synopsis:       [patch] decimal suffix in split
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 08 23:30:01 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Marcin Gryszkalis
>Release:        FreeBSD 6.2-RELEASE i386
>Organization:
>Environment:
FreeBSD smb.obligo.pl 6.2-RELEASE-p4 FreeBSD 6.2-RELEASE-p4 #1: Mon Apr 30 19:49:09 CEST 2007     root@smb.obligo.pl:/aux/obj/aux/src/sys/MGKERNEL  i386
>Description:
This is patch that adds -d flag to use decimal suffixes (00, 01, 02...) instead of traditional (aa, ab). Makes split [more] compatible with GNU split.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- split.c	Sun Jul 11 16:44:23 2004
+++ split.c.new	Sun Sep  9 01:08:21 2007
@@ -71,6 +71,7 @@
 char	 fname[MAXPATHLEN];		/* File name prefix. */
 regex_t	 rgx;
 int	 pflag;
+int	 dflag;
 long	 sufflen = 2;			/* File name suffix length. */
 
 void newfile(void);
@@ -88,7 +89,7 @@
 
 	setlocale(LC_ALL, "");
 
-	while ((ch = getopt(argc, argv, "-0123456789a:b:l:p:")) != -1)
+	while ((ch = getopt(argc, argv, "-0123456789a:b:l:p:d")) != -1)
 		switch (ch) {
 		case '0': case '1': case '2': case '3': case '4':
 		case '5': case '6': case '7': case '8': case '9':
@@ -147,6 +148,9 @@
 				errx(EX_USAGE,
 				    "%s: illegal line count", optarg);
 			break;
+        case 'd': /* decimal suffix */
+            dflag = 1;
+            break;
 		default:
 			usage();
 		}
@@ -301,6 +305,8 @@
 	static long fnum;
 	static int defname;
 	static char *fpnt;
+    char beg, end;
+    int pattlen;
 
 	if (ofd == -1) {
 		if (fname[0] == '\0') {
@@ -314,9 +320,19 @@
 		ofd = fileno(stdout);
 	}
 
+    if (dflag) { 
+        beg = '0'; 
+        end = '9';
+    } else {
+        beg = 'a';
+        end = 'z';
+    }
+
+    pattlen = end - beg + 1;
+
 	/* maxfiles = 26^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);
 
 	/*
@@ -324,7 +340,7 @@
 	 * magic characters.
 	 */
 	if (fnum == maxfiles) {
-		if (!defname || fname[0] == 'z')
+		if (!defname || fname[0] == end)
 			errx(EX_DATAERR, "too many files");
 		++fname[0];
 		fnum = 0;
@@ -334,8 +350,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';
 


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709082329.l88NTDFF049763>