fix ENTER && add executable file

This commit is contained in:
kinou-p 2022-03-09 11:29:52 +01:00
parent 5c83326d9b
commit 830a977272
3 changed files with 27 additions and 16 deletions

24
main.c
View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */ /* 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"); printf("\033[0m");
} }
int main(int ac, char **av, char **path) void print_prompt(char **path)
{ {
char *input; char *input;
t_cmd *cmd; t_cmd *cmd;
printf("---MINISHELL START---\n");
while (1) while (1)
{ {
red(); red();
input = readline("$~ "); printf("~$");
normal();
input = readline(" ");
if (ft_strlen(input))
{
add_history(input); add_history(input);
cmd = set_cmd(input, path); cmd = set_cmd(input, path);
normal(); if (cmd)
execute(cmd); execute(cmd);
}
} }
}
int main(int ac, char **av, char **path)
{
printf("---MINISHELL START---\n");
print_prompt(path);
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */ /* 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; char *swap;
swap = 0; 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); free_double(path);
return (exec[0]); return (exec[0]);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */ /* 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 = malloc(sizeof(t_s_cmd));
s_cmd->cmd = get_command(split_line, cmd->path); s_cmd->cmd = get_command(split_line, cmd->path);
if (!s_cmd->cmd) if (!s_cmd->cmd)
{
printf("get command crash");
return (0); return (0);
}
s_cmd->infile = 0; s_cmd->infile = 0;
s_cmd->outfile = 0; s_cmd->outfile = 0;
s_cmd->nb_args = double_size(split_line); 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); cmd->s_cmds[i] = set_s_cmd(cmds[i], cmd);
if (!cmd->s_cmds[i]) if (!cmd->s_cmds[i])
{ {
printf("get command crash"); printf("invalid command\n");
return (0); return (0);
} }
i++; i++;
@ -81,6 +78,10 @@ t_cmd *set_cmd(char *input, char **env)
cmd->infile = 0; cmd->infile = 0;
cmd->nb_s_cmd = double_size(cmds); cmd->nb_s_cmd = double_size(cmds);
cmd = split_cmd(cmd, cmds); //split each cmd into args in s_cmd cmd = split_cmd(cmd, cmds); //split each cmd into args in s_cmd
cmd->current_s_cmd = cmd->s_cmds[0]; if (cmd)
return (cmd); {
cmd->current_s_cmd = cmd->s_cmds[0];//set first s_cmd
return (cmd);
}
return (0);
} }