Re: svn commit: r242725 - head/bin/ls

2012-11-08 Thread Jaakko Heinonen
On 2012-11-08, Greg Lehey wrote:
> New Revision: 242725

> - return (strcoll(a->fts_name, b->fts_name));
> +if (f_samesort)
> + return (strcoll(b->fts_name, a->fts_name));
> +else
> + return (strcoll(a->fts_name, b->fts_name));

Please use tabs instead of spaces in indentations. Similarly in r242722.

This patch should fix some whitespace problems:

%%%
Index: bin/ls/ls.c
===
--- bin/ls/ls.c (revision 242746)
+++ bin/ls/ls.c (working copy)
@@ -185,7 +185,7 @@ main(int argc, char *argv[])
fts_options = FTS_PHYSICAL;
if (getenv("LS_SAMESORT"))
f_samesort = 1;
-   while ((ch = getopt(argc, argv,
+   while ((ch = getopt(argc, argv,
"1ABCD:FGHILPRSTUWXZabcdfghiklmnopqrstuwxy,")) != -1) {
switch (ch) {
/*
@@ -241,7 +241,7 @@ main(int argc, char *argv[])
f_timesort = 1;
f_sizesort = 0;
break;
-/* Other flags.  Please keep alphabetic. */
+   /* Other flags.  Please keep alphabetic. */
case ',':
f_thousands = 1;
break;
@@ -250,10 +250,10 @@ main(int argc, char *argv[])
f_octal = 1;
f_octal_escape = 0;
break;
-case 'D':
-f_timeformat = optarg;
-break;
-case 'F':
+   case 'D':
+   f_timeformat = optarg;
+   break;
+   case 'F':
f_type = 1;
f_slash = 0;
break;
@@ -861,7 +861,7 @@ label_out:
d.s_size = sizelen;
d.s_user = maxuser;
}
-if (f_thousands)/* make space for commas */
+   if (f_thousands)/* make space for commas */
d.s_size += (d.s_size - 1) / 3;
printfcn(&d);
output = 1;
Index: bin/ls/cmp.c
===
--- bin/ls/cmp.c(revision 242746)
+++ bin/ls/cmp.c(working copy)
@@ -78,9 +78,9 @@ modcmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_mtim.tv_nsec <
a->fts_statp->st_mtim.tv_nsec)
return (-1);
-if (f_samesort)
+   if (f_samesort)
return (strcoll(b->fts_name, a->fts_name));
-else
+   else
return (strcoll(a->fts_name, b->fts_name));
 }
 
@@ -107,9 +107,9 @@ acccmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_atim.tv_nsec <
a->fts_statp->st_atim.tv_nsec)
return (-1);
-if (f_samesort)
+   if (f_samesort)
return (strcoll(b->fts_name, a->fts_name));
-else
+   else
return (strcoll(a->fts_name, b->fts_name));
 }
 
@@ -136,9 +136,9 @@ birthcmp(const FTSENT *a, const FTSENT *
if (b->fts_statp->st_birthtim.tv_nsec <
a->fts_statp->st_birthtim.tv_nsec)
return (-1);
-if (f_samesort)
+   if (f_samesort)
return (strcoll(b->fts_name, a->fts_name));
-else
+   else
return (strcoll(a->fts_name, b->fts_name));
 }
 
@@ -165,9 +165,9 @@ statcmp(const FTSENT *a, const FTSENT *b
if (b->fts_statp->st_ctim.tv_nsec <
a->fts_statp->st_ctim.tv_nsec)
return (-1);
-if (f_samesort)
+   if (f_samesort)
return (strcoll(b->fts_name, a->fts_name));
-else
+   else
return (strcoll(a->fts_name, b->fts_name));
 }
 
%%%

-- 
Jaakko
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r242725 - head/bin/ls

2012-11-07 Thread Greg Lehey
Author: grog
Date: Thu Nov  8 00:24:26 2012
New Revision: 242725
URL: http://svnweb.freebsd.org/changeset/base/242725

Log:
  Add y flag and environment variable LS_SAMESORT to specify the same
  sorting order for time and name with the -t option.  IEEE Std 1003.2
  (POSIX.2) mandates that the -t option sort in descending order, and
  that if two files have the same timestamp, they should be sorted in
  ascending order of their names.  The -r flag reverses both of these
  sort orders, so they're never the same.  This creates significant
  problems for sequentially named files stored on FAT file systems,
  where it can be impossible to list them in the order in which they
  were created.
  
  Add , (comma) option to print file sizes grouped and separated by
  thousands using the non-monetary separator returned by localeconv(3),
  typically a comma or period.
  
  MFC after:  14 days

