Skip to content

Development #1

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

Open
wants to merge 115 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
5f37d86
commit init development
RogerioLS Mar 31, 2024
6ebc0f7
Create validates.c
lucasl09 Apr 4, 2024
2f387cd
Create line_var.c
lucasl09 Apr 4, 2024
d3a14dc
Create line_var.c
lucasl09 Apr 4, 2024
a721bc9
Delete sources/variables/line_var.c
lucasl09 Apr 4, 2024
c74cb98
Create signal.c
lucasl09 Apr 7, 2024
0ae75e1
Create exit_type.c
lucasl09 Apr 7, 2024
f9a7cbb
Delete sources/mandatory/signal directory
lucasl09 Apr 7, 2024
89cd9ab
Create utils.c
lucasl09 Apr 7, 2024
69be71b
Create minishell.h
lucasl09 Apr 7, 2024
00248cb
Update mini_shell.h
lucasl09 Apr 7, 2024
1cdb704
Delete sources/mandatory/minishell.h
lucasl09 Apr 7, 2024
bd6bae0
Create in.c
lucasl09 Apr 7, 2024
3f2aa6f
Add files via upload
lucasl09 Apr 7, 2024
b71d746
edit Makefile
lucasl09 Apr 7, 2024
9edacfe
Update exit_type.c
lucasl09 Apr 7, 2024
bfeb224
Update mini_shell.h
lucasl09 Apr 7, 2024
af6cae2
main.c modification
RogerioLS Apr 7, 2024
f4b0769
Merge branch 'development' of https://github.com/RogerioLS/Minishell-…
RogerioLS Apr 7, 2024
4830ad4
main
RogerioLS Apr 7, 2024
5981f10
main rog and lucas
RogerioLS Apr 10, 2024
f205497
Delete sources/libft/in.c
lucasl09 Apr 11, 2024
fda85fb
Delete sources/libft directory
lucasl09 Apr 11, 2024
64be957
libft commited
lucasl09 Apr 11, 2024
e9207d7
Update mini_shell.h
lucasl09 Apr 11, 2024
d83edd2
new mini_shell.h
lucasl09 Apr 11, 2024
f46498a
Delete includes/mandatory directory
lucasl09 Apr 11, 2024
8e33afc
Update utils.c
lucasl09 Apr 11, 2024
3914a92
Update exit_type.c
lucasl09 Apr 11, 2024
c8e2e46
Update line_var.c
lucasl09 Apr 11, 2024
00ed968
Update validates.c
lucasl09 Apr 11, 2024
8a840df
Update mini_shell.h
lucasl09 Apr 11, 2024
1ddc510
Create mini_shell.h
lucasl09 Apr 11, 2024
3468144
Delete includes/mini_shell.h
lucasl09 Apr 11, 2024
daf0fc4
Update utils.c
lucasl09 Apr 11, 2024
e39280e
Update exit_type.c
lucasl09 Apr 11, 2024
c0d05e6
Update line_var.c
lucasl09 Apr 11, 2024
0605f85
Update validates.c
lucasl09 Apr 11, 2024
fb8340d
Update Makefile
lucasl09 Apr 11, 2024
912d7d2
add modifictions
RogerioLS Apr 13, 2024
b45e33e
init as a tokenizer.c
lucasl09 Apr 14, 2024
2f36af7
Update main_rog.c with tokenizer.c
lucasl09 Apr 14, 2024
d65c983
init utils2.c
lucasl09 Apr 14, 2024
abec432
Update utils.c
lucasl09 Apr 14, 2024
768d3ca
Update utils2.c
lucasl09 Apr 14, 2024
bfa4f77
Update tokenizer.c
lucasl09 Apr 14, 2024
f8a73c2
init create_token.c
lucasl09 Apr 14, 2024
7089c96
Delete sources/mandatory/main/main_lucas.c
lucasl09 Apr 14, 2024
87fd7e0
update main_lucas.c
lucasl09 Apr 14, 2024
dcfea70
Update Makefile
lucasl09 Apr 14, 2024
c4921fc
Update utils.c
lucasl09 Apr 14, 2024
0559191
Update utils2.c
lucasl09 Apr 14, 2024
ca52cf1
Update mini_shell.h
lucasl09 Apr 14, 2024
cff2eae
commented main_rog.c
lucasl09 Apr 14, 2024
576a98a
Update create_token.c
lucasl09 Apr 14, 2024
8e1e54b
commented more functions on main_rog.c
lucasl09 Apr 14, 2024
6ed1fba
init free_type.c
lucasl09 Apr 14, 2024
78b08f6
FREE and tokenizer commited
lucasl09 Apr 14, 2024
6f1b8c9
Update tokens
lucasl09 Apr 14, 2024
047833d
add all free's
lucasl09 Apr 14, 2024
c770d77
Update utils2.c
lucasl09 Apr 14, 2024
f90c9ee
Update mini_shell.h
lucasl09 Apr 14, 2024
a65af44
Update mini_shell.h
lucasl09 Apr 14, 2024
526de30
Update utils2.c
lucasl09 Apr 14, 2024
cbbef5b
Update utils.c
lucasl09 Apr 14, 2024
aff0dac
norminette adjust
lucasl09 Apr 14, 2024
dfa0f23
norminette adjust
lucasl09 Apr 14, 2024
0981a91
norminette adjust
lucasl09 Apr 14, 2024
e39e912
temp adjust to main_rog.c
lucasl09 Apr 14, 2024
f29b763
norminette adjust
lucasl09 Apr 14, 2024
2dbc2a5
init tests for create_token.c
lucasl09 Apr 14, 2024
4d21fa5
init some tests for create_token.c
lucasl09 Apr 14, 2024
12d0abe
Update create_token.c
lucasl09 Apr 14, 2024
e9a9296
Update create_token.c
lucasl09 Apr 14, 2024
e18a392
init tests rn main_lucas.c
lucasl09 Apr 14, 2024
b7dbfa5
commited for tokenization
lucasl09 Apr 14, 2024
03f5c64
Update main_lucas.c
lucasl09 Apr 14, 2024
6aadb7b
Update main_lucas.c
lucasl09 Apr 14, 2024
a19f1b0
started some tests
lucasl09 Apr 14, 2024
a854659
test num 8 [main_lucas.c]
lucasl09 Apr 14, 2024
49f8123
Update create_token.c
lucasl09 Apr 14, 2024
0d8ea2e
Update main_rog.c
lucasl09 Apr 14, 2024
05fb010
Update create_token.c
lucasl09 Apr 14, 2024
91fe026
Update mini_shell.h
lucasl09 Apr 14, 2024
a2d4a4f
Update main_lucas.c
lucasl09 Apr 14, 2024
23f0cc9
add objects
RogerioLS Apr 14, 2024
e27441c
Merge branch 'development' of https://github.com/RogerioLS/Minishell-…
RogerioLS Apr 14, 2024
426469b
organizations functions
RogerioLS Apr 14, 2024
6adfa34
some builtins has been add
lucasl09 Apr 21, 2024
c415a6e
bultins update
lucasl09 Apr 21, 2024
3360137
core dump fixed
lucasl09 Apr 21, 2024
6209de2
refactoring the ft_strtok function
RogerioLS Apr 29, 2024
ca7e4ad
ft_cd and ft_pwd add
lucasl09 May 1, 2024
46b157e
add functions from lucas the project real
RogerioLS May 5, 2024
12339d4
file .log
RogerioLS May 5, 2024
597c4f0
fixed command env
lucasl09 May 5, 2024
37e57f7
finish merge code lucas
RogerioLS May 11, 2024
7ca4559
Update execute_command2.c
lucasl09 May 12, 2024
6a34fe4
Update execute_command.c
lucasl09 May 12, 2024
1bc865b
Update signal.c
lucasl09 May 12, 2024
46d3251
Update create_token.c
lucasl09 May 12, 2024
e0ad254
Update main_lucas.c
lucasl09 May 12, 2024
3131b5f
fixed echo
lucasl09 May 12, 2024
677c9b3
Update mini_shell.h
lucasl09 May 12, 2024
0b503b3
new source for command without redirect or heredoc
lucasl09 May 19, 2024
6ec154f
commented some functions ./=
lucasl09 May 19, 2024
f7d963c
created function variable expansion
RogerioLS May 19, 2024
c2b8245
rum expand variables
RogerioLS May 20, 2024
113dc44
implamention expansio
RogerioLS Jun 1, 2024
658bbb2
add funtions Lucas
RogerioLS Jun 2, 2024
caa8955
add funtions Lucas
RogerioLS Jun 2, 2024
6010303
simple echo for subject
lucasl09 Jun 8, 2024
8f83c5b
fixed heredoc and delimiter
lucasl09 Jun 8, 2024
72e015f
fixed delimiter and init global signals
lucasl09 Jun 8, 2024
80f1dd6
breaking functions
RogerioLS Jun 13, 2024
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
121 changes: 121 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: roglopes <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/03/31 16:34:27 by roglopes #+# #+# #
# Updated: 2024/06/01 17:40:31 by roglopes ### ########.fr #
# #
# **************************************************************************** #

