1
/* printquoted.c -- print a specified string with any necessary quoting.
3
Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000,
4
2003, 2004, 2005 Free Software Foundation, Inc.
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
30
/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
38
#include "printquoted.h"
42
* Print S according to the format FORMAT, but if the destination is a tty,
43
* convert any potentially-dangerous characters. The logic in this function
44
* was taken from ls.c in coreutils (at Sun Jun 5 20:42:51 2005 UTC).
47
print_quoted (FILE *fp,
48
const struct quoting_options *qopts,
55
char smallbuf[BUFSIZ];
56
size_t len = quotearg_buffer (smallbuf, sizeof smallbuf, s, -1, qopts);
58
if (len < sizeof smallbuf)
62
/* The original coreutils code uses alloca(), but I don't
63
* want to take on the anguish of introducing alloca() to
66
buf = xmalloc (len + 1);
67
quotearg_buffer (buf, len + 1, s, -1, qopts);
70
/* Replace any remaining funny characters with '?'. */
71
len = qmark_chars(buf, len);
73
fprintf(fp, format, buf); /* Print the quoted version */
82
/* no need to quote things. */
83
fprintf(fp, format, s);