From 2e795a5fda861324c6fb847ba0ee0ed1382583f4 Mon Sep 17 00:00:00 2001 From: James Youngman Date: Sat, 25 Jun 2011 15:47:38 +0100 Subject: Simplify -fprintf %%; handle %% like a regular format specifier. * find/print.c (make_segment): Handle foo%% by simply generating a format string of foo%% (that is, let vfprintf handle the escaped %). (insert_fprintf): Handle %% as KIND_FORMAT instead of KIND_PLAIN. (do_fprintf): Handle %%. --- ChangeLog | 7 +++++++ find/print.c | 50 ++++++++++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc6f9454..6cdc8b33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-06-25 James Youngman + Simplify -fprintf %%; handle %% like a regular format specifier. + * find/print.c (make_segment): Handle foo%% by simply generating a + format string of foo%% (that is, let vfprintf handle the escaped + %). + (insert_fprintf): Handle %% as KIND_FORMAT instead of KIND_PLAIN. + (do_fprintf): Handle %%. + Clarify variable naming in insert_fprintf. * find/print.c (insert_fprintf): Rename some variables for greater clarity: diff --git a/find/print.c b/find/print.c index e0a1331b..31a46cd8 100644 --- a/find/print.c +++ b/find/print.c @@ -116,6 +116,10 @@ make_segment (struct segment **segment, assert (kind == KIND_FORMAT); switch (format_char) { + case '%': /* literal % */ + *fmt++ = '%'; + break; + case 'l': /* object of symlink */ pred->need_stat = true; mycost = NeedsLinkName; @@ -297,36 +301,34 @@ insert_fprintf (struct format_val *vec, segstart = fmt_inpos + 1; /* Move past the escape. */ fmt_editpos = fmt_inpos; /* Incremented immediately by `for'. */ } - else if (*fmt_editpos == '%') + else if (fmt_editpos[0] == '%') { - if (fmt_editpos[1] == 0) + if (fmt_editpos[1] == '%') + { + /* % escapes itself. That is, %% produces just %. */ + fmt_inpos = fmt_editpos+1; + } + else if (fmt_editpos[1] == 0) { /* Trailing %. We don't like those. */ error (EXIT_FAILURE, 0, _("error: %s at end of format string"), fmt_editpos); } - else if (fmt_editpos[1] == '%') - { - segmentp = make_segment (segmentp, - segstart, fmt_editpos - segstart + 1, - KIND_PLAIN, 0, 0, - our_pred); - fmt_editpos++; - segstart = fmt_editpos + 1; - continue; - } - /* Scan past flags, width and precision, to verify kind. */ - for (fmt_inpos = fmt_editpos; - *++fmt_inpos && strchr ("-+ #", *fmt_inpos);) + else { - /* Do nothing. */ + /* Scan past flags, width and precision, to verify kind. */ + for (fmt_inpos = fmt_editpos; + *++fmt_inpos && strchr ("-+ #", *fmt_inpos);) + { + /* Do nothing. */ + } + while (ISDIGIT (*fmt_inpos)) + fmt_inpos++; + if (*fmt_inpos == '.') + for (fmt_inpos++; ISDIGIT (*fmt_inpos); fmt_inpos++) + /* Do nothing. */ ; } - while (ISDIGIT (*fmt_inpos)) - fmt_inpos++; - if (*fmt_inpos == '.') - for (fmt_inpos++; ISDIGIT (*fmt_inpos); fmt_inpos++) - /* Do nothing. */ ; - if (strchr ("abcdDfFgGhHiklmMnpPsStuUyYZ", *fmt_inpos)) + if (strchr ("abcdDfFgGhHiklmMnpPsStuUyYZ%", *fmt_inpos)) { segmentp = make_segment (segmentp, segstart, fmt_inpos - segstart, KIND_FORMAT, *fmt_inpos, 0, @@ -1174,6 +1176,10 @@ do_fprintf (struct format_val *dest, } } break; + + case '%': + checked_fprintf (dest, segment->text); + break; } /* end of KIND_FORMAT case */ break; -- cgit v1.2.1