This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Special handling of "%H" (Re: Support for %d$c format specifierin diagnostics.c)
Hi,
The closest we can come with, say, warning() is as follows.
This is because gcc's output formating doesn't support spcifying width
directly (as number literal) in format specifier. For string, though,
we can use .* to give the width as another argument. For positonal
paramaeter, this width argument also must be given in positional
notation (according SUS specification.).
/* modified test from a post by Jonathan Lennox */
{
char *str = "Hello!";
warning("String = %2$.*1$s, extra=%3$d", 10, str, i);
warning("%.*s\n%.*s\n%.*s\n%.*s\n%.*s\n%.*s",
1, str, 2, str, 3, str, 4, str, 5, str, 6, str );
warning("%1$.*2$s\n%1$.*3$s\n%1$.*4$s\n%1$.*5$s\n%1$.*6$s\n%1$.*7$s",
str, 1, 2, 3, 4, 5, 6);
}
Output from above.
cc1: warning: String = Hello!
cc1: warning: H
He
Hel
Hell
Hello
Hello!
cc1: warning: H
He
Hel
Hell
Hello
Hello!
Good? Aha, NO!
We are printing one character too many as compared with
Jonathan's example !?
I checked and got suspicious to the parameter to pp_append_text().
I decremened the third argument to pp_append_text() by 1 and retried.
The problem is with the unpatched original. Near line 304 of the
original pretty-print.c:
n = va_arg (*text->args_ptr, int);
s = va_arg (*text->args_ptr, const char *);
pp_append_text (pp, s, s + n); <---
the 3rd argument should read s + n - 1
New Output: (the above mods removed the strange "H" that was on the
same line following "warning:", too.)
cc1: warning: String = Hello!
cc1: warning:
H
He
Hel
Hell
Hello
cc1: warning:
H
He
Hel
Hell
Hello
Happy Hacking,
Ishikawa, Chiaki
PS: In my latest posted patch, the handling of 's', 'p' were left
unmodified. (I must have missed bring over the
change during the patch regeneration after the pretty-print.[ch]
abd diagnostic.[ch] reorganization.
They should read something like this. (in pp_format_text().
case 's':
if(!use_pos_specifier)
pp_string (pp, va_arg (*text->args_ptr, const char *));
else
pp_string (pp, text->arg_array[arg_index].v.cptr);
break;
case 'p':
if(!use_pos_specifier)
pp_pointer (pp, va_arg (*text->args_ptr, void *));
else
pp_pointer (pp, text->arg_array[arg_index].v.ptr);
break;
Sorry about this oversight.
--
int main(void){int j=2003;/*(c)2003 cishikawa. */
char t[] ="<CI> @abcdefghijklmnopqrstuvwxyz.,\n\"";
char *i ="g>qtCIuqivb,gCwe\np@.ietCIuqi\"tqkvv is>dnamz";
while(*i)((j+=strchr(t,*i++)-(int)t),(j%=sizeof t-1),
(putchar(t[j])));return 0;}/* under GPL */