Skip to content

Commit

Permalink
solve space problem and copy last version
Browse files Browse the repository at this point in the history
  • Loading branch information
qfeuilla committed Aug 22, 2020
1 parent ca71863 commit f252d71
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 83 deletions.
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ all: $(NAME)
@printf "${NC}"

$(NAME): ${OBJECTS}
@rm -rf logs
@mkdir logs
@make -C ${LIB_DIR}
@printf "${YELLOW}=> "
cc ${FLAGS} ${MAIN} ${OBJECTS} ${INCLUDE_DIRS} ${LIB} -o ${NAME}
Expand All @@ -74,12 +72,7 @@ start: all
valgrind_start: all
@valgrind --leak-check=full --show-leak-kinds=definite ./${NAME}

test: all
@cc ${MAIN_TEST} ${OBJECTS} ${INCLUDE_DIRS} ${LIB} -o test_exec
@./test_exec

clean:
@rm -rf logs
@printf "${RED}X "
rm -rf ${OBJECTS}
@printf "${NC}"
Expand All @@ -95,4 +88,4 @@ fclean: clean

re: fclean all

.PHONY: all start clean fclean re ${NAME}
.PHONY: all start clean fclean re
9 changes: 7 additions & 2 deletions includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/24 13:40:30 by frthierr #+# #+# */
/* Updated: 2020/08/16 11:10:21 by qfeuilla ### ########.fr */
/* Updated: 2020/08/17 15:19:46 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -96,6 +96,7 @@ typedef struct s_expand_tk_dt
int pb;
char *tmp;
char *final_token;
int is_err;
t_quotes qt;
} t_expand_tk_dt;

Expand Down Expand Up @@ -153,6 +154,10 @@ char *expand_token_quote(char *tk, t_expand_tk_dt d);
size_t ft_strlen_etokens(char *s);
int is_specialchar_dquote(char c);
int is_quote_only(char *tk);
char *return_token(char **tk, int check_quote);
int expand_quote_set_vals(char *tk,\
t_expand_tk_dt *d, int *check_quote);
char *return_expand_tk_quote(t_expand_tk_dt *d, int check_quote);

/*
** _____COMMANDS_____
Expand Down
Binary file modified minishell.dSYM/Contents/Resources/DWARF/minishell
Binary file not shown.
3 changes: 2 additions & 1 deletion srcs/builtins/builtin_cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/03 11:18:29 by frthierr #+# #+# */
/* Updated: 2020/08/10 14:18:32 by frthierr ### ########.fr */
/* Updated: 2020/08/18 10:12:01 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -80,6 +80,7 @@ static int handle_deleted_dir(char *arg)
return (1);
if (modify_path(new_dir, "PWD="))
return (1);
free(new_dir);
return (0);
}

Expand Down
18 changes: 10 additions & 8 deletions srcs/builtins/builtin_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtin_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: franciszer <franciszer@student.42.fr> +#+ +:+ +#+ */
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/03 11:30:42 by frthierr #+# #+# */
/* Updated: 2020/08/11 18:57:54 by franciszer ### ########.fr */
/* Updated: 2020/08/18 09:47:25 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,17 +20,19 @@ int builtin_exit(char **args)
ft_putendl_fd("exit", 2);
while (args[i])
i++;
if (i > 2)
if (g_env_modified)
free_argv(g_env, INT_MAX);
if (args[1] && (!ft_is_strdigit(args[1]) || ft_strlen(args[1]) > 10))
{
ft_perror("numeric argument required");
g_exit_status = 255;
}
else if (i > 2)
{
g_exit_status = 1;
ft_perror(ERR_TOO_MANY_ARGS);
return (1);
}
else if (args[1] && (!ft_is_strdigit(args[1]) || ft_strlen(args[1]) > 10))
{
ft_perror("numeric argument required");
g_exit_status = 255;
}
else if (args[1])
g_exit_status = ft_atoi(args[1]);
exit_minishell(EXIT_NOW, NULL, NULL, NULL);
Expand Down
2 changes: 1 addition & 1 deletion srcs/builtins/builtin_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/03 15:25:27 by frthierr #+# #+# */
/* Updated: 2020/08/13 18:30:54 by frthierr ### ########.fr */
/* Updated: 2020/08/21 15:51:36 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
92 changes: 90 additions & 2 deletions srcs/builtins/builtin_export3.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,110 @@
/* ::: :::::::: */
/* builtin_export3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: franciszer <franciszer@student.42.fr> +#+ +:+ +#+ */
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/10 13:58:47 by frthierr #+# #+# */
/* Updated: 2020/08/11 19:06:52 by franciszer ### ########.fr */
/* Updated: 2020/08/22 12:55:02 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

char *remove_plus_sign(char *arg)
{
char *new_arg;
size_t i;
size_t j;

i = 0;
j = 0;
if (!(new_arg = malloc(sizeof(char) * (ft_strlen(arg) + 1))))
return (NULL);
while (arg[i])
{
if (arg[i] != '+')
new_arg[j++] = arg[i++];
else
i++;
}
return (new_arg);
}


t_list *replance_envvar_init_vals(int *replaced)
{
t_list *env_list;

if (!(env_list = ft_argv_to_list(g_env)))
return (NULL);
*replaced = 0;
if (g_env_modified)
free_argv(g_env, INT_MAX);
g_env_modified = 1;
return (env_list);
}

int replace_envvar_util(t_list *nav, char *arg)
{
char *current_env;
size_t len;

current_env = (char*)nav->content;
len = ft_strlen(current_env);
if (current_env[len - 1] != '=' &&\
!ft_strncmp(current_env, arg, ft_strlen(current_env)))
{
free(nav->content);
if (!(nav->content = ft_strdup(arg)))
return (-1);
return (1);
}
return (0);
}


int replace_envvar(char *arg)
{
t_list *env_list;
t_list *nav;
char *current_env;
int replaced;
char *new_arg;

if (!ft_strchr(arg, '=') && (current_env = get_env(arg)))
{
free(current_env);
return (1);
}
if (!(new_arg = remove_plus_sign(arg)))
return (0);
if (!(env_list = replance_envvar_init_vals(&replaced)))
return (0);
nav = env_list;
while (nav && !replaced)
{
if ((replaced = replace_envvar_util(nav, new_arg)) == -1)
return (0);
nav = nav->next;
}
if (!(g_env = list_to_argv(env_list)))
return (0);
ft_lstclear(&env_list, free);
free(new_arg);
if (replaced)
return (1);
return (0);
}

int export_envvar(int i, char **argv)
{
char *var;
int syntax_check;
int return_value;
char *to_free;

if (replace_envvar(argv[i]))
return (0);
if ((syntax_check = export_check_syntax(argv[i])) == 1)
return (1);
if (syntax_check == 3 && !(argv[i] = added_var(argv[i])))
Expand Down
12 changes: 6 additions & 6 deletions srcs/builtins/builtin_pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/03 13:56:49 by frthierr #+# #+# */
/* Updated: 2020/08/11 16:30:25 by frthierr ### ########.fr */
/* Updated: 2020/08/17 12:54:43 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"


static char *set_new_pwd(void)
static char *set_new_pwd(void)
{
char *pwd;
char **new_pwd;

if (!(pwd = getcwd(NULL, 0)))
return (NULL);
return (NULL);
if (!(new_pwd = malloc(sizeof(char*) * 3)))
return (NULL);
if (!(new_pwd[0] = ft_strdup("export")))
Expand All @@ -36,9 +35,10 @@ int builtin_pwd(void)
{
char *pwd;

if (!(pwd = get_env("PWD")) && !(pwd = set_new_pwd()))
if (!(pwd = get_env("PWD")))
{
return (1);
if (!(pwd = set_new_pwd()))
return (1);
}
ft_putendl_fd(pwd, STDOUT_FILENO);
free(pwd);
Expand Down
6 changes: 3 additions & 3 deletions srcs/builtins/builtin_unset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtin_unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: franciszer <franciszer@student.42.fr> +#+ +:+ +#+ */
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/05 11:40:02 by franciszer #+# #+# */
/* Updated: 2020/08/11 19:15:39 by franciszer ### ########.fr */
/* Updated: 2020/08/17 12:45:36 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -88,7 +88,7 @@ int builtin_unset(char **argv)
{
int i;
int ret_value;

ret_value = 0;
i = 1;
while (argv[i])
Expand Down
15 changes: 7 additions & 8 deletions srcs/commands/search_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* search_path.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/02 14:02:44 by frthierr #+# #+# */
/* Updated: 2020/08/08 13:48:29 by qfeuilla ### ########.fr */
/* Updated: 2020/08/18 09:25:05 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -74,8 +74,8 @@ char *search_path(char *command)

if (is_custom(command))
return (ft_strdup(command));
if (!(path = get_env("PATH"))
|| !(path_array = ft_split(path, ':')))
if (!(path = get_env("PATH")) ||\
!(path_array = ft_split(path, ':')))
return (NULL);
i = 0;
while (path_array[i])
Expand All @@ -88,8 +88,7 @@ char *search_path(char *command)
i++;
}
if (open(command, O_CLOEXEC) != -1)
return (ft_strdup(command));
if ((command_path = search_relativepath(command)))
return (command_path);
return (return_free_av(NULL, &path_array, &path));
return (return_free_av(ft_strdup(command), &path_array, &path));
command_path = search_relativepath(command);
return (return_free_av(command_path, &path_array, &path));
}
3 changes: 1 addition & 2 deletions srcs/launch_commands/command_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/02 16:21:03 by frthierr #+# #+# */
/* Updated: 2020/08/11 15:41:21 by frthierr ### ########.fr */
/* Updated: 2020/08/17 12:46:06 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,6 +65,5 @@ void exit_minishell(int action, t_list *token_list,
if (args_to_free)
free_argv(*args_to_free, INT_MAX);
}
system("minishell leaks");
exit(g_exit_status);
}
4 changes: 2 additions & 2 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/24 13:39:32 by frthierr #+# #+# */
/* Updated: 2020/08/11 16:42:19 by frthierr ### ########.fr */
/* Updated: 2020/08/17 12:40:19 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,7 +49,7 @@ int main(int argc, char **argv, char **env)
g_in_fork = 0;
if (argc > 1 || argv[1])
{
ft_perror(ERR_TOO_MANY_ARGS);
ft_perror("ERR_TOO_MANY_ARGS");
return (1);
}
g_env = env;
Expand Down
2 changes: 1 addition & 1 deletion srcs/parsing/parsing_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: frthierr <frthierr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/25 14:28:17 by frthierr #+# #+# */
/* Updated: 2020/08/11 14:30:48 by frthierr ### ########.fr */
/* Updated: 2020/08/17 16:39:36 by frthierr ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
3 changes: 0 additions & 3 deletions srcs/parsing/prompt_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ int check_semicol_error(t_list *token_list)
if (!ft_strncmp((char*)tmp->content, ";", 2))
{
if (prev_is_semicol)
{
printf("here\n");
return (g_semicol_error = 1);
}
else
prev_is_semicol = 1;
}
Expand Down
Loading

0 comments on commit f252d71

Please sign in to comment.