update: integrated hashmaps in builtins, and replaced command calls by builtins

This commit is contained in:
2025-12-02 09:11:01 +01:00
parent dce51960b1
commit b1cf1d8560
6 changed files with 83 additions and 25 deletions

33
src/builtins/builtins.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/01 17:04:57 by sede-san #+# #+# */
/* Updated: 2025/12/01 17:54:26 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
u_int8_t set_builtins(
t_minishell *msh
) {
msh->builtins = ft_hashmap_new(4, ft_hashmap_hashstr, ft_hashmap_strcmp);
if (msh->builtins == NULL)
return (0);
ft_hashmap_put(msh->builtins, ft_strdup("cd"), builtin_cd);
ft_hashmap_put(msh->builtins, ft_strdup("echo"), builtin_echo);
ft_hashmap_put(msh->builtins, ft_strdup("exit"), builtin_exit);
ft_hashmap_put(msh->builtins, ft_strdup("pwd"), builtin_pwd);
return (1);
}
u_int8_t is_builtin(
const char *command_name,
t_minishell *msh
) {
return (ft_hashmap_contains_key(msh->builtins, command_name));
}