-
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.
- Loading branch information
Showing
4 changed files
with
47 additions
and
21 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,20 +6,24 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/03 12:40:50 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/05 11:57:24 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/05 12:18:23 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
|
||
t_list *get_env_node(char *var) | ||
{ | ||
char *var_eq; | ||
t_list *envp_entry; | ||
|
||
var_eq = ft_strjoin(var, "="); | ||
envp_entry = *g_glob->envp; | ||
while (envp_entry \ | ||
&& ft_strncmp((char *)envp_entry->content, var, ft_strlen(var))) | ||
&& ft_strncmp((char *)envp_entry->content, var_eq, ft_strlen(var_eq)) \ | ||
&& ft_strncmp((char *)envp_entry->content, var, ft_strlen(var) + 1)) | ||
envp_entry = envp_entry->next; | ||
free(var_eq); | ||
return (envp_entry); | ||
} | ||
|
||
|
@@ -30,8 +34,8 @@ static void ft_chdir(char *dir, int size) | |
t_list *pwd; | ||
t_list *old_pwd; | ||
|
||
pwd = get_env_node("PWD="); | ||
old_pwd = get_env_node("OLDPWD="); | ||
pwd = get_env_node("PWD"); | ||
old_pwd = get_env_node("OLDPWD"); | ||
ret = NULL; | ||
free_null(old_pwd->content); | ||
tmp = ft_strdup(pwd->content + 4); | ||
|
@@ -74,7 +78,7 @@ void cd(char *cmd, int fd_out) | |
ft_chdir(cmd_split[1], 16); | ||
} | ||
else | ||
ft_chdir(get_env_node("HOME=")->content + 5, 16); | ||
ft_chdir(get_env_node("HOME")->content + 5, 16); | ||
clean_and_free(cmd_split); | ||
exit(0); | ||
} | ||
|
@@ -115,7 +119,7 @@ bool cd_parent(void) | |
return (true); | ||
} | ||
else | ||
ft_chdir(get_env_node("HOME=")->content + 5, 16); | ||
ft_chdir(get_env_node("HOME")->content + 5, 16); | ||
free_tab(cmd_split); | ||
g_glob->exit_ret = 0; | ||
return (true); | ||
|
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: brenaudo <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/04 14:56:54 by brenaudo #+# #+# */ | ||
/* Updated: 2023/01/05 11:59:22 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/05 12:28:03 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -26,17 +26,7 @@ static void export_no_arg(int fd_out) | |
{ | ||
envp_entry_split = cut_on_first(envp[i], '='); | ||
if (envp_entry_split && ft_strncmp(envp_entry_split[0], "_", 2)) | ||
{ | ||
ft_putstr_fd("declare -x ", fd_out); | ||
ft_putstr_fd(envp_entry_split[0], fd_out); | ||
if (envp_entry_split[1][0]) | ||
{ | ||
ft_putstr_fd("=\"", fd_out); | ||
ft_putstr_fd(envp_entry_split[1], fd_out); | ||
ft_putchar_fd('\"', fd_out); | ||
} | ||
ft_putchar_fd('\n', fd_out); | ||
} | ||
print_export_line(envp_entry_split, fd_out); | ||
free_tab(envp_entry_split); | ||
} | ||
free_tab(envp); | ||
|
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: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/11/27 20:30:45 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/05 11:48:27 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/05 12:27:38 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -155,6 +155,7 @@ void print_cmds(void); | |
void print_cmd_not_found(char *str); | ||
void print_error_dir_cd(char *dir); | ||
void print_exit_num_error(char *cmd); | ||
void print_export_line(char **envp_entry_split, int fd_out); | ||
void print_label(t_label label); | ||
void print_nodes(void *n); | ||
void pwd(char *cmd, int fd_out); | ||
|
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: brenaudo <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/04 16:26:02 by brenaudo #+# #+# */ | ||
/* Updated: 2023/01/04 16:26:18 by brenaudo ### ########.fr */ | ||
/* Updated: 2023/01/05 12:27:11 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -64,6 +64,37 @@ char **cut_on_first(char *str, char sep) | |
while (str && str[i] && str[i] != sep) | ||
i++; | ||
ret[0] = ft_substr(str, 0, i); | ||
ret[1] = ft_substr(str, i + 1, ft_strlen(str) - i); | ||
ret[1] = ft_substr(str, i, ft_strlen(str) - i); | ||
return (ret); | ||
} | ||
|
||
char *longest_str(char *s1, char *s2) | ||
{ | ||
int i; | ||
int j; | ||
|
||
i = 0; | ||
j = 0; | ||
while (s1 && s1[i]) | ||
i++; | ||
while (s2 && s2[j]) | ||
j++; | ||
if (i > j) | ||
return (s1); | ||
else | ||
return (s2); | ||
} | ||
|
||
void print_export_line(char **envp_entry_split, int fd_out) | ||
{ | ||
ft_putstr_fd("declare -x ", fd_out); | ||
ft_putstr_fd(envp_entry_split[0], fd_out); | ||
if (envp_entry_split[1][0]) | ||
{ | ||
ft_putchar_fd(envp_entry_split[1][0], fd_out); | ||
ft_putchar_fd('\"', fd_out); | ||
ft_putstr_fd(envp_entry_split[1] + 1, fd_out); | ||
ft_putchar_fd('\"', fd_out); | ||
} | ||
ft_putchar_fd('\n', fd_out); | ||
} |