remove individuals headers to avoid circular dependencies
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
/* computorv1.c */
|
||||
|
||||
#include "computorv1.h"
|
||||
|
||||
void remove_spaces(char *s)
|
||||
/**
|
||||
* GLOBALS
|
||||
*/
|
||||
|
||||
char *input_g_err;
|
||||
token *tokens_g_err;
|
||||
|
||||
/**
|
||||
* PROGRAM
|
||||
*/
|
||||
|
||||
static void remove_spaces(char *s)
|
||||
{
|
||||
char *read = s;
|
||||
char *write = s;
|
||||
@@ -23,7 +36,7 @@ void remove_spaces(char *s)
|
||||
}
|
||||
}
|
||||
|
||||
int count_any_of(const char *s, const char *set)
|
||||
static int count_any_of(const char *s, const char *set)
|
||||
{
|
||||
int count = 0;
|
||||
for (; *s != '\0'; s++)
|
||||
@@ -36,10 +49,24 @@ int count_any_of(const char *s, const char *set)
|
||||
return count;
|
||||
}
|
||||
|
||||
static void token_fill_null(token *tokens, size_t arg_len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < arg_len)
|
||||
{
|
||||
tokens[i].type = TOKEN_END;
|
||||
tokens[i].tag = TOKEN_NO_TAG;
|
||||
tokens[i].value_char = '\0';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int i;
|
||||
int arg_len;
|
||||
size_t arg_len;
|
||||
int terms_count_prediction;
|
||||
char *input;
|
||||
|
||||
@@ -48,79 +75,61 @@ int main(int ac, char **av)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// tmp debug output
|
||||
ft_putstr("-> received args :\n"); // debug
|
||||
i = 0;
|
||||
while (i < ac)
|
||||
{
|
||||
ft_putstr(" ");
|
||||
ft_putnbr(i);
|
||||
ft_putstr(" : ");
|
||||
ft_putstr(av[i]);
|
||||
ft_putchar('\n');
|
||||
i++;
|
||||
}
|
||||
|
||||
// init
|
||||
input = av[1];
|
||||
input_g_err = input;
|
||||
remove_spaces(input);
|
||||
arg_len = ft_strlen(input) + 1; // +1 for last END token
|
||||
|
||||
token tokens[arg_len];
|
||||
// by security, make the last token as END (even though the real END token will likely be lower)
|
||||
tokens[arg_len - 1].type = TOKEN_END;
|
||||
tokens[arg_len - 1].tag = TOKEN_NO_TAG;
|
||||
tokens[arg_len - 1].value_char = '\0';
|
||||
// lexerize
|
||||
token tokens[arg_len];
|
||||
tokens_g_err = tokens;
|
||||
token_fill_null(tokens, arg_len);
|
||||
int tokens_count = lexerize(input, tokens);
|
||||
if (tokens_count == 0)
|
||||
{
|
||||
stop_errors(ERROR_BASE, tokens, input, "test error");
|
||||
stop_errors(ERROR_TOKEN_COUNT, "lexer returned 0 token");
|
||||
}
|
||||
|
||||
// parse
|
||||
terms_count_prediction = count_any_of(input, "-+=") + 2; // +1 for first term that can have no leading '+', +1 for last term == NULL
|
||||
|
||||
ft_putstr("-> terms_count_prediction : "); // debug
|
||||
ft_putnbr(terms_count_prediction); // debug
|
||||
ft_putchar('\n'); // debug
|
||||
|
||||
term terms[terms_count_prediction];
|
||||
int term_count = parse(tokens, terms, terms_count_prediction);
|
||||
{
|
||||
stop_errors(ERROR_TERM_COUNT, "parser returned 0 term");
|
||||
}
|
||||
|
||||
ft_putstr("-> terms_count : "); // debug
|
||||
ft_putnbr(term_count); // debug
|
||||
ft_putchar('\n'); // debug
|
||||
|
||||
// tmp debug output
|
||||
ft_putchar('\n'); // debug
|
||||
// DEBUG
|
||||
ft_putstr("-> terms_count_prediction : ");
|
||||
ft_putnbr(terms_count_prediction);
|
||||
ft_putchar('\n');
|
||||
ft_putstr("-> terms_count : ");
|
||||
ft_putnbr(term_count);
|
||||
ft_putchar('\n');
|
||||
ft_putchar('\n');
|
||||
i = 0;
|
||||
while (terms[i].position != TERM_END)
|
||||
{
|
||||
ft_printf("term %2i :\n", i);
|
||||
|
||||
// position
|
||||
ft_printf(" position : ");
|
||||
if (terms[i].position == TERM_LEFT)
|
||||
ft_printf("%s\n", "TERM_LEFT");
|
||||
if (terms[i].position == TERM_RIGHT)
|
||||
ft_printf("%s\n", "TERM_RIGHT");
|
||||
|
||||
// sign
|
||||
ft_printf(" sign : ");
|
||||
if (terms[i].sign == TERM_PLUS)
|
||||
ft_printf("%s\n", "TERM_PLUS");
|
||||
if (terms[i].sign == TERM_MINUS)
|
||||
ft_printf("%s\n", "TERM_MINUS");
|
||||
|
||||
// coefficient
|
||||
printf(" coefficient : %g\n", terms[i].coefficient);
|
||||
|
||||
// exponent
|
||||
ft_printf(" exponent : %d\n", terms[i].exponent);
|
||||
|
||||
i++;
|
||||
}
|
||||
ft_putchar('\n'); // debug
|
||||
// END tmp debug output
|
||||
ft_putchar('\n');
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user