tokenization but simple and double quotes works hehe
This commit is contained in:
@@ -1,22 +1,9 @@
|
||||
#include "tokenizer.h"
|
||||
|
||||
t_token get_token(char *str)
|
||||
{
|
||||
t_token token;
|
||||
|
||||
if (!strncmp(str, "&", 1) || !strncmp(str, "|", 1) || !strncmp(str, "(", 1)
|
||||
|| !strncmp(str, ")", 1) || !strncmp(str, "<", 1) || !strncmp(str, ">",
|
||||
1))
|
||||
token = OPERATOR;
|
||||
else
|
||||
token = WORD;
|
||||
return (token);
|
||||
}
|
||||
|
||||
int is_meta(char c)
|
||||
{
|
||||
if (c == '&' || c == '|' || c == '<' || c == '>' || c == '(' || c == ')'
|
||||
|| c == '"')
|
||||
|| c == '"' || c == 39)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
@@ -42,3 +29,63 @@ int is_sticked(char *val)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_str_count(char *s, char c)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = -1;
|
||||
count = 0;
|
||||
while (s[++i])
|
||||
if (s[i] == c)
|
||||
count++;
|
||||
return (count);
|
||||
}
|
||||
|
||||
|
||||
int trim_nodes(t_node *head)
|
||||
{
|
||||
t_node *it;
|
||||
char *tmp;
|
||||
char in_quote;
|
||||
|
||||
it = head;
|
||||
in_quote = 0;
|
||||
while (it != NULL)
|
||||
{
|
||||
if (ft_str_count(it->val, 39) == 1
|
||||
|| ft_str_count(it->val, '"') == 1)
|
||||
{
|
||||
if (!in_quote)
|
||||
in_quote = it->val[0];
|
||||
else if (it->val[0] == in_quote)
|
||||
in_quote = 0;
|
||||
}
|
||||
if (!in_quote)
|
||||
{
|
||||
tmp = ft_strtrim(it->val, " \t\n");
|
||||
if (!tmp)
|
||||
return (0);
|
||||
free(it->val);
|
||||
it->val = tmp;
|
||||
}
|
||||
it = it->next;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user