Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: ttsubo <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/04/03 12:55:20 by ttsubo #+# #+# #
# Updated: 2025/05/04 16:50:59 by ttsubo ### ########.fr #
# Updated: 2025/05/04 19:49:07 by ttsubo ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -60,13 +60,13 @@ endef

# 2.Add the source code when it is added
ROOT_SRC = main.c minish_signal.c initialize.c error.c
COMMON_SRC = validate_key.c error_mes.c
COMMON_SRC = validate_key.c error_mes.c free_functions.c free_functions_2.c
INVOKE_CMD_SRC = create_envp.c exec_pipeline.c execute_cmd.c \
execute_cmd_helper.c invoke_command.c pipeline_helper.c \
redirect.c fds.c wait_pipeline.c
TOKENIZER_SRC = tokenizer.c tokenizer_error.c read_token.c \
is_quote_closed.c get_token_capa.c is_redirect_validate.c
PARSER_SRC = allocate_cmds.c parser.c parser_free.c parser_utils.c setup_cmds.c \
PARSER_SRC = allocate_cmds.c parser.c parser_utils.c setup_cmds.c \
allocate_cmds_utils.c allocate_cmds_utils_2.c \
expand_env.c expand_tokens.c
BUILTIN_SRC = cd.c exit.c pwd.c echo.c env.c unset.c export.c \
Expand Down
3 changes: 1 addition & 2 deletions inc/builtin/env_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 10:25:47 by dayano #+# #+# */
/* Updated: 2025/05/04 12:14:29 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 18:49:36 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,7 +17,6 @@

void free_env_content(char *value);
void remove_env_node(t_env **env_lst, t_env *target);
void free_env_list(t_env *head);
void cleanup_minish(t_minish *minish);
void handle_error_and_exit(const char *func_name, t_minish *minish);
void add_env_back(t_env **lst, t_env *new);
Expand Down
38 changes: 0 additions & 38 deletions inc/common/cmd.h

This file was deleted.

4 changes: 2 additions & 2 deletions inc/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 11:44:19 by ttsubo #+# #+# */
/* Updated: 2025/05/04 12:18:40 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 19:17:09 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,10 +16,10 @@
# include <stdbool.h>
# include <stddef.h>
# include "libft.h"
# include "cmd.h"
# include "error.h"
# include "initialize.h"
# include "struct.h"
# include "free_functions.h"

bool is_key_start(int c);
bool is_key_char(int c);
Expand Down
23 changes: 15 additions & 8 deletions inc/parser_free.h → inc/common/free_functions.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_free.h :+: :+: :+: */
/* free_functions.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/02 21:22:56 by ttsubo #+# #+# */
/* Updated: 2025/05/02 21:27:46 by ttsubo ### ########.fr */
/* Created: 2025/05/04 17:50:02 by ttsubo #+# #+# */
/* Updated: 2025/05/04 20:13:57 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PARSER_FREE_H
# define PARSER_FREE_H
#ifndef FREE_FUNCTIONS_H
# define FREE_FUNCTIONS_H

void free_tokens(char **tokens);
void free_cmd(t_cmd *cmd);
void free_cmds(t_cmd **cmds);
# include "stdlib.h"
# include "struct.h"

void free_str(char **pstr);
void free_strs(char ***pstrs);
void free_node(t_env **pnode);
void free_nodes(t_env **phead);
void free_cmd(t_cmd **pcmd);
void free_cmds(t_cmd ***pcmds);
void free_prompt(char ***ptokens, t_cmd ***pcmds, char **pline);

#endif
24 changes: 23 additions & 1 deletion inc/common/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 17:10:22 by dayano #+# #+# */
/* Updated: 2025/04/29 11:57:58 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 19:16:10 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef STRUCT_H
# define STRUCT_H

# include <sys/wait.h>

typedef enum e_redir_type
{
REDIR_NONE,
REDIR_OUT,
REDIR_APPEND,
REDIR_IN,
REDIR_HEREDOC
} t_redir_type;

typedef struct s_env
{
char *key;
Expand All @@ -27,4 +38,15 @@ typedef struct s_minish
int last_status;
} t_minish;

typedef struct s_cmd
{
t_redir_type type;
int argc;
char **argv;
int capa;
int status;
pid_t pid;
struct s_cmd *next;
} t_cmd;

#endif
3 changes: 1 addition & 2 deletions inc/invoke_cmd/exec_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 13:12:27 by dayano #+# #+# */
/* Updated: 2025/05/04 12:33:03 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 19:17:55 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef EXEC_PIPELINE_H
# define EXEC_PIPELINE_H

# include "cmd.h"
# include "common.h"
# include "execute_cmd.h"
# include "invoke_command.h"
Expand Down
6 changes: 3 additions & 3 deletions inc/invoke_cmd/invoke_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
/* ::: :::::::: */
/* invoke_command.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/20 21:21:13 by dayano #+# #+# */
/* Updated: 2025/05/04 18:32:13 by dayano ### ########.fr */
/* Updated: 2025/05/04 20:45:51 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef INVOKE_COMMAND_H
# define INVOKE_COMMAND_H

# include "cmd.h"
# include "common.h"
# include "create_envp.h"
# include "exec_pipeline.h"
# include "execute_cmd.h"
Expand Down
6 changes: 3 additions & 3 deletions inc/invoke_cmd/pipeline_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
/* ::: :::::::: */
/* pipeline_helper.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/24 14:32:27 by dayano #+# #+# */
/* Updated: 2025/04/28 14:56:23 by dayano ### ########.fr */
/* Updated: 2025/05/04 19:18:38 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PIPELINE_HELPER_H
# define PIPELINE_HELPER_H

# include "cmd.h"
# include "common.h"
# include <fcntl.h>
# include <stdbool.h>

Expand Down
6 changes: 3 additions & 3 deletions inc/invoke_cmd/redirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
/* ::: :::::::: */
/* redirect.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/28 15:20:03 by dayano #+# #+# */
/* Updated: 2025/04/28 15:30:35 by dayano ### ########.fr */
/* Updated: 2025/05/04 19:19:04 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef REDIRECT_H
# define REDIRECT_H

# include "cmd.h"
# include "common.h"

void redirect(t_cmd *cmd);
void redirect_stdout(t_cmd *cmd);
Expand Down
5 changes: 2 additions & 3 deletions inc/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 14:14:59 by ttsubo #+# #+# */
/* Updated: 2025/05/02 21:25:06 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 19:19:21 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PARSER_H
# define PARSER_H

# include "cmd.h"
# include "parser_free.h"
# include "common.h"
# include "expand_env.h"
# include "libft.h"

Expand Down
18 changes: 2 additions & 16 deletions src/builtin/env_utils_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,17 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:17:22 by dayano #+# #+# */
/* Updated: 2025/05/01 14:27:15 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 18:49:19 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#include "main.h"

void free_env_list(t_env *head)
{
t_env *next;

while (head)
{
next = head->next;
free(head->key);
free(head->value);
free(head);
head = next;
}
}

void cleanup_minish(t_minish *minish)
{
if (!minish)
return ;
free_env_list(minish->env);
free_nodes(&minish->env);
free(minish);
}

Expand Down
4 changes: 2 additions & 2 deletions src/builtin/split_key_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/01 14:27:33 by ttsubo #+# #+# */
/* Updated: 2025/05/01 14:54:33 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 21:03:01 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -77,7 +77,7 @@ int split_key_value(char *str, char **key_out, char **val_out)
{
*val_out = _strip_quotes(str, val_start);
if (!*val_out)
return (free(*key_out), *key_out = NULL, 1);
return (free_str(key_out), 1);
}
return (0);
}
66 changes: 66 additions & 0 deletions src/common/free_functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/04 17:48:51 by ttsubo #+# #+# */
/* Updated: 2025/05/04 18:20:48 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#include "free_functions.h"

void free_str(char **pstr)
{
if (!pstr || !*pstr)
return ;
free(*pstr);
*pstr = NULL;
}

void free_strs(char ***pstrs)
{
int i;
char **strs;

i = 0;
if (!pstrs || !*pstrs)
return ;
strs = *pstrs;
while (strs[i])
free_str(&strs[i++]);
free(strs);
*pstrs = NULL;
}

void free_node(t_env **pnode)
{
t_env *node;

if (!pnode || !*pnode)
return ;
node = *pnode;
free(node->key);
free(node->value);
free(node);
*pnode = NULL;
}

void free_nodes(t_env **phead)
{
t_env *curr;
t_env *next;

if (!phead || !*phead)
return ;
curr = *phead;
while (curr)
{
next = curr->next;
free_node(&curr);
curr = next;
}
*phead = NULL;
}
Loading