Skip to content

Commit

Permalink
export normed
Browse files Browse the repository at this point in the history
  • Loading branch information
zakissimo committed Jan 6, 2023
1 parent 92dc051 commit 6b1c5d6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 45 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: zhabri <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/04 08:44:16 by zhabri #+# #+# #
# Updated: 2023/01/03 13:17:27 by zhabri ### ########.fr #
# Updated: 2023/01/06 10:39:22 by zhabri ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -58,6 +58,7 @@ SRCS = add_cmd.c \
utils_cd.c \
utils_exit.c \
utils_export.c \
utils_export_bis.c \
utils_heredocs.c \
utils_pipex.c \
utils_signal.c \
Expand Down
45 changes: 5 additions & 40 deletions export.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: brenaudo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 14:56:54 by brenaudo #+# #+# */
/* Updated: 2023/01/05 14:47:39 by zhabri ### ########.fr */
/* Updated: 2023/01/06 10:49:20 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -73,18 +73,6 @@ static bool is_valid_identifier(char *identifier, char *var)
return (true);
}

static bool plus_end_str(char *str)
{
int i;

i = 0;
while (str && str[i] && str[i + 1])
i++;
if (str && str[i] == '+')
return (true);
return (false);
}

static void handle_export_add(char *var)
{
char *tmp;
Expand All @@ -104,36 +92,13 @@ static void handle_export_add(char *var)
{
env_cpy = get_env_node(var_split[0]);
if (env_cpy == NULL)
{
if (!plus_char)
ft_lstadd_back(g_glob->envp, ft_lstnew(ft_strdup(var)));
else
ft_lstadd_back(g_glob->envp, \
ft_lstnew(ft_strdup(ft_strjoin(var_split[0], var_split[1]))));
}

init_new_var(plus_char, var, var_split);
else if (var_split[1][0])
{
if (!plus_char)
{
free(env_cpy->content);
env_cpy->content = ft_strdup(var);
}
else
{
if (ft_strchr(env_cpy->content, '='))
env_cpy->content = ft_strjoinf(env_cpy->content, var_split[1] + 1);
else
env_cpy->content = ft_strjoinf(env_cpy->content, var_split[1]);
}

}
free_tab(var_split);
g_glob->exit_ret = 0;
edit_var(plus_char, var, var_split, env_cpy);
free_and_set_exit_ret(var_split, 0);
return ;
}
free_tab(var_split);
g_glob->exit_ret = 1;
free_and_set_exit_ret(var_split, 1);
}

bool export_parent(void)
Expand Down
13 changes: 9 additions & 4 deletions minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/27 20:30:45 by zhabri #+# #+# */
/* Updated: 2023/01/05 12:27:38 by zhabri ### ########.fr */
/* Updated: 2023/01/06 10:48:51 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -82,7 +82,7 @@ void add_cmd(t_token *token, t_list **cmds, bool *pb);
void add_to_tab(char **tab, char *str);
int builtin(char *cmd);
void call_builtin(int built_in, t_cmd *cmd, int *pipes, \
int *children_pid);
int *children_pid);
void cd(char *cmd, int fd_out);
bool cd_parent(void);
void change_sig_handling(char *cmd, int *pipes);
Expand All @@ -95,14 +95,16 @@ void clear_cmds(void);
void close_pipes(int *pipes);
char **cut_on_first(char *str, char sep);
void echo(char *cmd, int fd_out);
void edit_var(bool plus_char, char *var, char **var_split, \
t_list *env_cpy);
void env(char *cmd, int fd_out);
char **envp_list_to_tab(void);
void eof_limiter_not_found(char *here_doc_entry, char *limiter);
void exit_child(char *cmd, int fd_out);
void exit_on_bad_cmd(char **cmd_split, \
int *pipes, char *cmd, int *children_pid);
int *pipes, char *cmd, int *children_pid);
void exit_on_permission(char **cmd_split, \
int *pipes, int *children_pid);
int *pipes, int *children_pid);
bool exit_parent(void);
void expand(t_token *var);
void export(char *cmd, int fd_out);
Expand All @@ -111,6 +113,7 @@ void final_clean_up(void);
int find_quote(const char *s, char c);
void find_var(t_token *token, char *input);
void free_and_null(char **tmp);
void free_and_set_exit_ret(char **var_split, int ret);
void free_null(void *var);
void free_op_list(void);
void free_tab(void *t);
Expand Down Expand Up @@ -140,6 +143,7 @@ void ignore_sig(int sig);
void init_children_pid(int **children_pid, int size);
t_cmd *init_cmd_token(int in, int out, char *str, bool reset);
void init_g_glob(void);
void init_new_var(bool plus_char, char *var, char **var_split);
void init_sig_callbacks(int process);
void insert_node(t_list **head, t_list *node, int idx);
bool is_valid_exit_arg(char *cmd);
Expand All @@ -151,6 +155,7 @@ char *op_error_trimmed(t_list *curr);
bool overflows_llong(char *str);
int pipe_error(void);
void pipex(void);
bool plus_end_str(char *str);
void print_cmds(void);
void print_cmd_not_found(char *str);
void print_error_dir_cd(char *dir);
Expand Down
60 changes: 60 additions & 0 deletions utils_export_bis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_export_bis.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 10:38:28 by zhabri #+# #+# */
/* Updated: 2023/01/06 10:48:30 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft/includes/libft.h"
#include "minishell.h"

bool plus_end_str(char *str)
{
int i;

i = 0;
while (str && str[i] && str[i + 1])
i++;
if (str && str[i] == '+')
return (true);
return (false);
}

void free_and_set_exit_ret(char **var_split, int ret)
{
free_tab(var_split);
g_glob->exit_ret = ret;
}

void init_new_var(bool plus_char, char *var, char **var_split)
{
if (!plus_char)
ft_lstadd_back(g_glob->envp, ft_lstnew(ft_strdup(var)));
else
ft_lstadd_back(g_glob->envp, \
ft_lstnew(ft_strdup(ft_strjoin(var_split[0], \
var_split[1]))));
}

void edit_var(bool plus_char, char *var, char **var_split, t_list *env_cpy)
{
if (!plus_char)
{
free(env_cpy->content);
env_cpy->content = ft_strdup(var);
}
else
{
if (ft_strchr(env_cpy->content, '='))
env_cpy->content = ft_strjoinf(env_cpy->content, \
var_split[1] + 1);
else
env_cpy->content = ft_strjoinf(env_cpy->content, \
var_split[1]);
}
}

0 comments on commit 6b1c5d6

Please sign in to comment.