-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor : #30/export - 함수 인자 변경
- Loading branch information
Showing
6 changed files
with
65 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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,44 +6,75 @@ | |
/* By: wonyang <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/09 16:46:45 by wonyang #+# #+# */ | ||
/* Updated: 2023/01/13 21:49:45 by wonyang ### ########seoul.kr */ | ||
/* Updated: 2023/01/14 18:28:52 by wonyang ### ########seoul.kr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <unistd.h> | ||
#include "return.h" | ||
#include "ds_envp.h" | ||
#include "libft.h" | ||
|
||
t_error print_envp(t_envp *envp); | ||
int print_envp(t_envp *envp); | ||
|
||
static int count_argument(char **argv) | ||
static bool is_valid_key(char *key) | ||
{ | ||
int i; | ||
if (ft_strcmp(key, "") == 0 | ||
|| ft_strchr(key, '\"') | ||
|| ft_strchr(key, '\'') | ||
|| ft_strchr(key, ' ')) | ||
{ | ||
ft_putstr_fd("bash: export: `", STDERR_FILENO); | ||
ft_putstr_fd(key, STDERR_FILENO); | ||
ft_putendl_fd("': not a valid identifier", STDERR_FILENO); | ||
return (false); | ||
} | ||
return (true); | ||
} | ||
|
||
i = 0; | ||
while (argv[i]) | ||
i++; | ||
return (i); | ||
static t_error check_argument(char *arg, t_envp *envp) | ||
{ | ||
char *key; | ||
|
||
if (ft_strchr(arg, '=') == 0) | ||
{ | ||
if (is_valid_key(arg) == false) | ||
return (FAIL); | ||
else if (search_key_enode(envp, arg)) | ||
return (SCS); | ||
else | ||
return (set_env(envp, arg, NULL)); | ||
} | ||
if (get_key(arg, &key) | ||
|| is_valid_key(key) == false) | ||
{ | ||
free(key); | ||
return (FAIL); | ||
} | ||
free(key); | ||
return (set_export(envp, arg)); | ||
} | ||
|
||
int ft_export(char **argv, t_envp *envp) | ||
{ | ||
int argc; | ||
t_error errno; | ||
|
||
errno = 0; | ||
if (!argv || !(*argv)) | ||
{ | ||
printf("ft_export argument error!\n"); | ||
return (1); | ||
} | ||
argc = count_argument(argv); | ||
if (argc == 1) | ||
errno = print_envp(envp); | ||
else if (argc == 2) | ||
errno = set_env(envp, argv[1], NULL); | ||
else | ||
errno = set_env(envp, argv[1], argv[2]); | ||
if (errno) | ||
return (1); | ||
return (0); | ||
argv++; | ||
if (!(*argv)) | ||
return (print_envp(envp)); | ||
while (*argv) | ||
{ | ||
if (check_argument(*argv, envp) != SCS) | ||
errno = 1; | ||
argv++; | ||
} | ||
return (errno); | ||
} |
This file contains 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: wonyang <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/09 20:04:00 by wonyang #+# #+# */ | ||
/* Updated: 2023/01/13 22:12:25 by wonyang ### ########seoul.kr */ | ||
/* Updated: 2023/01/14 17:06:19 by wonyang ### ########seoul.kr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -94,20 +94,20 @@ static char **make_arr(t_envp *envp) | |
return (key_arr); | ||
} | ||
|
||
t_error print_envp(t_envp *envp) | ||
int print_envp(t_envp *envp) | ||
{ | ||
int i; | ||
char **key_arr; | ||
|
||
key_arr = make_arr(envp); | ||
if (!key_arr) | ||
return (ERROR); | ||
return (1); | ||
i = 0; | ||
while (key_arr[i]) | ||
{ | ||
print_line(envp, key_arr[i]); | ||
i++; | ||
} | ||
free(key_arr); | ||
return (SCS); | ||
return (0); | ||
} |
This file contains 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 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: wonyang <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/13 18:36:41 by wonyang #+# #+# */ | ||
/* Updated: 2023/01/14 12:58:24 by wonyang ### ########seoul.kr */ | ||
/* Updated: 2023/01/14 18:36:25 by wonyang ### ########seoul.kr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,10 +23,10 @@ extern t_global g_var; | |
|
||
bool is_builtin_cmd(t_tnode *node) | ||
{ | ||
t_token *token; | ||
t_token *token; | ||
const char cmd[7][7] = {"echo", "pwd", "cd", "env", "export", \ | ||
"unset", "exit"}; | ||
int i; | ||
int i; | ||
|
||
if (!node || !node->content) | ||
{ | ||
|
This file contains 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 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: wonyang <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/08 22:30:32 by wonyang #+# #+# */ | ||
/* Updated: 2023/01/14 13:00:36 by wonyang ### ########seoul.kr */ | ||
/* Updated: 2023/01/14 18:34:14 by wonyang ### ########seoul.kr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -93,6 +93,7 @@ int main(int argc, char **argv, char **env) | |
ft_lstclear(&lst, del_t_paren); | ||
clear_node(node, del_t_token); | ||
free(str); | ||
// system("leaks minishell | grep leaks"); | ||
} | ||
clear_envp(&(g_var.envp)); | ||
return (g_var.status); | ||
|