diff --git a/.github/README/minishelln.png b/.github/README/minishelln.png new file mode 100644 index 0000000..0d7bc6e Binary files /dev/null and b/.github/README/minishelln.png differ diff --git a/README.md b/README.md index 33025d4..fcf1b40 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,118 @@ -## Dependencies +
-- Debian/Ubuntu -``` -sudo apt-get install make libreadline-dev + + + + + + +

minishell

+ + +

A simple bash-like shell written in C.

+ + + Score + + + Language +
+ Last commit +
+ + + +
+ +--- + +## â„šī¸ About Project + +> The purpose of this project is to create a simple bash-like shell. + +DETAILED INFO + +For detailed info, refer to this project [subject](docs/en.subject.pdf). + +## 🚀 Getting Started + +### Prerequisites + +- GCC compiler +- Make utility +- Unix-like system (Linux, macOS, WSL) + +### Install prerequisites + +- APT + + ```bash + sudo apt install build-essential libreadline-dev + ``` + +- Pacman + + ```bash + sudo pacman -Sy base-devel readline-devel + ``` + +## 🔧 Build + +1. **Clone the repository:** + ```bash + git clone https://github.com/sdevsantiago/minishell.git + cd minishell + ``` + +2. **Compile the project:** + ```bash + make # Full compilation + ``` + +3. **Clean build files:** + ```bash + make clean # Remove object files + ``` + +#### Available Make Targets + +| Command | Description | +|---------|-------------| +| `make` | Compiles all | +| `make all` | Same as `make` | +| `make clean` | Remove object files (*.o) | +| `make fclean` | Remove object files and binaries | +| `make re` | Clean and rebuild everything | + +## 👨‍đŸ’ģ Usage + +### Basic Usage + +INSTRUCTIONS + +## 📏 Norminette + +The code strictly complies with 42's **Norminette v4**: + +```bash +norminette *.c *.h ``` -## How to install +More info in the official [Norminette](https://github.com/42school/norminette) repository. -1. Clone the repository -``` -git clone https://github.com/sdevsantiago/minishell.git && cd minishell -``` +## đŸ™‡â€â™‚ī¸ Special thanks -2. Build the project -``` -make && make clean -``` +- [lrcouto](https://github.com/lrcouto) and [ayogun](https://github.com/ayogun) for creating and publishing, respectively, the [42-project-badges](https://github.com/ayogun/42-project-badges) repository. +- [gcamerli](https://github.com/gcamerli) for creating the [42unlicense](https://github.com/gcamerli/42unlicense) repository. -3. Execute the program -``` -./minishell -``` +## âš–ī¸ License + +
+ + + + + +
+ +**This work is published under the terms of [42 Unlicense](LICENSE).** This means you are free to use, modify, and share this software. diff --git a/src/features/builtins/todo/alias.c b/include/.gitkeep similarity index 100% rename from src/features/builtins/todo/alias.c rename to include/.gitkeep diff --git a/include/builtins.h b/include/builtins.h deleted file mode 100644 index fa44f68..0000000 --- a/include/builtins.h +++ /dev/null @@ -1,70 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* builtins.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san -# include - -// cd.c - -int cd_builtin(int argc, char const *argv[]); - -# define CD_HELP - -// echo.c - -typedef struct s_echo_flags -{ - int newline; // print newline after everything has been printed -} t_echo_flags; - -int echo_builtin(int argc, char const *argv[]); - -# define ECHO_HELP - -// // env.c - -// int env_builtin(int argc, char const *argv[], char **envp); - -// exit.c - -int exit_builtin(int argc, char const *argv[]); - -# define EXIT_HELP - -// export.c - -int export_builtin(int argc, char const *argv[], char **envp); - -# define EXPORT_HELP - -// printenv.c - -int printenv_builtin(int argc, char const *argv[], char const *envp[]); - -# define PRINTENV_HELP - -// pwd.c - -int pwd_builtin(int argc, char const *argv[]); - -# define PWD_HELP - -// unset.c - -int unset_builtin(int argc, char const *argv[], char **envp); - -# define UNSET_HELP - -#endif diff --git a/include/history.h b/include/history.h deleted file mode 100644 index 0f80e4f..0000000 --- a/include/history.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* history.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san -# include -# include -# include -# include - -typedef struct s_cmd -{ - int argc; - char **argv; -} t_cmd; - -typedef struct s_history -{ - char *hist_file; - size_t hist_file_size; - t_cdlist hist; - size_t hist_size; -} t_history; - -typedef struct s_minishell -{ - char **envp; - t_history *history; - char *history_file; -} t_minishell; - -/* ******************************** Features ******************************** */ - -/* History */ - -// history.c -void ms_add_history(const char *line); -int ms_read_history(const char *hist_file); -void ms_write_history(const char *hist_file); - -/* ******************************* Commands ********************************* */ - -// command_utils.c - -int is_absolutepath(char const *cmd); -int is_builtin(t_cmd *cmd); -int is_local(char const *cmd); - -// exec.c - -int exec_cmd(t_cmd *cmd, char **envp); -int exec_builtin(t_cmd *cmd, char **envp); - -// parse.c - -t_cmd parse_cmd(char *line, t_minishell *minishell); - -// signals.c - -void init_signal(void); - -/* ********************************* Utils ********************************** */ - -// get_hostname.c -char *get_hostname(void); - -/* ******************************** Builtins ******************************** */ - -// builtin_utils.c -int is_builtin(t_cmd *cmd); - -#endif diff --git a/src/features/builtins/todo/builtin.c b/src/.gitkeep similarity index 100% rename from src/features/builtins/todo/builtin.c rename to src/.gitkeep diff --git a/src/commands/command_utils.c b/src/commands/command_utils.c deleted file mode 100644 index 39f0ff9..0000000 --- a/src/commands/command_utils.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* command_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san argv[0], "cd\0", 3) == 0) - return (cd_builtin(cmd->argc, (char const **)cmd->argv)); - else if (ft_strncmp(cmd->argv[0], "echo\0", 5) == 0) - return (echo_builtin(cmd->argc, (char const **)cmd->argv)); - // else if (ft_strncmp(cmd->argv[0], "env\0", 4) == 0) - // return (env_builtin(cmd->argc, (char const **)cmd->argv, envp)); - // else if (ft_strncmp(cmd->argv[0], "exit\0", 5) == 0) - // return (exit_builtin(cmd->argc, (char const **)cmd->argv)); - else if (ft_strncmp(cmd->argv[0], "export\0", 7) == 0) - return (export_builtin(cmd->argc, (char const **)cmd->argv, envp)); - else if ((ft_strncmp(cmd->argv[0], "env\0", 4) == 0 && cmd->argc == 1) - || ft_strncmp(cmd->argv[0], "printenv\0", 9) == 0) - return (printenv_builtin( - cmd->argc, (char const **)cmd->argv, (char const **)envp)); - else if (ft_strncmp(cmd->argv[0], "pwd\0", 4) == 0) - return (pwd_builtin(cmd->argc, (char const **)cmd->argv)); - else if (ft_strncmp(cmd->argv[0], "unset\0", 6) == 0) - return (unset_builtin(cmd->argc, (char const **)cmd->argv, envp)); - return (1); -} - -int exec_cmd( - t_cmd *cmd, - char **envp) -{ - int exit_code; - pid_t pid; - - exit_code = 0; - pid = fork(); - if (pid == 0) - exit_code = execve(cmd->argv[0], cmd->argv, envp); - waitpid(pid, NULL, 0); - return (exit_code); -} - diff --git a/src/commands/parse.c b/src/commands/parse.c deleted file mode 100644 index abd7fb5..0000000 --- a/src/commands/parse.c +++ /dev/null @@ -1,82 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san argv[0], "cd\0", 3) == 0 - || ft_strncmp(cmd->argv[0], "echo\0", 5) == 0 - || (ft_strncmp(cmd->argv[0], "env\0", 4) == 0 && cmd->argc == 1) - || ft_strncmp(cmd->argv[0], "exit\0", 5) == 0 - || ft_strncmp(cmd->argv[0], "export\0", 7) == 0 - || ft_strncmp(cmd->argv[0], "printenv\0", 9) == 0 - || ft_strncmp(cmd->argv[0], "pwd\0", 4) == 0 - || ft_strncmp(cmd->argv[0], "unset\0", 6) == 0); -} diff --git a/src/features/builtins/cd.c b/src/features/builtins/cd.c deleted file mode 100644 index 277a075..0000000 --- a/src/features/builtins/cd.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* cd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san newline = 1; -} diff --git a/src/features/builtins/env.c b/src/features/builtins/env.c deleted file mode 100644 index 4b66cc5..0000000 --- a/src/features/builtins/env.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* env.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san 2) - { - fprintf(stderr, "exit: too many arguments\n"); - exit_code = -1; - } - else - exit_code = (unsigned int)((unsigned char)(ft_atol(argv[1]))); - } - return (exit_code); -} diff --git a/src/features/builtins/export.c b/src/features/builtins/export.c deleted file mode 100644 index 354caa6..0000000 --- a/src/features/builtins/export.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* export.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san history_file); - while (1) - { - if (line) - free(line); - char *prompt = NULL; - if (prompt) - { - line = readline(prompt); - free(prompt); - } - else - line = readline("minishell> "); - if (!line) - { - write_history(minishell->history_file); - cmd = parse_cmd("exit", minishell); - exit_code = exit_builtin(cmd.argc, (const char **)cmd.argv); - if (exit_code != -1) - break ; - } - if (*line) - { - add_history(line); - cmd = parse_cmd(line, minishell); - free(line); - line = NULL; - if (ft_strncmp(cmd.argv[0], "exit\0", 5) == 0) - { - exit_code = exit_builtin(cmd.argc, (const char **)cmd.argv); - write_history(minishell->history_file); - if (exit_code != -1) - break ; - } - else if (is_builtin(&cmd)) - exec_builtin(&cmd, minishell->envp); - else - exec_cmd(&cmd, minishell->envp); - } - } - - write_history(minishell->history_file); - rl_clear_history(); - if (line) - free(line); - return (exit_code); -} - -/** - * @brief Clears and frees resources associated with a t_minishell instance. - * - * This function performs the following actions: - * - Zeroes out the contents of the history_file string. - * - Frees the memory allocated for the history_file. - * - Frees the memory allocated for the path array using ft_free_split. - * - Zeroes out the entire t_minishell structure. - * - * @param minishell Pointer to the t_minishell structure to be cleared and - * freed. - */ -static void clear_minishell( - t_minishell *minishell -) -{ - ft_bzero(minishell->history_file, - ft_strlen(minishell->history_file) * sizeof(char)); - free(minishell->history_file); - ft_bzero(minishell, sizeof(t_minishell)); -} diff --git a/src/utils/get_hostname.c b/src/utils/get_hostname.c deleted file mode 100644 index 74759f1..0000000 --- a/src/utils/get_hostname.c +++ /dev/null @@ -1,46 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_hostname.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sede-san