bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tweaking default `ls -l` output to use locale before posix


From: Paul Eggert
Subject: Re: tweaking default `ls -l` output to use locale before posix
Date: Tue, 27 Sep 2005 13:43:59 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Andreas Schwab <address@hidden> writes:

> Emacs can use --dired now, so this should not be an issue.

OK, thanks.  I just now checked, and if I understand it aright this
started happening with Emacs 21.3 (released March 2003).

Can we safely assume that everyone in non-POSIX locales with oddball
time stamp formats and who wants to use recent coreutils is also using
Emacs 21.3 or later?  It sounds a bit risky, but perhaps it would be
OK.  (After the next coreutils release, that is.)

If we can assume Emacs works, then that removes the last major worry I
had about 'locale' time stamp format being the default.  To
recapitulate the worries, this was:

  * Poorly configured hosts would generate English time stamps in
    non-English locales (this would be fixed by having
    --time-stamp='locale' default to long-iso formats in such locales
    -- a fix that is not done yet).

  * Time stamps were not all the same width, leading to jagged
    columns.  (Fixed in GNU/Linux by having the locales done right;
    other hosts like Solaris will just have jagged columns, I guess.
    If this turns into a real problem we can have ls autoadjust the
    widths as it already does for several other columns.)

  * Emacs got confused.


Mike, what do you think about the following patch for Gentoo, in place
of what Gentoo is doing currently?  It implements the suggestion I
have in mind.  This is not installed in coreutils: it's just a
proposal.


2005-09-27  Paul Eggert  <address@hidden>

        * NEWS: ls now defaults to --time-style="locale", but this
        style now behaves like posix-long-iso if your locale appears
        to be messed up.
        * doc/coreutils.texi (Formatting file timestamps): Document that
        --time-style="locale" is now the default.  Update advice for
        Emacs 21.3 and later.
        * src/ls.c (decode_switches): Implement the above.

Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.313
diff -p -u -r1.313 NEWS
--- NEWS        25 Sep 2005 06:07:48 -0000      1.313
+++ NEWS        27 Sep 2005 20:38:29 -0000
@@ -1,5 +1,11 @@
 GNU coreutils NEWS                                    -*- outline -*-
 
+** ls now defaults to --time-style="locale" rather than
+  --time-style="posix-long-iso".  However, --time-style="locale" now
+  behaves like --time-style="posix-long-iso" if your locale settings
+  appear to be messed up.  This change attempts to have the default be
+  the best of both worlds.
+
 * Major changes in release 5.3.1-cvs (2005-??-??) [unstable]
 
 ** Bring back support for `head -NUM', `tail -NUM', etc. even when
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.285
diff -p -u -r1.285 coreutils.texi
--- doc/coreutils.texi  25 Sep 2005 06:08:17 -0000      1.285
+++ doc/coreutils.texi  27 Sep 2005 20:38:32 -0000
@@ -6047,7 +6047,7 @@ and might generate timestamps like @samp
 @vindex LC_TIME
 List @acronym{POSIX}-locale timestamps if the @env{LC_TIME} locale
 category is @acronym{POSIX}, @var{style} timestamps otherwise.  For
-example, the default style, which is @samp{posix-long-iso}, lists
+example, the @samp{posix-long-iso} style lists
 timestamps like @samp{Mar 30@ @ 2002} and @samp{Mar 30 23:45} when in
 the @acronym{POSIX} locale, and like @samp{2002-03-30 23:45} otherwise.
 @end table
@@ -6056,10 +6056,11 @@ the @acronym{POSIX} locale, and like @sa
 @vindex TIME_STYLE
 You can specify the default value of the @option{--time-style} option
 with the environment variable @env{TIME_STYLE}; if @env{TIME_STYLE} is not set
-the default style is @samp{posix-long-iso}.  @acronym{GNU} Emacs 21 and
-later can parse @acronym{ISO} dates, but older Emacs versions do not, so if
-you are using an older version of Emacs and specify a address@hidden
-locale, you may need to set @samp{TIME_STYLE="locale"}.
+the default style is @samp{locale}.  @acronym{GNU} Emacs 21.3 and
+later use the @option{--dired} option and therefore can parse any date
+format, but if you are using Emacs 21.1 or 21.2 and specify a
address@hidden locale you may need to set
address@hidden"posix-long-iso"}.
 
 To avoid certain denial-of-service attacks, timestamps that would be
 longer than 1000 bytes may be treated as errors.
Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.399
diff -p -u -r1.399 ls.c
--- src/ls.c    16 Sep 2005 07:50:33 -0000      1.399
+++ src/ls.c    27 Sep 2005 20:38:33 -0000
@@ -1823,7 +1823,7 @@ decode_switches (int argc, char **argv)
 
       if (! style)
        if (! (style = getenv ("TIME_STYLE")))
-         style = "posix-long-iso";
+         style = "locale";
 
       while (strncmp (style, posix_prefix, sizeof posix_prefix - 1) == 0)
        {
@@ -1859,6 +1859,7 @@ decode_switches (int argc, char **argv)
            break;
 
          case long_iso_time_style:
+         case_long_iso_time_style:
            long_time_format[0] = long_time_format[1] = "%Y-%m-%d %H:%M";
            break;
 
@@ -1870,10 +1871,17 @@ decode_switches (int argc, char **argv)
          case locale_time_style:
            if (hard_locale (LC_TIME))
              {
+               /* Ensure that the locale has translations for both
+                  formats.  If not, fall back on long-iso format.  */
                int i;
                for (i = 0; i < 2; i++)
-                 long_time_format[i] =
-                   dcgettext (NULL, long_time_format[i], LC_TIME);
+                 {
+                   char const *locale_format =
+                     dcgettext (NULL, long_time_format[i], LC_TIME);
+                   if (locale_format == long_time_format[i])
+                     goto case_long_iso_time_style;
+                   long_time_format[i] = locale_format;
+                 }
              }
          }
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]