Skip to content

Commit

Permalink
single quote doit etre egal a command not found
Browse files Browse the repository at this point in the history
  • Loading branch information
zakissimo committed Jan 12, 2023
1 parent 9ceb9fc commit cadaa19
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 16 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/10 11:24:53 by zhabri ### ########.fr #
# Updated: 2023/01/12 14:29:11 by zhabri ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -56,6 +56,7 @@ SRCS = add_cmd.c \
utils.c \
utils_bis.c \
utils_cd.c \
utils_dollar.c \
utils_exit.c \
utils_export.c \
utils_export_bis.c \
Expand Down
3 changes: 2 additions & 1 deletion builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/03 10:49:26 by zhabri #+# #+# */
/* Updated: 2023/01/10 13:01:15 by zhabri ### ########.fr */
/* Updated: 2023/01/12 15:27:17 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,6 +30,7 @@ int builtin(char *cmd)
}
i++;
}
printf("jsp: %s\n", cmd_split[0]);
free_tab(cmd_split);
return (-1);
}
Expand Down
21 changes: 13 additions & 8 deletions dollar.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 13:06:15 by zhabri #+# #+# */
/* Updated: 2023/01/12 11:12:07 by zhabri ### ########.fr */
/* Updated: 2023/01/12 15:17:15 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

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

static void infile_exception(t_token *var)
{
int i;
char *second_part;
char *tmp;
char **arg_split;

arg_split = ft_split_quotes_keep_sep(var->arg, "<>|");
Expand All @@ -26,15 +26,17 @@ static void infile_exception(t_token *var)
i = 1;
while (arg_split[i])
{
tmp = ft_strjoin("\"", arg_split[i]);
tmp = ft_strjoinf(tmp, "\"");
second_part = ft_strjoinf(second_part, tmp);
free(tmp);
infile_exception_tmp(&second_part, arg_split[i]);
i++;
}
}
free(var->arg);
var->arg = ft_strjoin(arg_split[0], second_part);
if (arg_split[0][0] == '<' || arg_split[0][0] == '>' || \
arg_split[0][0] == '|')
var->arg = ft_strjoinf(ft_strjoin("\"", arg_split[0]), "\"");
else
var->arg = ft_strdup(arg_split[0]);
var->arg = ft_strjoinf(var->arg, second_part);
free(second_part);
free_tab(arg_split);
}
Expand Down Expand Up @@ -116,7 +118,10 @@ void find_var(t_token *token, char *input)
i++;
len++;
}
token->arg = ft_substr(input, token->str_idx + 1, len);
if (len == 0 && (input[i] == '\'' || input[i] == '\"'))
token->arg = ft_strdup("-");
else
token->arg = ft_substr(input, token->str_idx + 1, len);
}
}
}
3 changes: 2 additions & 1 deletion minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 11:49:37 by zhabri #+# #+# */
/* Updated: 2023/01/10 12:53:16 by zhabri ### ########.fr */
/* Updated: 2023/01/12 15:21:41 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -39,6 +39,7 @@ void events(t_list **head)
{
scan_heredocs();
get_cmd();
print_cmds();
if (!g_glob->sig_int)
pipex();
unlink_heredocs();
Expand Down
3 changes: 2 additions & 1 deletion 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/12 14:12:34 by zhabri ### ########.fr */
/* Updated: 2023/01/12 14:28:56 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -146,6 +146,7 @@ char *get_path(char *cmd, bool shaone);
void handle_sigint(void);
void handle_sigquit(void);
void ignore_sig(int sig);
void infile_exception_tmp(char **second_part, char *arg_split);
void init_children_pid(int **children_pid, int size);
t_cmd *init_cmd_token(int in, int out, char *str, bool reset);
void init_ft_chdir(t_list **pwd, t_list **old_pwd, char **ret);
Expand Down
5 changes: 4 additions & 1 deletion pipex_children.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/26 16:35:44 by zhabri #+# #+# */
/* Updated: 2023/01/10 13:05:55 by zhabri ### ########.fr */
/* Updated: 2023/01/12 15:29:21 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -40,13 +40,16 @@ void child(t_cmd *cmd, int *pipes, int *children_pid)
char **envp;
char **cmd_split;

ft_printf("0- cmd: %s\n", cmd->str);
if (cmd->fd_in != -1 && cmd->fd_out != -1 \
&& cmd->str && cmd->str[0] != '\0')
{
g_glob->exit_ret = 1;
cmd_split = ft_split_quotes(cmd->str, " \t");
cmd_split[0] = remove_quotes(cmd_split[0]);
ft_printf("1- cmd: %s\n", cmd_split[0]);
cmd_split[0] = get_path(cmd_split[0], false);
ft_printf("2- cmd: %s\n", cmd_split[0]);
exit_on_error(cmd, cmd_split, pipes, children_pid);
dup_and_close(cmd, pipes);
envp = envp_list_to_tab();
Expand Down
4 changes: 2 additions & 2 deletions print.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 13:24:06 by zhabri #+# #+# */
/* Updated: 2023/01/10 11:37:26 by zhabri ### ########.fr */
/* Updated: 2023/01/12 15:21:09 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -48,7 +48,7 @@ void print_cmds(void)
if (!(((t_cmd *)cmd->content)->str))
printf("cmd is NULL\n");
else
printf("cmd: %d\n", (((t_cmd *)cmd->content)->str[0]));
printf("cmd: %s\n", (((t_cmd *)cmd->content)->str));
}
cmd = cmd->next;
}
Expand Down
2 changes: 1 addition & 1 deletion utils_bis.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 13:16:51 by zhabri #+# #+# */
/* Updated: 2023/01/09 11:17:04 by zhabri ### ########.fr */
/* Updated: 2023/01/12 14:53:57 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
22 changes: 22 additions & 0 deletions utils_dollar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_dollar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/12 14:26:56 by zhabri #+# #+# */
/* Updated: 2023/01/12 14:28:25 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

void infile_exception_tmp(char **second_part, char *arg_split)
{
char *tmp;

tmp = ft_strjoinf(ft_strjoin("\"", arg_split), "\"");
*second_part = ft_strjoinf(*second_part, tmp);
free(tmp);
}

0 comments on commit cadaa19

Please sign in to comment.