Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Demirkylych committed Jun 17, 2024
2 parents 518bd0f + 48399c3 commit 6785b06
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 52 deletions.
21 changes: 21 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"inc",
"src/test",
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Используйте IntelliSense, чтобы узнать о возможных атрибутах.
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Запустить",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/minishell",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Включить автоматическое форматирование для gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Задать для варианта приложения дизассемблирования значение Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}

]
}
21 changes: 19 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"cSpell.words": [
"dmdemirk",
"minishell"
]
"maxishell",
"minishell",
"OLDPWD",
"putendl",
"putstr",
"strcdup"
],
"files.associations": {
"*.css": "tailwindcss",
"*.tsx": "typescriptreact",
"tokens.h": "c",
"test.h": "c",
"env.h": "c",
"stdio.h": "c",
"pipe.h": "c",
"shell.h": "c",
"libft.h": "c",
"assert.h": "c"
}
}
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ENV_DIR = $(SRC_DIR)/env
APP_DIR = $(SRC_DIR)/app
COMMON_DIR = $(SRC_DIR)/common
PARSER_DIR = $(SRC_DIR)/parser
PIPE_DIR = $(SRC_DIR)/pipe
BUILTINS_DIR = $(SRC_DIR)/builtins
EXECUTE_DIR = $(SRC_DIR)/execute
TEST_DIR = $(SRC_DIR)/test
Expand All @@ -60,22 +61,26 @@ ENV_SOURCES = $(wildcard $(ENV_DIR)/*.c)
COMMON_SOURCES = $(wildcard $(COMMON_DIR)/*.c)
UTILS_SOURCES = $(wildcard $(UTILS_DIR)/*.c)
PARSER_SOURCES = $(wildcard $(PARSER_DIR)/*.c)
PIPE_SOURCES = $(wildcard $(PIPE_DIR)/*.c)
BUILTINS_SOURCES = $(wildcard $(BUILTINS_DIR)/*.c)
EXECUTE_SOURCES = $(wildcard $(EXECUTE_DIR)/*.c)

MAIN_TEST_SOURCE = $(wildcard $(TEST_DIR)/*.c)
ENV_TEST_SOURCES = $(wildcard $(TEST_DIR)/env/*.c)
ENV_TEST_SOURCES = $(wildcard $(TEST_DIR)/env/*.c)
PIPE_TEST_SOURCES = $(wildcard $(TEST_DIR)/pipe/*.c)

SOURCES = $(MAIN_SOURCE) \
$(APP_SOURCES) \
$(ENV_SOURCES) \
$(COMMON_SOURCES) \
$(UTILS_SOURCES) \
$(PARSER_SOURCES) \
$(PIPE_SOURCES) \
$(BUILTINS_SOURCES) \
$(EXECUTE_SOURCES) \
$(MAIN_TEST_SOURCE) \
$(ENV_TEST_SOURCES)
$(ENV_TEST_SOURCES) \
$(PIPE_TEST_SOURCES)
# Building
BUILD_DIR = ./build
MAIN_OBJECT = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/src/%.o, $(MAIN_SOURCE))
Expand All @@ -84,10 +89,12 @@ ENV_OBJECTS = $(patsubst $(ENV_DIR)/env/%.c, $(BUILD_DIR)/src/app/env/%.o, $(
COMMON_OBJECTS = $(patsubst $(COMMON_DIR)/%.c, $(BUILD_DIR)/common/app/%.o, $(COMMON_SOURCES))
UTILS_OBJECTS = $(patsubst $(UTILS_DIR)/%.c, $(BUILD_DIR)/utils/%.o, $(UTILS_SOURCES))
PARSER_OBJECTS = $(patsubst $(PARSER_DIR)/%.c, $(BUILD_DIR)/src/parser/%.o, $(PARSER_SOURCES))
PIPE_OBJECTS = $(patsubst $(PIPE_DIR)/%.c, $(BUILD_DIR)/src/pipe/%.o, $(PIPE_SOURCES))
BUILTINS_OBJECTS = $(patsubst $(BUILTINS_DIR)/%.c, $(BUILD_DIR)/src/builtins/%.o, $(BUILTINS_SOURCES))
EXECUTE_OBJECTS = $(patsubst $(EXECUTE_DIR)/%.c, $(BUILD_DIR)/src/execute/%.o, $(EXECUTE_SOURCES))
MAIN_TEST_OBJECT = $(patsubst $(TEST_DIR)/%.c, $(BUILD_DIR)/src/test/%.o, $(MAIN_TEST_SOURCE))
ENV_TEST_OBJECTS = $(patsubst $(TEST_DIR)/env/%.c, $(BUILD_DIR)/src/test/env/%.o, $(ENV_TEST_SOURCES))
PIPE_TEST_OBJECTS = $(patsubst $(TEST_DIR)/pipe/%.c, $(BUILD_DIR)/src/test/pipe/%.o, $(PIPE_TEST_SOURCES))

OBJECTS = $(MAIN_OBJECT) \
$(APP_OBJECTS) \
Expand All @@ -97,6 +104,7 @@ OBJECTS = $(MAIN_OBJECT) \
$(BUILTINS_OBJECTS) \
$(UTILS_OBJECTS) \
$(PARSER_OBJECTS) \
$(PIPE_OBJECTS)

TEST_OBJECTS = $(APP_OBJECTS) \
$(ENV_OBJECTS) \
Expand All @@ -105,8 +113,10 @@ TEST_OBJECTS = $(APP_OBJECTS) \
$(BUILTINS_OBJECTS) \
$(UTILS_OBJECTS) \
$(PARSER_OBJECTS) \
$(PIPE_OBJECTS) \
$(MAIN_TEST_OBJECT) \
$(ENV_TEST_OBJECTS)
$(ENV_TEST_OBJECTS) \
$(PIPE_TEST_OBJECTS)

# Processing
all: $(NAME)
Expand Down Expand Up @@ -139,6 +149,10 @@ $(BUILD_DIR)/src/parser/%.o: $(PARSER_DIR)/%.c
@mkdir -p $(@D)
@$(COMPILER) $(CFLAGS) $(INCLUDES) -c $< -o $@

$(BUILD_DIR)/src/pipe/%.o: $(PIPE_DIR)/%.c
@mkdir -p $(@D)
@$(COMPILER) $(CFLAGS) $(INCLUDES) -c $< -o $@

$(LIBFT):
@cd $(LIB_DIR)/libft -s && make -s

Expand Down Expand Up @@ -169,6 +183,10 @@ $(BUILD_DIR)/test/env/%.o: $(TEST_DIR)/env/%.c
@mkdir -p $(@D)
@$(COMPILER) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@

$(BUILD_DIR)/test/pipe/%.o: $(TEST_DIR)/%.c
@mkdir -p $(@D)
@$(COMPILER) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@

test: $(TEST_OBJECTS) $(LIBFT)
@$(COMPILER) $(CFLAGS) $(TEST_OBJECTS) $(TEST_INCLUDES) $(LIBFT) -o $@ $(READLINE)
@echo "$(YELLOW)tests compiled$(DEF_COLOR)"
Expand Down
8 changes: 4 additions & 4 deletions inc/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/03 16:34:46 by dmdemirk #+# #+# */
/* Updated: 2024/06/04 12:18:43 by dmdemirk ### ########.fr */
/* Updated: 2024/06/17 11:02:55 by dmdemirk ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,8 +20,8 @@ int builtin_cd(t_minishell_data *data);
int builtin_echo(t_minishell_data *data);
int builtin_env(t_minishell_data *data);
int builtin_exit(t_minishell_data *data);
// int export(char **argv);
// int pwd(char **argv);
// int unset(char **argv);
int builtin_export(t_minishell_data *data);
int builtin_pwd(t_minishell_data *data);
int builtin_unset(t_minishell_data *data);

#endif
2 changes: 1 addition & 1 deletion inc/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void init_env(t_env **data_envp, char **envp);
void add_env_node(t_env **data_envp, char *line);
char *get_env(t_env *envp, const char *key);
void set_env(t_env **env, const char *key, const char *value);
void unset_env(t_env **env, const char *name);
int unset_env(t_env **env, const char *name);

/* utils */
char **env_to_array(t_env *envp);
Expand Down
21 changes: 21 additions & 0 deletions inc/pipe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipe.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 11:02:59 by dmdemirk #+# #+# */
/* Updated: 2024/06/17 11:03:00 by dmdemirk ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PIPE_H
# define PIPE_H

# include "shell.h"

/* pipe */
void builtin_pipe(t_minishell_data *data);

#endif
21 changes: 12 additions & 9 deletions src/builtins/cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/03 16:31:07 by dmdemirk #+# #+# */
/* Updated: 2024/06/10 17:18:38 by dmdemirk ### ########.fr */
/* Updated: 2024/06/17 11:13:55 by dmdemirk ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,30 +15,33 @@
#include "shell.h"
#include "env.h"

/*
Functionality:
- Change the current directory
- Update the PWD and OLDPWD environment variables
- If no argument is provided, change to the HOME directory
- If the target directory does not exist, print an error message
*/

int builtin_cd(t_minishell_data *data)
{
char *target_dir;
char *home_dir;
char cwd[4096];

printf("builtin_cd\n");
home_dir = get_env(data->envp, "HOME");
target_dir = (char *)data->args[1];
if (!target_dir)
target_dir = home_dir;
else if (target_dir[0] == '~')
target_dir = ft_strjoin(home_dir, target_dir + 1);
else if (ft_strncmp(target_dir, "..", 2) == 0)
{
target_dir = get_env(data->envp, "PWD");
target_dir = ft_strcdup(target_dir, '/');
}
if (chdir(target_dir) != 0)
{
ft_putstr_fd("bash: cd: ", 2);
perror(target_dir);
return (1);
}
set_env(&data->envp, "OLDPWD", get_env(data->envp, "PWD"));
set_env(&data->envp, "PWD", target_dir);
if (getcwd(cwd, sizeof(cwd)) != NULL)
set_env(&data->envp, "PWD", cwd);
return (0);
}
5 changes: 5 additions & 0 deletions src/builtins/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "libft.h"
#include "shell.h"

/*
Functionality:
- Print the argument
*/

int builtin_echo(t_minishell_data *data)
{
int newline;
Expand Down
20 changes: 9 additions & 11 deletions src/builtins/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/03 16:32:34 by dmdemirk #+# #+# */
/* Updated: 2024/06/10 17:20:42 by dmdemirk ### ########.fr */
/* Updated: 2024/06/11 16:44:41 by dmdemirk ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdio.h>
#include "shell.h"
#include "env.h"
#include "libft.h"

/*
Functionality:
- Print the environment
*/

void print_env_stack(t_env *envp);
int builtin_env(t_minishell_data *data);
Expand All @@ -31,16 +37,8 @@ void print_env_stack(t_env *envp)

int builtin_env(t_minishell_data *data)
{
int i;
char *value;

i = 1;
printf("\nbuiltin_env\n");
printf("Print envp:\n");
if (data->args[i])
{
value = get_env(data->envp, data->args[i]);
printf("%s\n", value);
}
if (ft_strcmp(data->args[0], "env") == 0 && data->args[1] == NULL)
print_env_stack(data->envp);
return (0);
}
14 changes: 12 additions & 2 deletions src/builtins/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/03 16:32:42 by dmdemirk #+# #+# */
/* Updated: 2024/06/10 17:20:54 by dmdemirk ### ########.fr */
/* Updated: 2024/06/17 11:13:42 by dmdemirk ### ########.fr */
/* */
/* ************************************************************************** */

#include "shell.h"
#include <unistd.h>
#include "libft.h"
#include <stdlib.h>
#include <stdio.h>
#include "env.h"

/*
Functionality:
- Exit the shell
- Free the environment
- Exit with the exit status
*/

int builtin_exit(t_minishell_data *data)
{
const char *message;

printf("\nbuiltin_exit\n");
message = "exit\n";
write(STDOUT_FILENO, message, ft_strlen(message));
free_env(data->envp);
exit(data->exit_status);
}
Loading

0 comments on commit 6785b06

Please sign in to comment.