bug-coreutils
[Top][All Lists]
Advanced

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

Re: reverting `stat --format=FMT'


From: Jim Meyering
Subject: Re: reverting `stat --format=FMT'
Date: Thu, 15 Dec 2005 19:53:10 +0100

Paul Eggert <address@hidden> wrote:

> Jim Meyering <address@hidden> writes:
>
>> As planned, here's the change to revert stat --format=FMT to
>> its previous behavior.  Note that with this change, backslash
>> escapes in a --format-specified format string are *not* interpreted.
>
> Looks good.  A couple of minor comments.
>
> Unless I read the code wrong, that patch mishandles the case
> where the printf format string ends in backslash, e.g., --printf='\'.

Good catch.  Thanks.
Here's a fix, to be checked in soon:

Index: src/stat.c
===================================================================
RCS file: /fetish/cu/src/stat.c,v
retrieving revision 1.90
diff -u -p -r1.90 stat.c
--- src/stat.c  15 Dec 2005 12:24:30 -0000      1.90
+++ src/stat.c  15 Dec 2005 18:27:26 -0000
@@ -665,6 +665,13 @@ print_it (char const *format, char const
                }
              putchar (esc_value);
            }
+         else if (*b == '\0')
+           {
+             error (0, 0, _("warning: backslash at end of format"));
+             putchar ('\\');
+             /* Arrange to exit the loop.  */
+             --b;
+           }
          else
            {
              print_esc_char (*b);
Index: tests/misc/stat-printf
===================================================================
RCS file: /fetish/cu/tests/misc/stat-printf,v
retrieving revision 1.1
diff -u -p -r1.1 stat-printf
--- tests/misc/stat-printf      15 Dec 2005 12:23:36 -0000      1.1
+++ tests/misc/stat-printf      15 Dec 2005 18:43:06 -0000
@@ -43,6 +43,8 @@ my @Tests =
 
      ['end-pct', "--printf=% .",       {OUT=>"%"}],
      ['pct-pct', "--printf=%% .",      {OUT=>"%"}],
+     ['end-bs',  "--printf='\\' .",    {OUT=>'\\'},
+        {ERR=>"$prog: warning: backslash at end of format\n"}],
 
      ['err-1', "--printf=%9% .",       {EXIT => 1},
         {ERR=>"$prog: %9%: invalid directive\n"}],


> This proposal supports \" but not \' or \? (meaning ", ', ?,
> respectively, the same as C).  I just checked Bash 3.1, and its printf
> supports \', \", and \?.  Perhaps coreutils printf formats should do
> the same, for consistency.  Bash printf also supports \e (ESC) and \E
> (ESC); that's not in C, but it might be useful to add that as well,
> for consistency.  This would apply both to stat and to printf.

Consistency would be nice.
You're welcome to change things.




reply via email to

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