NAME = minishell

SOURCES_DIR = sources/
OBJECTS_DIR = objects/

HEADERS = -I ./includes/mandatory/ -I ./libft/include/

MAIN_DIR = $(SOURCES_DIR)mandatory/main/
UTILS_DIR = $(SOURCES_DIR)mandatory/utils/
VARIABLES_DIR = $(SOURCES_DIR)mandatory/variables/
TOKEN_DIR = $(SOURCES_DIR)mandatory/tokenizer/
FREE_DIR = $(SOURCES_DIR)mandatory/free/
PROMPT_DIR = $(SOURCES_DIR)mandatory/prompt/
COMMAND_DIR = $(SOURCES_DIR)mandatory/command/
EXPANSION_DIR = $(SOURCES_DIR)mandatory/expansion/

LIBFT = ./libft/libft.a

CFLAGS = -Wextra -Wall -Werror -g3
CC = cc

VALGRIND_LOG = valgrind.log

MAIN_SOURCES = $(MAIN_DIR)main.c

UTILS_SOURCES = $(UTILS_DIR)utils.c \
$(UTILS_DIR)utils2.c \
$(UTILS_DIR)utils_execute_command.c

TOKEN_SOURCES = $(TOKEN_DIR)tokenizer.c \
$(TOKEN_DIR)create_token.c \

