From owner-freebsd-standards Tue Mar 5 1:57:38 2002 Delivered-To: freebsd-standards@freebsd.org Received: from descent.robbins.dropbear.id.au (250.a.006.mel.iprimus.net.au [210.50.44.250]) by hub.freebsd.org (Postfix) with ESMTP id 2142B37B402 for ; Tue, 5 Mar 2002 01:57:29 -0800 (PST) Received: (from tim@localhost) by descent.robbins.dropbear.id.au (8.11.6/8.11.6) id g259vYI31205; Tue, 5 Mar 2002 20:57:34 +1100 (EST) (envelope-from tim) Date: Tue, 5 Mar 2002 20:57:33 +1100 From: "Tim J. Robbins" To: Kyle Martin Cc: freebsd-standards@FreeBSD.ORG Subject: Re: ls(1) patch for review Message-ID: <20020305205733.A31150@descent.robbins.dropbear.id.au> References: <20020305030632.A1990@marvin.idsi.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20020305030632.A1990@marvin.idsi.net>; from mkm@ieee.org on Tue, Mar 05, 2002 at 03:06:32AM -0600 Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, Mar 05, 2002 at 03:06:32AM -0600, Kyle Martin wrote: > +.It Fl p > +Write a slash > +.Pq Pa \&\ > +after each filename if that file is a directory. It writes a /, and the \ confuses groff. How about this: .It Fl p Write a slash .Pq Ql / after each filename if that file is a directory. > +.It Fl x > +The same as -C, except that the multi-text-column output is produced with entries sorted across, rather tahn down, the columns. This line should be wrapped at 80 columns or less. > void > +printstream(DISPLAY *dp) > +{ > + FTSENT *p; > + > + for (p = dp->list; p; p = p->fts_link) { > + if (p->fts_number != NO_PRINT) { > + (void)printaname(p, dp->s_inode, dp->s_block); > + if (p->fts_link) > + (void)printf(", "); > + } > + } > + (void)putchar('\n'); > +} The lines output by the stream format must not exceed the width of the terminal. See GNU ls for an example. > + > +void > printcol(DISPLAY *dp) > { > extern int termwidth; > static FTSENT **array; > static int lastentries = -1; > @@ -280,25 +295,47 @@ > if (num % numcols) > ++numrows; > > if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) > (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); > - for (row = 0; row < numrows; ++row) { > - endcol = colwidth; > - for (base = row, chcnt = col = 0; col < numcols; ++col) { > - chcnt += printaname(array[base], dp->s_inode, > - dp->s_block); > - if ((base += numrows) >= num) > - break; > - while ((cnt = ((chcnt + tabwidth) & ~(tabwidth - 1))) > - <= endcol) { > - (void)putchar(f_notabs ? ' ' : '\t'); > - chcnt = cnt; > + > + if (f_sortacross) { *snip* Wouldn't it be better to have a separate function for each of these two output functions instead of having one big `if' and almost nothing in common between the two? I think there is also a problem with -x outputting tabs before newlines (\t\n) but I can't quite track it down. Different terminals handle this differently, it makes the output ugly on some. > * print [inode] [size] name > @@ -362,33 +399,44 @@ > } > > static int > printtype(u_int mode) > { > - switch (mode & S_IFMT) { > - case S_IFDIR: > - (void)putchar('/'); > - return (1); > - case S_IFIFO: > - (void)putchar('|'); > - return (1); > - case S_IFLNK: > - (void)putchar('@'); > - return (1); > - case S_IFSOCK: > - (void)putchar('='); > - return (1); > - case S_IFWHT: > - (void)putchar('%'); > - return (1); > - default: > - } > - if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) { > - (void)putchar('*'); > - return (1); > + if (f_slash) { > + if ((mode & S_IFMT) == S_IFDIR) { > + (void)putchar('/'); > + return (1); > + } > + else > + return (0); > + } > + > + else { else needs to go on the line with the closing brace. > + switch (mode & S_IFMT) { > + case S_IFDIR: > + (void)putchar('/'); > + return (1); > + case S_IFIFO: > + (void)putchar('|'); > + return (1); > + case S_IFLNK: > + (void)putchar('@'); > + return (1); > + case S_IFSOCK: > + (void)putchar('='); > + return (1); > + case S_IFWHT: > + (void)putchar('%'); > + return (1); > + default: This default: is not needed and is possibily illegal. This wasn't added by your change, but should be fixed: "warning: ANSI C forbids label at end of compound statement" Wouldn't it be better to have the -p and -F functionality split off into separate functions? Keep up the good work. Tim To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message