aboutsummaryrefslogtreecommitdiff
path: root/test_mini
diff options
context:
space:
mode:
Diffstat (limited to 'test_mini')
-rwxr-xr-xtest_mini/a.outbin17620 -> 17636 bytes
-rw-r--r--test_mini/cat36
-rw-r--r--test_mini/lexer.c6
-rw-r--r--test_mini/lexer_utils.c43
-rw-r--r--test_mini/main.c27
-rw-r--r--test_mini/speudo_code55
6 files changed, 97 insertions, 70 deletions
diff --git a/test_mini/a.out b/test_mini/a.out
index 9622ab0..4d79529 100755
--- a/test_mini/a.out
+++ b/test_mini/a.out
Binary files differ
diff --git a/test_mini/cat b/test_mini/cat
new file mode 100644
index 0000000..45dcc70
--- /dev/null
+++ b/test_mini/cat
@@ -0,0 +1,36 @@
+ARGV:
+[0] ./a.out
+[1] echo
+[2] salutsalut
+[3] parfait
+
+ENV:
+[0] USER=nassimehaddacha
+[1] PATH=/Users/nassimehaddacha/miniconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/nassimehaddacha/miniconda/bin:/Users/nassimehaddacha/miniconda3/condabin
+[2] LOGNAME=nassimehaddacha
+[3] SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.VYiVzHotCo/Listeners
+[4] HOME=/Users/nassimehaddacha
+[5] SHELL=/bin/zsh
+[6] __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x62
+[7] TMPDIR=/var/folders/3s/wv71r7ws2hj4d1ss15_3vg4w0000gn/T/
+[8] XPC_SERVICE_NAME=0
+[9] XPC_FLAGS=0x0
+ARGV:
+[0] ./a.out
+[1] echo
+[2] salutsalut
+[3] parfait
+
+ENV:
+[0] USER=nassimehaddacha
+[1] PATH=/Users/nassimehaddacha/miniconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/nassimehaddacha/miniconda/bin:/Users/nassimehaddacha/miniconda3/condabin
+[2] LOGNAME=nassimehaddacha
+[3] SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.VYiVzHotCo/Listeners
+[4] HOME=/Users/nassimehaddacha
+[5] SHELL=/bin/zsh
+[6] __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x62
+[7] TMPDIR=/var/folders/3s/wv71r7ws2hj4d1ss15_3vg4w0000gn/T/
+[8] XPC_SERVICE_NAME=0
+[9] XPC_FLAGS=0x0
+echo4
+0
diff --git a/test_mini/lexer.c b/test_mini/lexer.c
index c847c1d..75197d6 100644
--- a/test_mini/lexer.c
+++ b/test_mini/lexer.c
@@ -10,6 +10,8 @@ int len_is_not_sep(char *input)
i = -1;
while(input[++i])
{
+ if (input[i] == '\\' && input[i + 1] == ' ')
+ i += 2;
if (lexer_sep(input[i]))
{
if (input[i + 1] == ' ')
@@ -19,7 +21,7 @@ int len_is_not_sep(char *input)
}
if (input[i] == '\'' || input[i] == '"')
{
- i = lexer_verif_entre_cote(input, i);
+ i += lexer_verif_entre_cote(input, i);
if (input[i] == ' ')
return(i + 1);
return(i);
@@ -83,7 +85,6 @@ void check_input_out(char *input)
free(str);
i += j;
}
-
}
t_token *create_token_list(void)
@@ -92,7 +93,6 @@ t_token *create_token_list(void)
if (!(lst_token = malloc(sizeof(t_token) * 1)))
return (NULL);
-
free(lst_token);
return (lst_token);
}
diff --git a/test_mini/lexer_utils.c b/test_mini/lexer_utils.c
index 35050b3..cef83ae 100644
--- a/test_mini/lexer_utils.c
+++ b/test_mini/lexer_utils.c
@@ -56,26 +56,33 @@ int lexe_space(char *input)
return(i);
}
-int simple_cote(char *input, int i)
+int lex_verif_simple_cote(char *input, int i)
{
- int cote;
-
- cote = 39;
- if (cote == input[i])
- return (1);
- return(0);
+ 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)
{
- while((input[++i] != '"' || simple_cote(input,i)) && (input[i] != '\0'))
- ;
- //i++;
- //if(input[i] == '"' || simple_cote(input,i))
- // return(lexer_verif_entre_cote(input, i));
- //if (input[i] == ' ')
- // while(input[i] == ' ')
- // i++;
- return(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);
}
diff --git a/test_mini/main.c b/test_mini/main.c
index 88a5127..5f9175f 100644
--- a/test_mini/main.c
+++ b/test_mini/main.c
@@ -2,11 +2,32 @@
#include "lexer.h"
#include "parse/parse.h"
-int main(void)
+int main(int argc, char **argv)
{
- int i = -1;
+ int i = 0;
+ char *input;
- lexer("echo \'bonjour\' \"ssss\'");
+ input = malloc(sizeof(char) * ft_strlen(argv[1]) + 2);
+ ft_strlcpy(input, argv[1], ft_strlen(argv[1]) + 1);
+ i = ft_strlen(input);
+ input[i + 1] = '\0';
+ printf("%s\n",argv[1] );
+ printf("%s\n",input );
+ lexer(input);
+ free(input);
exit(0);
return (0);
}
+/*
+#include <stdio.h>
+int main(int argc, char **argv, char **envp)
+{
+ printf("ARGV:\n");
+ for (int i = 0; i < argc; i++)
+ printf("[%d] %s\n", i, argv[i]);
+ printf("\nENV:\n");
+ for (int i = 0; envp[i] != NULL && i < 10; i++)
+ printf("[%d] %s\n", i, envp[i]);
+ return 0;
+}
+*/
diff --git a/test_mini/speudo_code b/test_mini/speudo_code
index c6ad4c1..ef776ce 100644
--- a/test_mini/speudo_code
+++ b/test_mini/speudo_code
@@ -2,51 +2,14 @@
is_space
-t_lex *lexer(char *input)
+#include <stdio.h>
+int main(int argc, char **argv, char **envp)
{
- char **out;
- int j;
- int i;
-
- i = 0;
- j = 0;
- if (!input)
- return (0);
- i = lexer_count_nb_element(input);
- if (!(out = malloc(sizeof(char *) * i + 1)))
- return (0);
- out[i + 1] = NULL;
- out = lexer_malloc_len_elem(input,i, out);
- return(out);
-
-}
-
-
-t_ftlst *lexer(char *input)
-{
- int i;
- int j;
- char *temp;
- enum e_token_tag token;
-
- i = -1;
- j = 0;
- if (!input)
- return (0);
- while(input[++i])
- {
- if(lexer_sep(input[i]))
- {
- printf("%d\n", i - j);
- token = ret_token_sep(input, i);
- temp = malloc(sizeof(char) * i - j + 1);
- ft_strlcpy(temp, &input[j], i - j);
- j = i;
- printf("%s\n", &input[i]);
- }
-
- }
- printf("%s\n", temp);
- free(temp);
- return (0);
+ printf("ARGV:\n");
+ for (int i = 0; i < argc; i++)
+ printf("[%d] %s\n", i, argv[i]);
+ printf("\nENV:\n");
+ for (int i = 0; envp[i] != NULL && i < 10; i++)
+ printf("[%d] %s\n", i, envp[i]);
+ return 0;
}