Modified:
  head/bin/ls/cmp.c
  head/bin/ls/ls.1
  head/bin/ls/ls.c
  head/bin/ls/ls.h
  head/bin/ls/print.c
  head/bin/ls/util.c

Modified: head/bin/ls/cmp.c
==
--- head/bin/ls/cmp.c   Wed Nov  7 23:50:28 2012(r242724)
+++ head/bin/ls/cmp.c   Thu Nov  8 00:24:26 2012(r242725)
@@ -78,7 +78,10 @@ modcmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_mtim.tv_nsec <
a->fts_statp->st_mtim.tv_nsec)
return (-1);
-   return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+   return (strcoll(b->fts_name, a->fts_name));
+else
+   return (strcoll(a->fts_name, b->fts_name));
 }
 
 int
@@ -104,7 +107,10 @@ acccmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_atim.tv_nsec <
a->fts_statp->st_atim.tv_nsec)
return (-1);
-   return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+   return (strcoll(b->fts_name, a->fts_name));
+else
+   return (strcoll(a->fts_name, b->fts_name));
 }
 
 int
@@ -130,7 +136,10 @@ birthcmp(const FTSENT *a, const FTSENT *
if (b->fts_statp->st_birthtim.tv_nsec <
a->fts_statp->st_birthtim.tv_nsec)
return (-1);
-   return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+   return (strcoll(b->fts_name, a->fts_name));
+else
+   return (strcoll(a->fts_name, b->fts_name));
 }
 
 int
@@ -156,7 +165,10 @@ statcmp(const FTSENT *a, const FTSENT *b
if (b->fts_statp->st_ctim.tv_nsec <
a->fts_statp->st_ctim.tv_nsec)
return (-1);
-   return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+   return (strcoll(b->fts_name, a->fts_name));
+else
+   return (strcoll(a->fts_name, b->fts_name));
 }
 
 int

Modified: head/bin/ls/ls.1
==
--- head/bin/ls/ls.1Wed Nov  7 23:50:28 2012(r242724)
+++ head/bin/ls/ls.1Thu Nov  8 00:24:26 2012(r242725)
@@ -32,7 +32,7 @@
 .\" @(#)ls.1   8.7 (Berkeley) 7/29/94
 .\" $FreeBSD$
 .\"
-.Dd September 28, 2011
+.Dd November 8, 2012
 .Dt LS 1
 .Os
 .Sh NAME
@@ -40,7 +40,7 @@
 .Nd list directory contents
 .Sh SYNOPSIS
 .Nm
-.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1
+.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,
 .Op Fl D Ar format
 .Op Ar
 .Sh DESCRIPTION
@@ -130,6 +130,8 @@ This option is equivalent to defining
 .Ev CLICOLOR
 in the environment.
 (See below.)
+This functionality can be compiled out by removing the definition of
+.Ev COLORLS .
 .It Fl H
 Symbolic links on the command line are followed.
 This option is assumed if
@@ -249,12 +251,35 @@ subsection below, except (if the long fo
 the directory totals are not output when the output is in a
 single column, even if multi-column output is requested.
 .It Fl t
-Sort by time modified (most recently modified
-first) before sorting the operands in lexicographical
-order.
+Sort by descending time modified (most recently modified first).  If two files
+have the same modification timestamp, sort their names in ascending
+lexicographical order.
+The
+.Fl r
+option reverses both of these sort orders.
+.Pp
+Note that these sort orders are contradictory: the time sequence is in
+descending order, the lexicographical sort is in ascending order.
+This behavior is mandated by
+.St -p1003.2 .
+This feature can cause problems listing files stored with sequential names on
+FAT file systems, such as from digital cameras, where it is possible to have
+more than one image with the same timestamp.
+In such a case, the photos cannot be listed in the sequence in which
+they were taken.
+To ensure the same sort order for time and for lexicographical sorting, set the
+environment variable
+.Ev LS_SAMESORT
+or use the
+.Fl y
+option.
+This causes
+.Nm
+to reverse the lexicographal sort order when sorting files with the
+same