From owner-freebsd-bugs@FreeBSD.ORG Fri Jun 3 13:10:04 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8054416A41C; Fri, 3 Jun 2005 13:10:04 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E14F543D48; Fri, 3 Jun 2005 13:10:02 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j53DA2nn034724; Fri, 3 Jun 2005 13:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j53DA2mw034723; Fri, 3 Jun 2005 13:10:02 GMT (envelope-from gnats) Resent-Date: Fri, 3 Jun 2005 13:10:02 GMT Resent-Message-Id: <200506031310.j53DA2mw034723@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Cc: mat@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mathieu Arnold Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9D7B316A41F for ; Fri, 3 Jun 2005 13:07:49 +0000 (GMT) (envelope-from mat@aragorn.in.absolight.net) Received: from plouf.absolight.net (plouf.absolight.net [193.30.224.136]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2247843D4C for ; Fri, 3 Jun 2005 13:07:48 +0000 (GMT) (envelope-from mat@aragorn.in.absolight.net) Received: from abeille.nerim.absolight.net (abeilled.free.absolight.net [82.229.45.53]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by plouf.absolight.net (Postfix) with ESMTP id DF947A2400E for ; Fri, 3 Jun 2005 15:07:47 +0200 (CEST) Received: from aragorn.in.absolight.net (unknown [192.168.8.52]) by abeille.nerim.absolight.net (Postfix) with ESMTP id 1052C1703E for ; Fri, 3 Jun 2005 15:10:58 +0200 (CEST) Received: by aragorn.in.absolight.net (Postfix, from userid 1000) id 0C9067CAD; Fri, 3 Jun 2005 15:07:45 +0200 (CEST) Message-Id: <20050603130745.0C9067CAD@aragorn.in.absolight.net> Date: Fri, 3 Jun 2005 15:07:45 +0200 (CEST) From: Mathieu Arnold To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 X-GNATS-Notify: mat@FreeBSD.org Cc: Subject: bin/81837: Sort by directories first option for ls(1) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Mathieu Arnold List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jun 2005 13:10:04 -0000 >Number: 81837 >Category: bin >Synopsis: Sort by directories first option for ls(1) >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: Fri Jun 03 13:10:02 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Mathieu Arnold >Release: FreeBSD 4.8-RELEASE i386 >Organization: Absolight >Environment: System: FreeBSD aragorn.in.absolight.net 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Wed Sep 3 12:54:37 CEST 2003 root@aragorn.reaumur.absolight.net:/usr/src/sys/compile/ARAGORN i386 >Description: This allow to have your directories sorted before your files, so that you don't have to look for which are files and which are directories : $ ls -l /usr/src/ total 156 -rw-r--r-- 1 root wheel 6189 8 jan 2004 COPYRIGHT -rw-r--r-- 1 root wheel 7736 1 aoû 2003 MAINTAINERS -rw-r--r-- 1 root wheel 7822 7 nov 2003 Makefile -rw-r--r-- 1 root wheel 26361 18 déc 2003 Makefile.inc1 -rw-r--r-- 1 root wheel 2749 8 mar 2003 README -rw-r--r-- 1 root wheel 60761 25 avr 12:47 UPDATING drwxr-xr-x 37 root wheel 1024 4 nov 2004 bin drwxr-xr-x 51 root wheel 1024 4 nov 2004 contrib drwxr-xr-x 5 root wheel 512 22 mai 2004 crypto drwxr-xr-x 19 root wheel 1536 4 nov 2004 etc drwxr-xr-x 13 root wheel 512 22 mai 2004 games drwxr-xr-x 4 root wheel 512 22 mai 2004 gnu drwxr-xr-x 6 root wheel 2048 4 nov 2004 include drwxr-xr-x 8 root wheel 512 4 nov 2004 kerberos5 drwxr-xr-x 68 root wheel 1536 4 nov 2004 lib drwxr-xr-x 35 root wheel 1024 4 nov 2004 libexec drwxr-xr-x 12 root wheel 512 4 nov 2004 release drwxr-xr-x 4 root wheel 512 22 mai 2004 rescue drwxr-xr-x 93 root wheel 2048 4 nov 2004 sbin drwxr-xr-x 6 root wheel 512 4 nov 2004 secure drwxr-xr-x 24 root wheel 512 4 nov 2004 share drwxr-xr-x 55 root wheel 1024 4 nov 2004 sys drwxr-xr-x 10 root wheel 512 4 nov 2004 tools drwxr-xr-x 217 root wheel 3584 4 nov 2004 usr.bin drwxr-xr-x 177 root wheel 3584 4 nov 2004 usr.sbin and : $ ls -lD /usr/src/ total 156 drwxr-xr-x 37 root wheel 1024 4 nov 2004 bin drwxr-xr-x 51 root wheel 1024 4 nov 2004 contrib drwxr-xr-x 5 root wheel 512 22 mai 2004 crypto drwxr-xr-x 19 root wheel 1536 4 nov 2004 etc drwxr-xr-x 13 root wheel 512 22 mai 2004 games drwxr-xr-x 4 root wheel 512 22 mai 2004 gnu drwxr-xr-x 6 root wheel 2048 4 nov 2004 include drwxr-xr-x 8 root wheel 512 4 nov 2004 kerberos5 drwxr-xr-x 68 root wheel 1536 4 nov 2004 lib drwxr-xr-x 35 root wheel 1024 4 nov 2004 libexec drwxr-xr-x 12 root wheel 512 4 nov 2004 release drwxr-xr-x 4 root wheel 512 22 mai 2004 rescue drwxr-xr-x 93 root wheel 2048 4 nov 2004 sbin drwxr-xr-x 6 root wheel 512 4 nov 2004 secure drwxr-xr-x 24 root wheel 512 4 nov 2004 share drwxr-xr-x 55 root wheel 1024 4 nov 2004 sys drwxr-xr-x 10 root wheel 512 4 nov 2004 tools drwxr-xr-x 217 root wheel 3584 4 nov 2004 usr.bin drwxr-xr-x 177 root wheel 3584 4 nov 2004 usr.sbin -rw-r--r-- 1 root wheel 6189 8 jan 2004 COPYRIGHT -rw-r--r-- 1 root wheel 7736 1 aoû 2003 MAINTAINERS -rw-r--r-- 1 root wheel 7822 7 nov 2003 Makefile -rw-r--r-- 1 root wheel 26361 18 déc 2003 Makefile.inc1 -rw-r--r-- 1 root wheel 2749 8 mar 2003 README -rw-r--r-- 1 root wheel 60761 25 avr 12:47 UPDATING >How-To-Repeat: >Fix: that's the current patch of today, it's also in mat_ls branch in perforce. --- current-ls-D.diff begins here --- --- //depot/vendor/freebsd/src/bin/ls/cmp.c 2005/06/03 11:37:01 +++ //depot/user/mat/src/ls/cmp.c 2005/06/03 13:06:06 @@ -157,3 +157,27 @@ return (sizecmp(b, a)); } + +#define IS_FTS_DIR(x) ((x)->fts_info == FTS_D \ + || (x)->fts_info == FTS_DOT \ + || (x)->fts_info == FTS_DC \ + || (x)->fts_info == FTS_DNR \ + || (x)->fts_info == FTS_DP) + +int +dirfcmp(const FTSENT *a, const FTSENT *b) +{ + + if ((IS_FTS_DIR(a) && IS_FTS_DIR(b)) || (!IS_FTS_DIR(a) && !IS_FTS_DIR(b))) + return (real_sortfcn(a, b)); + return (IS_FTS_DIR(a) ? -1 : 1); +} + +int +revdirfcmp(const FTSENT *a, const FTSENT *b) +{ + + if ((IS_FTS_DIR(a) && IS_FTS_DIR(b)) || (!IS_FTS_DIR(a) && !IS_FTS_DIR(b))) + return (real_sortfcn(a, b)); + return (IS_FTS_DIR(b) ? -1 : 1); +} --- //depot/vendor/freebsd/src/bin/ls/extern.h 2005/06/03 11:37:01 +++ //depot/user/mat/src/ls/extern.h 2005/06/03 12:52:48 @@ -40,6 +40,11 @@ int revstatcmp(const FTSENT *, const FTSENT *); int sizecmp(const FTSENT *, const FTSENT *); int revsizecmp(const FTSENT *, const FTSENT *); +int dirfcmp(const FTSENT *, const FTSENT *); +int revdirfcmp(const FTSENT *, const FTSENT *); + +/* save the real sortfcn when sorting directories first */ +int (*real_sortfcn)(const FTSENT *, const FTSENT *); void printcol(const DISPLAY *); void printlong(const DISPLAY *); --- //depot/vendor/freebsd/src/bin/ls/ls.1 2005/06/03 12:37:04 +++ //depot/user/mat/src/ls/ls.1 2005/06/03 12:52:48 @@ -83,6 +83,8 @@ is the numeric value of the character in octal. .It Fl C Force multi-column output; this is the default when output is to a terminal. +.It Fl D +Sorts directories first .It Fl F Display a slash .Pq Ql / --- //depot/vendor/freebsd/src/bin/ls/ls.c 2005/06/03 11:37:01 +++ //depot/user/mat/src/ls/ls.c 2005/06/03 12:52:48 @@ -104,6 +104,7 @@ /* flags */ int f_accesstime; /* use time of last access */ +static int f_dirfirstsort; /* put directories first */ int f_flags; /* show flags associated with a file */ int f_humanval; /* show human-readable file sizes */ int f_inode; /* print inode */ @@ -181,7 +182,7 @@ fts_options = FTS_PHYSICAL; while ((ch = getopt(argc, argv, - "1ABCFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) { + "1ABCDFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) { switch (ch) { /* * The -1, -C, -x and -l options all override each other so @@ -200,6 +201,9 @@ case 'C': f_sortacross = f_longform = f_singlecol = 0; break; + case 'D': + f_dirfirstsort = 1; + break; case 'l': f_longform = 1; f_singlecol = 0; @@ -364,12 +368,12 @@ #endif /* - * If not -F, -i, -l, -s, -S or -t options, don't require stat + * If not -D, -F, -i, -l, -s, -S or -t options, don't require stat * information, unless in color mode in which case we do * need this to determine which colors to display. */ if (!f_inode && !f_longform && !f_size && !f_timesort && - !f_sizesort && !f_type + !f_sizesort && !f_type && !!f_dirfirstsort #ifdef COLORLS && !f_color #endif @@ -412,6 +416,11 @@ sortfcn = revsizecmp; else /* Use modification time. */ sortfcn = revmodcmp; + if (f_dirfirstsort) { + real_sortfcn = sortfcn; + sortfcn = revdirfcmp; + } + } else { if (!f_timesort && !f_sizesort) sortfcn = namecmp; @@ -423,6 +432,11 @@ sortfcn = sizecmp; else /* Use modification time. */ sortfcn = modcmp; + if (f_dirfirstsort) { + real_sortfcn = sortfcn; + sortfcn = dirfcmp; + } + } /* Select a print function. */ --- //depot/vendor/freebsd/src/bin/ls/util.c 2005/06/03 11:37:01 +++ //depot/user/mat/src/ls/util.c 2005/06/03 12:52:48 @@ -222,9 +222,9 @@ { (void)fprintf(stderr, #ifdef COLORLS - "usage: ls [-ABCFGHLPRSTWZabcdfghiklmnopqrstuwx1]" + "usage: ls [-ABCDFGHLPRSTWZabcdfghiklmnopqrstuwx1]" #else - "usage: ls [-ABCFHLPRSTWZabcdfghiklmnopqrstuwx1]" + "usage: ls [-ABCDFHLPRSTWZabcdfghiklmnopqrstuwx1]" #endif " [file ...]\n"); exit(1); --- current-ls-D.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: