bug-findutils
[Top][All Lists]
Advanced

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

[PATCH 7/8] Reserve format specifiers %(, %{ and %[ for future use.


From: James Youngman
Subject: [PATCH 7/8] Reserve format specifiers %(, %{ and %[ for future use.
Date: Sat, 18 Jun 2011 15:51:00 +0100

* find/print.c (insert_fprintf): Reject %(, %{ and %[.
(make_segment): Remove code which previously supposedly rejected
these format specifiers, but in fact did nothing.   Replace with
an assertion to document the fact that we do not expect to see
these format characters in make_segment.
* find/testsuite/find.gnu/printf-reserved.exp: New test case, for
%(, %{ and %[, which are all rejected.
* find/testsuite/Makefile.am (EXTRA_DIST_EXP): Add
find.gnu/printf-reserved.exp.
* doc/find.texi (Reserved and Unkown Directives): Document this.
* find/find.1: Document this.
* NEWS: Mention this change.
---
 ChangeLog                                   |   14 +++++++++
 NEWS                                        |    7 ++++
 doc/find.texi                               |   28 ++++++++++++++----
 find/find.1                                 |    2 +
 find/print.c                                |   41 ++++++++++++++++----------
 find/testsuite/Makefile.am                  |    1 +
 find/testsuite/find.gnu/printf-reserved.exp |    3 ++
 7 files changed, 73 insertions(+), 23 deletions(-)
 create mode 100644 find/testsuite/find.gnu/printf-reserved.exp

diff --git a/ChangeLog b/ChangeLog
index 25d45fa..2be5757 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2011-06-18  James Youngman  <address@hidden>
 
+       Reserve format specifiers %(, %{ and %[ for future use.
+       * find/print.c (insert_fprintf): Reject %(, %{ and %[.
+       (make_segment): Remove code which previously supposedly rejected
+       these format specifiers, but in fact did nothing.   Replace with
+       an assertion to document the fact that we do not expect to see
+       these format characters in make_segment.
+       * find/testsuite/find.gnu/printf-reserved.exp: New test case, for
+       %(, %{ and %[, which are all rejected.
+       * find/testsuite/Makefile.am (EXTRA_DIST_EXP): Add
+       find.gnu/printf-reserved.exp.
+       * doc/find.texi (Reserved and Unkown Directives): Document this.
+       * find/find.1: Document this.
+       * NEWS: Mention this change.
+
        Additional test cases for printf field width, precision and sign.
        * find/testsuite/find.gnu/printf.exp: Add test cases for left and
        right string alignment (%-10p), string truncation (%10.6p),
diff --git a/NEWS b/NEWS
index 9912045..2f031d4 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,13 @@ bug #29512.
 
 ** Functional Changes to find
 
+For find -printf, the format specifiers %{, %[ and %( are all now
+reserved for future use.  Previously these would print {, [ and (
+respectively, but in any case those characters can just be printed
+literally like this: find -printf "{[(".  Code changes intended to
+explain that these are reserved went into findutils-4.5.5, but this
+code had, before now, had no effect.
+
 When expanding "-printf '%F'", find reads /etc/mtab.  We now take the
 last match found in this file, rather than the first, to better deal
 with implementations which have duplicate entries (for example
diff --git a/doc/find.texi b/doc/find.texi
index 4f2e3c8..f086792 100644
--- a/doc/find.texi
+++ b/doc/find.texi
@@ -1742,13 +1742,9 @@ because many of the fields, even numeric ones, are 
printed with %s.
 The format flag @samp{-} does work; it forces left-alignment of the
 field.
 
address@hidden is a literal percent sign.  A @samp{%} character followed by
-an unrecognised character (i.e., not a known directive or @code{printf}
-field width and precision specifier), is discarded (but the
-unrecognised character is printed), and a warning message is printed
-to the standard error output (because it was probably a typo).  Don't
-rely on this behaviour, because other directives may be added in the
-future.
address@hidden is a literal percent sign.  @xref{Reserved and Unknown
+Directives}, for a description of how format directives not mentioned
+below are handled.
 
 A @samp{%} at the end of the format argument causes undefined
 behaviour since there is no following character.  In some locales, it
@@ -1762,6 +1758,7 @@ from the novel you are reading.
 * Location Directives::
 * Time Directives::
 * Other Directives::
+* Reserved and Unknown Directives::
 * Formatting Flags::
 @end menu
 
@@ -1927,6 +1924,23 @@ File's last modification time in the format specified by 
@var{k}
 File's SELinux context, or empty string if the file has no SELinux context.
 @end table
 
address@hidden Reserved and Unknown Directives
address@hidden Reserved and Unknown Directives
+
+The @samp{%(}, @address@hidden and @samp{%[} format directives, with or
+without field with and precision specifications, are reserved for
+future use. Don't use them and don't rely on current experiment to
+predict future behaviour.  To print @samp{(}, simply use @samp{(}
+rather than @samp{%(}.  Likewise for @address@hidden and @samp{[}.
+
+Similarly, a @samp{%} character followed by any other unrecognised
+character (i.e., not a known directive or @code{printf} field width
+and precision specifier), is discarded (but the unrecognised character
+is printed), and a warning message is printed to the standard error
+output (because it was probably a typo).  Don't rely on this
+behaviour, because other directives may be added in the future.
+
+
 @node Time Formats
 @subsection Time Formats
 
diff --git a/find/find.1 b/find/find.1
index 9a61d84..2ffdd8e 100644
--- a/find/find.1
+++ b/find/find.1
@@ -1374,6 +1374,8 @@ U=unknown type (shouldn't happen)
 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
 .IP %Z
 (SELinux only) file's security context.
+.IP "%{ %[ %("
+Reserved for future use.
 .PP
 A `%' character followed by any other character is discarded, but the
 other character is printed (don't rely on this, as further format
diff --git a/find/print.c b/find/print.c
index 52da71d..177bf91 100644
--- a/find/print.c
+++ b/find/print.c
@@ -67,6 +67,10 @@ make_segment (struct segment **segment,
   enum EvaluationCost mycost = NeedsNothing;
   char *fmt;
 
+  assert (format_char != '{');
+  assert (format_char != '[');
+  assert (format_char != '(');
+
   *segment = xmalloc (sizeof (struct segment));
 
   (*segment)->segkind = kind;
@@ -181,15 +185,6 @@ make_segment (struct segment **segment,
       pred->need_stat = true;
       mycost = NeedsStatInfo;
       break;
-
-    case '{':
-    case '[':
-    case '(':
-      error (EXIT_FAILURE, 0,
-            _("error: the format directive `%%%c' is reserved for future use"),
-            (int)kind);
-      /*NOTREACHED*/
-      break;
     }
   *fmt = '\0';
 
@@ -326,13 +321,27 @@ insert_fprintf (struct format_val *vec,
            }
          else
            {
-             /* An unrecognized % escape.  Print the char after the %. */
-             error (0, 0, _("warning: unrecognized format directive `%%%c'"),
-                    *scan2);
-             segmentp = make_segment (segmentp, format, scan - format,
-                                      KIND_PLAIN, 0, 0,
-                                      our_pred);
-             format = scan + 1;
+             switch (*scan2)
+               {
+               case '{':
+               case '[':
+               case '(':
+                 error (EXIT_FAILURE, 0,
+                        _("error: the format directive `%%%c' is reserved for 
future use"),
+                        (int)*scan2);
+                 /*NOTREACHED*/
+                 break;
+
+               default:
+                 /* An unrecognized % escape.  Print the char after the %. */
+                 error (0, 0,
+                        _("warning: unrecognized format directive `%%%c'"),
+                        *scan2);
+                 segmentp = make_segment (segmentp, format, scan - format,
+                                          KIND_PLAIN, 0, 0,
+                                          our_pred);
+                 format = scan + 1;
+               }
              continue;
            }
        }
diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am
index e944456..d7b4163 100644
--- a/find/testsuite/Makefile.am
+++ b/find/testsuite/Makefile.am
@@ -170,6 +170,7 @@ find.gnu/printf-nonlocal-symlink.exp \
 find.gnu/printf-slash.exp \
 find.gnu/printf-symlink.exp \
 find.gnu/printf-h.exp \
+find.gnu/printf-reserved.exp \
 find.gnu/prune-default-print.exp \
 find.gnu/regex1.exp \
 find.gnu/regex2.exp \
diff --git a/find/testsuite/find.gnu/printf-reserved.exp 
b/find/testsuite/find.gnu/printf-reserved.exp
new file mode 100644
index 0000000..3072312
--- /dev/null
+++ b/find/testsuite/find.gnu/printf-reserved.exp
@@ -0,0 +1,3 @@
+find_start f { . -maxdepth 0 -printf '%(' }
+find_start f { . -maxdepth 0 -printf '%\{' }
+find_start f { . -maxdepth 0 -printf '%\[' }
-- 
1.7.2.5




reply via email to

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