Implement putstr and putstrn in ui_file

In my tour of the ui_file subsystem, I found that fputstr and fputstrn
can be simplified.  The _filtered forms are never used (and IMO
unlikely to ever be used) and so can be removed.  And, the interface
can be simplified by removing a callback function and moving the
implementation directly to ui_file.

A new self-test is included.  Previously, I think nothing was testing
this code.

Regression tested on x86-64 Fedora 34.
This commit is contained in:
Tom Tromey
2021-12-31 10:40:02 -07:00
parent 28a4e64dd1
commit d53fd721a1
10 changed files with 158 additions and 139 deletions

View File

@ -1129,103 +1129,6 @@ parse_escape (struct gdbarch *gdbarch, const char **string_ptr)
return target_char;
}
/* Print the character C on STREAM as part of the contents of a literal
string whose delimiter is QUOTER. Note that this routine should only
be called for printing things which are independent of the language
of the program being debugged.
printchar will normally escape backslashes and instances of QUOTER. If
QUOTER is 0, printchar won't escape backslashes or any quoting character.
As a side effect, if you pass the backslash character as the QUOTER,
printchar will escape backslashes as usual, but not any other quoting
character. */
static void
printchar (int c, do_fputc_ftype do_fputc, ui_file *stream, int quoter)
{
c &= 0xFF; /* Avoid sign bit follies */
if (c < 0x20 || /* Low control chars */
(c >= 0x7F && c < 0xA0) || /* DEL, High controls */
(sevenbit_strings && c >= 0x80))
{ /* high order bit set */
do_fputc ('\\', stream);
switch (c)
{
case '\n':
do_fputc ('n', stream);
break;
case '\b':
do_fputc ('b', stream);
break;
case '\t':
do_fputc ('t', stream);
break;
case '\f':
do_fputc ('f', stream);
break;
case '\r':
do_fputc ('r', stream);
break;
case '\033':
do_fputc ('e', stream);
break;
case '\007':
do_fputc ('a', stream);
break;
default:
{
do_fputc ('0' + ((c >> 6) & 0x7), stream);
do_fputc ('0' + ((c >> 3) & 0x7), stream);
do_fputc ('0' + ((c >> 0) & 0x7), stream);
break;
}
}
}
else
{
if (quoter != 0 && (c == '\\' || c == quoter))
do_fputc ('\\', stream);
do_fputc (c, stream);
}
}
/* Print the character C on STREAM as part of the contents of a
literal string whose delimiter is QUOTER. Note that these routines
should only be call for printing things which are independent of
the language of the program being debugged. */
void
fputstr_filtered (const char *str, int quoter, struct ui_file *stream)
{
while (*str)
printchar (*str++, fputc_filtered, stream, quoter);
}
void
fputstr_unfiltered (const char *str, int quoter, struct ui_file *stream)
{
while (*str)
printchar (*str++, fputc_unfiltered, stream, quoter);
}
void
fputstrn_filtered (const char *str, int n, int quoter,
struct ui_file *stream)
{
for (int i = 0; i < n; i++)
printchar (str[i], fputc_filtered, stream, quoter);
}
void
fputstrn_unfiltered (const char *str, int n, int quoter,
do_fputc_ftype do_fputc, struct ui_file *stream)
{
for (int i = 0; i < n; i++)
printchar (str[i], do_fputc, stream, quoter);
}
/* Number of lines per page or UINT_MAX if paging is disabled. */
static unsigned int lines_per_page;