diff options
| author | nass1pro <nass1pro@gmail.com> | 2020-06-12 10:12:03 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-13 11:42:46 +0200 |
| commit | c5cde6afd3cecb44bbe9da0c28d970524da80228 (patch) | |
| tree | 98ec558582ed20a120e13b4a376fd206fb620da0 /src/lexer/lexer_utils.c | |
| parent | 39c04561ae4956cb836c6117789cbc7926cfbd65 (diff) | |
| download | minishell-c5cde6afd3cecb44bbe9da0c28d970524da80228.tar.gz minishell-c5cde6afd3cecb44bbe9da0c28d970524da80228.tar.bz2 minishell-c5cde6afd3cecb44bbe9da0c28d970524da80228.zip | |
probleme
token ok reste trim and exception
ok
Diffstat (limited to 'src/lexer/lexer_utils.c')
| -rw-r--r-- | src/lexer/lexer_utils.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c new file mode 100644 index 0000000..72d8288 --- /dev/null +++ b/src/lexer/lexer_utils.c @@ -0,0 +1,89 @@ + +#include "lexer.h" + + + +enum e_token_tag ret_token_sep_redir_append(char *input, int i) +{ + if (input[i + 1] == '>') + return(LTAG_REDIR_APPEND); + return (LTAG_REDIR_OUT); + +} + +enum e_token_tag ret_token(char *input, int i) +{ + if (input[i] == ';') + return(LTAG_AND); + if (input[i] == '&') + return(LTAG_END); + if (input[i] == '|' && input[i + 1] == '|') + return(LTAG_OR); + if(input[i] == '|') + return(LTAG_PIPE); + if (input[i] == '>') + return(ret_token_sep_redir_append(input,i)); + if (input[i] == '<') + return(LTAG_REDIR_IN); + if (input[i] == '(') + return(LTAG_PARENT_OPEN); + if (input[i] == ')') + return(LTAG_PARENT_CLOSE); + return(0); + +} + + +int lexer_sep(char input) +{ + char *sep; + int i; + + i = 0; + sep = ";&|><()"; + while(sep[i] != '\0') + { + if(sep[i] == input) + return(1); + i++; + } + return (0); +} + +int lexe_space(char *input) +{ + int i; + + i=0; + while(input[i] == ' ') + i++; + return(i); +} + +static int lex_verif_simple_cote(char *input, int i) +{ + i++; + while(input[i] != '\0') + { + ++i; + if(input[i] == '\'') + break; + } + if (input[i + 1] == ' ') + while(input[i + 1] == ' ') + i++; + return(i + 1); +} + +int lexer_verif_entre_cote(char *input, int i) +{ + if(input[i] == '\'') + return(lex_verif_simple_cote(input, i)); + i++; + while(input[i] != '"' && (input[i] != '\0')) + ++i; + if (input[i + 1] == ' ') + while(input[i + 1] == ' ') + i++; + return(i + 1); +} |
