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,
int *);
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,
int *nbytes)
80 const char *p = str - 1;
84 while (ncols >= 0 && *++p)
85 if ((*p & 0xc0) != 0x80) {
101 if ((*p & 0xc0) == 0x80)
119static int ovprintf(
struct options *opts,
const char *format,
va_list ap)
123 if (opts ==
NULL || (opts->stream ==
NULL && opts->_str ==
NULL))
125 else if (opts->stream)
128 if ((
long int)opts->size >= 0) {
130 nbytes =
vsnprintf(opts->_str, opts->_size, format,
ap);
131 opts->_size -= nbytes;
137 opts->_str += nbytes;
154static int oprintf(
struct options *opts,
const char *format, ...)
160 nbytes = ovprintf(opts, format,
ap);
177static int oaprintf(
struct options *opts,
const char *format,
va_list ap)
192 nbytes += oprintf(opts,
asis);
199 while (*++c && *q != *c)
260 _(
"Failed to parse string specifier: %s"), p);
267 int wcount = count_wide_chars(s);
272 width += count_wide_chars_in_cols(s,
prec,
279 spec[0] ==
'-' ?
"-" :
"", width);
284 nbytes += oprintf(opts,
spec, s);
293 nbytes += ovprintf(opts, p,
aq);
301 nbytes += ovprintf(opts, p,
aq);
356 _(
"Format specifier exceeds the buffer size (%d)"),
366 nbytes += oprintf(opts,
asis);
381 return oaprintf(
NULL, format,
ap);
396 opts.stream = stream;
400 return oaprintf(&opts, format,
ap);
416 opts.str = opts._str = str;
419 return oaprintf(&opts, format,
ap);
437 opts.str = opts._str = str;
438 opts.size = opts._size = size;
440 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