Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executor merge #14

Merged
merged 93 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
0683ca5
🔧 chore(Makefile): update SRC variable to include 'lists/init' file
LithiumOx Jul 13, 2023
5cc22c0
🔀 chore(enum.h): update enum values and comments
LithiumOx Jul 15, 2023
5b29f05
Merge branch 'check_bad_quotes_parantheses' into lists+enum+struct
LithiumOx Jul 15, 2023
4a240dc
🔧 chore(c_cpp_properties.json): update includePath for Mac configuration
LithiumOx Jul 15, 2023
61c53f6
🔧 fix(c_cpp_properties.json): update include paths to include subdire…
LithiumOx Jul 16, 2023
5c1cbd5
🔧 fix(minishell.h): update last modified timestamp
LithiumOx Jul 17, 2023
e926911
🔧 chore(Makefile): fix typo in INCLUDES variable
LithiumOx Jul 17, 2023
02dfb7f
🐛 fix(libft): update subproject commit hash
LithiumOx Jul 17, 2023
f5a7657
🔀 chore(libft): update subproject commit hash
LithiumOx Jul 17, 2023
02b94e5
🐛 fix(main.c): remove unnecessary printf statement and free memory in…
LithiumOx Jul 17, 2023
eb4349f
📝 chore(launch.json): add launch configuration for debugging
LithiumOx Jul 17, 2023
3af23d3
🐛 fix(launch.json): update launch arguments to a longer string
LithiumOx Jul 17, 2023
ed49ebd
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 17, 2023
761a2cc
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 17, 2023
43b3dbc
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 17, 2023
b731b03
🐛 fix(main.c): fix typo in variable name 'lenght' to 'length' in pret…
LithiumOx Jul 17, 2023
65a3005
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 18, 2023
a54318d
🐛 fix(main.c): fix indentation in pretty_print_vector function
LithiumOx Jul 18, 2023
26a5da0
🔧 chore(launch.json): update args in Debug configuration
LithiumOx Jul 18, 2023
28574ac
🔀 chore(libft): update libft submodule to commit 9f4b1373abd91ac57a2f…
LithiumOx Jul 18, 2023
7d9a9e6
🐛 fix(enum.h): update timestamp in file header
LithiumOx Jul 18, 2023
9b29e5d
🐛 fix(main.c): fix typo in variable name 't' to 'tokens'
LithiumOx Jul 18, 2023
a1ca21d
Merge branch 'main' into lists+enum+struct
LithiumOx Jul 18, 2023
c9e353a
🔀 chore(structs.h): update include statement for enum.h
LithiumOx Jul 18, 2023
07610cc
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 19, 2023
e207d98
🐛 fix(lexer/index.c): fix memory leak in create_quote_string function
LithiumOx Jul 19, 2023
1a766bb
makefile debugger, header define DEBUG
Jul 19, 2023
c677b86
🔧 chore(main.c): update last updated timestamp in file header
LithiumOx Jul 19, 2023
5129774
🔄 chore(libft): update libft submodule to commit db80f60
LithiumOx Jul 19, 2023
4b4cd9c
🔧 chore(Makefile): add new source files to the build process to ensur…
Jul 19, 2023
f750563
🔨 chore(libft): update libft submodule to commit 1e79ca0e5fccbe5157bc…
LithiumOx Jul 19, 2023
ed0ec86
🐛 fix(server.ts): change port variable case from lowercase port to up…
Jul 19, 2023
db7eea9
🐛 fix(launch.json): update launch arguments to include additional tes…
Jul 20, 2023
5b4cc2f
🐛 fix(Makefile): remove unnecessary dependency on $(READLINE) in $(NA…
LithiumOx Jul 20, 2023
495a5f8
🐛 fix(Makefile): add missing parser/tokens2 file to the SRC variable
LithiumOx Jul 20, 2023
505f16a
🔧 fix(enum.h): add PARENTHESES enum value
LithiumOx Jul 20, 2023
b255cc3
🐛 fix(server.ts): change port variable case from lowercase port to up…
Jul 20, 2023
e3c5f82
🐛 fix(Makefile): remove unused file from source list
LithiumOx Jul 20, 2023
af8cc97
🐛 fix(launch.json): update args in Debug configuration to fix syntax …
Jul 20, 2023
335b2a4
🔧 fix(minishell.h): update timestamp in file header comments
LithiumOx Jul 20, 2023
4c7d6ea
🐛 fix(lexer/index.c): fix indentation and spacing issues in check_nex…
Jul 20, 2023
59ecb84
🐛 fix(server.ts): change port variable case from lowercase port to up…
LithiumOx Jul 20, 2023
6610f93
🐛 fix(main.c): uncomment parser function call
LithiumOx Jul 20, 2023
9f30689
🔄 chore(libft): update libft submodule to commit 3a821f1
LithiumOx Jul 20, 2023
6128e43
🔨 chore(libft): update subproject commit hash
LithiumOx Jul 21, 2023
5aa4fd0
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 21, 2023
9a0fc6a
🐛 fix(server.ts): change port variable case from lowercase port to up…
LithiumOx Jul 21, 2023
9713736
🔧 fix(main.c): update check_leaks function to include visual formatti…
LithiumOx Jul 21, 2023
45df33f
🔥 refactor(main.c): remove unused code and commented out function
LithiumOx Jul 21, 2023
306131d
🐛 fix(Makefile): add missing file 'utils/global' to SRC variable
LithiumOx Jul 21, 2023
decfc2c
🐛 fix(global.c): free env vector when exit is true in free_global fun…
LithiumOx Jul 21, 2023
ba6ea2c
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 21, 2023
3c1311f
🔄 chore(libft): update subproject commit hash
LithiumOx Jul 21, 2023
fef0dbd
🐛 fix(minishell.h): change function signature of check_quotes_paranth…
LithiumOx Jul 21, 2023
8d9b484
🔧 fix(enum.h): add ENV_QUESTION enum value to the list of types
LithiumOx Jul 21, 2023
4f8fcb4
🔧 fix(minishell.h): remove unused is_env_questionmark function
LithiumOx Jul 21, 2023
2d6f421
🐛 fix(launch.json): update program path to include current directory …
Jul 21, 2023
170f558
🔀 chore(libft): update libft submodule to commit 9cce6eca4ccf2b425ce0…
LithiumOx Jul 21, 2023
70687a6
🔧 chore(Makefile): add -fsanitize=address flag to DEBUG_FLAGS
LithiumOx Jul 24, 2023
aaa0485
🔀 chore(libft): update subproject commit hash
LithiumOx Jul 24, 2023
826c91c
🔥 refactor(token.c): remove debug print statements
LithiumOx Jul 24, 2023
9c277d7
🐛 fix(launch.json): update args value to include escaped quotes and s…
LithiumOx Jul 24, 2023
31132d8
🐛 fix(Makefile): remove address sanitizer flag from DEBUG_FLAGS
LithiumOx Jul 29, 2023
a8e47f1
bugfix: lexer, fixed ignoring first character
Jul 31, 2023
b74405b
setup, no code
Jul 31, 2023
103c1ba
only setup+explanation
Jul 31, 2023
3f031e2
inbetween commit
Aug 2, 2023
3f7500a
BRRRR heel veel text geschreven ter voorbereiding exec - removed ; fr…
JdeBaaij Aug 4, 2023
e503fc2
🔧 fix(settings.json): add file associations for "__locale" and "__str…
JdeBaaij Aug 12, 2023
2bcbf3a
🔧 fix(structs.h): update struct field names for better clarity and se…
JdeBaaij Aug 12, 2023
2d3d6d2
temp
JdeBaaij Aug 16, 2023
9cdba87
heredoc setup + structs
Aug 16, 2023
28ee1bb
moving computer
Aug 17, 2023
55ba96d
switching pc
Aug 17, 2023
95bed6e
🔧 chore(.gitignore): add .heredoc file to the repository to track her…
JdeBaaij Aug 18, 2023
35b3dfa
temp
Aug 18, 2023
2dc96ba
tmp
Aug 18, 2023
68579d4
🐛 fix(server.ts): change port variable case from lowercase port to up…
JdeBaaij Aug 19, 2023
7d42904
temp
JdeBaaij Aug 19, 2023
682e11d
🔀 chore(libft): update submodule commit reference
LithiumOx Aug 28, 2023
35008c9
🐛 fix(create_processes.c): change ft_vector_get to vector_get
LithiumOx Aug 28, 2023
61ef2e3
🐛 fix(print_vector.c): change function call from vec->get to vec_get
LithiumOx Aug 28, 2023
c6e178f
added verify_token function, started on shortening group.c function
Aug 30, 2023
bed0180
small fix on verify_token
JdeBaaij Aug 30, 2023
3007a2e
split group.c, exec is next to be completed
JdeBaaij Aug 30, 2023
7063fbd
brrrrrrrrrr
Sep 1, 2023
0a1dad0
replacing global wiht t_shell data, passing data everywhere so it can…
Sep 3, 2023
502c594
.
JdeBaaij Sep 6, 2023
86ad7e5
New plan: put type in struct to define the error + str, if a function…
Sep 6, 2023
17b9028
comment on how to proceed in todo.txt
JdeBaaij Sep 7, 2023
90887f1
more todo
JdeBaaij Sep 7, 2023
edabb67
🔧 fix(shell.c): initialize exit_type and exit_msg variables in init_s…
JdeBaaij Sep 7, 2023
bf94b4f
lexer changed to bool
JdeBaaij Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
!includes/*
!libft/*
!readline/*
!.heredoc
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[submodule "libft"]
path = libft
url = git@github.com:lithiumox-codam/libft.git
branch = minishell
[submodule "builtins"]
path = src/builtins
url = git@github.com:lithiumox-codam/built-ins.git
Expand Down
21 changes: 17 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"configurations": [
{
"name": "Mac",
"os": "mac",
"includePath": [
"${workspaceFolder}/includes",
"${workspaceFolder}/../libft",
"../libft"
"${workspaceFolder}/includes/**",
"${workspaceFolder}/libft/includes/**"
],
"macFrameworkPath": [
"/Library/Frameworks"
Expand All @@ -15,7 +15,20 @@
"cStandard": "c17",
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.makefile-tools"
},
{
"name": "Ubuntu",
"os": "linux",
"includePath": [
"${workspaceFolder}/includes/**",
"${workspaceFolder}//libft/includes/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/./minishell",
"preLaunchTask": "build",
"args": [
"\"(city \"test\" 'test' > < >> << || | && () )\""
],
"cwd": "${workspaceFolder}"
}
]
}
14 changes: 13 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@
"comments": false,
"strings": false
},
},
"files.associations": {
"sstream": "c",
"__locale": "c",
"__string": "c",
"array": "c",
"iterator": "c",
"string": "c",
"string_view": "c",
"vector": "c",
"minishell.h": "c",
"random": "c"
}
}
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make re DEBUG=1",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$tsc"
]
},
]
}
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
NAME = minishell
SRC = main \
check_input
SRC = main check_input utils/error structs/token structs/group parser/index parser/token_vec2 parser/quotes parser/token_vec debug/print_vector lexer/index lexer/string lexer/token lexer/op_split structs/env structs/shell group/group group/heredoc parser/verify_token exec/exec exec/create_processes exec/redirect exec/exec_process utils/miscellaneous exec/utils
SRCS = $(addsuffix .c, $(addprefix src/, $(SRC)))
OBJS = $(patsubst src/%.c, build/%.o, $(SRCS))
LIBFT = libft/libft.a
READLINE = readline/libreadline.a

DEBUG ?= 0
DEBUG_FLAGS = -g
G_FLAGS = -DREADLINE_LIBRARY
CODAM_FLAGS = -Wall -Wextra -Werror
LIBS = libft/libft.a readline/libreadline.a readline/libhistory.a
LINKER = -lncurses
INCLUDES = -I $(CURDIR)/includes -I $(CURDIR)/libft -I $(CURDER)/readline
INCLUDES = -I $(CURDIR)/includes -I $(CURDIR)/libft/includes -I $(CURDER)/readline

COLOR_INFO = \033[1;36m
COLOR_SUCCESS = \033[1;32m
Expand All @@ -23,19 +24,19 @@ EMOJI_RUN = 🚀

all: $(NAME)

$(NAME): $(LIBFT) $(READLINE) $(OBJS)
$(NAME): $(LIBFT) $(OBJS)
@printf "$(COLOR_INFO)$(EMOJI_INFO) Compiling $(NAME)...$(COLOR_RESET)\t"
@cc $(OBJS) $(CODAM_FLAGS) $(LINKER) $(INCLUDES) $(LIBS) -o $@
@cc $(OBJS) $(CODAM_FLAGS) $(if DEBUG, $(DEBUG_FLAGS)) -DDEBUG=$(DEBUG) $(LINKER) $(INCLUDES) $(LIBS) -o $@
@sleep 0.25
@printf "✅\n"

build/%.o: src/%.c includes/minishell.h
build/%.o: src/%.c includes/minishell.h includes/structs.h includes/enum.h
@mkdir -p $(@D)
@cc $(INCLUDES) $(CODAM_FLAGS) -c $< -o $@
@cc $(INCLUDES) $(CODAM_FLAGS) $(if DEBUG, $(DEBUG_FLAGS)) -DDEBUG=$(DEBUG) -c $< -o $@

$(LIBFT):
@printf "$(COLOR_INFO)$(EMOJI_INFO) Initializing submodules...$(COLOR_RESET)\t"
@git submodule update --init --recursive > /dev/null
# @git submodule update --init --recursive > /dev/null
@sleep 0.25
@printf "✅\n"
@printf "$(COLOR_INFO)$(EMOJI_INFO) Building Libft...$(COLOR_RESET)\t\t"
Expand All @@ -61,7 +62,7 @@ clean:
fclean: clean
@printf "$(COLOR_INFO)$(EMOJI_CLEAN) Removing executable...$(COLOR_RESET)\t"
@$(MAKE) -C libft fclean > /dev/null
@rm -f $(LIBS)
@rm -f libft/libft.a
@rm -f $(NAME)
@sleep 0.25
@printf "✅\n"
Expand All @@ -77,6 +78,8 @@ re: fclean $(NAME)

bonus: all

readline: $(READLINE)

module-update:
@printf "$(COLOR_INFO)$(EMOJI_INFO) Updating submodules...$(COLOR_RESET)\t"
@git submodule update --remote --merge
Expand Down
87 changes: 87 additions & 0 deletions includes/enum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* enum.h :+: :+: */
/* +:+ */
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* Created: 2023/07/13 17:41:00 by mdekker/jde #+# #+# */
/* Updated: 2023/09/07 03:46:17 by mdekker/jde ######## odam.nl */
/* */
/* ************************************************************************** */

#ifndef ENUM_H
# define ENUM_H

/**
* @brief The enum for the different types of token_vec
*
* @param DOUBLE_QUOTE (")
* @param SINGLE_QUOTE (')
* @param PIPE (|)
* @param PARENTHESES (())
* @param OR (||)
* @param AND (&&)
* @param ENV ($)
* @param DQ_ENV An environment variable in double quotes ("$")
* @param ENV_QUESTION An environment variable with a question mark ("$?")
* @param STRING A string
* @param O_REDIRECT (>)
* @param I_REDIRECT (<)
* @param A_REDIRECT (>>)
* @param HEREDOC (<<)
*/
typedef enum e_types
{
UNKNOWN,
STRING,
DOUBLE_QUOTE,
SINGLE_QUOTE,
PARENTHESES,
PIPE,
OR,
AND,
ENV,
DQ_ENV,
ENV_QUESTION,
O_REDIRECT,
I_REDIRECT,
A_REDIRECT,
HEREDOC
} t_types;

/**
* @brief The enum for the different types of errors
*
* @param PERROR A perror
* @param NOT_FOUND A not found error
* @param PERMISSION A permission error
* @param SYNTAX A syntax error
* @param SYNTAX_MINI A syntax error for the minishell
* @param SIGNAL_C A signal interrupt
*
*/
typedef enum e_exit
{
GOOD,
PERROR,
MALLOC,
NOT_FOUND,
PERMISSION,
SYNTAX,
SYNTAX_MINI,
SIGNAL_C
} t_exit;

/**
* @brief defines which process is being executed
*/
typedef enum e_process
{
SINGLE,
LEFT,
RIGHT,
MIDDLE,
} t_process;

#endif
81 changes: 77 additions & 4 deletions includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,95 @@
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* Created: 2023/07/09 21:25:59 by mdekker #+# #+# */
/* Updated: 2023/07/16 14:03:45 by mdekker/jde ######## odam.nl */
/* Updated: 2023/09/06 20:29:47 by mdekker/jde ######## odam.nl */
/* */
/* ************************************************************************** */

#ifndef MINISHELL_H
# define MINISHELL_H

# include <errno.h>
# include <fcntl.h>
# include <libft.h>
# include <structs.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>
# include <stdbool.h>
# include <structs.h>
# include <unistd.h>

/* input_check */
# ifndef DEBUG
# define DEBUG 0
# endif

/* init shell */
t_shell *init_shell(char **env, bool first_init);
void free_shell(t_shell *data, bool close_shell);

/* lexer */
void lexer(char *input, t_shell *data);
bool check_quotes_parantheses(char *input);
bool create_string(char *str, size_t *i, t_vector *vec);
bool create_quote_string(char *str, size_t *i, t_vector *vec);
bool create_paran_string(char *str, size_t *i, t_vector *vec);
void operator_split(t_shell *data);
char **split(t_token *token);

/* parser */
void parser(t_shell *data);
void parse_one(t_token *token);
bool is_encased_dq(char *str);
bool is_encased_sq(char *str);
bool is_encased_parentheses(char *str);
bool is_pipe(char *str);
bool is_r_redirect(char *str);
bool is_l_redirect(char *str);
bool is_a_redirect(char *str);
bool is_heredoc(char *str);
bool contains_env_var(char *str);
bool is_or(char *str);
bool is_and(char *str);
void verify_token_vec(t_shell *data);

/* group */
void group_token_vec(t_shell *data);
void heredoc(char *filename, char *stop, t_types type, t_shell *data);

/* executor */
int executor(t_shell *data);
bool create_processes(t_shell *data);
void exec_process(t_group *group, t_process type);
void redirect_input(t_group *group, size_t i);

/* exec_utils */
bool is_built_in(char *str);
char **combine_env(t_vector *env_vec);
char **create_cmd(t_vector *input);
bool is_redirect(t_token *token);
bool is_string_type(t_token *token);

/* structs */
t_token *create_token(char *value, t_types type);
void clear_token(void *data);
t_token *dup_token(t_token *input);
t_env *create_env(char *key, char *value);
void clear_env(void *data);
t_group *create_group(void);
void clear_group(void *data);
void clear_fname(void *data);
t_exec *create_exec(void);
void clear_exec(t_exec *exec);

/* general utils */
void exit_mini(char *str, int exit_code);
void err(t_exit type, char *name, t_shell *data, bool free_struct);
char *rm_quotes(t_token *token);

/* debug */
void print_vector(t_vector *vec, void (*printer)(void *, size_t));
void print_token(void *data, size_t i);
char *print_type(t_types type);
void print_env(void *data, size_t i);

#endif
Loading
Loading