NetBSD Problem Report #11228
Received: (qmail 17526 invoked from network); 14 Oct 2000 17:11:57 -0000
Message-Id: <Pine.SOL.4.21.0010141808330.3055-100000@draco.cus.cam.ac.uk>
Date: Sat, 14 Oct 2000 18:11:52 +0100 (BST)
From: Ben Harris <bjh21@netbsd.org>
Sender: Ben Harris <bjh21@cus.cam.ac.uk>
To: gnats-bugs@gnats.netbsd.org
Subject: POSIX.2: unexpand -t <tablist> not supported
>Number: 11228
>Category: standards
>Synopsis: POSIX.2: unexpand -t <tablist> not supported
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: christos
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Oct 14 17:12:00 +0000 2000
>Closed-Date: Sun Dec 21 02:33:49 +0000 2008
>Last-Modified: Sun Dec 21 02:35:00 +0000 2008
>Originator: Ben Harris
>Release: 2000-02-07
>Organization:
>Environment:
NetBSD cromarty 1.4X NetBSD 1.4X (CROMARTY) #9: Wed May 3 23:49:51 BST 2000
bjh21@cromarty:/usr/src/sys/arch/macppc/compile/CROMARTY macppc
>Description:
POSIX.2 specifies that "unexpand" should be able to take a "-t <tablist>"
option to specify where it assumes tab stops are. NetBSD's one doesn't
accept this.
>How-To-Repeat:
cromarty:~$ unexpand -t 8
unexpand: illegal option -- t
usage: unexpand [-a] [file ...]
>Fix:
>Release-Note:
>Audit-Trail:
From: Ben Harris <bjh21@netbsd.org>
To: gnats-bugs@gnats.netbsd.org
Cc:
Subject: standards/11228: part-fixed
Date: Thu, 10 Apr 2003 11:11:50 +0100 (BST)
As of unexpand.c rev 1.10, unexpand supports a <tablist> consisting of a
single number (indicating stops every <tablist> positions), but not an
actual list.
See PR bin/21058 for details of that change.
--
Ben Harris <bjh21@netbsd.org>
Portmaster, NetBSD/acorn26 <URL:http://www.netbsd.org/Ports/acorn26/>
Responsible-Changed-From-To: standards-manager->kleink
Responsible-Changed-By: perry
Responsible-Changed-When: Thu Apr 24 00:04:59 UTC 2003
Responsible-Changed-Why:
klaus indicated in a mail message that he would "write the rest myself"...
From: "Perry E. Metzger" <perry@piermont.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: standards/11228
Date: 23 Apr 2003 20:05:42 -0400
To: Ben Harris <bjh21@netbsd.org>
Cc: standards-manager@netbsd.org, gnats-admin@netbsd.org
Subject: Re: standards/11228: part-fixed
From: Klaus Klein <kleink@reziprozitaet.de>
Date: 10 Apr 2003 12:43:51 +0200
Ben Harris <bjh21@netbsd.org> writes:
> The following reply was made to PR standards/11228; it has been noted by GNATS.
>
> From: Ben Harris <bjh21@netbsd.org>
> To: gnats-bugs@gnats.netbsd.org
> Cc:
> Subject: standards/11228: part-fixed
> Date: Thu, 10 Apr 2003 11:11:50 +0100 (BST)
>
> As of unexpand.c rev 1.10, unexpand supports a <tablist> consisting of a
> single number (indicating stops every <tablist> positions), but not an
> actual list.
>
> See PR bin/21058 for details of that change.
Thanks for the notification; I only noticed the discussion past the PR
when the change discussed in it had already been applied, so I decided
to not further augment 21058's trail but write the rest myself which
I'll commit shortly.
- Klaus
From: Roy Marples <roy@NetBSD.org>
To:
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: standards/11228
Date: Thu, 11 Dec 2008 12:39:58 +0000
--=-HVYMB68FLwp8tn7UjP/x
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
This patch should add the requested functionality.
It also has the advantage of not using a fixed size buffer.
Comments?
Thanks
Roy
Index: unexpand/unexpand.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/usr.bin/unexpand/unexpand.c,v
retrieving revision 1.13
diff -u -p -r1.13 unexpand.c
--- unexpand/unexpand.c 21 Jul 2008 14:19:27 -0000 1.13
+++ unexpand/unexpand.c 11 Dec 2008 11:56:42 -0000
@@ -45,6 +45,7 @@ __RCSID("$NetBSD: unexpand.c,v 1.13 2008
/*
* unexpand - put tabs into a file replacing blanks
*/
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -52,45 +53,58 @@ __RCSID("$NetBSD: unexpand.c,v 1.13 2008
#include <errno.h>
#include <err.h>
=20
-char genbuf[BUFSIZ];
-char linebuf[BUFSIZ];
+#define NSTOPS 20
=20
-int main(int, char **);
-void tabify(int, uint);
+static int all;
+static size_t nstops;
+static size_t tabstops[NSTOPS];
+
+int main(int, char **);
+static void tabify(const char *, size_t);
=20
int
main(int argc, char **argv)
{
- int all, c;
- uint tabsize;
- ulong l;
- char *ep;
+ int c;
+ char *ep, *tab;
+ char *line;
+ size_t i, len;
=20
setprogname(argv[0]);
=20
- all =3D 0;
- tabsize =3D 8;
+ nstops =3D 1;
+ tabstops[0] =3D 8;
+
while ((c =3D getopt(argc, argv, "at:")) !=3D -1) {
switch (c) {
case 'a':
all++;
break;
case 't':
- errno =3D 0;
- l =3D strtoul(optarg, &ep, 0);
- /*
- * If every input char is a tab, the line length
- * must not exceed maxuint.
- */
- tabsize =3D (int)l * BUFSIZ;
- tabsize /=3D BUFSIZ;
- if (*ep !=3D 0 || errno !=3D 0 || (ulong)tabsize !=3D l)
- errx(EXIT_FAILURE, "Invalid tabstop \"%s\"",
- optarg);
+ all =3D 0;
+ nstops =3D 0;
+ while ((tab =3D strsep(&optarg, ", "))) {
+ if (*tab =3D=3D '\0')=20
+ continue;=20
+ if (nstops >=3D NSTOPS)=20
+ errx(EXIT_FAILURE,=20
+ "too many tab stops (max %d)",
+ NSTOPS);=20
+ errno =3D 0;
+ i =3D strtoul(tab, &ep, 0);
+ if (errno || *ep || i <=3D 0)
+ errx(EXIT_FAILURE,
+ "%s: invalid tabstop", tab);
+ if (nstops > 0 && tabstops[nstops - 1] >=3D i)
+ errx(EXIT_FAILURE,
+ "%s: bad tabstop spec", tab);
+ tabstops[nstops++] =3D i;
+ }
break;
case '?':
default:
- fprintf(stderr, "usage: %s [-a] [-t tabstop] [file ...]\n",
+ fprintf(stderr, "usage: %s"
+ " [-a] [-t tabstop] [file ...]\n",
getprogname());
exit(EXIT_FAILURE);
/* NOTREACHED */
@@ -107,58 +121,84 @@ main(int argc, char **argv)
}
argc--, argv++;
}
- while (fgets(genbuf, BUFSIZ, stdin) !=3D NULL) {
- tabify(all, tabsize);
- printf("%s", linebuf);
- }
+ while ((line =3D fgetln(stdin, &len)) !=3D NULL)
+ tabify(line, len);
} while (argc > 0);
exit(EXIT_SUCCESS);
/* NOTREACHED */
}
=20
-void
-tabify(int all, uint tabsize)
+static void
+tabify(const char *line, size_t len)
{
- char *cp, *dp;
- uint dcol;
- uint ocol;
- uint tcol;
-
- ocol =3D 0;
- dcol =3D 0;
- cp =3D genbuf, dp =3D linebuf;
- for (;;) {
- switch (*cp) {
+ const char *e, *p;
+ size_t dcol, ocol, limit, n;
=20
- case ' ':
+ dcol =3D ocol =3D 0;
+ limit =3D nstops =3D=3D 1 ? UINT_MAX : tabstops[nstops - 1] - 1;
+ e =3D line + len;
+ for (p =3D line; p < e; p++) {
+ if (*p =3D=3D ' ') {
dcol++;
- break;
-
- case '\t':
- dcol =3D (dcol + tabsize) / tabsize * tabsize;
- break;
-
- default:
- if (dcol > ocol + 1) {
- tcol =3D (ocol + tabsize) / tabsize * tabsize;
- while (tcol <=3D dcol) {
- *dp++ =3D '\t';
- ocol =3D tcol;
- tcol +=3D tabsize;
+ continue;
+ } else if (*p =3D=3D '\t') {
+ if (nstops =3D=3D 1) {
+ dcol =3D (1 + dcol / tabstops[0]) * tabstops[0];
+ continue;
+ } else {
+ for (n =3D 0;
+ tabstops[n] - 1 < dcol && n < nstops;
+ n++)
+ ;
+ if (n < nstops - 1 && tabstops[n] - 1 < limit) {
+ dcol =3D tabstops[n];
+ continue;
}
}
- while (ocol < dcol) {
- *dp++ =3D ' ';
- ocol++;
- }
- if (*cp =3D=3D 0 || all =3D=3D 0) {
- strlcpy(dp, cp,
- sizeof(linebuf) - (dp - linebuf));
- return;
+ }
+
+ /* Output our tabs */
+ if (nstops =3D=3D 1) {
+ while (((ocol + tabstops[0]) / tabstops[0]) <=3D
+ (dcol / tabstops[0]))
+ {
+ if (dcol - ocol < 2)
+ break;
+ putchar('\t');
+ ocol =3D (1 + ocol / tabstops[0]) * tabstops[0];
+ }
+ } else {
+ for (n =3D 0; tabstops[n] - 1 < ocol && n < nstops; n++)
+ ;
+ while (ocol < dcol && n < nstops && ocol < limit) {
+ putchar('\t');
+ ocol =3D tabstops[n++];
+ }
+ }
+
+ /* Output remaining spaces */
+ while (ocol < dcol && ocol < limit) {
+ putchar(' ');
+ ocol++;
+ }
+
+ /* Output our char */
+ putchar(*p);
+ if (*p =3D=3D '\b') {
+ if (ocol > 0) {
+ ocol--;
+ dcol--;
}
- *dp++ =3D *cp;
- dcol =3D ++ocol;
+ } else {
+ ocol++;
+ dcol++;
+ }
+
+ /* Output remainder of line */
+ if (!all || dcol >=3D limit) {
+ for (p++; p < e; p++)
+ putchar(*p);
+ return;
}
- cp++;
}
}
Index: expand/expand.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/usr.bin/expand/expand.1,v
retrieving revision 1.10
diff -u -p -r1.10 expand.1
--- expand/expand.1 7 Aug 2003 11:13:39 -0000 1.10
+++ expand/expand.1 11 Dec 2008 11:56:42 -0000
@@ -29,7 +29,7 @@
.\"
.\" @(#)expand.1 8.1 (Berkeley) 6/9/93
.\"
-.Dd April 8, 2003
+.Dd December 11, 2003
.Dt EXPAND 1
.Os
.Sh NAME
@@ -43,7 +43,7 @@
.Op Ar
.Nm unexpand
.Op Fl a
-.Op Fl t Ar tabstop
+.Op Fl t Ar tab1,tab2,...,tabn=20
.Op Ar
.Sh DESCRIPTION
.Nm
--=-HVYMB68FLwp8tn7UjP/x
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (NetBSD)
iQEcBAABAgAGBQJJQQoeAAoJEFl/l+qa1FVJ1MkH/1sOIY7GBynBBqCX7sfS8vHk
zb0CNp41DswCTNTBOF71buVKIIJh8RTczftfIb0UntkNCDXIAHbdjBoMJUevZjoq
uCUjnRzvGruOLcvEOeGhyTqQEgoyXiTW1iim5f5We5lQoHhZrAt7aaRGTpxcmeGj
3Y9bGvPS2f4TNX5gJMZx5rcsjBj7qkDWZBjgbFEpaOmegPVOB9ZxwGL0slTj0JdT
Reah57P4Z20uQMpi6QVY7wv85SB4FS9At7h9mCRcBsf3G1KRoPNT44cW3h9FXo4/
3gy8KXng35Hc8uzr9nUZmCKrS35TzKvZxfwsME6L0zcEwB1pGfe9dRJceSHVR8I=
=jNAR
-----END PGP SIGNATURE-----
--=-HVYMB68FLwp8tn7UjP/x--
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, kleink@NetBSD.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org, Ben Harris <bjh21@netbsd.org>
Cc:
Subject: Re: standards/11228
Date: Thu, 11 Dec 2008 11:50:33 -0500
On Dec 11, 12:45pm, roy@NetBSD.org (Roy Marples) wrote:
-- Subject: Re: standards/11228
| This patch should add the requested functionality.
| It also has the advantage of not using a fixed size buffer.
|
| Comments?
|
| Thanks
|
| Roy
Great, why don't you also fix the number of tabstops so that it is dynamically
allocated too?
christos
Responsible-Changed-From-To: kleink->christos
Responsible-Changed-By: christos@NetBSD.org
Responsible-Changed-When: Sat, 20 Dec 2008 21:33:49 -0500
Responsible-Changed-Why:
I took care of it
State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Sat, 20 Dec 2008 21:33:49 -0500
State-Changed-Why:
fixed
From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/11228 CVS commit: src/usr.bin
Date: Sun, 21 Dec 2008 02:33:13 +0000 (UTC)
Module Name: src
Committed By: christos
Date: Sun Dec 21 02:33:13 UTC 2008
Modified Files:
src/usr.bin/expand: expand.1
src/usr.bin/unexpand: Makefile unexpand.c
Log Message:
PR/11228: Ben Harris: Unexpand -t should take tab list. Based on patch
supplied by Roy Marples.
To generate a diff of this commit:
cvs rdiff -r1.10 -r1.11 src/usr.bin/expand/expand.1
cvs rdiff -r1.6 -r1.7 src/usr.bin/unexpand/Makefile
cvs rdiff -r1.13 -r1.14 src/usr.bin/unexpand/unexpand.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.