mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
builtin: implement pwd
This commit is contained in:
parent
1c4733b1cc
commit
5ce4a2b85f
7 changed files with 167 additions and 2 deletions
|
|
@ -6,11 +6,12 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
||||
/* Updated: 2025/03/28 16:56:47 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/31 14:21:40 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "simple_cmd_execute.h"
|
||||
#include "builtins.h"
|
||||
#include "libft.h"
|
||||
#include "../../subst/subst.h"
|
||||
#include "../../env/env_convert.h"
|
||||
|
|
@ -38,6 +39,28 @@ static void command_not_found(t_simple_cmd *cmd)
|
|||
cmd->words->word->word);
|
||||
}
|
||||
|
||||
static t_builtin_type get_builtin(t_simple_cmd *cmd)
|
||||
{
|
||||
char *word;
|
||||
|
||||
word = cmd->words->word->word;
|
||||
if (ft_strcmp("pwd", word) == 0)
|
||||
return (BUILTIN_PWD);
|
||||
return (BUILTIN_INVALID);
|
||||
}
|
||||
|
||||
static t_builtin_type execute_builtin(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
t_builtin_type type;
|
||||
static t_builtin_type (*builtins[])(t_simple_cmd *, t_minishell *) = {
|
||||
[BUILTIN_INVALID] = builtin_invalid,
|
||||
[BUILTIN_PWD] = builtin_pwd,
|
||||
};
|
||||
|
||||
type = get_builtin(cmd);
|
||||
return (builtins[type](cmd, app));
|
||||
}
|
||||
|
||||
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
char *exe;
|
||||
|
|
@ -45,6 +68,8 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
|||
|
||||
if (cmd == NULL || cmd->words == NULL || cmd->words->word == NULL)
|
||||
return ;
|
||||
if (execute_builtin(cmd, app) != BUILTIN_INVALID)
|
||||
return ;
|
||||
exe = get_cmdpath(cmd->words->word->word, app);
|
||||
if (exe == NULL)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue