diff options
author | James Youngman <jay@gnu.org> | 2011-06-18 13:06:39 +0100 |
---|---|---|
committer | James Youngman <jay@gnu.org> | 2011-06-19 11:49:34 +0100 |
commit | 9cb1805e619b0f3aebd0984856de24964218bce2 (patch) | |
tree | 6b0cb58b35e8b836c9aabee695a1edf4bf59344d | |
parent | e0de8fd4e7978cb606a3eaa9cc0884b8beac9080 (diff) | |
download | findutils-9cb1805e619b0f3aebd0984856de24964218bce2.tar.gz |
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.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | doc/find.texi | 28 | ||||
-rw-r--r-- | find/find.1 | 2 | ||||
-rw-r--r-- | find/print.c | 41 | ||||
-rw-r--r-- | find/testsuite/Makefile.am | 1 | ||||
-rw-r--r-- | find/testsuite/find.gnu/printf-reserved.exp | 3 |
7 files changed, 73 insertions, 23 deletions
@@ -1,5 +1,19 @@ 2011-06-18 James Youngman <jay@gnu.org> + 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), @@ -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 4f2e3c87..f086792e 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. -@samp{%%} 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. +@samp{%%} 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 +@node Reserved and Unknown Directives +@subsubsection Reserved and Unknown Directives + +The @samp{%(}, @samp{%@{} 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 @samp{@{} 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 9a61d844..2ffdd8e6 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 52da71db..177bf913 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 fdd496bb..fde9fae7 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 00000000..30723126 --- /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 '%\[' } |