FREE_SOURCES = $(FREE_DIR)free_type.c

VARIABLES_SOURCES = $(VARIABLES_DIR)exit_type.c \
$(VARIABLES_DIR)line_var.c \
$(VARIABLES_DIR)validates.c \

PROMPT_SOURCES = $(PROMPT_DIR)prompt.c \
$(PROMPT_DIR)signal.c

COMMAND_SOURCES = $(COMMAND_DIR)execute_command.c \
$(COMMAND_DIR)execute_command2.c

EXPANSION_SOURCES = $(EXPANSION_DIR)variable_expansion.c

SOURCES = $(MAIN_SOURCES) $(UTILS_SOURCES) $(VARIABLES_SOURCES) \
$(TOKEN_SOURCES) $(FREE_SOURCES) $(PROMPT_SOURCES) \
$(COMMAND_SOURCES) $(EXPANSION_SOURCES)

OBJS = $(patsubst $(SOURCES_DIR)%.c,$(OBJECTS_DIR)%.o, $(SOURCES))

COUNT := 0
RED = \033[0;31m
GREEN = \033[0;32m
MAGENTA = \033[0;35m
RESET = \033[0m
CYAN = \033[36;1;3;208m
YELLOW = \033[0;33m
COLOR_LIMITER = "\033[0m"

all: create_objects_dir libft $(OBJECTS_DIR) $(NAME)

$(OBJECTS_DIR)%.o: $(SOURCES_DIR)%.c
@mkdir -p $(@D)
@$(eval COUNT=$(shell expr $(COUNT) + 1))
@$(CC) $(CFLAGS) -o $@ -c $< $(HEADERS)
@printf "$(GREEN)Compiling Push Swap %d%%\r$(RESET)" $$(echo $$(($(COUNT) * 100 / $(words $(SOURCES_DIR)))))

$(NAME): $(OBJS)
@$(CC) $(CFLAGS) $(OBJS) $(HEADERS) $(LIBFT) -o $(NAME) -lreadline

create_objects_dir:
@mkdir -p $(OBJECTS_DIR)

libft:
@make -C ./libft --no-print-directory

clean:
@make clean -C ./libft --no-print-directory
@rm -rf $(OBJECTS_DIR)
@rm -rf $(VALGRIND_LOG)
@printf "$(RED)Deleted objects Mini Shell$(RESET)\n"

fclean: clean
@echo "Cleaning all... 🧹"
@rm -rf $(NAME)
@make fclean -C ./libft --no-print-directory
@printf "$(RED)Project is deleted Mini Shell$(RESET)\n"
@printf "$(RED)File valgrind.log deleted$(RESET)\n"
@echo "✨ Cleaning complete! ✨"

norm:
@norminette -R CheckForbiddenSource
@echo "$(CYAN)NORMINETTE OK $(RESET)"

valgrind: all
@valgrind --leak-check=full \
--show-reachable=yes \
--show-leak-kinds=all -s \
--track-origins=yes \
--log-file=$(VALGRIND_LOG) \
./$(NAME)
@cat $(VALGRIND_LOG)

re: fclean all
@echo "$(BLUE) $(NAME) Cleaned and rebuilt everything!"

.PHONY: all clean fclean re libft bonus norm create_objects_dir valgrind
Binary file added a.out
Binary file not shown.
200 changes: 200 additions & 0 deletions includes/mandatory/mini_shell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mini_shell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roglopes <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/31 16:52:11 by roglopes #+# #+# */
/* Updated: 2024/06/02 18:27:25 by roglopes ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef MINI_SHELL_H
# define MINI_SHELL_H

# include "../../libft/include/ft_printf.h"
# include "../../libft/include/get_next_line.h"
# include "../../libft/include/libft.h"
# include <dirent.h>
# include <errno.h>
# include <fcntl.h>
# include <grp.h>
# include <limits.h>
# include <linux/limits.h>
# include <pwd.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <signal.h>
# include <stdbool.h>
# include <stddef.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/errno.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <unistd.h>

# define MAX_PATH_LEN 1024
# define ARG_MAX 4096 // Máximo do próprio shell//

enum e_token_type
{
TOKEN_WORD,
TOKEN_OPERATOR,
TOKEN_HEREDOC,
TOKEN_APPEND,
TOKEN_PIPE,
TOKEN_DOLLAR,
TOKEN_L_PAREN,
TOKEN_R_PAREN,
TOKEN_QUOTE,
TOKEN_DOUBLE_QUOTE,
TOKEN_L_REDIR,
TOKEN_R_REDIR
};

typedef struct s_mini
{
char *name;
char *cmd_line;
int exported;
int aftercmd;
struct s_mini *next;
} t_mini;

typedef struct s_token
{
char *text;
enum e_token_type type;
struct s_token *next;
} t_token;

typedef struct s_alias
{
char *name;
char *command;
struct s_alias *next;
} t_alias;

typedef enum
{
COMMAND_SIMPLE,
COMMAND_PIPELINE,
COMMAND_REDIRECTION_INPUT,
COMMAND_REDIRECTION_OUTPUT,
COMMAND_REDIRECTION_APPEND
} CommandType;

typedef struct s_command
{
char *text;
CommandType type;
struct s_command *next;
} t_command;

// Tokenizer
t_token *create_token(const char *text, enum e_token_type type);
t_token *input_tokenizer(char *input);
bool is_operator_char(char c);
bool is_inside_quotes(char *cursor);
char *skip_quotes(char *cursor);
bool is_operator_or_end(char *cursor);
int classify_token(const char *token);
char **tokens_to_argv(t_token *tokens);

// Utils
char *ft_strtok(char *str, const char *delim);

/* we will probably delete */
char *ft_antispace(char *buff);
/* we will probably delete */
char *ft_firstword(char *buff);

// Utils2
size_t ft_strcspn(const char *s, const char *reject);
size_t ft_strspn(const char *s, const char *accept);

// Variables
/* we will probably delete all*/
int ft_exit(char *buff);
bool commandline_var(char *cmd);
bool validate_name(char *var_name);

// Free
void ft_free_commands(t_command *head);
void ft_free_tokens(t_token *head);

// Prompt
char *prompt(void);
int afterprompt(int is_after);
void parse_input(char *input, char *result);
void handle_double_quotes(char **input, char *result,
size_t *res_len);
void handle_single_quotes(char **input, char *result,
size_t *res_len);

// Signal
void handle_signal(int sign);

// Command
void handle_redirection_and_execution(char **tokens,
int input_fd, int output_fd);
int handle_heredoc(char **tokens, int i);
int handle_redirection(char **tokens, int *input_fd,
int *output_fd, int i);

void execute_command(char **args);
void handle_internal_command(char **args);

void ft_pwd(int argc, char **argv);
void ft_echo(char **args);
void ft_unset(char **args);
char *ft_realpath(const char *path,
char *resolved_path);

char *read_command(void);
size_t ft_arraylen(char **array);
void export_variable(char **args);
void ft_cd(char *path);
void clear_screen(void);
void print_environment(void);
void process_arguments(char **args, char *path,
int *long_format);
void ft_free_string_array(char **array);
char *ft_strjoin_free(char *s1, char *s2);

char ***parse_commands_with_pipes(char **args);
int count_pipes(char **args);
char ***allocate_commands(int num_pipes);
void split_commands(char **args, char ***commands);


void execute_pipeline(char ***commands);
int count_commands(char ***commands);
void create_pipes(int *pipefds, int num_pipes);
void close_pipes(int *pipefds, int num_pipes);
void setup_redirection(int *pipefds, int num_pipes, int i);
void execute_command_in_pipeline(char **command, int *pipefds, int num_pipes, int i);

int execute_external_command(char **args);

// Command Utils
char *ft_strcpy(char *dest, const char *src);
void process_arguments(char **args, char *path,
int *long_format);
void print_file_info(struct dirent *entry, char *path);
int ft_lstsize_token(t_token *head);

// Expansion
char *expand_variable(const char *variable);
void append_variable_expanded(char **expanded,
const char **cursor);
void append_char_expanded(char **expanded,
const char **cursor);
void expand_token(t_token *token);
void expand_variables_tokens(t_token *head);

#endif
42 changes: 42 additions & 0 deletions libft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
NAME=libft.a
CC=cc
CFLAGS=-Wall -Wextra -Werror
RM = rm -f
INC = -I./include

FILES_LIB = ft_isalpha ft_isdigit ft_isalnum ft_isascii ft_isprint \
ft_strlen ft_memset ft_bzero ft_memcpy ft_memmove \
ft_strlcpy ft_strlcat ft_toupper ft_tolower ft_strchr \
ft_strrchr ft_strncmp ft_memchr ft_memcmp ft_strnstr \
ft_atoi ft_calloc ft_strdup ft_substr ft_strjoin \
ft_strtrim ft_split ft_itoa ft_strmapi ft_striteri \
ft_putchar_fd ft_putstr_fd ft_putendl_fd ft_putnbr_fd \
ft_isspace ft_lstsize ft_strcmp
FILES_GNL = get_next_line get_next_line_utils
FILES_PRINTF = ft_printf printf_utils

SRC_DIR_LIB = src/
SRC_DIR_GNL = gnl/
SRC_DIR_PRINTF = printf/

OBJ_LIB = $(addprefix $(SRC_DIR_LIB), $(addsuffix .o, $(FILES_LIB)))
OBJ_PRINTF = $(addprefix $(SRC_DIR_PRINTF), $(addsuffix .o, $(FILES_PRINTF)))
OBJ_GNL = $(addprefix $(SRC_DIR_GNL), $(addsuffix .o, $(FILES_GNL)))

all: $(NAME)

$(NAME): $(OBJ_LIB) $(OBJ_PRINTF) $(OBJ_GNL)

%.o: %.c
$(CC) $(INC) $(CFLAGS) -c $< -o $@
ar rcs $(NAME) $@

clean:
rm -f $(OBJ_LIB) $(OBJ_PRINTF) $(OBJ_GNL)

fclean: clean
$(RM) $(NAME)

re: clean all

.PHONY: all clean fclean re
Loading