fix: fix invalid indent value case

feat: implemented main.c
This commit is contained in:
Renge 2022-02-15 12:54:42 -05:00
parent 3d7131a43e
commit 395b2b254b
3 changed files with 49 additions and 32 deletions

View File

@ -26,10 +26,10 @@
* @return A valid pointer if the operation is completely successful,
* NULL if there is any error.
*/
ARGO_VALUE *argo_read_value(FILE *f) {
// ARGO_VALUE *argo_read_value(FILE *f) {
// TO BE IMPLEMENTED.
abort();
}
// abort();
// }
/**
* @brief Read JSON input from a specified input stream, attempt to
@ -94,10 +94,10 @@ int argo_read_number(ARGO_NUMBER *n, FILE *f) {
* @return Zero if the operation is completely successful,
* nonzero if there is any error.
*/
int argo_write_value(ARGO_VALUE *v, FILE *f) {
// int argo_write_value(ARGO_VALUE *v, FILE *f) {
// TO BE IMPLEMENTED.
abort();
}
// abort();
// }
/**
* @brief Write canonical JSON representing a specified string
@ -119,10 +119,10 @@ int argo_write_value(ARGO_VALUE *v, FILE *f) {
* @return Zero if the operation is completely successful,
* nonzero if there is any error.
*/
int argo_write_string(ARGO_STRING *s, FILE *f) {
// int argo_write_string(ARGO_STRING *s, FILE *f) {
// TO BE IMPLEMENTED.
abort();
}
// abort();
// }
/**
* @brief Write canonical JSON representing a specified number
@ -142,7 +142,7 @@ int argo_write_string(ARGO_STRING *s, FILE *f) {
* @return Zero if the operation is completely successful,
* nonzero if there is any error.
*/
int argo_write_number(ARGO_NUMBER *n, FILE *f) {
// int argo_write_number(ARGO_NUMBER *n, FILE *f) {
// TO BE IMPLEMENTED.
abort();
}
// abort();
// }

View File

@ -23,6 +23,23 @@ int main(int argc, char **argv)
USAGE(*argv, EXIT_FAILURE);
if(global_options == HELP_OPTION)
USAGE(*argv, EXIT_SUCCESS);
else if (global_options == VALIDATE_OPTION)
{
argo_read_value(stdin);
return EXIT_SUCCESS;
}
else if (global_options == CANONICALIZE_OPTION)
{
ARGO_VALUE *json = argo_read_value(stdin);
argo_write_value(json, stdout);
return EXIT_SUCCESS;
}
else if (global_options & PRETTY_PRINT_OPTION)
{
ARGO_VALUE *json = argo_read_value(stdin);
argo_write_value(json, stdout);
return EXIT_SUCCESS;
}
// TO BE IMPLEMENTED
return EXIT_FAILURE;
}

View File

@ -40,14 +40,6 @@ int validargs(int argc, char **argv)
global_options = VALIDATE_OPTION;
isValid = 1;
}
else
{
if (parse_arg(*(++ptr)) == -1)
{
global_options = VALIDATE_OPTION;
isValid = 1;
}
}
break;
case 2:
if (argc == 2)
@ -57,18 +49,21 @@ int validargs(int argc, char **argv)
}
else
{
switch (parse_arg(*(++ptr)))
if (parse_arg(*(++ptr)) == 1)
{
case -1:
global_options = CANONICALIZE_OPTION;
isValid = 1;
int indented_value;
if (argc == 3) {
indented_value = 4;
}
else {
indented_value = str2int(*(++ptr));
}
if (indented_value == -1) {
break;
case 1:
global_options = CANONICALIZE_OPTION + PRETTY_PRINT_OPTION + str2int(*(++ptr));
}
global_options = CANONICALIZE_OPTION + PRETTY_PRINT_OPTION + indented_value;
isValid = 1;
break;
default:
break;
}
}
break;
@ -123,9 +118,14 @@ int str2int(char *arg)
}
else
{
ans = 4;
ans = -1;
break;
}
}
if (ans < 256 && ans >= 0) {
return ans;
}
else {
return -1;
}
}