wip improve printer

This commit is contained in:
hugogogo
2026-05-10 02:17:25 +02:00
parent 8445604656
commit 647c9a54b1
3 changed files with 51 additions and 85 deletions

View File

@@ -38,35 +38,6 @@ static size_t count_any_of(const char *s, const char *set)
return count;
}
static void tokens_fill_null(s_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++;
}
}
static void terms_fill_null(s_term *terms, size_t terms_count_prediction)
{
size_t i;
i = 0;
while (i < terms_count_prediction)
{
terms[i].coefficient = 0.0;
terms[i].exponent = 0;
terms[i].position = TERM_POS_END;
terms[i].sign = TERM_SIGN_END;
i++;
}
}
static int get_max_exponent(s_term *terms)
{
int i;
@@ -115,20 +86,6 @@ static int get_number_of_exponents(s_term *terms, int max_exponent)
return nbr_of_exponent;
}
static void polynom_fill_null(s_polynom *polynom, int len)
{
int i;
i = 0;
while (i < len)
{
polynom[i].coefficient = 0.0;
polynom[i].exponent = 0;
polynom[i].sign = TERM_SIGN_END;
i++;
}
}
void launch_computorv1(char *input)
{
int max_exponent;
@@ -146,7 +103,7 @@ void launch_computorv1(char *input)
print_debug("\n-> tokens[%i]\n", arg_len);
s_token tokens[arg_len];
tokens_g_err = tokens;
tokens_fill_null(tokens, arg_len);
ft_bzero(tokens, sizeof(tokens));
lexerize(input, tokens);
// parse
@@ -154,7 +111,7 @@ void launch_computorv1(char *input)
print_debug("-> terms[%i]\n\n", terms_count_prediction);
s_term terms[terms_count_prediction];
terms_g_err = terms;
terms_fill_null(terms, terms_count_prediction);
ft_bzero(terms, sizeof(terms));
parse(tokens, terms, terms_count_prediction);
// reduce
@@ -164,7 +121,7 @@ void launch_computorv1(char *input)
print_debug("-> nbr_of_exponents: %i\n\n", nbr_of_exponents);
s_polynom polynom[nbr_of_exponents + 2]; // +1 for last term, +1 for the degree (eg. degree 2 means 3 terms)
polynom_g_err = polynom;
polynom_fill_null(polynom, nbr_of_exponents + 2);
ft_bzero(polynom, sizeof(polynom));
degree = reduce(terms, polynom, max_exponent);
print_debug("-> degree: %i\n\n", degree);