Skip to content

Commit

Permalink
syntax error fix, we still have a problem when creating cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
vctrubio committed Feb 25, 2023
1 parent 175c723 commit 0e8e2c0
Show file tree
Hide file tree
Showing 49 changed files with 58 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"array": "c",
"string_view": "c",
"initializer_list": "c",
"utility": "c"
"utility": "c",
"sstream": "c"
}
}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LIBFT = lib/libft.a

CC = gcc

# CFLAGS = -fsanitize=address
CFLAGS = -Werror -Wall -Wextra -g -I $(HEADER) -fsanitize=address

SRCS = $(wildcard ./srcs/*.c)
Expand Down
2 changes: 1 addition & 1 deletion include/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ char **line_to_matrix(char *line);

//parse2.c
void ft_do_quote(char **output, char c);
void ft_do_pipe(char **output);
int readline_check(char **p2line);

//parse_clean.c
//for late to remove quotes- but we will do this at the very end
char *parse_clean(char **p2str);

//parse_envp.c
Expand Down
Binary file modified lib/libft.a
Binary file not shown.
1 change: 1 addition & 0 deletions lol.c”
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
“cat lol.c
Binary file modified minishell
Binary file not shown.
Binary file modified srcs/builtins.o
Binary file not shown.
Binary file modified srcs/builtins_background.o
Binary file not shown.
Binary file modified srcs/builtins_background2.o
Binary file not shown.
Binary file modified srcs/builtins_checkers.o
Binary file not shown.
Binary file modified srcs/builtins_runners.o
Binary file not shown.
2 changes: 1 addition & 1 deletion srcs/cmd_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool add_cmds(char **matrix)
validate_rl(matrix);
if (_shell()->valid_input == false)
{
printf("SYNTAX ERROR: unexpected token ...\n");
printf("\033[0;31msyntax error near unexpected token `newline'\033[0m\n");
return (false);
}
else
Expand Down
Binary file modified srcs/cmd_build.o
Binary file not shown.
Binary file modified srcs/cmd_build2.o
Binary file not shown.
Binary file modified srcs/concat.o
Binary file not shown.
Binary file modified srcs/create_files.o
Binary file not shown.
Binary file modified srcs/error.o
Binary file not shown.
Binary file modified srcs/exec.o
Binary file not shown.
Binary file modified srcs/free.o
Binary file not shown.
Binary file modified srcs/heredoc.o
Binary file not shown.
Binary file modified srcs/initializers.o
Binary file not shown.
Binary file modified srcs/loop.o
Binary file not shown.
Binary file modified srcs/loop_new.o
Binary file not shown.
Binary file modified srcs/loop_utils.o
Binary file not shown.
2 changes: 1 addition & 1 deletion srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void minishell(void)
matrix = line_to_matrix(line);
if (add_cmds(matrix) && init_remove_qt())
{
// print_tcmd(_shell()->head);
print_tcmd(_shell()->head);
pipe_commands(_shell()->head);
}
else
Expand Down
Binary file modified srcs/main.o
Binary file not shown.
Binary file modified srcs/matrix_fts.o
Binary file not shown.
Binary file modified srcs/matrix_utils.o
Binary file not shown.
60 changes: 28 additions & 32 deletions srcs/parse.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vrubio < [email protected] > +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/22 15:20:00 by vrubio #+# #+# */
/* Updated: 2022/12/22 15:20:01 by vrubio ### ########.fr */
/* */
/* ************************************************************************** */

#include "../include/minishell.h"
//parsing of quotes

static char *buffer_quotes(char **buff, char c, char *str, int i)
{
Expand All @@ -33,7 +20,6 @@ static char *buffer_scan_for_quotes(char *str)
f = 0;
k = 0;
i = -1;
c = 0;
while (str[++i])
{
if ((str[i] == '\'' || str[i] == '"'))
Expand All @@ -49,25 +35,19 @@ static char *buffer_scan_for_quotes(char *str)
return (str);
}

static void buffer2string_quotes(char **buff, char **str, int *i)
int check_last_char_if_its_pipe(char *str)
{
if (ft_strexist("'\"\2", **buff) && *(*buff) != '\0' && *(*buff
+ 1) == **buff)
(*buff) += 2;
if (ft_strexist("'\"\2", **buff) && *(*buff) != '\0' && (**buff
+ 1 != **buff))
(*str) = buffer_quotes(&(*buff), **buff, (*str), *i);
else if (**buff)
(*str)[(*i)++] = *(*buff)++;
int i;

i = ft_strlen(str);
if (str[i - 1] == '|')
return (1);
return (0);
}

static char *buffer_to_string(char **buff)
static char *buffer_to_string(char **buff, int i, char *str)
{
char *str;
int i;

str = ft_calloc(sizeof(char), (ft_strlen(*buff) + 1));
i = 0;
str = calloc(sizeof(char), (ft_strlen(*buff) + 1));
while (**buff)
{
i = ft_strlen(str);
Expand All @@ -82,7 +62,12 @@ static char *buffer_to_string(char **buff)
str[i++] = *(*buff)++;
return (str);
}
buffer2string_quotes(buff, &str, &i);
if ((**buff == '\'' || **buff == '"') && *(*buff + 1) == **buff)
(*buff) += 2;
if ((**buff == '\'' || **buff == '"') && (**buff + 1 != **buff))
str = buffer_quotes(&(*buff), **buff, str, i);
else if (**buff)
str[i++] = *(*buff)++;
}
return (buffer_scan_for_quotes(str));
}
Expand All @@ -91,17 +76,28 @@ char **line_to_matrix(char *line)
{
char **matrix;
int i;
char *buff;

matrix = malloc(sizeof(char *) * (r_size(line) + 1));
buff = NULL;
matrix = malloc(sizeof(char *) * (r_size(line) + 4));
i = 0;
while (*line)
{
while (ft_isspace(*line))
line++;
if (!line || ft_strlen(line) == 0)
break ;
matrix[i++] = buffer_to_string(&line);
matrix[i++] = buffer_to_string(&line, 0, NULL);
}
if (matrix[i - 1] && check_last_char_if_its_pipe(matrix[i - 1]))
{
while (!buff || ft_strlen(buff) == 0)
buff = readline("pipe> ");
add_history(buff);
matrix[i++] = ft_strdup(buff);
free (buff);
}
matrix[i] = 0;
print_arrays(matrix);
return (matrix);
}
Binary file modified srcs/parse.o
Binary file not shown.
19 changes: 19 additions & 0 deletions srcs/parse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ void ft_do_quote(char **output, char c)
ft_do_quote(output, c);
}

