Filter out any garbage in the scan output

This commit is contained in:
Přemysl Eric Janouch 2014-09-20 18:27:03 +02:00
parent 38a0077033
commit b9571ec01f
1 changed files with 18 additions and 2 deletions

View File

@ -1174,6 +1174,20 @@ struct node_print_data
struct node_print_level **tail; ///< Where to place further levels struct node_print_level **tail; ///< Where to place further levels
}; };
static char *
node_escape_text (const char *text)
{
struct str filtered;
str_init (&filtered);
char c;
while ((c = *text++))
str_append_c (&filtered,
(isascii (c) && (isgraph (c) || c == ' ')) ? c : '.');
return str_steal (&filtered);
}
static void static void
node_print_tree_level (struct node *self, struct node_print_data *data) node_print_tree_level (struct node *self, struct node_print_data *data)
{ {
@ -1191,10 +1205,12 @@ node_print_tree_level (struct node *self, struct node_print_data *data)
fputs (indent.str, stdout); fputs (indent.str, stdout);
str_free (&indent); str_free (&indent);
char *escaped = node_escape_text (self->text);
self->bold self->bold
? print_bold (stdout, self->text) ? print_bold (stdout, escaped)
: fputs (self->text, stdout); : fputs (escaped, stdout);
fputc ('\n', stdout); fputc ('\n', stdout);
free (escaped);
struct node_print_level level; struct node_print_level level;
level.next = NULL; level.next = NULL;