-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/create envp #163
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
Merged
Merged
Feature/create envp #163
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e6600cc
fix main func
dayano74 ae96fc3
Merge branch 'main' into feature/invoke_command
dayano74 73d6bf4
Include stdbool.h
dayano74 db9122d
Merge branch 'main' into feature/invoke_command
dayano74 b2eb794
fix main func for parse_line and invoke_cmd
dayano74 4072b2f
add stdbool.h and updatep prompt
dayano74 b2f118f
implement invoke_command and create helper func prototype
dayano74 5e953f1
fix comment msg
dayano74 3a16430
fix conflict
dayano74 30850e4
fix conflict
dayano74 eb3353c
Merge branch 'main' into feature/invoke_command
dayano74 033d56d
Add header and Define tentative functioins
dayano74 f0234f9
add exec_pipeline base
dayano74 82732b8
Add create_envp
dayano74 5786bfb
ビルドエラー解消
cacapon 22c6431
Merge branch 'main' into feature/create-envp
cacapon 06c70ab
fix a part of comment
dayano74 e5609bf
Merge remote-tracking branch 'origin/feature/create-envp' into featur…
dayano74 80868ab
fix norm error
dayano74 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,16 +6,17 @@ | |
| # By: ttsubo <[email protected]> +#+ +:+ +#+ # | ||
| # +#+#+#+#+#+ +#+ # | ||
| # Created: 2025/04/03 12:55:20 by ttsubo #+# #+# # | ||
| # Updated: 2025/04/24 15:32:30 by ttsubo ### ########.fr # | ||
| # Updated: 2025/04/25 18:21:35 by ttsubo ### ########.fr # | ||
| # # | ||
| # **************************************************************************** # | ||
|
|
||
| NAME = minishell | ||
| CC = cc | ||
|
|
||
| SRC_DIR = src/ | ||
| PARSER_SRC_DIR = src/parser/ | ||
| TOKENIZER_SRC_DIR = src/tokenizer/ | ||
| PERSER_SRC_DIR = src/perser/ | ||
| INVOKE_CMD_SRC_DIR = src/invoke_cmd/ | ||
| BUILTIN_SRC_DIR = src/builtin/ | ||
| INC_DIR = inc/ | ||
| OBJ_DIR = obj/ | ||
|
|
@@ -26,20 +27,24 @@ W_FLG = -Wall -Wextra -Werror | |
| I_FLG = -I$(INC_DIR) -I$(FT_DIR) | ||
| L_FLG = -lreadline -lft | ||
|
|
||
| SRC = main.c minish_signal.c initialize.c debug.c | ||
| SRC = main.c minish_signal.c initialize.c | ||
| INVOKE_CMD_SRC = create_envp.c exec_pipeline.c execute_cmd.c \ | ||
| execute_cmd_helper.c invoke_command.c pipeline_helper.c | ||
| TOKENIZER_SRC = tokenizer.c tokenizer_error.c read_token.c \ | ||
| is_quote_closed.c get_token_capa.c is_redirect_validate.c | ||
| PERSER_SRC = allocate_cmds.c perser.c perser_utils.c setup_cmds.c | ||
| PARSER_SRC = allocate_cmds.c parser.c parser_utils.c setup_cmds.c | ||
| BUILTIN_SRC = cd.c exit.c pwd.c echo.c env.c unset.c \ | ||
| env_utils.c env_utils_2.c builtin_utils.c | ||
|
|
||
| SRCS = $(addprefix $(SRC_DIR), $(SRC)) | ||
| SRCS += $(addprefix $(PARSER_SRC_DIR), $(PARSER_SRC)) | ||
| SRCS += $(addprefix $(TOKENIZER_SRC_DIR), $(TOKENIZER_SRC)) | ||
| SRCS += $(addprefix $(PERSER_SRC_DIR), $(PERSER_SRC)) | ||
| SRCS += $(addprefix $(INVOKE_CMD_SRC_DIR), $(INVOKE_CMD_SRC)) | ||
| SRCS += $(addprefix $(BUILTIN_SRC_DIR), $(BUILTIN_SRC)) | ||
| OBJS = $(addprefix $(OBJ_DIR), $(SRC:.c=.o)) | ||
| OBJS += $(addprefix $(OBJ_DIR), $(PARSER_SRC:.c=.o)) | ||
| OBJS += $(addprefix $(OBJ_DIR), $(TOKENIZER_SRC:.c=.o)) | ||
| OBJS += $(addprefix $(OBJ_DIR), $(PERSER_SRC:.c=.o)) | ||
| OBJS += $(addprefix $(OBJ_DIR), $(INVOKE_CMD_SRC:.c=.o)) | ||
| OBJS += $(addprefix $(OBJ_DIR), $(BUILTIN_SRC:.c=.o)) | ||
|
|
||
| LIBFT=libft.a | ||
|
|
@@ -55,10 +60,13 @@ $(FT_DIR)$(LIBFT): | |
| $(OBJ_DIR)%.o: $(SRC_DIR)%.c | ||
| $(CC) $(W_FLG) $(I_FLG) -c $< -o $@ | ||
|
|
||
| $(OBJ_DIR)%.o: $(PARSER_SRC_DIR)%.c | ||
| $(CC) $(W_FLG) $(I_FLG) -c $< -o $@ | ||
|
|
||
| $(OBJ_DIR)%.o: $(TOKENIZER_SRC_DIR)%.c | ||
| $(CC) $(W_FLG) $(I_FLG) -c $< -o $@ | ||
|
|
||
| $(OBJ_DIR)%.o: $(PERSER_SRC_DIR)%.c | ||
| $(OBJ_DIR)%.o: $(INVOKE_CMD_SRC_DIR)%.c | ||
| $(CC) $(W_FLG) $(I_FLG) -c $< -o $@ | ||
|
|
||
| $(OBJ_DIR)%.o: $(BUILTIN_SRC_DIR)%.c | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* create_envp.h :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/24 13:58:03 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/24 13:59:24 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #ifndef CREATE_ENVP_H | ||
| # define CREATE_ENVP_H | ||
|
|
||
| # include "struct.h" | ||
|
|
||
| char **create_envp(t_minish *minish); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* exec_pipeline.h :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/21 13:12:27 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/24 14:17:43 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #ifndef EXEC_PIPELINE_H | ||
| # define EXEC_PIPELINE_H | ||
|
|
||
| # include "cmd.h" | ||
|
|
||
| void exec_pipeline(t_cmd *cmd_head, t_minish *minish); | ||
| int wait_pipeline(t_cmd *cmd_head); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* execute_cmd.h :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/21 21:39:18 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/24 15:03:36 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #ifndef EXECUTE_CMD_H | ||
| # define EXECUTE_CMD_H | ||
|
|
||
| # define PATH_PREFIX_LEN 5 | ||
| # define EQUAL_LEN 1 | ||
|
|
||
| void execute_cmd(t_cmd *cmd, t_minish *minish); | ||
|
|
||
| // execute_cmd_helper.c | ||
| char *join_path(char *dir, char *cmd); | ||
| char *get_path_line(char **envp); | ||
| void free_str_array(char **str); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| /* By: ttsubo <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/03 12:50:38 by ttsubo #+# #+# */ | ||
| /* Updated: 2025/04/24 15:28:00 by ttsubo ### ########.fr */ | ||
| /* Updated: 2025/04/25 18:16:36 by ttsubo ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
|
|
@@ -16,15 +16,19 @@ | |
| # include "builtin.h" | ||
| # include "builtin_utils.h" | ||
| # include "cmd.h" | ||
| # include "create_envp.h" | ||
| # include "env_utils.h" | ||
| # include "env_utils_2.h" | ||
| # include "exec_pipeline.h" | ||
| # include "execute_cmd.h" | ||
| # include "initialize.h" | ||
| # include "invoke_command.h" | ||
| # include "libft.h" | ||
| # include "minish_signal.h" | ||
| # include "parser.h" | ||
| # include "pipeline_helper.h" | ||
| # include "struct.h" | ||
| # include "tokenizer.h" | ||
| # include "perser.h" | ||
| # include <readline/history.h> | ||
| # include <readline/readline.h> | ||
| # include <stdbool.h> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,22 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* perser.h :+: :+: :+: */ | ||
| /* parser.h :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: ttsubo <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/21 14:14:59 by ttsubo #+# #+# */ | ||
| /* Updated: 2025/04/24 15:22:00 by ttsubo ### ########.fr */ | ||
| /* Updated: 2025/04/25 18:16:23 by ttsubo ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #ifndef PERSER_H | ||
| # define PERSER_H | ||
| #ifndef PARSER_H | ||
| # define PARSER_H | ||
|
|
||
| # include "cmd.h" | ||
| # include "libft.h" | ||
|
|
||
| t_cmd **perser(char **tokens); | ||
| t_cmd **parser(char **tokens); | ||
| size_t cmds_len(t_cmd **cmds); | ||
| int is_separator(char *token); | ||
| void free_cmds(t_cmd **cmds, size_t count); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* pipeline_helper.h :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/24 14:32:27 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/24 15:02:17 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #ifndef PIPELINE_HELPER_H | ||
| # define PIPELINE_HELPER_H | ||
|
|
||
| # include "cmd.h" | ||
| # include <stdbool.h> | ||
|
|
||
| // pipeline_helper.c | ||
| void redirect_stdout(t_cmd *cmd); | ||
| bool is_redirect(t_cmd *cmd); | ||
| bool is_head(t_cmd *cmd); | ||
| bool is_tail(t_cmd *cmd); | ||
| bool is_builtin(t_cmd *cmd); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* create_envp.c :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/24 13:56:59 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/24 15:38:39 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #include "main.h" | ||
|
|
||
| int count_value(t_minish *minish) | ||
| { | ||
| int count; | ||
| t_env *current_env; | ||
|
|
||
| count = 0; | ||
| current_env = minish->env; | ||
| while (current_env) | ||
| { | ||
| if (current_env->value) | ||
| count++; | ||
| current_env = current_env->next; | ||
| } | ||
| return (count); | ||
| } | ||
|
|
||
| static char *get_envp_key_value(t_env *env) | ||
| { | ||
| char *result; | ||
| int key_len; | ||
| int value_len; | ||
| int buf_size; | ||
|
|
||
| key_len = ft_strlen(env->key); | ||
| value_len = ft_strlen(env->value); | ||
| buf_size = key_len + EQUAL_LEN + value_len + 1; | ||
| result = (char *)ft_calloc(buf_size, sizeof(char)); | ||
| if (!result) | ||
| perror("ft_calloc"); | ||
| ft_strlcpy(result, env->key, buf_size); | ||
| ft_strlcat(result, "=", buf_size); | ||
| ft_strlcat(result, env->value, buf_size); | ||
| if (!result) | ||
| perror("ft_strlcat"); | ||
| return (result); | ||
| } | ||
|
|
||
| char **create_envp(t_minish *minish) | ||
| { | ||
| char **envp; | ||
| t_env *env; | ||
| int i; | ||
| int count; | ||
|
|
||
| count = count_value(minish); | ||
| envp = (char **)ft_calloc(count, sizeof(char *)); | ||
| if (!envp) | ||
| return (NULL); | ||
| env = minish->env; | ||
| i = 0; | ||
| while (env) | ||
| { | ||
| if (env->value) | ||
| envp[i] = get_envp_key_value(env); | ||
| env = env->next; | ||
| i++; | ||
| } | ||
| envp[i] = NULL; | ||
| return (envp); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここでしか使われていないならstaticつけた方がいいかもです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね。修正します