fix: wrong indent value

This commit is contained in:
Renge 2022-02-19 13:12:02 -05:00
parent b7357ef2ff
commit 1685df579f

View File

@ -859,6 +859,10 @@ int argo_write_basic(ARGO_BASIC *b, FILE *f)
return -1; return -1;
break; break;
} }
if (indent_level == 0 && global_options & PRETTY_PRINT_OPTION)
{
fprintf(f, "\n");
}
return 0; return 0;
} }
@ -899,6 +903,10 @@ int argo_write_number(ARGO_NUMBER *n, FILE *f)
{ {
return -1; return -1;
} }
if (indent_level == 0 && global_options & PRETTY_PRINT_OPTION)
{
fprintf(f, "\n");
}
return 0; return 0;
} }
@ -1054,6 +1062,10 @@ int argo_write_string(ARGO_STRING *s, FILE *f)
} }
} }
fprintf(f, "\""); fprintf(f, "\"");
if (indent_level == 0 && global_options & PRETTY_PRINT_OPTION)
{
fprintf(f, "\n");
}
return 0; return 0;
} }
@ -1061,10 +1073,10 @@ int argo_write_object(ARGO_VALUE *o, FILE *f)
{ {
fprintf(f, "{"); fprintf(f, "{");
indent_level++; indent_level++;
print_indent(f);
ARGO_VALUE *ptr = o; ARGO_VALUE *ptr = o;
while (ptr->next->type != ARGO_NO_TYPE) while (ptr->next->type != ARGO_NO_TYPE)
{ {
print_indent(f);
argo_write_string(&ptr->next->name, f); argo_write_string(&ptr->next->name, f);
fprintf(f, ":"); fprintf(f, ":");
if (global_options & PRETTY_PRINT_OPTION) if (global_options & PRETTY_PRINT_OPTION)
@ -1077,7 +1089,6 @@ int argo_write_object(ARGO_VALUE *o, FILE *f)
if (ptr->next->type != ARGO_NO_TYPE) if (ptr->next->type != ARGO_NO_TYPE)
{ {
fprintf(f, ","); fprintf(f, ",");
print_indent(f);
} }
} }
indent_level--; indent_level--;
@ -1094,16 +1105,15 @@ int argo_write_array(ARGO_VALUE *a, FILE *f)
{ {
fprintf(f, "["); fprintf(f, "[");
indent_level++; indent_level++;
print_indent(f);
ARGO_VALUE *ptr = a; ARGO_VALUE *ptr = a;
while (ptr->next->type != ARGO_NO_TYPE) while (ptr->next->type != ARGO_NO_TYPE)
{ {
print_indent(f);
argo_write_value(ptr->next, f); argo_write_value(ptr->next, f);
ptr = ptr->next; ptr = ptr->next;
if (ptr->next->type != ARGO_NO_TYPE) if (ptr->next->type != ARGO_NO_TYPE)
{ {
fprintf(f, ","); fprintf(f, ",");
print_indent(f);
} }
} }
indent_level--; indent_level--;