fix: refactored validargs

This commit is contained in:
Renge 2022-02-16 18:17:09 -05:00
parent 395b2b254b
commit 1589be8e64
2 changed files with 42 additions and 32 deletions

View File

@ -5,6 +5,7 @@
#include "global.h"
#include "debug.h"
// ARGO_VALUE *argo_read_value_helper(FILE *f, ARGO_VALUE *this);
/**
* @brief Read JSON input from a specified input stream, parse it,
* and return a data structure representing the corresponding value.
@ -27,10 +28,35 @@
* NULL if there is any error.
*/
// ARGO_VALUE *argo_read_value(FILE *f) {
// TO BE IMPLEMENTED.
// abort();
// // TO BE IMPLEMENTED.
// argo_value_storage->next = NULL;
// argo_value_storage->prev = NULL;
// return argo_read_value_helper(f, argo_value_storage);
// }
// ARGO_VALUE *argo_read_value_helper(FILE *f, ARGO_VALUE *this) {
// int i = fgetc(f);
// int started = 0;
// while (i != EOF) {
// switch (i)
// {
// case '\b':
// case '\f':
// case '\r':
// case '\t':
// break;
// case '\n':
// argo_lines_read++;
// argo_chars_read = 0;
// default:
// break;
// }
// i = fgetc(f);
// }
// return this;
// }
/**
* @brief Read JSON input from a specified input stream, attempt to
* parse it as a JSON string literal, and return a data structure
@ -49,10 +75,10 @@
* @return Zero if the operation is completely successful,
* nonzero if there is any error.
*/
int argo_read_string(ARGO_STRING *s, FILE *f) {
// int argo_read_string(ARGO_STRING *s, FILE *f) {
// TO BE IMPLEMENTED.
abort();
}
// abort();
// }
/**
* @brief Read JSON input from a specified input stream, attempt to
@ -76,10 +102,10 @@ int argo_read_string(ARGO_STRING *s, FILE *f) {
* @return Zero if the operation is completely successful,
* nonzero if there is any error.
*/
int argo_read_number(ARGO_NUMBER *n, FILE *f) {
// int argo_read_number(ARGO_NUMBER *n, FILE *f) {
// TO BE IMPLEMENTED.
abort();
}
// abort();
// }
/**
* @brief Write canonical JSON representing a specified value to

View File

@ -4,7 +4,7 @@
#include "global.h"
#include "debug.h"
int parse_arg(char *arg);
char parse_arg(char *arg);
int str2int(char *arg);
/**
@ -30,18 +30,18 @@ int validargs(int argc, char **argv)
char **ptr = argv;
switch (parse_arg(*(++ptr)))
{
case 8:
case 'h':
global_options = HELP_OPTION;
isValid = 1;
break;
case 4:
case 'v':
if (argc == 2)
{
global_options = VALIDATE_OPTION;
isValid = 1;
}
break;
case 2:
case 'c':
if (argc == 2)
{
global_options = CANONICALIZE_OPTION;
@ -49,7 +49,7 @@ int validargs(int argc, char **argv)
}
else
{
if (parse_arg(*(++ptr)) == 1)
if (parse_arg(*(++ptr)) == 'p')
{
int indented_value;
if (argc == 3) {
@ -77,33 +77,17 @@ int validargs(int argc, char **argv)
return -1;
}
int parse_arg(char *arg)
char parse_arg(char *arg)
{
int ans = -1;
if (*arg == '-')
{
char arg1 = *(++arg), arg2 = *(++arg);
if (arg2 == '\0')
{
if (arg1 == 'h')
{
ans = 8;
}
else if (arg1 == 'v')
{
ans = 4;
}
else if (arg1 == 'c')
{
ans = 2;
}
else if (arg1 == 'p')
{
ans = 1;
}
return arg1;
}
}
return ans;
return '\0';
}
int str2int(char *arg)