void ft_do_pipe(char **output)
{
char *buff;
char *tmp;

buff = readline("pipe> ");
if (ft_strlen(buff) == 0)
ft_do_pipe(output);
else
{
add_history(buff);
tmp = ft_strdup(buff);
ft_stradd(&(*output), tmp);
free(buff);
free(tmp);
}
}


int readline_check(char **p2line)
{
char *line;
Expand Down
Binary file modified srcs/parse2.o
Binary file not shown.
1 change: 1 addition & 0 deletions srcs/parse_clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ char *parse_clean(char **p2str)
i = 0;
while (*str)
{
// printf("EVAL----%s\n", str);
if (*str == 2 || *str == '\'' || *str == '"')
{
c = *str++;
Expand Down
Binary file modified srcs/parse_clean.o
Binary file not shown.
Binary file modified srcs/parse_env.o
Binary file not shown.
Binary file modified srcs/path.o
Binary file not shown.
Binary file modified srcs/piping.o
Binary file not shown.
Binary file modified srcs/piping2.o
Binary file not shown.
Binary file modified srcs/piping_redir.o
Binary file not shown.
Binary file modified srcs/prompt.o
Binary file not shown.
Binary file modified srcs/shell.o
Binary file not shown.
Binary file modified srcs/tester.o
Binary file not shown.
Binary file modified srcs/utils2.o
Binary file not shown.
Binary file modified srcs/utils_array.o
Binary file not shown.
Binary file modified srcs/utils_fd.o
Binary file not shown.
Binary file modified srcs/utils_parsing.o
Binary file not shown.
7 changes: 3 additions & 4 deletions srcs/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ static void ft_validate_pipe_matrix(char **line, int i, int j)
_shell()->valid_input = false;
}
}
if (line[i + 1] == NULL)
_shell()->valid_input = false;
}

static void ft_validate_redir_output_matrix(char **line, int i)
Expand Down Expand Up @@ -64,9 +62,10 @@ void validate_rl(char **matrix)
j = -1;
while (matrix[i][++j])
{
if (matrix[i][j] == '\"' || matrix[i][j] == '\'')

if (matrix[i][j] == '"' || matrix[i][j] == '\'')
{
c = matrix[i][j];
c = matrix[i][j++];
while (matrix[i][j] && matrix[i][j] != c)
j++;
}
Expand Down
Binary file modified srcs/validation.o
Binary file not shown.
Binary file modified srcs/var_expansion.o
Binary file not shown.

0 comments on commit 0e8e2c0

Please sign in to comment.