Fixed indentation in builtin_printf.cpp

This commit is contained in:
Siteshwar Vashisht 2013-03-03 15:16:18 +05:30
parent fb3a41d3ad
commit fba984272a

View file

@ -203,7 +203,6 @@ print_esc_char (wchar_t c)
besides the backslash. besides the backslash.
If OCTAL_0 is nonzero, octal escapes are of the form \0ooo, where o If OCTAL_0 is nonzero, octal escapes are of the form \0ooo, where o
is an octal digit; otherwise they are of the form \ooo. */ is an octal digit; otherwise they are of the form \ooo. */
static int print_esc (const wchar_t *escstart, bool octal_0) static int print_esc (const wchar_t *escstart, bool octal_0)
{ {
const wchar_t *p = escstart + 1; const wchar_t *p = escstart + 1;
@ -259,7 +258,6 @@ static int print_esc (const wchar_t *escstart, bool octal_0)
|| (uni_value >= 0xd800 && uni_value <= 0xdfff)) || (uni_value >= 0xd800 && uni_value <= 0xdfff))
append_format(stderr_buffer, _(L"invalid universal character name \\%c%0*x"), append_format(stderr_buffer, _(L"invalid universal character name \\%c%0*x"),
esc_char, (esc_char == L'u' ? 4 : 8), uni_value); esc_char, (esc_char == L'u' ? 4 : 8), uni_value);
append_format(stdout_buffer, L"%lc", uni_value); append_format(stdout_buffer, L"%lc", uni_value);
} }
else else
@ -316,7 +314,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
length_modifier = PRIdMAX; length_modifier = PRIdMAX;
length_modifier_len = sizeof PRIdMAX - 2; length_modifier_len = sizeof PRIdMAX - 2;
break; break;
case L'a': case L'e': case L'f': case L'g': case L'a': case L'e': case L'f': case L'g':
case L'A': case L'E': case L'F': case L'G': case L'A': case L'E': case L'F': case L'G':
length_modifier = L"L"; length_modifier = L"L";
@ -331,7 +328,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
length_modifier_len = 0; length_modifier_len = 0;
break; break;
} }
p = new wchar_t[length + length_modifier_len + 2]; p = new wchar_t[length + length_modifier_len + 2];
q = static_cast<wchar_t*>(mempcpy (p, start, sizeof(wchar_t) * length)); q = static_cast<wchar_t*>(mempcpy (p, start, sizeof(wchar_t) * length));
q = static_cast<wchar_t*>(mempcpy (q, length_modifier, sizeof(wchar_t) * length_modifier_len)); q = static_cast<wchar_t*>(mempcpy (q, length_modifier, sizeof(wchar_t) * length_modifier_len));
@ -368,7 +364,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
case L'x': case L'x':
case L'X': case L'X':
{ {
uintmax_t arg = vstrtoumax (argument); uintmax_t arg = vstrtoumax (argument);
if (!have_field_width) if (!have_field_width)
{ {
@ -396,7 +391,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
case L'g': case L'g':
case L'G': case L'G':
{ {
long double arg = vstrtold (argument); long double arg = vstrtold (argument);
if (!have_field_width) if (!have_field_width)
{ {
@ -421,7 +415,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
else else
append_format(stdout_buffer, fmt.c_str(), field_width, *argument); append_format(stdout_buffer, fmt.c_str(), field_width, *argument);
break; break;
case L's': case L's':
if (!have_field_width) if (!have_field_width)
{ {
@ -432,7 +425,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
} }
else else
{ {
if (!have_precision) if (!have_precision)
append_format(stdout_buffer, fmt.c_str(), field_width, argument); append_format(stdout_buffer, fmt.c_str(), field_width, argument);
else else
@ -440,7 +432,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
} }
break; break;
} }
free (p); free (p);
} }
@ -448,8 +439,7 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
arguments to any `%' directives. arguments to any `%' directives.
Return the number of elements of ARGV used. */ Return the number of elements of ARGV used. */
static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) static int print_formatted (const wchar_t *format, int argc, wchar_t **argv) {
{
int save_argc = argc; /* Preserve original value. */ int save_argc = argc; /* Preserve original value. */
const wchar_t *f; /* Pointer into `format'. */ const wchar_t *f; /* Pointer into `format'. */
const wchar_t *direc_start; /* Start of % directive. */ const wchar_t *direc_start; /* Start of % directive. */
@ -460,25 +450,20 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
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. */ wchar_t 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;
@ -491,9 +476,8 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
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'] = 1;
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
@ -512,78 +496,71 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
default: default:
goto no_more_flag_characters; goto no_more_flag_characters;
} }
}
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;
else else
append_format(stderr_buffer, _(L"invalid field width: %ls"), append_format(stderr_buffer, _(L"invalid field width: %ls"), *argv);
*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'] = 0;
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. */
precision = -1; precision = -1;
} }
else if (INT_MAX < prec) else if (INT_MAX < prec)
append_format(stderr_buffer, _(L"invalid precision: %ls"), append_format(stderr_buffer, _(L"invalid precision: %ls"), *argv);
*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;
} }
} }
}
while (*f == L'l' || *f == L'L' || *f == L'h' while (*f == L'l' || *f == L'L' || *f == L'h'
|| *f == L'j' || *f == L't' || *f == L'z') || *f == L'j' || *f == L't' || *f == L'z')
++f; ++f;
{ {
unsigned wchar_t conversion = *f; unsigned wchar_t conversion = *f;
if (! ok[conversion]) if (! ok[conversion])
@ -606,7 +583,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion
append_format (stdout_buffer, L"%lc", *f); append_format (stdout_buffer, L"%lc", *f);
} }
} }
return save_argc - argc; return save_argc - argc;
} }
@ -614,7 +590,7 @@ static int builtin_printf(parser_t &parser, wchar_t **argv)
{ {
wchar_t *format; wchar_t *format;
int args_used; int args_used;
int argc=builtin_count_args(argv); int argc = builtin_count_args(argv);
if (argc <= 1) if (argc <= 1)
{ {