+++ /dev/null
-{
- "configurations": [
- {
- "name": "macos-clang-x64",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "compilerPath": "/usr/bin/clang",
- "cStandard": "${default}",
- "cppStandard": "${default}",
- "intelliSenseMode": "macos-clang-x64",
- "compilerArgs": [
- ""
- ]
- }
- ],
- "version": 4
- }
\ No newline at end of file
+++ /dev/null
-{
- "version": "0.2.0",
- "configurations": [
- {
- "name": "C/C++ Runner: Debug Session",
- "type": "lldb",
- "request": "launch",
- "args": [],
- "cwd": "/Users/chuhlig/Desktop/merged_minishell/",
- "program": "/Users/chuhlig/Desktop/merged_minishell/minishell"
- }
- ]
- }
\ No newline at end of file
+++ /dev/null
-{
- "C_Cpp_Runner.cCompilerPath": "clang",
- "C_Cpp_Runner.cppCompilerPath": "clang++",
- "C_Cpp_Runner.debuggerPath": "lldb",
- "C_Cpp_Runner.cStandard": "",
- "C_Cpp_Runner.cppStandard": "",
- "C_Cpp_Runner.msvcBatchPath": "",
- "C_Cpp_Runner.useMsvc": false,
- "C_Cpp_Runner.warnings": [
- "-Wall",
- "-Wextra",
- "-Wpedantic",
- "-Wshadow",
- "-Wformat=2",
- "-Wcast-align",
- "-Wconversion",
- "-Wsign-conversion",
- "-Wnull-dereference"
- ],
- "C_Cpp_Runner.msvcWarnings": [
- "/W4",
- "/permissive-",
- "/w14242",
- "/w14287",
- "/w14296",
- "/w14311",
- "/w14826",
- "/w44062",
- "/w44242",
- "/w14905",
- "/w14906",
- "/w14263",
- "/w44265",
- "/w14928"
- ],
- "C_Cpp_Runner.enableWarnings": true,
- "C_Cpp_Runner.warningsAsError": false,
- "C_Cpp_Runner.compilerArgs": [],
- "C_Cpp_Runner.linkerArgs": [],
- "C_Cpp_Runner.includePaths": [],
- "C_Cpp_Runner.includeSearch": [
- "*",
- "**/*"
- ],
- "C_Cpp_Runner.excludeSearch": [
- "**/build",
- "**/build/**",
- "**/.*",
- "**/.*/**",
- "**/.vscode",
- "**/.vscode/**"
- ],
- "C_Cpp_Runner.useAddressSanitizer": false,
- "C_Cpp_Runner.useUndefinedSanitizer": false,
- "C_Cpp_Runner.useLeakSanitizer": false,
- "C_Cpp_Runner.showCompilationTime": false,
- "C_Cpp_Runner.useLinkTimeOptimization": false,
- "C_Cpp_Runner.msvcSecureNoWarnings": false,
- "files.associations": {
- "minishell.h": "c",
- "ast.h": "c",
- "env.h": "c"
- }
- }
\ No newline at end of file
+++ /dev/null
-{
- "tasks": [
- {
- "type": "cppbuild",
- "label": "C/C++: clang build active file",
- "command": "/usr/bin/clang",
- "args": [
- "-fcolor-diagnostics",
- "-fansi-escape-codes",
- "-g",
- "${file}",
- "-o",
- "${fileDirname}/${fileBasenameNoExtension}"
- ],
- "options": {
- "cwd": "${fileDirname}"
- },
- "problemMatcher": [
- "$gcc"
- ],
- "group": {
- "kind": "build",
- "isDefault": true
- },
- "detail": "Task generated by Debugger."
- }
- ],
- "version": "2.0.0"
-}
\ No newline at end of file
parse_cmd.c collect_redirs.c print_ast.c interpreter.c env.c \
get_cmd_path.c env_to_strlst.c execute_cmd.c format_string.c \
builtins_part_one.c builtins_part_two.c env_tools.c error.c \
- read_heredoc.c create_files.c
+ read_heredoc.c create_files.c builtins_part_three.c handle_redir.c
OBJ_DIR := _obj
OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o))
debug: CFLAGS += -fsanitize=address -fsanitize=undefined \
-fno-sanitize-recover=all -fsanitize=float-divide-by-zero \
-fsanitize=float-cast-overflow -fno-sanitize=null \
- -fno-sanitize=alignment
+ -fno-sanitize=alignment -fno-sanitize=object-size \
+ -fno-sanitize=vptr -fno-sanitize=return -fno-sanitize=signed-integer-overflow \
+ -fno-sanitize=bounds -fno-sanitize=pointer-subtract -fno-sanitize=pointer-compare
debug: CFLAGS += -DDEBUG=1
debug: clean all
+++ /dev/null
-_=/Users/chuhlig/Desktop/merged_minishell/minishell/./minishell
-TERM=xterm-256color
-USER_ZDOTDIR=/Users/chuhlig
-ZDOTDIR=/Users/chuhlig
-VSCODE_INJECTION=1
-VSCODE_GIT_IPC_HANDLE=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/vscode-git-e47956ed09.sock
-VSCODE_GIT_ASKPASS_MAIN=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js
-VSCODE_GIT_ASKPASS_EXTRA_ARGS=
-VSCODE_GIT_ASKPASS_NODE=/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin)
-GIT_ASKPASS=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
-COLORTERM=truecolor
-LANG=en_US.UTF-8
-TERM_PROGRAM_VERSION=1.95.3
-TERM_PROGRAM=vscode
-OLDPWD=/Users/chuhlig/Desktop/merged_minishell
-PWD=/Users/chuhlig/Desktop/merged_minishell/minishell
-SHLVL=1
-ORIGINAL_XDG_CURRENT_DESKTOP=undefined
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-__CF_USER_TEXT_ENCODING=0x1928E:0x0:0x2
-SHELL=/bin/zsh
-HOME=/Users/chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.ECcBYJZkxn/Listeners
-LOGNAME=chuhlig
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Users/chuhlig/goinfre/.brew/bin
-MallocNanoZone=0
-USER=chuhlig
-_=/Users/chuhlig/Desktop/merged_minishell/minishell/./minishell
-TERM=xterm-256color
-USER_ZDOTDIR=/Users/chuhlig
-ZDOTDIR=/Users/chuhlig
-VSCODE_INJECTION=1
-VSCODE_GIT_IPC_HANDLE=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/vscode-git-e47956ed09.sock
-VSCODE_GIT_ASKPASS_MAIN=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js
-VSCODE_GIT_ASKPASS_EXTRA_ARGS=
-VSCODE_GIT_ASKPASS_NODE=/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin)
-GIT_ASKPASS=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
-COLORTERM=truecolor
-LANG=en_US.UTF-8
-TERM_PROGRAM_VERSION=1.95.3
-TERM_PROGRAM=vscode
-OLDPWD=/Users/chuhlig/Desktop/merged_minishell
-PWD=/Users/chuhlig/Desktop/merged_minishell/minishell
-SHLVL=1
-ORIGINAL_XDG_CURRENT_DESKTOP=undefined
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-__CF_USER_TEXT_ENCODING=0x1928E:0x0:0x2
-SHELL=/bin/zsh
-HOME=/Users/chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.ECcBYJZkxn/Listeners
-LOGNAME=chuhlig
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Users/chuhlig/goinfre/.brew/bin
-MallocNanoZone=0
-USER=chuhlig
-
-
-//some test case about built in command
- bash-3.2$ ls
-Applications Music
-Desktop Pictures
-Documents francinette
-Downloads getting-started
-Library goinfre
-Movies setup_docker_environment
-bash-3.2$ pwd
-/Users/chuhlig
-bash-3.2$ ls | cd / | ls
-Applications Music
-Desktop Pictures
-Documents francinette
-Downloads getting-started
-Library goinfre
-Movies setup_docker_environment
-bash-3.2$ pwd
-/Users/chuhlig
-bash-3.2$ env
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$ export test=test | unset USER
-bash-3.2$ env
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$ env | grep test
-bash-3.2$ ls | cd / | env
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$ ls | cd / | env
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$ ls | cd / | env
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$ ls | cd / | env | cd /
-bash-3.2$ pwd
-/Users/chuhlig
-bash-3.2$ ls | cd / | env | cd ~
-bash-3.2$ ls | cd / | env | cd -
-bash: cd: OLDPWD not set
-bash-3.2$ ls | cd - | env
-bash: cd: OLDPWD not set
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$
-bash-3.2$ ls | cd - | env
-bash: cd: OLDPWD not set
-TERM_PROGRAM=iTerm.app
-TERM=xterm-256color
-SHELL=/bin/zsh
-TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/
-TERM_PROGRAM_VERSION=3.5.10
-TERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-USER=chuhlig
-SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BLODixwZXQ/Listeners
-__CF_USER_TEXT_ENCODING=0x0:0:0
-TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
-TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
-PATH=/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities
-PWD=/Users/chuhlig
-LANG=en_US.UTF-8
-ITERM_PROFILE=Default
-XPC_FLAGS=0x0
-XPC_SERVICE_NAME=0
-SHLVL=2
-HOME=/Users/chuhlig
-COLORFGBG=7;0
-LC_TERMINAL_VERSION=3.5.10
-ITERM_SESSION_ID=w0t0p0:EC167FE5-607B-4E5F-A816-E8EF7FA09EC7
-LOGNAME=chuhlig
-LC_TERMINAL=iTerm2
-COLORTERM=truecolor
-_=/usr/bin/env
-bash-3.2$
-
-
-//////////////////////////////////////////////////////////////////
-
-static int handle_redirections(t_redirection *redirs) {
- if (redirs[0].type == INPUT_LIMITER) {
- int pipe_fds[2];
- if (pipe(pipe_fds) == -1) {
- perror("pipe");
- return -1;
- }
- write(pipe_fds[1], redirs[0].specifier, strlen(redirs[0].specifier));
- close(pipe_fds[1]);
- dup2(pipe_fds[0], STDIN_FILENO);
- close(pipe_fds[0]);
- } else if (redirs[0].type == INPUT_FILE) {
- int fd = open(redirs[0].specifier, O_RDONLY);
- if (fd == -1) {
- perror(redirs[0].specifier);
- return -1;
- }
- dup2(fd, STDIN_FILENO);
- close(fd);
- }
-
- if (redirs[1].type == OUTPUT_OVERRIDE) {
- int fd = open(redirs[1].specifier, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (fd == -1) {
- perror(redirs[1].specifier);
- return -1;
- }
- dup2(fd, STDOUT_FILENO);
- close(fd);
- } else if (redirs[1].type == OUTPUT_APPEND) {
- int fd = open(redirs[1].specifier, O_WRONLY | O_CREAT | O_APPEND, 0644);
- if (fd == -1) {
- perror(redirs[1].specifier);
- return -1;
- }
- dup2(fd, STDOUT_FILENO);
- close(fd);
- }
- return 0;
-}
-
-static int eval_rec(t_node *node, t_env **env, int in_fd) {
- pid_t pid;
- int p[2], result;
-
- if (node->type == PIPE_NODE) {
- pipe(p);
- pid = fork();
- if (pid == 0) {
- close(p[0]);
- dup2(in_fd, STDIN_FILENO);
- dup2(p[1], STDOUT_FILENO);
- result = eval_rec(node->content.pipe.left, env, in_fd);
- exit(result);
- } else {
- close(p[1]);
- dup2(p[0], STDIN_FILENO);
- result = eval_rec(node->content.pipe.right, env, p[0]);
- }
- } else if (node->type == CMD_NODE) {
- result = execute_cmd(&node->content.cmd, env);
- } else {
- panic("UNREACHABLE");
- result = EXIT_FAILURE;
- }
- return result;
-}
-
-int eval(t_node *node, t_env **env) {
- return eval_rec(node, env, STDIN_FILENO);
-}
-
-int execute_cmd(t_cmd *cmd, t_env **env) {
- if (handle_redirections(cmd->redirs) == -1) {
- return EXIT_FAILURE;
- }
-
- if (is_builtin(cmd->args[0])) {
- return execute_builtin(cmd->args, env);
- } else {
- pid_t pid = fork();
- if (pid == 0) {
- char *cmd_path = get_cmd_path(cmd->args[0], *env);
- if (!cmd_path) {
- fprintf(stderr, "%s: command not found\n", cmd->args[0]);
- exit(EXIT_FAILURE);
- }
- execve(cmd_path, cmd->args, env_to_strlst(*env));
- perror("execve");
- exit(EXIT_FAILURE);
- } else {
- int status;
- waitpid(pid, &status, 0);
- return WEXITSTATUS(status);
- }
- }
-}
-have to update env list/tokenlist order or update the existing code to handle the order of the tokenlist/env list
-
-echo "Hello" | grep H this works
-
-also more to do on heredoc
-
-and for the for part of domenic removing the " ' frome the string
-beside
-
-
-
-t_redirection *collect_redirs(t_token **tokens)
-{
- t_redirection *result;
- t_token *cur;
-
- cur = *tokens;
- result = malloc(sizeof(t_redirection) * 2);
- if (result == NULL)
- return (free_tokens(*tokens), NULL);
- set_redir(&result[0], 0, NULL);
- set_redir(&result[1], 0, NULL);
- while (cur != NULL && cur->next != NULL)
- {
- if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)
- collect_and_check_redir(result, &cur);
- else if (cur->type == REDIR_TOKEN)
- return (free(result), NULL);
- else
- cur = cur->next;
- }
- if (cur && cur->type == REDIR_TOKEN)
- return (free(result), NULL);
- return (result);
-}
-
-static void collect_and_check_redir(t_redirection *result, t_token **cur)
-{
- char *heredoc_data;
- t_token *next_token;
-
- heredoc_data = NULL;
- if ((*cur)->content.redir_type == INPUT_LIMITER)
- {
- // Handle Here Document (<<)
- heredoc_data = read_heredoc((*cur)->next->content.string);
- if (!heredoc_data)
- {
- perror("Heredoc allocation failed");
- return ;
- }
- set_redir(&result[0], INPUT_LIMITER, heredoc_data);
- }
- else if ((*cur)->content.redir_type == INPUT_FILE)
- {
- // Handle Input File (<)
- set_redir(&result[0], INPUT_FILE, ft_strdup((*cur)->next->content.string));
- }
- else if ((*cur)->content.redir_type == OUTPUT_OVERRIDE)
- {
- // Handle Output File Overwrite (>)
- set_redir(&result[1], OUTPUT_OVERRIDE, ft_strdup((*cur)->next->content.string));
- }
- else if ((*cur)->content.redir_type == OUTPUT_APPEND)
- {
- // Handle Output File Append (>>)
- set_redir(&result[1], OUTPUT_APPEND, ft_strdup((*cur)->next->content.string));
- }
- else
- {
- // Handle unexpected cases
- printf("Unknown redirection type encountered\n");
- }
- // Advance the token pointer to skip the redirection token and its argument
- next_token = (*cur)->next;
- free_token_and_connect(*cur); // Free the current redirection token
- if (next_token)
- {
- *cur = next_token->next; // Move to the next token after the argument
- }
- else
- {
- *cur = NULL; // No more tokens
- }
-}
-
-collect args apassen x
-alsso fur arg x
-muss in rpl parse x
-und in parse cmd collect args and x
-
-format args seems to work later test x
-
-
-Test 1: ✅ echo hello world
-Test 2: ✅ echo "hello world"
-Test 3: ✅ echo 'hello world'
-Test 4: ✅ echo hello'world'
-Test 5: ✅ echo hello""world
-Test 6: ✅ echo ''
-Test 7: ✅ echo "$PWD"
-Test 8: ✅ echo '$PWD'
-
-format_string problem
-Test 9: ❌ echo "aspas ->'"
-mini output = (aspas ->")
-bash output = (aspas ->')
-Test 10: ❌ echo "aspas -> ' "
-mini output = (aspas -> ")
-bash output = (aspas -> ' )
-Test 11: ✅ echo 'aspas ->"'
-Test 12: ✅ echo 'aspas -> " '
-Test 13: ❌ echo "> >> < * ? [ ] | ; [ ] || && ( ) & # $ <<"
-mini output = (> >> < README.md bash.supp bash_outfiles bonus bonus_bonus builtins extras local.supp loop.out manual_tests mini_outfiles os_specific outfiles pipes redirects syntax test_files tester wildcards ? [ ] | ; [ ] || && ( ) & # )
-bash output = (> >> < README.md bash.supp bash_outfiles bonus bonus_bonus builtins extras local.supp loop.out manual_tests mini_outfiles os_specific outfiles pipes redirects syntax test_files tester wildcards ? [ ] | ; [ ] || && ( ) & # $ <<)
-Test 14: ✅ echo '> >> < * ? [ ] | ; [ ] || && ( ) & # $ <<'
-Test 15: ❌ echo "exit_code ->$? user ->$USER home -> $HOME"
-mini output = (exit_code ->/Users/chuhlig)
-bash output = (exit_code ->0 user ->chuhlig home -> /Users/chuhlig)
-Test 16: ✅ echo 'exit_code ->$? user ->$USER home -> $HOME'
-Test 17: ❌ echo "$"
-mini output = (0)
-bash output = ($)
-Test 18: ✅ echo '$'
-Test 19: ❌ echo $
-mini output = (0)
-bash output = ($)
-Test 20: ✅ echo $?
-Test 21: ❌ echo $?HELLO
-mini output = ()
-bash output = (0HELLO)
-Test 22: ✅ pwd
-Test 23: ✅ pwd oi
-
-Test 24: ❌ export hello //stupid
-mini exit code = 1
-bash exit code = 0
-Test 25: ✅ export HELLO=123
-Test 26: ✅⚠️ export A-
-mini error = ()
-bash error = ( not a valid identifier)
- fucking extra function for identifier
-
-Test 27: ❌ export HELLO=123 A
-mini exit code = 1
-bash exit code = 0
-auch dum
-Test 28: ✅ export HELLO="123 A-"
-Test 29: ❌ export hello world
-mini exit code = 1
-bash exit code = 0
-Test 30: ❌ export HELLO-=123
-mini exit code = 0
-bash exit code = 1
-mini error = ()
-bash error = ( not a valid identifier)
-Test 31: ❌ export =
-mini exit code = 0
-bash exit code = 1
-mini error = ()
-bash error = ( not a valid identifier)
-Test 32: ✅⚠️ export 123
-mini error = ()
-bash error = ( not a valid identifier)
-Test 33: ✅ unset
-Test 34: ✅ unset HELLO
-Test 35: ✅ unset HELLO1 HELLO2
-Test 36: ✅ unset HOME
-Test 37: ✅ unset PATH
-Test 38: ✅ unset SHELL
-
-
-Test 39: ❌ cd $PWD
-mini exit code = 139
-bash exit code = 0
-Test 40: ❌ cd $PWD hi
-mini exit code = 139
-bash exit code = 0
-Test 41: ❌ cd 123123
-mini exit code = 139
-bash exit code = 1
-mini error = ()
-bash error = ( No such file or directory)
-
-Test 42: ✅ exit 123
-Test 43: ✅ exit 298
-Test 44: ✅ exit +100
-Test 45: ✅ exit "+100"
-Test 46: ✅ exit +"100"
-Test 47: ✅ exit -100
-Test 48: ✅ exit "-100"
-Test 49: ✅ exit -"100"
-
-needs a update
-Test 50: ❌ exit hello
-mini exit code = 0
-bash exit code = 255
-mini error = ()
-bash error = ( numeric argument required)
-
-edge case
-Test 51: ❌ exit 42 world
-mini exit code = 42
-bash exit code = 1
-mini error = ()
-bash error = ( too many arguments)
-Test 52: ✅
-———————————— pipes
-Test 53: ❌ env | sort | grep -v SHLVL | grep -v ^_
-mini output = (?=0 COLORTERM=truecolor GIT_ASKPASS=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh HOME=/Users/chuhlig LANG=en_US.UTF-8 LOGNAME=chuhlig MallocNanoZone=0 ORIGINAL_XDG_CURRENT_DESKTOP=undefined PATH=/Users/chuhlig/goinfre/.brew/bin:/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Users/chuhlig/goinfre/.brew/bin:/Users/chuhlig/Library/Application Support/Code/User/globalStorage/github.copilot-chat/debugCommand PWD=/Users/chuhlig/Desktop/minishell/minishell_tester SHELL=/bin/zsh SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.8vcs8lnaog/Listeners TERM=xterm-256color TERM_PROGRAM=vscode TERM_PROGRAM_VERSION=1.96.2 TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/ USER=chuhlig USER_ZDOTDIR=/Users/chuhlig VSCODE_GIT_ASKPASS_EXTRA_ARGS= VSCODE_GIT_ASKPASS_MAIN=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js VSCODE_GIT_ASKPASS_NODE=/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) VSCODE_GIT_IPC_HANDLE=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/vscode-git-a7f217e79d.sock VSCODE_INJECTION=1 XPC_FLAGS=0x0 XPC_SERVICE_NAME=0 ZDOTDIR=/Users/chuhlig)
-bash output = (COLORTERM=truecolor GIT_ASKPASS=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh HOME=/Users/chuhlig LANG=en_US.UTF-8 LOGNAME=chuhlig MallocNanoZone=0 ORIGINAL_XDG_CURRENT_DESKTOP=undefined PATH=/Users/chuhlig/goinfre/.brew/bin:/Users/chuhlig/goinfre/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Apple/usr/bin:/Users/chuhlig/goinfre/.brew/bin:/Users/chuhlig/Library/Application Support/Code/User/globalStorage/github.copilot-chat/debugCommand PWD=/Users/chuhlig/Desktop/minishell/minishell_tester SHELL=/bin/zsh SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.8vcs8lnaog/Listeners TERM=xterm-256color TERM_PROGRAM=vscode TERM_PROGRAM_VERSION=1.96.2 TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/ USER=chuhlig USER_ZDOTDIR=/Users/chuhlig VSCODE_GIT_ASKPASS_EXTRA_ARGS= VSCODE_GIT_ASKPASS_MAIN=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js VSCODE_GIT_ASKPASS_NODE=/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) VSCODE_GIT_IPC_HANDLE=/var/folders/zz/zyxvpxvq6csfxvn_n000ckjr0034mf/T/vscode-git-a7f217e79d.sock VSCODE_INJECTION=1 XPC_FLAGS=0x0 XPC_SERVICE_NAME=0 ZDOTDIR=/Users/chuhlig)
-Test 54: ✅ cat ./test_files/infile_big | grep oi
-Test 55: ✅ cat minishell.h | grep ");"$
-Test 56: ✅ export GHOST=123 | env | grep GHOST
-———————————— redirects
-Test 57: ✅ grep hi <./test_files/infile
-Test 58: ✅ grep hi "<infile" < ./test_files/infile
-Test 59: ✅ echo hi < ./test_files/infile bye bye
-Test 60: ✅ grep hi <./test_files/infile_big <./test_files/infile
-
-
-Test 61: ❌ echo <"./test_files/infile" "bonjour 42" string handling issue
-mini output = ()
-bash output = (bonjour 42)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 62: ❌ cat <"./test_files/file name with spaces"
-mini output = ()
-bash output = (😈 😈 😈 This will break your minishell 😈 😈 😈)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 63: ✅ cat <./test_files/infile_big ./test_files/infile
-Test 64: ✅ cat <"1""2""3""4""5"
-Test 65: ✅ echo <"./test_files/infile" <missing <"./test_files/infile"
-Test 66: ✅ echo <missing <"./test_files/infile" <missing
-Test 67: ❌ cat <"./test_files/infile"
-mini output = ()
-bash output = (hi hello world 42)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 68: ❌ echo <"./test_files/infile_big" | cat <"./test_files/infile"
-mini output = ()
-bash output = (hi hello world 42)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory No such file or directory)
-bash error = ()
-Test 69: ✅⚠️ echo <"./test_files/infile_big" | cat "./test_files/infile"
-mini error = ( No such file or directory)
-bash error = ()
-Test 70: ❌ echo <"./test_files/infile_big" | echo <"./test_files/infile"
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory No such file or directory)
-bash error = ()
-Test 71: ❌ echo hi | cat <"./test_files/infile"
-mini output = ()
-bash output = (hi hello world 42)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 72: ✅ echo hi | cat "./test_files/infile"
-Test 73: ✅⚠️ cat <"./test_files/infile" | echo hi
-mini error = ( No such file or directory)
-bash error = ( Broken pipe)
-Test 74: ❌ cat <"./test_files/infile" | grep hello
-mini output = ()
-bash output = (hello)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 75: ✅⚠️ cat <"./test_files/infile_big" | echo hi
-mini error = ( No such file or directory)
-bash error = ( Broken pipe)
-Test 76: ✅ cat <missing
-Test 77: ✅ cat <missing | cat
-Test 78: ✅ cat <missing | echo oi
-Test 79: ❌ cat <missing | cat <"./test_files/infile" tokenizer check again
-
-mini output = ()
-bash output = (hi hello world 42)
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory No such file or directory) should be esier to find
-bash error = ( No such file or directory)
-Test 80: ✅ echo <123 <456 hi | echo 42
-Test 81: ✅ ls >./outfiles/outfile01
-Test 82: ✅ ls > ./outfiles/outfile01
-Test 83: ✅ echo hi > ./outfiles/outfile01 bye
-
-
-check this extra
-
-Test 84: ❌ ls >./outfiles/outfile01 >./outfiles/outfile02
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-bash outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-Test 85: ❌ ls >./outfiles/outfile01 >./test_files/invalid_permission
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-Test 86: ❌ ls >"./outfiles/outfile with spaces"
-Only in ./bash_outfiles: outfile with spaces
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 87: ❌ ls >"./outfiles/outfile""1""2""3""4""5"
-Only in ./bash_outfiles: outfile12345
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 88: ❌ ls >"./outfiles/outfile01" >./test_files/invalid_permission >"./outfiles/outfile02"
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-mini error = ( No such file or directory)
-bash error = ( Permission denied)
-Test 89: ✅ ls >./test_files/invalid_permission >"./outfiles/outfile01" >./test_files/invalid_permission
-Test 90: ❌ cat <"./test_files/infile" >"./outfiles/outfile01"
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-hi
-hello
-world
-42
-mini exit code = 1
-bash exit code = 0
-mini error = ( No such file or directory)
-bash error = ()
-Test 91: ✅ echo hi >./outfiles/outfile01 | echo bye
-Test 92: ❌ echo hi >./outfiles/outfile01 >./outfiles/outfile02 | echo bye
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-hi
-bash outfiles:
-hi
-Test 93: ✅ echo hi | echo >./outfiles/outfile01 bye
-Test 94: ❌ echo hi | echo bye >./outfiles/outfile01 >./outfiles/outfile02
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-bye
-bash outfiles:
-bye
-Test 95: ✅ echo hi >./outfiles/outfile01 | echo bye >./outfiles/outfile02
-Test 96: ❌ echo hi >./outfiles/outfile01 >./test_files/invalid_permission | echo bye
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-Test 97: ✅ echo hi >./test_files/invalid_permission | echo bye
-Test 98: ❌ echo hi >./test_files/invalid_permission >./outfiles/outfile01 | echo bye
-Only in ./mini_outfiles: outfile01
-mini outfiles:
-hi
-bash outfiles:
-cat: ./bash_outfiles/*: No such file or directory
-mini error = ()
-bash error = ( Permission denied)
-Test 99: ✅ echo hi | echo bye >./test_files/invalid_permission
-Test 100: ❌ echo hi | >./outfiles/outfile01 echo bye >./test_files/invalid_permission
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-mini exit code = 139
-bash exit code = 1
-mini error = ()
-bash error = ( Permission denied)
-
-update for this.
-
-Test 101: ❌ echo hi | echo bye >./test_files/invalid_permission >./outfiles/outfile01
-Only in ./mini_outfiles: outfile01
-mini outfiles:
-bye
-bash outfiles:
-cat: ./bash_outfiles/*: No such file or directory
-mini exit code = 0
-bash exit code = 1
-mini error = ()
-bash error = ( Permission denied)
-Test 102: ✅⚠️ cat <"./test_files/infile" >./test_files/invalid_permission
-mini error = ( No such file or directory)
-bash error = ( Permission denied)
-Test 103: ✅⚠️ cat >./test_files/invalid_permission <"./test_files/infile"
-mini error = ( No such file or directory)
-bash error = ( Permission denied)
-Test 104: ✅ cat <missing >./outfiles/outfile01
-Test 105: ❌ cat >./outfiles/outfile01 <missing
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-Test 106: ✅ cat <missing >./test_files/invalid_permission
-Test 107: ✅⚠️ cat >./test_files/invalid_permission <missing
-mini error = ( No such file or directory)
-bash error = ( Permission denied)
-Test 108: ❌ cat >./outfiles/outfile01 <missing >./test_files/invalid_permission
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-Test 109: ✅ ls >>./outfiles/outfile01
-Test 110: ✅ ls >> ./outfiles/outfile01
-Test 111: ✅ ls >>./outfiles/outfile01 >./outfiles/outfile01
-Test 112: ✅ ls >./outfiles/outfile01 >>./outfiles/outfile01
-Test 113: ❌ ls >./outfiles/outfile01 >>./outfiles/outfile01 >./outfiles/outfile02
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-bash outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-Test 114: ❌ ls >>./outfiles/outfile01 >>./outfiles/outfile02
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-bash outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-Test 115: ✅ ls >>./test_files/invalid_permission
-Test 116: ❌ ls >>./test_files/invalid_permission >>./outfiles/outfile01
-Only in ./mini_outfiles: outfile01
-mini outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-bash outfiles:
-cat: ./bash_outfiles/*: No such file or directory
-mini exit code = 0
-bash exit code = 1
-mini error = ()
-bash error = ( Permission denied)
-Test 117: ❌ ls >>./outfiles/outfile01 >>./test_files/invalid_permission
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-Test 118: ❌ ls >./outfiles/outfile01 >>./test_files/invalid_permission >>./outfiles/outfile02
-Only in ./bash_outfiles: outfile01
-Only in ./mini_outfiles: outfile02
-mini outfiles:
-README.md
-bash.supp
-bash_outfiles
-bonus
-bonus_bonus
-builtins
-extras
-local.supp
-loop.out
-manual_tests
-mini_outfiles
-os_specific
-outfiles
-pipes
-redirects
-syntax
-test_files
-tester
-wildcards
-bash outfiles:
-mini exit code = 0
-bash exit code = 1
-mini error = ()
-bash error = ( Permission denied)
-Test 119: ✅ ls <missing >>./test_files/invalid_permission >>./outfiles/outfile02
-Test 120: ✅⚠️ ls >>./test_files/invalid_permission >>./outfiles/outfile02 <missing
-mini error = ( No such file or directory)
-bash error = ( Permission denied)
-Test 121: ✅ echo hi >>./outfiles/outfile01 | echo bye
-Test 122: ❌ echo hi >>./outfiles/outfile01 >>./outfiles/outfile02 | echo bye
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-hi
-bash outfiles:
-hi
-Test 123: ✅ echo hi | echo >>./outfiles/outfile01 bye
-Test 124: ❌ echo hi | echo bye >>./outfiles/outfile01 >>./outfiles/outfile02
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-bye
-bash outfiles:
-bye
-Test 125: ✅ echo hi >>./outfiles/outfile01 | echo bye >>./outfiles/outfile02
-Test 126: ✅ echo hi >>./test_files/invalid_permission | echo bye
-Test 127: ❌ echo hi >>./test_files/invalid_permission >./outfiles/outfile01 | echo bye
-Only in ./mini_outfiles: outfile01
-mini outfiles:
-hi
-bash outfiles:
-cat: ./bash_outfiles/*: No such file or directory
-mini error = ()
-bash error = ( Permission denied)
-Test 128: ✅ echo hi | echo bye >>./test_files/invalid_permission
-Test 129: ❌ echo hi | echo >>./outfiles/outfile01 bye >./test_files/invalid_permission
-Only in ./bash_outfiles: outfile01
-mini outfiles:
-cat: ./mini_outfiles/*: No such file or directory
-bash outfiles:
-Test 130: ✅ cat <minishell.h>./outfiles/outfile
-Test 131: ✅ cat <minishell.h|ls
-———————————— extras
-Test 132: ✅
-
-udpate this
-Test 133: ❌ $PWD
-mini exit code = 1
-bash exit code = 126
-mini error = ( Permission denied)
-bash error = ( is a directory)
-Test 134: ❌ $EMPTY
-mini exit code = 1
-bash exit code = 0
-mini error = ( Permission denied)
-bash error = ()
-Test 135: ❌ $EMPTY echo hi
-mini output = ()
-bash output = (hi)
-mini exit code = 1
-bash exit code = 0
-mini error = ( Permission denied)
-bash error = ()
-Test 136: ❌ ./test_files/invalid_permission
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 126
-mini error = ()
-bash error = ( Permission denied)
-Test 137: ❌ ./missing.out
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( No such file or directory)
-Test 138: ❌ missing.out
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
-Test 139: ❌ "aaa"
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
-Test 140: ❌ test_files
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
-Test 141: ❌ ./test_files
-mini exit code = 1
-bash exit code = 126
-mini error = ( Permission denied)
-bash error = ( is a directory)
-Test 142: ❌ /test_files
-mini exit code = 1
-bash exit code = 127
-Test 143: ❌ minishell.h
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
-Test 144: ❌ $
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
-Test 145: ❌ $?
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
-Test 146: ❌ README.md
-mini output = (command not found)
-bash output = ()
-mini exit code = 1
-bash exit code = 127
-mini error = ()
-bash error = ( command not found)
\ No newline at end of file
/* ::: :::::::: */
/* ast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 11:48:27 by dkaiser #+# #+# */
-/* Updated: 2025/01/16 18:26:30 by dkaiser ### ########.fr */
+/* Updated: 2025/01/18 19:28:51 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
-#include "debug_tools.h"
-#include "stdlib.h"
+#ifndef AST_H
+# define AST_H
+# include "debug_tools.h"
+# include "stdlib.h"
enum e_node_type
{
t_node *new_string_node(char *string);
void free_node(t_node *node);
+
+#endif
\ No newline at end of file
/* ::: :::::::: */
/* debug_tools.h :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 18:34:37 by dkaiser #+# #+# */
-/* Updated: 2024/06/28 15:05:12 by dkaiser ### ########.fr */
+/* Updated: 2025/01/19 21:08:15 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DEBUG_TOOLS_H
# define DEBUG_TOOLS_H
+# include <stdarg.h>
+# include "debug_tools.h"
# include "libft.h"
void dbg(char *str);
void panic(char *msg);
+
+
+void dbg2(const char *format, ...);
+
+
#endif
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/08 16:53:39 by dkaiser #+# #+# */
-/* Updated: 2025/01/14 16:50:55 by chuhlig ### ########.fr */
+/* Updated: 2025/01/18 18:43:07 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
int ft_env(t_env *env);
int builtin_exit(char **args, t_env **env);
t_env *env_new(char *name);
+t_env *check_existing(t_env *env, char *av);
#endif
\ No newline at end of file
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 17:14:49 by dkaiser #+# #+# */
-/* Updated: 2025/01/16 18:38:44 by dkaiser ### ########.fr */
+/* Updated: 2025/01/18 19:30:43 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
int eval(t_node *node, t_env **env);
char *get_cmd_path(char *cmd, t_env *env, int *return_code);
int execute_cmd(t_cmd *cmd, t_env **env);
-char *format_string(char *str, t_env *env);
+char *format_string(char *str, t_env *env, int is_literal);
int set_return_code(int return_code, t_env **env);
int handle_redirections(t_redirection *redirs);
void *error(int err_code, char *err_text, int exit_code,
int *ret_code);
char *read_heredoc(char *delimiter);
-void create_files(t_list *files);
+int handle_input_redirection(t_redirection *redir);
+int handle_output_redirection(t_redirection *redir);
+int handle_redirections(t_redirection *redirs);
+int handle_pipe_parent(int p[2], t_node *node, t_env **env);
+int handle_pipe_child(int p[2], t_node *node,
+ t_env **env, int in_fd);
+int open_file(char *path, int flags, int mode);
+int eval_rec(t_node *node, t_env **env, int in_fd);
+void create_files(t_list *files);
+
#endif
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */
-/* Updated: 2024/08/29 15:26:23 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 12:37:59 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
void free_tokens(t_token *tokens);
void tokenizer(char *s, t_token **token_list,
char quote_check);
+void print_token(t_token *token);
#endif
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 19:51:59 by chuhlig ### ########.fr */
+/* Updated: 2025/01/18 18:33:33 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "env.h"
#include <stdio.h>
-int echo(char **av)
-{
- int i;
- int f;
-
- i = 1;
- f = 1;
- if (av[1] == NULL || av[1][0] == '\0')
- {
- write(1, "\n", 1);
- return (0);
- }
- if (ft_strncmp(av[1], "-n", 3) == 0)
- {
- i++;
- f = 0;
- }
- while (av[i])
- {
- write(1, av[i], ft_strlen(av[i]));
- i++;
- if (av[i])
- write(1, " ", 1);
- }
- if (f)
- write(1, "\n", 1);
- return (0);
-}
-
-void exit_shell(t_env **env, int exit_status)
-{
- free_envlst(env);
- exit(exit_status);
-}
-
-int builtin_exit(char **args, t_env **env)
-{
- int exit_status;
-
- if (args[1])
- exit_status = ft_atoi(args[1]);
- else
- exit_status = 0;
- exit_shell(env, exit_status);
- return (exit_status);
-}
-
int unset(char **av, t_env **env)
{
t_env *current;
i = 0;
while (av[++i])
{
- if (ft_strchr(av[i], '?'))
- return (1);
current = *env;
prev = NULL;
while (current)
{
while (env)
{
+ if (ft_strcmp("$", av) == 0)
+ return (NULL);
if (ft_strcmp(env->name, av) == 0)
return (env);
env = env->next;
return (NULL);
}
-int export(char **av, t_env **env)
+void export_export(char *av, t_env **env)
{
char *tmp;
t_env *current;
- int i;
current = NULL;
+ tmp = ft_strchr(av, '=');
+ *tmp = '\0';
+ current = check_existing(*env, av);
+ if (current)
+ free(current->value);
+ else
+ {
+ current = env_new(ft_strdup(av));
+ current->next = *env;
+ *env = current;
+ }
+ current->value = ft_strdup(tmp + 1);
+}
+
+int is_valid_identifier(char *str)
+{
+ int i;
+
i = 0;
- while (av[++i])
+ if (!ft_isalpha(str[0]) && str[0] != '_')
+ return (0);
+ while (str[i] && str[i] != '=')
{
- if ((ft_strchr(av[i], '=')))
- {
- tmp = ft_strchr(av[i], '=');
- *tmp = '\0';
- if (ft_strchr(av[i], '?'))
- return (1);
- current = check_existing(*env, av[i]);
- if (current)
- free(current->value);
- else
- {
- current = env_new(ft_strdup(av[i]));
- current->next = *env;
- *env = current;
- }
- current->value = ft_strdup(tmp + 1);
- }
- else
- return (1);
+ if (!ft_isalnum(str[i]) && str[i] != '_')
+ return (0);
+ i++;
}
- return (0);
+ return (1);
}
-void set_return_code(int return_code, t_env **env)
+int export(char **av, t_env **env)
{
- t_env *cur;
+ char *equal_sign;
+ int i;
- cur = check_existing(*env, "?");
- if (cur)
- free(cur->value);
- else
+ i = 0;
+ while (av[++i])
{
- cur = env_new(ft_strdup("?"));
- cur->next = *env;
- *env = cur;
+ equal_sign = ft_strchr(av[i], '=');
+ if (equal_sign)
+ *equal_sign = '\0';
+ if (!is_valid_identifier(av[i]))
+ {
+ write(1, "Minishell $ export: not a valid identifier\n", 43);
+ if (equal_sign)
+ *equal_sign = '=';
+ continue ;
+ }
+ if (equal_sign)
+ {
+ *equal_sign = '=';
+ export_export(av[i], env);
+ }
}
- cur->value = ft_itoa(return_code);
+ return (0);
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* builtins_part_three.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2025/01/18 18:29:24 by chuhlig #+# #+# */
+/* Updated: 2025/01/18 18:34:29 by chuhlig ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "env.h"
+
+void exit_shell(t_env **env, int exit_status)
+{
+ free_envlst(env);
+ exit(exit_status);
+}
+
+int builtin_exit(char **av, t_env **env)
+{
+ int exit_status;
+
+ if (av[1])
+ exit_status = ft_atoi(av[1]);
+ else
+ exit_status = 0;
+ exit_shell(env, exit_status);
+ return (exit_status);
+}
+
+void set_return_code(int return_code, t_env **env)
+{
+ t_env *cur;
+
+ cur = check_existing(*env, "?");
+ if (cur)
+ free(cur->value);
+ else
+ {
+ cur = env_new(ft_strdup("?"));
+ cur->next = *env;
+ *env = cur;
+ }
+ cur->value = ft_itoa(return_code);
+}
+
+int echo(char **av)
+{
+ int i;
+ int f;
+
+ i = 1;
+ f = 1;
+ if (av[1] == NULL || av[1][0] == '\0')
+ {
+ write(1, "\n", 1);
+ return (0);
+ }
+ if (ft_strncmp(av[1], "-n", 3) == 0)
+ {
+ i++;
+ f = 0;
+ }
+ while (av[i])
+ {
+ write(1, av[i], ft_strlen(av[i]));
+ i++;
+ if (av[i])
+ write(1, " ", 1);
+ }
+ if (f)
+ write(1, "\n", 1);
+ return (0);
+}
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 20:52:16 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 19:31:17 by chuhlig ### ########.fr */
+/* Updated: 2025/01/18 18:57:12 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
}
if (chdir(current->value) == -1)
return (1);
+ update_pwd(env);
}
else
{
{
while (env != NULL)
{
- if (strchr(env->name, '?'))
+ if (ft_strchr(env->name, '?'))
{
env = env->next;
continue ;
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */
-/* Updated: 2025/01/16 18:19:36 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 13:00:04 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
static int set_heredoc_data(t_token *cur, t_redirection *result,
t_env *env);
-t_redirection *collect_redirs(t_token **tokens, t_env *env, t_list **create_files)
+t_redirection *collect_redirs(t_token **tokens, t_env *env,
+ t_list **create_files)
{
t_redirection *result;
t_token *cur;
return (result);
}
-static t_redirection *set_redir(t_redirection *redir, int type, char *spec,
- t_env *env)
-{
- t_redirection *result;
-
- redir->type = type;
- if (spec != NULL)
- redir->specifier = format_string(spec, env);
- else
- redir->specifier = spec;
- if (redir->type == OUTPUT_APPEND || redir->type == OUTPUT_OVERRIDE)
- {
- result = malloc(sizeof(t_redirection));
- if (!result)
- return (NULL);
- result->type = type;
- result->specifier = spec;
- return (result);
- }
- return (NULL);
-}
-
static void collect_and_check_redir(t_redirection *result, t_token **cur,
t_env *env, t_list **create_files)
{
ft_lstadd_back(create_files, ft_lstnew(set_redir(&result[1],
OUTPUT_APPEND, str, env)));
next_token = (*cur)->next;
- free_token_and_connect(*cur);
+ // free_token_and_connect(*cur);
if (next_token)
{
*cur = next_token->next;
*cur = NULL;
}
+static t_redirection *set_redir(t_redirection *redir, int type, char *spec,
+ t_env *env)
+{
+ t_redirection *result;
+
+ redir->type = type;
+ if (spec != NULL)
+ redir->specifier = format_string(spec, env, ft_atoi("0"));
+ else
+ redir->specifier = spec;
+ if (redir->type == OUTPUT_APPEND || redir->type == OUTPUT_OVERRIDE)
+ {
+ result = malloc(sizeof(t_redirection));
+ if (!result)
+ return (NULL);
+ result->type = type;
+ result->specifier = spec;
+ return (result);
+ }
+ return (NULL);
+}
+
+
+
static int set_heredoc_data(t_token *cur, t_redirection *result, t_env *env)
{
char *heredoc_data;
/* ::: :::::::: */
/* create_files.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/16 16:23:51 by dkaiser #+# #+# */
-/* Updated: 2025/01/16 19:16:33 by dkaiser ### ########.fr */
+/* Updated: 2025/01/19 14:36:59 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
{
dbg("Test");
if (files->content == NULL)
- continue;
+ continue ;
file = (t_redirection *)files->content;
if (access(file->specifier, F_OK) != -1 && access(file->specifier, W_OK) == -1)
- break;
+ break ;
if (file->type == OUTPUT_OVERRIDE)
{
fd = open(file->specifier, O_WRONLY | O_CREAT | O_TRUNC, 0644);
fd = open(file->specifier, O_WRONLY | O_CREAT | O_APPEND, 0644);
close(fd);
}
- /* if (files->next == NULL) */
- /* break; */
- /* if (((t_redirection *) files->next->content)->type == 0) */
- /* break; */
+ if (files->next == NULL)
+ break ;
+ if (((t_redirection *) files->next->content)->type == 0)
+ break ;
files = files->next;
}
}
/* ::: :::::::: */
/* debug_tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 15:34:14 by dkaiser #+# #+# */
-/* Updated: 2024/06/28 15:04:43 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 12:50:36 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "debug_tools.h"
+#include <stdio.h>
+#include <stdarg.h>
void dbg(char *msg)
{
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:22:28 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 19:34:10 by chuhlig ### ########.fr */
+/* Updated: 2025/01/18 18:50:49 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
static char *get_var_assign(t_env *cur);
-char **env_to_strlst(t_env *env)
+static int getsize(t_env *env)
{
int size;
t_env *cur;
- char **result;
- int i;
size = 0;
cur = env;
- while (cur != NULL)
+ while (cur)
{
- if (ft_strchr(cur->name, '?'))
- {
- cur = cur->next;
- continue ;
- }
- size++;
+ if (!ft_strchr(cur->name, '?'))
+ size++;
cur = cur->next;
}
+ return (size);
+}
+
+char **env_to_strlst(t_env *env)
+{
+ int size;
+ t_env *cur;
+ char **result;
+ int i;
+
+ size = 0;
+ cur = env;
+ size = getsize(env);
result = malloc(sizeof(char *) * (size + 1));
if (result == NULL)
return (NULL);
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:21:35 by chuhlig #+# #+# */
-/* Updated: 2025/01/16 18:38:00 by dkaiser ### ########.fr */
+/* Updated: 2025/01/19 19:15:46 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:30:11 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 18:06:17 by dkaiser ### ########.fr */
+/* Updated: 2025/01/19 20:24:05 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "minishell.h"
-static void append_slice(char **dst, char *src, int start, int end);
-static void append_var(char **dst, char *src, int *pos, t_env *env);
-
-char *format_string(char *str, t_env *env)
+void append_var_exit_code(char **dst, t_env *env)
{
+ char *exit_code;
char *result;
- int pos;
- int start;
- int is_literal;
- pos = 0;
- start = 0;
- is_literal = 0;
- result = NULL;
- if (str == NULL)
- return (NULL);
- while (str[pos] != '\0')
+ exit_code = env_get(env, "?");
+ if (exit_code)
{
- if (str[pos] == '\'')
- {
- append_slice(&result, str, start, pos);
- start = pos + 1;
- is_literal = !is_literal;
- }
- if (str[pos] == '"' && !is_literal)
- {
- append_slice(&result, str, start, pos);
- start = pos + 1;
- }
- if (str[pos] == '$' && !is_literal)
- {
- append_slice(&result, str, start, pos);
- append_var(&result, str, &pos, env);
- start = pos;
- continue ;
- }
- pos++;
+ result = ft_strjoin(*dst, exit_code);
+ free(*dst);
+ *dst = result;
}
- append_slice(&result, str, start, pos);
- return (result);
}
static void append_slice(char **dst, char *src, int start, int end)
if (*dst != NULL)
len = ft_strlen(*dst);
else
- {
len = 0;
- }
result = malloc(len + (end - start) + 1);
if (!result)
return ;
i = 0;
*pos += 1;
- while (src[*pos + i] != '\0' && src[*pos + i] != '\'' && src[*pos
- + i] != '"' && src[*pos + i] != '$')
- {
+ while (ft_isalnum(src[*pos + i]) || src[*pos + i] == '_')
i++;
- }
- var = malloc(i + 1);
- if (var == NULL)
+ if (i == 0)
return ;
- var[i] = '\0';
- i--;
- while (i >= 0)
- {
- var[i] = src[*pos + i];
- i--;
- }
+ var = ft_substr(src, *pos, i);
value = env_get(env, var);
- if (value != NULL)
+ if (value)
{
result = ft_strjoin(*dst, value);
free(*dst);
*dst = result;
}
- *pos += ft_strlen(var);
+ *pos += i;
+ free(var);
+}
+
+static void handle_dollar_sign(char **result, char *str, int *pos, t_env *env)
+{
+ if (str[*pos + 1] == '?')
+ {
+ append_var_exit_code(result, env);
+ *pos += 2;
+ }
+ else if (ft_isalnum(str[*pos + 1]) || str[*pos + 1] == '_')
+ append_var(result, str, pos, env);
+ else
+ {
+ append_slice(result, str, *pos, *pos + 1);
+ (*pos)++;
+ }
+}
+
+char *format_string(char *str, t_env *env, int is_literal)
+{
+ char *result;
+ int pos;
+ int start;
+
+ pos = 0;
+ start = 0;
+ result = NULL;
+ if (!str)
+ return (NULL);
+ while (str[pos])
+ {
+ if (str[pos] == '\'' || (str[pos] == '\"' && !is_literal)
+ || (str[pos] == '$' && !is_literal))
+ {
+ append_slice(&result, str, start, pos);
+ if (str[pos] == '$')
+ handle_dollar_sign(&result, str, &pos, env);
+ else
+ is_literal ^= (str[pos++] == '\'');
+ start = pos;
+ continue ;
+ }
+ pos++;
+ }
+ return (append_slice(&result, str, start, pos), result);
}
/* ::: :::::::: */
/* free_token.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 14:38:57 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 14:23:56 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 12:49:48 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "token.h"
+#include "debug_tools.h"
void free_token(t_token *token)
{
if (token->next != NULL)
token->next->previous = NULL;
free(token);
+ token = NULL;
}
void free_token_and_connect(t_token *token)
if (token->next != NULL)
token->next->previous = token->previous;
free(token);
+ token = NULL;
}
void free_tokens(t_token *tokens)
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:19:59 by chuhlig #+# #+# */
-/* Updated: 2025/01/15 16:38:39 by dkaiser ### ########.fr */
+/* Updated: 2025/01/19 18:56:22 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
}
*return_code = 127;
printf("%s:", cmd);
- ft_putstr_fd(" command not found", 2);
+ ft_putstr_fd(" command not found", 2);//output is shit even if its fine for tester
return (NULL);
}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* handle_redir.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2025/01/18 18:34:51 by chuhlig #+# #+# */
+/* Updated: 2025/01/18 18:47:31 by chuhlig ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "minishell.h"
+
+int handle_input_redirection(t_redirection *redir)
+{
+ int fd;
+
+ if (redir->type == INPUT_FILE)
+ {
+ fd = open_file(redir->specifier, O_RDONLY, 0);
+ if (fd < 0)
+ return (-1);
+ dup2(fd, STDIN_FILENO);
+ close(fd);
+ }
+ else if (redir->type == INPUT_LIMITER)
+ {
+ fd = open_file("/tmp/heredoc_tmp", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd < 0)
+ return (-1);
+ write(fd, redir->specifier, ft_strlen(redir->specifier));
+ close(fd);
+ fd = open_file("/tmp/heredoc_tmp", O_RDONLY, 0);
+ if (fd < 0)
+ return (-1);
+ dup2(fd, STDIN_FILENO);
+ close(fd);
+ }
+ return (0);
+}
+
+int handle_output_redirection(t_redirection *redir)
+{
+ int fd;
+
+ if (redir->type == OUTPUT_OVERRIDE)
+ {
+ fd = open_file(redir->specifier, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd < 0)
+ return (-1);
+ dup2(fd, STDOUT_FILENO);
+ close(fd);
+ }
+ else if (redir->type == OUTPUT_APPEND)
+ {
+ fd = open_file(redir->specifier, O_WRONLY | O_CREAT | O_APPEND, 0644);
+ if (fd < 0)
+ return (-1);
+ dup2(fd, STDOUT_FILENO);
+ close(fd);
+ }
+ return (0);
+}
+
+int handle_redirections(t_redirection *redirs)
+{
+ if (redirs[0].type == INPUT_FILE || redirs[0].type == INPUT_LIMITER)
+ {
+ if (handle_input_redirection(&redirs[0]) < 0)
+ return (-1);
+ }
+ if (redirs[1].type == OUTPUT_OVERRIDE || redirs[1].type == OUTPUT_APPEND)
+ {
+ if (handle_output_redirection(&redirs[1]) < 0)
+ return (-1);
+ }
+ return (0);
+}
+
+int handle_pipe_parent(int p[2], t_node *node, t_env **env)
+{
+ int original_stdin;
+ int result;
+
+ close(p[1]);
+ original_stdin = dup(STDIN_FILENO);
+ dup2(p[0], STDIN_FILENO);
+ result = eval_rec(node->content.pipe.right, env, p[0]);
+ dup2(original_stdin, STDIN_FILENO);
+ close(original_stdin);
+ close(p[0]);
+ return (result);
+}
+
+int handle_pipe_child(int p[2], t_node *node, t_env **env, int in_fd)
+{
+ close(p[0]);
+ dup2(in_fd, STDIN_FILENO);
+ dup2(p[1], STDOUT_FILENO);
+ close(p[1]);
+ exit(eval_rec(node->content.pipe.left, env, in_fd));
+}
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:15:49 by chuhlig #+# #+# */
-/* Updated: 2025/01/16 18:44:39 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 12:48:49 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "debug_tools.h"
#include "minishell.h"
-int handle_redirections(t_redirection *redirs)
+int eval_rec(t_node *node, t_env **env, int in_fd);
+
+int open_file(char *path, int flags, int mode)
{
int fd;
- if (redirs[0].type == INPUT_FILE)
- {
- fd = open(redirs[0].specifier, O_RDONLY);
- if (fd < 0)
- {
- perror("open");
- return (-1);
- }
- dup2(fd, STDIN_FILENO);
- close(fd);
- }
- else if (redirs[0].type == INPUT_LIMITER)
- {
- fd = open("/tmp/heredoc_tmp", O_WRONLY | O_TRUNC, 0644);
- if (fd < 0)
- {
- perror("open");
- return (-1);
- }
- write(fd, redirs[0].specifier, ft_strlen(redirs[0].specifier));
- close(fd);
- fd = open("/tmp/heredoc_tmp", O_RDONLY);
- if (fd < 0)
- {
- perror("open");
- return (-1);
- }
- dup2(fd, STDIN_FILENO);
- close(fd);
- }
- if (redirs[1].type == OUTPUT_OVERRIDE)
- {
- fd = open(redirs[1].specifier, O_WRONLY | O_TRUNC, 0644);
- if (fd < 0)
- {
- perror("open");
- return (-1);
- }
- dup2(fd, STDOUT_FILENO);
- close(fd);
- }
- else if (redirs[1].type == OUTPUT_APPEND)
- {
- fd = open(redirs[1].specifier, O_WRONLY | O_APPEND, 0644);
- if (fd < 0)
- {
- perror("open");
- return (-1);
- }
- dup2(fd, STDOUT_FILENO);
- close(fd);
- }
- return (0);
+ fd = open(path, flags, mode);
+ if (fd < 0)
+ perror("open");
+ return (fd);
}
int eval_rec(t_node *node, t_env **env, int in_fd)
{
- pid_t pid;
int p[2];
+ pid_t pid;
int result;
- int original_stdin;
if (node->type == PIPE_NODE)
{
- pipe(p);
+ if (pipe(p) == -1)
+ return (perror("pipe"), EXIT_FAILURE);
pid = fork();
+ if (pid == -1)
+ return (perror("fork"), close(p[0]), close(p[1]), EXIT_FAILURE);
if (pid == 0)
- {
- close(p[0]);
- dup2(in_fd, STDIN_FILENO);
- dup2(p[1], STDOUT_FILENO);
- result = eval_rec(node->content.pipe.left, env, in_fd);
- exit(result);
- }
- else
- {
- close(p[1]);
- original_stdin = dup(STDIN_FILENO);
- dup2(p[0], STDIN_FILENO);
- result = eval_rec(node->content.pipe.right, env, p[0]);
- dup2(original_stdin, STDIN_FILENO);
- close(original_stdin);
- }
+ handle_pipe_child(p, node, env, in_fd);
+ result = handle_pipe_parent(p, node, env);
}
else if (node->type == CMD_NODE)
result = execute_cmd(&node->content.cmd, env);
/* ::: :::::::: */
/* new_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 11:21:03 by dkaiser #+# #+# */
-/* Updated: 2025/01/16 18:25:54 by dkaiser ### ########.fr */
+/* Updated: 2025/01/19 19:01:01 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
node->content.cmd.redirs[1] = redirs[1];
node->content.cmd.create_files = create_files;
free(redirs);
+ redirs = NULL;//1
return (node);
}
return (NULL);
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2025/01/16 19:06:03 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 12:44:44 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
{
char **args;
t_redirection *redirs;
- t_list *create_files;
+ t_list *create_files;
create_files = NULL;
redirs = collect_redirs(&tokens, *env, &create_files);
static char **collect_args(t_token **tokens, t_env **env)
{
t_token *cur;
+ t_token *next;//2
char **result;
int i;
i = 0;
while (cur != NULL && cur->type == STRING_TOKEN)
{
+ next = cur->next;//2
if (cur->previous)
free_token(cur->previous);
- result[i] = format_string(cur->content.string, *env);
+ result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
i++;
- cur = cur->next;
+ // cur = cur->next;
+ cur = next;//2
}
result[i] = NULL;
return (result);
-}
+}
\ No newline at end of file
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 15:53:29 by dkaiser #+# #+# */
-/* Updated: 2025/01/11 16:06:54 by chuhlig ### ########.fr */
+/* Updated: 2025/01/19 18:59:00 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
if (left_side_tokens == NULL)
{
free_tokens(tokens);
+ tokens = NULL;//1
return (NULL);
}
else if (tokens != NULL)
if (result == split)
result = NULL;
free_token(split);
+ split = NULL;//1
return (result);
}
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */
-/* Updated: 2025/01/14 15:39:58 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 12:45:00 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
while (1)
{
input = readline(prompt);
- if (input == NULL)
+ if (input == NULL)
{
if (*promptflag > 1)
(*promptflag)--;
free(input);
}
}
+
+//echo hi | >./outfiles/outfile01 echo bye >./test_files/invalid_permission
\ No newline at end of file
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 15:08:43 by dkaiser #+# #+# */
-/* Updated: 2025/01/14 14:11:29 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 12:15:32 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */