diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-13 12:01:52 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-13 12:01:52 +0200 |
| commit | d93d65f4c73332e2b3ac9af368f996d654ece06c (patch) | |
| tree | 1c32b59fdfec26f65ff09a138a253a5acc82db3e /src/lexer/lexer_utils.c | |
| parent | f08325f76ba4aac15dc3125b7779045956863a4b (diff) | |
| parent | 72ec3b700e8e3142eb9e79098a357f01a6085589 (diff) | |
| download | minishell-d93d65f4c73332e2b3ac9af368f996d654ece06c.tar.gz minishell-d93d65f4c73332e2b3ac9af368f996d654ece06c.tar.bz2 minishell-d93d65f4c73332e2b3ac9af368f996d654ece06c.zip | |
Merge remote-tracking branch 'origin/lexer'
Diffstat (limited to 'src/lexer/lexer_utils.c')
| -rw-r--r-- | src/lexer/lexer_utils.c | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c index f028113..986db50 100644 --- a/src/lexer/lexer_utils.c +++ b/src/lexer/lexer_utils.c @@ -1,13 +1,42 @@ - #include "lexer.h" -int lexer_sep(char input) +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 = ";&<>|"; + sep = ";&|><()"; while(sep[i] != '\0') { if(sep[i] == input) @@ -17,12 +46,40 @@ int lexer_sep(char input) return (0); } -int lexer_verif_entre_cote(char *input, int i) +int lexe_space(char *input) { - while((input[++i] != '"' || input[i] == '\'') && (input[i] != '\0')) - ; - i++; - if(input[i] == '"' || input[i] == '\'') - return(lexer_verif_entre_cote(input, i)); + 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); +} |
