fix ENTER && add executable file
This commit is contained in:
parent
5c83326d9b
commit
830a977272
20
main.c
20
main.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
||||
/* Updated: 2022/03/08 20:22:56 by apommier ### ########.fr */
|
||||
/* Updated: 2022/03/09 11:16:07 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,20 +22,30 @@ void normal()
|
||||
printf("\033[0m");
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **path)
|
||||
void print_prompt(char **path)
|
||||
{
|
||||
char *input;
|
||||
t_cmd *cmd;
|
||||
|
||||
printf("---MINISHELL START---\n");
|
||||
while (1)
|
||||
{
|
||||
red();
|
||||
input = readline("$~ ");
|
||||
printf("~$");
|
||||
normal();
|
||||
input = readline(" ");
|
||||
if (ft_strlen(input))
|
||||
{
|
||||
add_history(input);
|
||||
cmd = set_cmd(input, path);
|
||||
normal();
|
||||
if (cmd)
|
||||
execute(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **path)
|
||||
{
|
||||
printf("---MINISHELL START---\n");
|
||||
print_prompt(path);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
|
||||
/* Updated: 2022/03/08 20:40:43 by apommier ### ########.fr */
|
||||
/* Updated: 2022/03/09 11:04:45 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -102,7 +102,7 @@ char *get_command(char **exec, char **path)
|
||||
char *swap;
|
||||
|
||||
swap = 0;
|
||||
if (exec[0][0] == '/' && !access(exec[0], F_OK))
|
||||
if ((exec[0][0] == '/' || exec[0][0] == '.') && !access(exec[0], F_OK))
|
||||
{
|
||||
free_double(path);
|
||||
return (exec[0]);
|
||||
|
||||
13
set_cmd.c
13
set_cmd.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/03/08 20:41:42 by apommier ### ########.fr */
|
||||
/* Updated: 2022/03/08 21:05:36 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,10 +33,7 @@ t_s_cmd *set_s_cmd(char *line, t_cmd *cmd)
|
||||
s_cmd = malloc(sizeof(t_s_cmd));
|
||||
s_cmd->cmd = get_command(split_line, cmd->path);
|
||||
if (!s_cmd->cmd)
|
||||
{
|
||||
printf("get command crash");
|
||||
return (0);
|
||||
}
|
||||
s_cmd->infile = 0;
|
||||
s_cmd->outfile = 0;
|
||||
s_cmd->nb_args = double_size(split_line);
|
||||
@ -54,7 +51,7 @@ t_cmd *split_cmd(t_cmd *cmd, char **cmds)
|
||||
cmd->s_cmds[i] = set_s_cmd(cmds[i], cmd);
|
||||
if (!cmd->s_cmds[i])
|
||||
{
|
||||
printf("get command crash");
|
||||
printf("invalid command\n");
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
@ -81,6 +78,10 @@ t_cmd *set_cmd(char *input, char **env)
|
||||
cmd->infile = 0;
|
||||
cmd->nb_s_cmd = double_size(cmds);
|
||||
cmd = split_cmd(cmd, cmds); //split each cmd into args in s_cmd
|
||||
cmd->current_s_cmd = cmd->s_cmds[0];
|
||||
if (cmd)
|
||||
{
|
||||
cmd->current_s_cmd = cmd->s_cmds[0];//set first s_cmd
|
||||
return (cmd);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user