Skip to content

Commit

Permalink
Merge branch 'Lexex_Parser' into Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
frouioui committed May 25, 2018
2 parents a44a32e + 6220929 commit 70f84e1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 54 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ SRCS = $(PATH_SRC)/check_args.c \
$(PATH_SRC)/shell_loop/prompt/display_bonus_prompt.c \
$(PATH_SRC)/shell_loop/prompt/display_prompt.c \
$(PATH_SRC)/shell_loop/parsing/get_command_line.c \
$(PATH_SRC)/shell_loop/parsing/parsing/get_word.c \
$(PATH_SRC)/shell_loop/parsing/parsing/my_str_to_words.c \
$(PATH_SRC)/shell_loop/parsing/parsing/my_strcpy_words.c \
$(PATH_SRC)/shell_loop/parsing/get_number_instruction.c \
$(PATH_SRC)/shell_loop/parsing/get_pipe_number.c \
$(PATH_SRC)/shell_loop/parsing/fill_up_instruction.c \
Expand Down
6 changes: 2 additions & 4 deletions lib/my/my_str_to_words_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ char **cut_line(char *line)
tab_arg = malloc(sizeof(*tab_arg) * (nb_arg + 1));
if (tab_arg == NULL)
return (NULL);
for (int i = 0; i < nb_arg; i += 1) {
for (int i = 0; i < nb_arg; i += 1)
tab_arg[i] = copy_args(line, &j);
printf("%s\n", tab_arg[i]);
}
tab_arg[nb_arg] = NULL;
return (tab_arg);
}
}
2 changes: 1 addition & 1 deletion src/shell_loop/parsing/get_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static unsigned int get_args_pipe(pipe_t **pipe, char **env, char **local)
int a = 0;

for (unsigned int i = 0; pipe[i]; i++) {
pipe[i]->args = cut_line(pipe[i]->full_instruction);
pipe[i]->args = my_str_to_words(pipe[i]->full_instruction);
if (pipe[i]->args == NULL)
return (FAILURE);
check_env_variable(pipe[i]->args, env);
Expand Down
26 changes: 0 additions & 26 deletions src/shell_loop/parsing/parsing/count_words.c

This file was deleted.

14 changes: 2 additions & 12 deletions src/shell_loop/parsing/parsing/get_word.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/

#include "shell.h"

static void check_reset(int *i, int *j, int reset)
{
if (reset == 1) {
if (reset == 0) {
*i = 0;
*j = 0;
}
Expand Down Expand Up @@ -41,14 +42,3 @@ char *get_word(char *str, int reset)
}
return (my_strcpy_words_parse(str, j, i++));
}

int main(void)
{
//gcc get_word.c my_strcpy_words.c -I../../../../include -g3 && ./a.out
char *str = "\"lol c un test \"mdr 'xd sa march lol' ptdr";
char **st = malloc(sizeof(char*) * 4);
for (int i = 0; i < 4; i++) {
printf("LE MOT : '%s'\n", get_word(str, 0));
}
return (0);
}
24 changes: 13 additions & 11 deletions src/shell_loop/parsing/parsing/my_str_to_words.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@

char **my_str_to_words(char *str)
{
int words = count_words(str);
char **word = malloc(sizeof(char *) * (words + 1));
//gcc get_word.c my_strcpy_words.c -I../../../../include -g3 && ./a.out
//char *str = "\"lol c un test \"mdr 'xd sa march lol' ptdr";
char **words = malloc(sizeof(char*) * 1);
char *temp = NULL;

if (words == 0)
return (NULL);
for (int i = 0; i < words; i++) {
if (i == 0)
word[i] = get_word(str, 1);
else
word[i] = get_word(str, 0);
words[0] = NULL;
for (int i = 0; (temp = get_word(str, i)) != NULL; i++) {
words = realloc(words, sizeof(char*) * (i+2));
words[i] = temp;
//printf("LE MOT : '%s'\n", words[i]);
words[i+1] = NULL;
}
word[words] = NULL;
return (word);
if (words[0] == NULL)
words = NULL;
return (words);
}
2 changes: 2 additions & 0 deletions src/shell_loop/parsing/parsing/my_strcpy_words.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ char *my_strcpy_words_parse(char *str, int start, int end)
int j = 0;
char *new_str = malloc(sizeof(char) * ((end - start) + 2));

if (start == end)
return (NULL);
while (i < end && str[i] != '\0') {
new_str[j] = str[i];
i++;
Expand Down

0 comments on commit 70f84e1

Please sign in to comment.