aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/eval.h6
-rw-r--r--include/lexer.h66
-rw-r--r--include/minishell.h12
-rw-r--r--include/parser.h5
-rw-r--r--src/eval/operation.c4
-rw-r--r--src/main.c3
-rw-r--r--src/parser/parser.c4
-rw-r--r--src/setup.c15
8 files changed, 53 insertions, 62 deletions
diff --git a/include/eval.h b/include/eval.h
index 2aa4f1d..e2f3c8b 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:30 by charles #+# #+# */
-/* Updated: 2020/10/06 17:22:12 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:40:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,7 @@
# include "lexer.h"
# include "parser.h"
-typedef struct
+typedef struct s_fork_param_args
{
t_env env;
t_ast *ast;
@@ -37,7 +37,7 @@ typedef struct
t_builtin_entry *builtin;
} t_fork_param_cmd;
-typedef int (*t_wrapped_func)(void *param);
+typedef int (*t_wrapped_func)(void *param);
# define FD_NONE -2
# define FD_WRITE 1
diff --git a/include/lexer.h b/include/lexer.h
index 72480d5..36dfd5b 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */
-/* Updated: 2020/10/08 17:38:33 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:44:09 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,25 +43,25 @@
** \param TAG_IS_SEP all of separator tags
*/
-enum e_tok
+enum e_tok
{
- TAG_AND = 1 << 0,
- TAG_END = 1 << 1,
- TAG_OR = 1 << 2,
- TAG_PIPE = 1 << 3,
- TAG_REDIR_IN = 1 << 4,
- TAG_REDIR_OUT = 1 << 5,
+ TAG_AND = 1 << 0,
+ TAG_END = 1 << 1,
+ TAG_OR = 1 << 2,
+ TAG_PIPE = 1 << 3,
+ TAG_REDIR_IN = 1 << 4,
+ TAG_REDIR_OUT = 1 << 5,
TAG_REDIR_APPEND = 1 << 6,
- TAG_PARENT_OPEN = 1 << 7,
+ TAG_PARENT_OPEN = 1 << 7,
TAG_PARENT_CLOSE = 1 << 8,
- TAG_STR = 1 << 9,
- TAG_STR_DOUBLE = 1 << 10,
- TAG_STR_SINGLE = 1 << 11,
- TAG_STICK = 1 << 12,
-
- TAG_IS_STR = TAG_STR | TAG_STR_SINGLE | TAG_STR_DOUBLE,
- TAG_IS_REDIR = TAG_REDIR_IN | TAG_REDIR_OUT | TAG_REDIR_APPEND,
- TAG_IS_SEP = TAG_AND | TAG_END | TAG_OR,
+ TAG_STR = 1 << 9,
+ TAG_STR_DOUBLE = 1 << 10,
+ TAG_STR_SINGLE = 1 << 11,
+ TAG_STICK = 1 << 12,
+
+ TAG_IS_STR = TAG_STR | TAG_STR_SINGLE | TAG_STR_DOUBLE,
+ TAG_IS_REDIR = TAG_REDIR_IN | TAG_REDIR_OUT | TAG_REDIR_APPEND,
+ TAG_IS_SEP = TAG_AND | TAG_END | TAG_OR,
};
/*
@@ -86,11 +86,16 @@ typedef struct s_tok_lst
} t_tok_lst;
t_tok_lst *tok_lst_new(enum e_tok tag, char *content);
-t_tok_lst *tok_lst_new_until(enum e_tok tag, char *content, size_t n);
-void tok_lst_push_back(t_tok_lst **tokens, t_tok_lst *pushed);
-t_tok_lst *tok_lst_push_front(t_tok_lst **tokens, t_tok_lst *pushed);
-void tok_lst_pop_front(t_tok_lst **tokens, void (*del)(void*));
-void *tok_lst_destroy(t_tok_lst **tokens, void (*del)(void*));
+t_tok_lst *tok_lst_new_until(
+ enum e_tok tag, char *content, size_t n);
+void tok_lst_push_back(
+ t_tok_lst **tokens, t_tok_lst *pushed);
+t_tok_lst *tok_lst_push_front(
+ t_tok_lst **tokens, t_tok_lst *pushed);
+void tok_lst_pop_front(
+ t_tok_lst **tokens, void (*del)(void*));
+void *tok_lst_destroy(
+ t_tok_lst **tokens, void (*del)(void*));
t_tok_lst *tok_lst_last(t_tok_lst *tokens);
t_tok_lst *tok_lst_uncons(t_tok_lst **tokens);
@@ -98,27 +103,26 @@ t_tok_lst *tok_lst_uncons(t_tok_lst **tokens);
** lexer.c
*/
-int len_until_sep(char *input);
+int len_until_sep(char *input);
int tok_len(char *input);
t_tok_lst *create_token_list(char *input, t_tok_lst **lst);
int lexer(char *input, t_tok_lst **out);
-
/*
** utils.c
*/
-enum e_tok tok_assign_tag(char *content);
-enum e_tok tok_assign_stick(t_tok_lst *tok);
-enum e_tok tok_assign_str(t_tok_lst *tok);
-int lexer_sep(char input);
-int lexer_space(char *input);
-int quote_len(char *input, int i);
+enum e_tok tok_assign_tag(char *content);
+enum e_tok tok_assign_stick(t_tok_lst *tok);
+enum e_tok tok_assign_str(t_tok_lst *tok);
+int lexer_sep(char input);
+int lexer_space(char *input);
+int quote_len(char *input, int i);
/*
** trim.c
*/
-int lexer_trim(t_tok_lst *lst);
+int lexer_trim(t_tok_lst *lst);
#endif
diff --git a/include/minishell.h b/include/minishell.h
index cba92df..b878f41 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -6,13 +6,12 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */
-/* Updated: 2020/10/09 12:41:09 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:45:24 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
-#include <stdio.h> // for debugging - dont remove
/*
** \file minishell.h
@@ -73,7 +72,9 @@ extern t_state g_state;
** path.c
*/
-int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], bool print);
+int path_search(
+ t_env env, char *exec_name,
+ char exec_path[PATH_MAX + 1], bool print);
/*
** env.c
@@ -101,7 +102,7 @@ typedef int (*t_builtin_func)(char **argv, t_env env);
** \param func Associated function
*/
-typedef struct
+typedef struct s_builtin_entry
{
char *name;
t_builtin_func func;
@@ -123,7 +124,8 @@ int builtin_exit(char **argv, t_env env);
*/
char **preprocess(t_tok_lst **tokens, t_env env);
-int preprocess_filename(t_tok_lst **tokens, t_env env, char **filename);
+int preprocess_filename(
+ t_tok_lst **tokens, t_env env, char **filename);
/*
** signal.c
diff --git a/include/parser.h b/include/parser.h
index b00407c..126ef8d 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -6,7 +6,7 @@
/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */
-/* Updated: 2020/10/07 16:33:16 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:45:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -36,7 +36,7 @@
# include "lexer.h"
# include "error.h"
-struct s_ast;
+struct s_ast;
/*
** \brief Operation struct
@@ -122,5 +122,4 @@ t_parsed *parse_op(t_tok_lst *input);
t_parsed *parse_expr(t_tok_lst *input);
t_parsed *parse_cmd(t_tok_lst *input);
-
#endif
diff --git a/src/eval/operation.c b/src/eval/operation.c
index cb7de34..6ec41f9 100644
--- a/src/eval/operation.c
+++ b/src/eval/operation.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 15:27:22 by charles #+# #+# */
-/* Updated: 2020/10/08 16:59:42 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 14:00:04 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -80,7 +80,7 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
dup2(prev_output, STDIN_FILENO);
close(prev_output);
}
- close(p[FD_WRITE]);
+ /* close(p[FD_WRITE]); */
fds[0] = FD_NONE;
fds[1] = FD_NONE;
exit(eval(fds, env, curr->data));
diff --git a/src/main.c b/src/main.c
index 0e1b29d..baa03b5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/10/09 12:39:36 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:57:22 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,7 +43,6 @@ int execute(t_env env, char *input)
parser_out = parse(lexer_out);
if (parser_out == NULL || parser_out->syntax_error)
{
- ast_destroy(parser_out->ast);
free(parser_out);
return (2);
}
diff --git a/src/parser/parser.c b/src/parser/parser.c
index 9d5a99d..cac820c 100644
--- a/src/parser/parser.c
+++ b/src/parser/parser.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */
-/* Updated: 2020/10/09 12:35:51 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:58:05 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -225,8 +225,8 @@ t_parsed *parse_expr(t_tok_lst *input)
tmp = parse_redir(input, &parsed->ast->redirs);
if (tmp == NULL || tmp->syntax_error)
return (tmp);
- free(tmp);
input = tmp->rest;
+ free(tmp);
}
parsed->rest = input;
return (parsed);
diff --git a/src/setup.c b/src/setup.c
index e069dba..844b9e4 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/16 15:46:09 by charles #+# #+# */
-/* Updated: 2020/10/07 11:21:14 by cacharle ### ########.fr */
+/* Updated: 2020/10/09 13:38:34 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,21 +29,8 @@ bool setup_env(t_env env)
!st_export_default(env, "SHLVL", "1") ||
!st_export_default(env, "PATH", "/sbin:"))
return (false);
-
- /* char *path_str = env_search(env, "PATH"); */
- /* if (ft_strstr(path_str, "/sbin") == NULL) */
- /* { */
- /* char *value = ft_strjoin("/sbin:", path_str); */
- /* env_export(env, "PATH", value); */
- /* free(value); */
- /* } */
-
if (path_search(env, "env", buf, false) != 0)
- {
ft_strcpy(buf, "/sbin/env");
- /* errorf("env: command not found\n"); */
- /* return (127); */
- }
env_export(env, "_", buf);
return (true);
}