fixes + norm

This commit is contained in:
gazhonsepaskwa
2025-02-11 16:47:02 +01:00
parent 23791a53d9
commit ced584b17a
13 changed files with 239 additions and 194 deletions

View File

@@ -6,7 +6,7 @@
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */
/* Updated: 2025/02/07 17:26:04 by nalebrun ### ########.fr */
/* Updated: 2025/02/11 16:31:30 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
@@ -33,26 +33,6 @@ static t_node *tokenize_base(char *str)
return (head);
}
static void set_token(t_node *head)
{
t_node *it;
t_token last_token;
t_pres last_pres;
it = head;
last_token = UNSET;
last_pres = UNDEFINED;
while (it != NULL)
{
it->token = get_token(it->val);
it->pressision = get_pressision(it->val, it->token, last_token,
last_pres);
last_token = it->token;
last_pres = it->pressision;
it = it->next;
}
}
static int unstick_nodes(t_node *head)
{
t_node *it;
@@ -89,7 +69,8 @@ static int stick_quote_node(t_node *head, char q)
it = head;
while (it != NULL)
{
if (ft_strchr(it->val, q) && ft_strchr(it->val, q) == ft_strrchr(it->val, q))
if (ft_strchr(it->val, q) && ft_strchr(it->val,
q) == ft_strrchr(it->val, q))
{
while (it->next && !ft_strchr(it->next->val, q))
if (!merge_with_next_node(it))
@@ -102,36 +83,19 @@ static int stick_quote_node(t_node *head, char q)
return (1);
}
void debug_token_list(t_node* lst, char *msg)
static void del_void_nodes(t_node **head)
{
t_node *cpy;
cpy = lst;
if (DEBUG)
{
ft_debug("==================================================================={%s}\n", msg);
while (cpy)
{
ft_fprintf(2, "| %10s | TOKEN : %3d | PRESSISION : %3d |\n", cpy->val, cpy->token, cpy->pressision);
cpy = cpy->next;
}
ft_debug("===================================================================\n\n");
}
}
void del_void_nodes(t_node **head)
{
t_node *cpy;
t_node *tmp;
t_node *cpy;
t_node *tmp;
cpy = *head;
if (ft_strlen((*head)->val) == 0)
{
cpy = (*head)->next;
free ((*head)->val);
free (*head);
free((*head)->val);
free(*head);
}
*head = cpy;
*head = cpy;
while (cpy)
{
if (cpy->next && ft_strlen(cpy->next->val) == 0)
@@ -152,19 +116,12 @@ t_node *tokenize(char *str)
head = tokenize_base(str);
if (!head)
return (NULL);
debug_token_list(head, "tokenize_base");
if (!trim_nodes(head))
return (NULL);
debug_token_list(head, "trim_nodes");
if (!unstick_nodes(head))
return (NULL);
debug_token_list(head, "unstick_nodes");
stick_quote_node(head, 39);
stick_quote_node(head, '"');
debug_token_list(head, "stick quote node");
// if (!trim_nodes(head))
// return (NULL);
// debug_token_list(head, "trim_nodes");
set_token(head);
del_void_nodes(&head);
debug_token_list(head, "tokenizer");

View File

@@ -6,7 +6,7 @@
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 14:24:05 by nalebrun #+# #+# */
/* Updated: 2025/02/07 18:04:31 by nalebrun ### ########.fr */
/* Updated: 2025/02/11 16:33:45 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,16 +15,15 @@
int is_meta(char c)
{
if (c == '&' || c == '|' || c == '<' || c == '>' || c == '(' || c == ')'
|| c == ';' || c == '{' || c == '}' || c == '['
|| c == ']')
|| c == ';' || c == '{' || c == '}' || c == '[' || c == ']')
return (1);
return (0);
}
int unic(int *meta)
int unic(int *meta)
{
int i;
int ref_meta;
int i;
int ref_meta;
i = -1;
ref_meta = meta[0];
@@ -38,7 +37,7 @@ int is_sticked(char *val)
{
int i;
int meta[100];
int meta_it;
int meta_it;
int unmeta;
i = 0;
@@ -85,8 +84,7 @@ int trim_nodes(t_node *head)
in_quote = 0;
while (it != NULL)
{
if (ft_str_count(it->val, 39) == 1
|| ft_str_count(it->val, '"') == 1)
if (ft_str_count(it->val, 39) == 1 || ft_str_count(it->val, '"') == 1)
{
if (!in_quote)
in_quote = it->val[0];
@@ -103,17 +101,3 @@ int trim_nodes(t_node *head)
}
return (1);
}
int find_quote_node(t_node *head, char q)
{
t_node *it;
it = head;
while (it != NULL)
{
if (it->val[0] == q)
return (1);
it = it->next;
}
return (0);
}

View File

@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenizer_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 16:10:17 by nalebrun #+# #+# */
/* Updated: 2025/02/11 16:33:26 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../../includes/minishell.h"
void debug_token_list(t_node *lst, char *msg)
{
t_node *cpy;
cpy = lst;
if (DEBUG)
{
ft_debug("====================================================\
==============={%s}\n",
msg);
while (cpy)
{
ft_fprintf(2, "| %10s | TOKEN : %3d | PRESSISION : %3d |\n",
cpy->val, cpy->token, cpy->pressision);
cpy = cpy->next;
}
ft_debug("====================================================\
===============\n\n");
}
}
void set_token(t_node *head)
{
t_node *it;
t_token last_token;
t_pres last_pres;
it = head;
last_token = UNSET;
last_pres = UNDEFINED;
while (it != NULL)
{
it->token = get_token(it->val);
it->pressision = get_pressision(it->val, it->token, last_token,
last_pres);
last_token = it->token;
last_pres = it->pressision;
it = it->next;
}
}
int find_quote_node(t_node *head, char q)
{
t_node *it;
it = head;
while (it != NULL)
{
if (it->val[0] == q)
return (1);
it = it->next;
}
return (0);
}