aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--include/minishell.h45
m---------libft0
-rw-r--r--src/builtin/cd.c0
-rw-r--r--src/builtin/echo.c0
-rw-r--r--src/builtin/env.c0
-rw-r--r--src/builtin/exit.c0
-rw-r--r--src/builtin/export.c0
-rw-r--r--src/builtin/pwd.c0
-rw-r--r--src/builtin/unset.c0
-rw-r--r--src/environment.c0
-rw-r--r--src/main.c3
-rw-r--r--src/parse.c6
-rw-r--r--src/path.c104
14 files changed, 156 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index c770274..f9480e1 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/02/03 04:14:24 by cacharle #+# #+# #
-# Updated: 2020/02/03 04:14:25 by cacharle ### ########.fr #
+# Updated: 2020/02/27 17:58:16 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -19,12 +19,14 @@ LIBFTDIR = libft
INCLUDEDIR = include
SRCDIR = src
OBJDIR = obj
+OBJDIRS = $(shell find $(SRCDIR) -type d | sed 's/src/$(OBJDIR)/')
INCLUDEFILES = minishell.h
INCLUDE = $(addprefix $(INCLUDEDIR)/, $(INCLUDEFILES))
-SRCFILES = main.c
-SRC = $(addprefix $(SRCDIR)/, $(SRCFILES))
+SRCFILES = $(shell find $(SRCDIR) -name "*.c")
+SRC = $(SRCFILES)
+# SRC = $(addprefix $(SRCDIR)/, $(SRCFILES))
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
@@ -35,15 +37,15 @@ LDFLAGS = -L$(LIBFTDIR) -lft
NAME = minishell
.PHONY: all
-all: libft_all make_obj_dir $(NAME)
+all: libft_all prebuild $(NAME)
.PHONY: test
test:
./$(TESTEXEC)
-.PHONY: make_obj_dir
-make_obj_dir:
- @if [ ! -d "$(OBJDIR)" ]; then echo "Making object dir"; mkdir $(OBJDIR); fi
+.PHONY: prebuild
+prebuild:
+ @for subdir in $(OBJDIRS); do echo "Making dir $$subdir"; mkdir -p $$subdir; done
$(NAME): $(OBJ)
@echo "Linking: $@"
diff --git a/include/minishell.h b/include/minishell.h
index f273a6f..cc28e10 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -6,22 +6,26 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */
-/* Updated: 2020/02/26 16:10:56 by cacharle ### ########.fr */
+/* Updated: 2020/02/27 18:07:06 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
+# include <stdlib.h>
+# include <string.h>
+# include <unistd.h>
+# include <fcntl.h>
+# include <dirent.h>
+# include <sys/wait.h>
+# include <signal.h>
+# include <sys/stat.h>
+
# include "libft.h"
# include "libft_ht.h"
-
-
-typedef struct
-{
- int argc;
- char **argv;
-} t_command;
+# include "libft_lst.h"
+# include "libft_util.h"
typedef int t_status;
@@ -45,9 +49,6 @@ typedef struct
t_ftlst *redirections;
} t_command;
-// parsing steps
-// 1. interpolation des variable
-
typedef enum
{
SEPARATOR_SEMICOLON,
@@ -69,6 +70,28 @@ typedef struct
t_parsing *ms_parse(char *input);
/*
+** path.c
+*/
+
+typedef struct
+{
+ t_ftht *commands;
+ t_ftlst *dirs;
+} t_path;
+
+t_path *ms_path_update(t_path *path, const char *path_str);
+void ms_path_destroy(t_path *path);
+
+/*
+** environment.c
+*/
+
+// t_ftht *ms_environment_update(t_ftht *environment, char **envp);
+// char **ms_environment_(t_ftht *environment, char **envp);
+// void ms_environment_destroy(t_ftht *environment);
+
+
+/*
** builtin*.c
*/
diff --git a/libft b/libft
-Subproject 08e90bf28afbad52e9768469304c8eec08a5d80
+Subproject 8c25da5fc72aee70bca61130103416f1f68d3e7
diff --git a/src/builtin/cd.c b/src/builtin/cd.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/cd.c
diff --git a/src/builtin/echo.c b/src/builtin/echo.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/echo.c
diff --git a/src/builtin/env.c b/src/builtin/env.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/env.c
diff --git a/src/builtin/exit.c b/src/builtin/exit.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/exit.c
diff --git a/src/builtin/export.c b/src/builtin/export.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/export.c
diff --git a/src/builtin/pwd.c b/src/builtin/pwd.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/pwd.c
diff --git a/src/builtin/unset.c b/src/builtin/unset.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/builtin/unset.c
diff --git a/src/environment.c b/src/environment.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/environment.c
diff --git a/src/main.c b/src/main.c
index fde85b7..d4c6729 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,9 @@
int main(int argc, char **argv, char **envp)
{
+ (void)argc;
+ (void)argv;
+ (void)envp;
// init
// find executable in PATH
diff --git a/src/parse.c b/src/parse.c
new file mode 100644
index 0000000..b4bb994
--- /dev/null
+++ b/src/parse.c
@@ -0,0 +1,6 @@
+#include "minishell.h"
+
+t_parsing *ms_parse(char *input)
+{
+ return NULL;
+}
diff --git a/src/path.c b/src/path.c
new file mode 100644
index 0000000..0a9dbd1
--- /dev/null
+++ b/src/path.c
@@ -0,0 +1,104 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* path.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */
+/* Updated: 2020/02/27 18:07:16 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "minishell.h"
+
+static void st_path_command_entry_del(t_ftht_content *content)
+{
+ if (content == NULL)
+ return ;
+ free(content->key);
+ free(content->value);
+}
+
+static int st_in_dirs(char **dirs, char *dir)
+{
+ while (*dirs != NULL)
+ if (ft_strcmp(*dirs++, dir) == 0)
+ return (TRUE); // maybe change ft_lstremove_if func to cmp instead of bool
+ return (FALSE);
+}
+
+static t_path *st_path_commands_update(t_path *path, char *dirname)
+{
+ DIR *dir;
+ struct dirent *entry;
+ char *tmp;
+
+ if ((dir = opendir(dirname)) == NULL)
+ return (NULL);
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if ((tmp = ft_strjoin(dirname, entry->d_name)) == NULL)
+ return (NULL);
+ if (ft_htset(path->commands, entry->d_name, st_path_command_entry_del) == NULL)
+ return (NULL);
+ }
+ if (closedir(dir) == -1)
+ return (NULL);
+ return (path);
+}
+
+/*
+** Update path list with `dirname`
+*/
+
+static t_path *st_path_dir_update(t_path *path, char *dirname)
+{
+ t_ftlst *front;
+
+ if (ft_lstlfind(path->dirs, (int (*)(void*, void*))ft_strcmp, dirname) == NULL)
+ {
+ if ((dirname = ft_strdup(dirname)) == NULL)
+ return (NULL);
+ if ((front = ft_lstnew(dirname)) == NULL)
+ {
+ free(dirname);
+ return (NULL);
+ }
+ ft_lstadd_front(&path->dirs, front);
+ }
+ return (st_path_commands_update(path, dirname));
+}
+
+/*
+** Update (or create if `path` is NULL) `path` according to `path_str`
+** (each directory is separated by a ':').
+*/
+
+t_path *ms_path_update(t_path *path, const char *path_str)
+{
+ int i;
+ char **dirs;
+
+ if (path == NULL)
+ if ((path = malloc(sizeof(t_path))) == NULL)
+ return (NULL);
+ if ((dirs = ft_split(path_str, ':')) == NULL)
+ return (NULL);
+ ft_lstremove_if(&path->dirs, (t_ftbool (*)(void*, void*))st_in_dirs, free, (void*)dirs); // change t_ftbool to std bool
+ i = -1;
+ while (dirs[i] != NULL)
+ if (st_path_dir_update(path, dirs[i]) == NULL)
+ return (ft_split_destroy(dirs));
+ ft_split_destroy(dirs);
+ return (path);
+}
+
+void ms_path_destroy(t_path *path)
+{
+ if (path == NULL)
+ return ;
+ ft_lstclear(&path->dirs, free);
+ ft_htdestroy(path->commands, st_path_command_entry_del);
+ free(path);
+}