chore: added core base utilities

This commit is contained in:
2025-10-22 17:05:00 +02:00
parent 2d56a6149d
commit c680555c0d
4 changed files with 102 additions and 1 deletions

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */ /* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/20 16:35:10 by sede-san #+# #+# */ /* Created: 2025/10/20 16:35:10 by sede-san #+# #+# */
/* Updated: 2025/10/20 20:20:30 by sede-san ### ########.fr */ /* Updated: 2025/10/22 16:59:56 by sede-san ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -36,4 +36,24 @@
# include <term.h> // tgetent(3), tgetflag(3), tgetnum(3), # include <term.h> // tgetent(3), tgetflag(3), tgetnum(3),
// tgetstr(3), tgoto(3), tputs(3) // tgetstr(3), tgoto(3), tputs(3)
/******************************************************************************/
/* Structures & Data Types */
/******************************************************************************/
typedef struct s_minishell t_minishell;
typedef struct s_minishell
{
char **env;
u_int8_t exit_status;
} t_minishell;
/* core/minishell.c */
extern int minishell_init(struct s_minishell *minishell, char **envp);
extern u_int8_t minishell_run(struct s_minishell *minishell);
extern void minishell_clear(struct s_minishell *minishell);
#endif /* MINISHELL_H */ #endif /* MINISHELL_H */

View File

45
src/core/minishell.c Normal file
View File

@@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/20 20:51:33 by sede-san #+# #+# */
/* Updated: 2025/10/22 17:02:52 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int minishell_init(
t_minishell *minishell,
char **envp
){
ft_bzero(minishell, sizeof(t_minishell));
minishell->env = envp;
return (1);
}
u_int8_t minishell_run(
t_minishell *minishell
){
char *line;
while (1)
{
line = readline("minishell > ");
if (!ft_strcmp(line, "exit"))
break ;
printf("%s\n", line);
free(line);
}
free(line);
return (minishell->exit_status);
}
void minishell_clear(
t_minishell *minishell
){
ft_bzero(minishell, sizeof(t_minishell));
}

36
src/main.c Normal file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/20 16:34:42 by sede-san #+# #+# */
/* Updated: 2025/10/22 16:58:08 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int main(
int argc,
char const *argv[],
char **envp
){
t_minishell minishell;
u_int8_t exit_status;
if (argc != 1 || argv[1] || !envp)
{
printf("Usage: ./minishell\n");
return (EXIT_FAILURE);
}
if (!minishell_init(&minishell, envp))
{
printf("Error: %s\n", "failed to initialize minishell");
return (EXIT_FAILURE);
}
exit_status = minishell_run(&minishell);
minishell_clear(&minishell);
return (exit_status);
}