mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Changed type of ok array in builtin_printf.cpp to bool
This commit is contained in:
parent
fba984272a
commit
ab52469fbb
1 changed files with 47 additions and 28 deletions
|
@ -448,22 +448,27 @@ static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) {
|
||||||
int field_width = 0; /* Arg to first '*'. */
|
int field_width = 0; /* Arg to first '*'. */
|
||||||
bool have_precision; /* True if PRECISION is valid. */
|
bool have_precision; /* True if PRECISION is valid. */
|
||||||
int precision = 0; /* Arg to second '*'. */
|
int precision = 0; /* Arg to second '*'. */
|
||||||
wchar_t ok[UCHAR_MAX + 1]; /* ok['x'] is true if %x is allowed. */
|
bool ok[UCHAR_MAX + 1] = { }; /* ok['x'] is true if %x is allowed. */
|
||||||
|
|
||||||
for (f = format; *f != L'\0'; ++f) {
|
for (f = format; *f != L'\0'; ++f)
|
||||||
switch (*f) {
|
{
|
||||||
|
switch (*f)
|
||||||
|
{
|
||||||
case L'%':
|
case L'%':
|
||||||
direc_start = f++;
|
direc_start = f++;
|
||||||
direc_length = 1;
|
direc_length = 1;
|
||||||
have_field_width = have_precision = false;
|
have_field_width = have_precision = false;
|
||||||
if (*f == L'%') {
|
if (*f == L'%')
|
||||||
|
{
|
||||||
append_format(stdout_buffer, L"%lc", L'%');
|
append_format(stdout_buffer, L"%lc", L'%');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*f == L'b') {
|
if (*f == L'b')
|
||||||
|
{
|
||||||
/* FIXME: Field width and precision are not supported
|
/* FIXME: Field width and precision are not supported
|
||||||
for %b, even though POSIX requires it. */
|
for %b, even though POSIX requires it. */
|
||||||
if (argc > 0) {
|
if (argc > 0)
|
||||||
|
{
|
||||||
print_esc_string (*argv);
|
print_esc_string (*argv);
|
||||||
++argv;
|
++argv;
|
||||||
--argc;
|
--argc;
|
||||||
|
@ -471,27 +476,28 @@ static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset (ok, 0, sizeof ok);
|
|
||||||
ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] =
|
ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] =
|
||||||
ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] =
|
ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] =
|
||||||
ok['s'] = ok['u'] = ok['x'] = ok['X'] = 1;
|
ok['s'] = ok['u'] = ok['x'] = ok['X'] = true;
|
||||||
|
|
||||||
for (;; f++, direc_length++) {
|
for (;; f++, direc_length++)
|
||||||
switch (*f) {
|
{
|
||||||
|
switch (*f)
|
||||||
|
{
|
||||||
#if (__GLIBC__ == 2 && 2 <= __GLIBC_MINOR__) || 3 <= __GLIBC__
|
#if (__GLIBC__ == 2 && 2 <= __GLIBC_MINOR__) || 3 <= __GLIBC__
|
||||||
case L'I':
|
case L'I':
|
||||||
#endif
|
#endif
|
||||||
case L'\'':
|
case L'\'':
|
||||||
ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] =
|
ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] =
|
||||||
ok['o'] = ok['s'] = ok['x'] = ok['X'] = 0;
|
ok['o'] = ok['s'] = ok['x'] = ok['X'] = false;
|
||||||
break;
|
break;
|
||||||
case '-': case '+': case ' ':
|
case '-': case '+': case ' ':
|
||||||
break;
|
break;
|
||||||
case L'#':
|
case L'#':
|
||||||
ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = 0;
|
ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = false;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
ok['c'] = ok['s'] = 0;
|
ok['c'] = ok['s'] = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto no_more_flag_characters;
|
goto no_more_flag_characters;
|
||||||
|
@ -499,10 +505,12 @@ static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
no_more_flag_characters:;
|
no_more_flag_characters:;
|
||||||
|
|
||||||
if (*f == L'*') {
|
if (*f == L'*')
|
||||||
|
{
|
||||||
++f;
|
++f;
|
||||||
++direc_length;
|
++direc_length;
|
||||||
if (argc > 0) {
|
if (argc > 0)
|
||||||
|
{
|
||||||
intmax_t width = vstrtoimax (*argv);
|
intmax_t width = vstrtoimax (*argv);
|
||||||
if (INT_MIN <= width && width <= INT_MAX)
|
if (INT_MIN <= width && width <= INT_MAX)
|
||||||
field_width = width;
|
field_width = width;
|
||||||
|
@ -511,27 +519,34 @@ static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) {
|
||||||
++argv;
|
++argv;
|
||||||
--argc;
|
--argc;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
field_width = 0;
|
field_width = 0;
|
||||||
}
|
}
|
||||||
have_field_width = true;
|
have_field_width = true;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
while (iswdigit(*f)) {
|
{
|
||||||
|
while (iswdigit(*f))
|
||||||
|
{
|
||||||
++f;
|
++f;
|
||||||
++direc_length;
|
++direc_length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*f == L'.') {
|
if (*f == L'.')
|
||||||
|
{
|
||||||
++f;
|
++f;
|
||||||
++direc_length;
|
++direc_length;
|
||||||
ok['c'] = 0;
|
ok['c'] = false;
|
||||||
if (*f == L'*') {
|
if (*f == L'*')
|
||||||
|
{
|
||||||
++f;
|
++f;
|
||||||
++direc_length;
|
++direc_length;
|
||||||
if (argc > 0) {
|
if (argc > 0)
|
||||||
|
{
|
||||||
intmax_t prec = vstrtoimax (*argv);
|
intmax_t prec = vstrtoimax (*argv);
|
||||||
if (prec < 0) {
|
if (prec < 0)
|
||||||
|
{
|
||||||
/* A negative precision is taken as if the
|
/* A negative precision is taken as if the
|
||||||
precision were omitted, so -1 is safe
|
precision were omitted, so -1 is safe
|
||||||
here even if prec < INT_MIN. */
|
here even if prec < INT_MIN. */
|
||||||
|
@ -539,19 +554,23 @@ static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
else if (INT_MAX < prec)
|
else if (INT_MAX < prec)
|
||||||
append_format(stderr_buffer, _(L"invalid precision: %ls"), *argv);
|
append_format(stderr_buffer, _(L"invalid precision: %ls"), *argv);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
precision = prec;
|
precision = prec;
|
||||||
}
|
}
|
||||||
++argv;
|
++argv;
|
||||||
--argc;
|
--argc;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
precision = 0;
|
precision = 0;
|
||||||
}
|
}
|
||||||
have_precision = true;
|
have_precision = true;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
while (iswdigit(*f)) {
|
{
|
||||||
|
while (iswdigit(*f))
|
||||||
|
{
|
||||||
++f;
|
++f;
|
||||||
++direc_length;
|
++direc_length;
|
||||||
}
|
}
|
||||||
|
@ -609,4 +628,4 @@ static int builtin_printf(parser_t &parser, wchar_t **argv)
|
||||||
argv += args_used;
|
argv += args_used;
|
||||||
}
|
}
|
||||||
while (args_used > 0 && argc > 0);
|
while (args_used > 0 && argc > 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue