Subject: Re: bin/21058: Teach unexpand -t
To: None <netbsd-bugs@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 04/07/2003 22:38:30
> >Synopsis:       Teach unexpand -t <tabstop>

Whether this is a good idea or not.

> +			tabsize=atoi(optarg);

strtoul() is better than atoi()...

> +			fprintf(stderr, "Space found, dcol: %d\n", dcol);
...
> +			fprintf(stderr, "Tab found, dcol pre: %d", dcol);
...
> +			fprintf(stderr, " post: %d\n", dcol);

A little verbose :-)

>  		default:
> -			while (((ocol + 8) &~ 07) <= dcol) {
> +			while ((((ocol + sz)/sz)*sz) <= dcol) {
>  				if (ocol + 1 == dcol)
>  					break;
>  				*dp++ = '\t';
> -				ocol += 8;
> -				ocol &= ~07;
> +				ocol += sz;
> +				ocol=(ocol/sz) * sz;

Not enough ' ' chars...
Also there are some optimisations that ought to be done to avoid
all the (expensive) divisions.


	David

-- 
David Laight: david@l8s.co.uk