unstick update && syntax check
This commit is contained in:
@@ -39,9 +39,9 @@ t_token get_token(char *str)
|
||||
{
|
||||
t_token token;
|
||||
|
||||
if (!ft_strncmp(str, "&", 1) || !ft_strncmp(str, "|", 1) || !ft_strncmp(str,
|
||||
"(", 1) || !ft_strncmp(str, ")", 1) || !ft_strncmp(str, "<", 1)
|
||||
|| !ft_strncmp(str, ">", 1))
|
||||
if (!ft_strncmp(str, "&", 1) || !ft_strncmp(str, "|", 1)
|
||||
|| !ft_strncmp(str, "(", 1) || !ft_strncmp(str, ")", 1)
|
||||
|| !ft_strncmp(str, "<", 1) || !ft_strncmp(str, ">", 1))
|
||||
token = OPERATOR;
|
||||
else
|
||||
token = WORD;
|
||||
|
||||
@@ -103,6 +103,23 @@ static int stick_quote_node(t_node *head, char q)
|
||||
return (1);
|
||||
}
|
||||
|
||||
void debug_token_list(t_node* lst, char *msg)
|
||||
{
|
||||
t_node *cpy;
|
||||
|
||||
cpy = lst;
|
||||
if (DEBUG)
|
||||
{
|
||||
ft_debug("========================={%s}\n", msg);
|
||||
while (cpy)
|
||||
{
|
||||
ft_debug("|%s|\n", cpy->val);
|
||||
cpy = cpy->next;
|
||||
}
|
||||
ft_debug("=========================\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
t_node *tokenize(char *str)
|
||||
{
|
||||
t_node *head;
|
||||
@@ -110,12 +127,18 @@ 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, "tokenizer");
|
||||
set_token(head);
|
||||
if (syntax_error(head))
|
||||
return (NULL);
|
||||
return (head);
|
||||
}
|
||||
|
||||
@@ -15,29 +15,49 @@
|
||||
int is_meta(char c)
|
||||
{
|
||||
if (c == '&' || c == '|' || c == '<' || c == '>' || c == '(' || c == ')'
|
||||
|| c == '"' || c == 39)
|
||||
|| c == '"' || c == 39 || c == ';' || c == '{' || c == '}' || c == '['
|
||||
|| c == ']')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int unic(int *meta)
|
||||
{
|
||||
int i;
|
||||
int ref_meta;
|
||||
|
||||
i = -1;
|
||||
ref_meta = meta[0];
|
||||
while (meta[++i] != -1)
|
||||
if (meta[i] != ref_meta)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int is_sticked(char *val)
|
||||
{
|
||||
int i;
|
||||
int meta;
|
||||
int meta[100];
|
||||
int meta_it;
|
||||
int unmeta;
|
||||
|
||||
i = 0;
|
||||
meta = 0;
|
||||
meta_it = 0;
|
||||
meta[0] = -1;
|
||||
unmeta = 0;
|
||||
while (val[i])
|
||||
{
|
||||
if (is_meta(val[i]))
|
||||
meta = 1;
|
||||
{
|
||||
meta[meta_it] = val[i];
|
||||
meta_it++;
|
||||
}
|
||||
if (!is_meta(val[i]))
|
||||
unmeta = 1;
|
||||
i++;
|
||||
}
|
||||
if (meta && unmeta)
|
||||
meta[meta_it] = -1;
|
||||
if ((meta[0] != -1 && unmeta) || !unic(meta))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@ char *copy_meta_xor(char *val, int *copied, int rev)
|
||||
int i;
|
||||
int j;
|
||||
char *out;
|
||||
char ref;
|
||||
|
||||
i = 0;
|
||||
while (is_meta(val[i]) ^ rev)
|
||||
ref = val[0];
|
||||
while ((is_meta(val[i]) && val[i] == ref) ^ rev)
|
||||
i++;
|
||||
*copied = i;
|
||||
out = malloc(i + 1);
|
||||
|
||||
Reference in New Issue
Block a user