28 #define CONVS "diouxXeEfFgGaAcsCSpnm%"
31 #define SPEC_BUF_SIZE 16
39 static int count_wide_chars(
const char *);
40 static int count_wide_chars_in_cols(
const char *,
int,
int *);
41 static int ovprintf(
struct options *,
const char *, va_list);
42 static int oprintf(
struct options *,
const char *, ...);
43 static int oaprintf(
struct options *,
const char *, va_list);
51 static int count_wide_chars(
const char *str)
53 int nwchars = 0, lead = 0;
58 if ((*str++ & 0xc0) != 0x80)
78 static int count_wide_chars_in_cols(
const char *str,
int ncols,
int *nbytes)
80 const char *p = str - 1;
81 int lead = 0, nwchars = 0;
84 while (ncols >= 0 && *++p)
85 if ((*p & 0xc0) != 0x80) {
101 if ((*p & 0xc0) == 0x80)
119 static int ovprintf(
struct options *opts,
const char *format, va_list ap)
123 if (opts ==
NULL || (opts->stream ==
NULL && opts->_str ==
NULL))
124 nbytes = vprintf(format, ap);
125 else if (opts->stream)
126 nbytes = vfprintf(opts->stream, format, ap);
128 if ((
long int)opts->size >= 0) {
130 nbytes = vsnprintf(opts->_str, opts->_size, format, ap);
131 opts->_size -= nbytes;
136 nbytes = vsprintf(opts->_str, format, ap);
137 opts->_str += nbytes;
154 static int oprintf(
struct options *opts,
const char *format, ...)
159 va_start(ap, format);
160 nbytes = ovprintf(opts, format, ap);
177 static int oaprintf(
struct options *opts,
const char *format, va_list ap)
183 p = asis = fmt = (
char *)
G_malloc(strlen(format) + 1);
188 char *q = p, *p_spec = spec;
192 nbytes += oprintf(opts, asis);
199 while (*++c && *q != *c)
211 int width = -1, prec = -1, use_ovprintf = 1;
219 if (*p_spec ==
'*') {
221 width = va_arg(ap,
int);
225 else if (*p_spec >=
'0' && *p_spec <=
'9') {
228 while (*p_spec >=
'0' && *p_spec <=
'9')
235 if (*p_spec ==
'.') {
238 if (*p_spec ==
'*') {
240 prec = va_arg(ap,
int);
244 else if (*p_spec >=
'0' && *p_spec <=
'9') {
247 while (*p_spec >=
'0' && *p_spec <=
'9')
260 _(
"Failed to parse string specifier: %s"), p);
263 s = va_arg(ap,
char *);
267 int wcount = count_wide_chars(s);
272 width += count_wide_chars_in_cols(s, prec,
278 sprintf(p_spec,
"%%%s%d",
279 spec[0] ==
'-' ?
"-" :
"", width);
281 p_spec += sprintf(p_spec,
".%d", prec);
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);
432 int G_vsnaprintf(
char *str,
size_t size,
const char *format, va_list ap)
437 opts.str = opts._str = str;
438 opts.size = opts._size = size;
440 return oaprintf(&opts, format, ap);
470 va_start(ap, format);
490 va_start(ap, format);
510 va_start(ap, format);
532 va_start(ap, format);
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