Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jan 2002 13:27:39 -0500
From:      Mike Barcroft <mike@FreeBSD.ORG>
To:        "Tim J. Robbins" <tim@robbins.dropbear.id.au>
Cc:        freebsd-standards@FreeBSD.ORG
Subject:   Re: split(1) -a option patch
Message-ID:  <20020125132739.B92720@espresso.q9media.com>
In-Reply-To: <20020124210956.A13091@descent.robbins.dropbear.id.au>; from tim@robbins.dropbear.id.au on Thu, Jan 24, 2002 at 09:09:56PM %2B1100
References:  <20020124210956.A13091@descent.robbins.dropbear.id.au>

next in thread | previous in thread | raw e-mail | index | archive | help
Tim J. Robbins <tim@robbins.dropbear.id.au> writes:
> This patch implements -a option of split command to control the number
> of letters used to generate filename suffix.

Could you please update your patch to -CURRENT sources.  There is
atleast one change to split.c that hasn't been MFC'd.

> diff -ru split.old/split.1 split/split.1
> --- split.old/split.1	Thu Jan 24 21:07:03 2002
> +++ split/split.1	Thu Jan 24 21:06:29 2002
> @@ -40,6 +40,7 @@
>  .Nd split a file into pieces
>  .Sh SYNOPSIS
>  .Nm
> +.Op Fl a Ar suffix_length
>  .Op Fl b Ar byte_count[k|m]
>  .Op Fl l Ar line_count
>  .Op Fl p Ar pattern
> @@ -54,6 +55,12 @@
>  .Pp
>  The options are as follows:
>  .Bl -tag -width Ds
> +.It Fl a
> +Use
> +.Ar suffix_length
> +letters to form the suffix of the file name. If
> +.Fl a
> +is not specified, two letters are used as the suffix.
>  .It Fl b
>  Create smaller files
>  .Ar byte_count

Okay.

> diff -ru split.old/split.c split/split.c
> --- split.old/split.c	Thu Jan 24 21:07:03 2002
> +++ split/split.c	Thu Jan 24 21:05:07 2002
> @@ -69,6 +69,7 @@
>  char	 fname[MAXPATHLEN];		/* File name prefix. */
>  regex_t	 rgx;
>  int	 pflag;
> +int	 sufflen;			/* File name suffix length. */
>  
>  void newfile __P((void));
>  void split1 __P((void));
> @@ -83,7 +84,7 @@
>  	int ch;
>  	char *ep, *p;
>  
> -	while ((ch = getopt(argc, argv, "-0123456789b:l:p:")) != -1)
> +	while ((ch = getopt(argc, argv, "-0123456789b:l:p:a:")) != -1)

These options need to be kept in alphabetical order.

>  		switch (ch) {
>  		case '0': case '1': case '2': case '3': case '4':
>  		case '5': case '6': case '7': case '8': case '9':
> @@ -130,6 +131,11 @@
>  				errx(EX_USAGE,
>  				    "%s: illegal line count", optarg);
>  			break;
> +		case 'a':		/* Suffix length */

Similarly, the case clauses need to be kept in alphabetical order.

> +			if ((sufflen = strtol(optarg, &ep, 10)) <= 0 || *ep)

Return value of strtol() doesn't match type of sufflen.

> +				err(EX_USAGE,
> +				    "%s: illegal suffix length", optarg);
> +			break;
>  		default:
>  			usage();
>  		}
> @@ -147,6 +153,9 @@
>  	if (*argv != NULL)
>  		usage();
>  
> +	if (strlen(fname) + sufflen >= sizeof (fname))

There shouldn't be a space between `sizeof' and `(fname)'.

This comparison will probably need some casting to prevent comparing
signed and unsigned diagnostics.

> +		err(EX_USAGE, "suffix is too long");
> +

Gratuitous vertical whitespace.

>  	if (pflag && (numlines != 0 || bytecnt != 0))
>  		usage();
>  
> @@ -277,6 +286,7 @@
>  	static long fnum;
>  	static int defname;
>  	static char *fpnt;
> +	long maxfiles, i, tfnum;

This belongs above the other types, since `long' is larger than the
other types.  Also, `i' comes before `m' in the alphabet.

>  
>  	if (ofd == -1) {
>  		if (fname[0] == '\0') {
> @@ -289,19 +299,24 @@
>  		}
>  		ofd = fileno(stdout);
>  	}
> +
> +	/* maxfiles = 26^sufflen, but don't use libm */

Sentences end with a period.

> +	for (maxfiles = 1, i = 0; i < sufflen; i++)
> +		maxfiles *= 26;
> +

Extra checking is needed here, since a 32-bit signed integer overflows
at a sufflen of 7.

>  	/*
>  	 * Hack to increase max files; original code wandered through
> -	 * magic characters.  Maximum files is 3 * 26 * 26 == 2028
> +	 * magic characters.
>  	 */
> -#define MAXFILES	676
> -	if (fnum == MAXFILES) {
> +	if (fnum == maxfiles) {
>  		if (!defname || fname[0] == 'z')
>  			errx(EX_DATAERR, "too many files");
>  		++fname[0];
>  		fnum = 0;
>  	}
> -	fpnt[0] = fnum / 26 + 'a';
> -	fpnt[1] = fnum % 26 + 'a';
> +	for (tfnum = fnum, i = sufflen; i != 0; i--, tfnum /= 26)
> +		fpnt[i - 1] = tfnum % 26 + 'a';
> +	fpnt[sufflen] = '\0';

Can you explain the purpose of this change?  I don't think I
completely understand it.

>  	++fnum;
>  	if (!freopen(fname, "w", stdout))
>  		err(EX_IOERR, "%s", fname);
> @@ -312,6 +327,7 @@
>  usage()
>  {
>  	(void)fprintf(stderr,
> -"usage: split [-b byte_count] [-l line_count] [-p pattern] [file [prefix]]\n");
> +"usage: split [-a sufflen] [-b byte_count] [-l line_count] [-p pattern] \n"
> +"\t\t[file [prefix]]\n");

This change breaks K&R.  Add a new fprintf().

>  	exit(EX_USAGE);
>  }


Best regards,
Mike Barcroft

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




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