blob: d7fe8f424d41b744ff83ad616f2e33881ee50b25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#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_sep(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);
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] == ' ')
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] == '\'')
break;
}
if (input[i + 1] == ' ')
while(input[i] == ' ')
i++;
return(i + 1);
}
|