28#define CONVS "diouxXeEfFgGaAcsCSpnm%"
31#define SPEC_BUF_SIZE 16
39static int count_wide_chars(
const char *);
40static int count_wide_chars_in_cols(
const char *,
int,
ptrdiff_t *);
41static int ovprintf(
struct options *,
const char *,
va_list);
42static int oprintf(
struct options *,
const char *, ...);
43static int oaprintf(
struct options *,
const char *,
va_list);
51static int count_wide_chars(
const char *str)
58 if ((*str++ & 0xc0) != 0x80)
78static int count_wide_chars_in_cols(
const char *str,
int ncols,
81 const char *p = str - 1;
85 while (ncols >= 0 && *++p)
86 if ((*p & 0xc0) != 0x80) {
102 if ((*p & 0xc0) == 0x80)
120static int ovprintf(
struct options *opts,
const char *format,
va_list ap)
124 if (opts ==
NULL || (opts->stream ==
NULL && opts->_str ==
NULL))
126 else if (opts->stream)
129 if ((
long int)opts->size >= 0) {
131 nbytes =
vsnprintf(opts->_str, opts->_size, format,
ap);
132 opts->_size -= nbytes;
138 opts->_str += nbytes;
155static int oprintf(
struct options *opts,
const char *format, ...)
161 nbytes = ovprintf(opts, format,
ap);
178static int oaprintf(
struct options *opts,
const char *format,
va_list ap)
193 nbytes += oprintf(opts,
asis);
200 while (*++c && *q != *c)
261 _(
"Failed to parse string specifier: %s"), p);
268 int wcount = count_wide_chars(s);
275 width += count_wide_chars_in_cols(s,
prec,
279 _(
"String precision is too large"));
287 spec[0] ==
'-' ?
"-" :
"", width);
292 nbytes += oprintf(opts,
spec, s);
301 nbytes += ovprintf(opts, p,
aq);
309 nbytes += ovprintf(opts, p,
aq);
364 _(
"Format specifier exceeds the buffer size (%d)"),
374 nbytes += oprintf(opts,
asis);
389 return oaprintf(
NULL, format,
ap);
404 opts.stream = stream;
408 return oaprintf(&opts, format,
ap);
424 opts.str = opts._str = str;
427 return oaprintf(&opts, format,
ap);
445 opts.str = opts._str = str;
446 opts.size = opts._size = size;
448 return oaprintf(&opts, format,
ap);
int G_snaprintf(char *str, size_t size, const char *format,...)
snprintf() version of G_aprintf(). See G_aprintf() for more details.
int G_aprintf(const char *format,...)
Adjust the width of string specifiers to the display space instead of the number of bytes for wide ch...
int G_saprintf(char *str, const char *format,...)
sprintf() version of G_aprintf(). See G_aprintf() for more details.
int G_vfaprintf(FILE *stream, const char *format, va_list ap)
vfprintf() version of G_aprintf(). See G_aprintf() for more details.
int G_vsnaprintf(char *str, size_t size, const char *format, va_list ap)
vsnprintf() version of G_aprintf(). See G_aprintf() for more details.
int G_vsaprintf(char *str, const char *format, va_list ap)
vsprintf() version of G_aprintf(). See G_aprintf() for more details.
int G_faprintf(FILE *stream, const char *format,...)
fprintf() version of G_aprintf(). See G_aprintf() for more details.
int G_vaprintf(const char *format, va_list ap)
vprintf() version of G_aprintf(). See G_aprintf() for more details.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf