update: functions done: echo + echo -n, pwd, exit with and without arguments / parser appears to work, test with commands and local files (only tested with ls -l)

This commit is contained in:
2025-08-04 00:38:53 +02:00
parent e89de4e20b
commit 3e7dd56340
14 changed files with 718 additions and 84 deletions

60
include/builtins.h Normal file
View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/01 17:18:21 by sede-san #+# #+# */
/* Updated: 2025/08/02 17:55:22 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUILTINS_H
# define BUILTINS_H
# include <string.h>
# include <stdio.h>
typedef int (*t_builtin_func)(int argc, char const *argv[]);
typedef struct s_builtin
{
const char *name;
t_builtin_func function;
} t_builtin;
// cd.c
int cd_builtin(int argc, char const *argv[]);
// echo.c
typedef struct s_echo_flags
{
int newline; // print newline after everything has been printed
} t_echo_flags;
int echo_builtin(int argc, char const *argv[]);
// env.c
int env_builtin(int argc, char const *argv[]);
// exit.c
int exit_builtin(int argc, char const *argv[]);
// export.c
int export_builtin(int argc, char const *argv[]);
// pwd.c
int pwd_builtin(int argc, char const *argv[]);
// unset.c
int unset_builtin(int argc, char const *argv[]);
#endif

View File

@@ -6,33 +6,52 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 03:42:51 by sede-san #+# #+# */
/* Updated: 2025/07/31 14:01:36 by sede-san ### ########.fr */
/* Updated: 2025/08/03 22:56:35 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include "builtins.h"
# include "libft.h"
# include "get_next_line.h"
# include <fcntl.h>
# include <signal.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <sys/wait.h>
# define HISTORY_FILE "/.minishell_history"
typedef struct s_env
typedef struct s_cmd
{
char *home;
char **path;
} t_env;
int argc;
char **argv;
char **envp;
} t_cmd;
# define HISTORY_FILE "/.minishell_history"
typedef struct s_minishell
{
char *prompt;
char *history_file;
t_env env;
char **envp;
} t_minishell;
/* ******************************* Commands ********************************* */
typedef int (*t_msh_cmdfunc)(char **args, char **env, t_minishell* minshell);
// exec.c
int exec_cmd(char *cmd, char **args, t_minishell *minishell);
// parse.c
t_cmd parse_cmd(char *line, t_minishell *minishell);
/* ********************************* Utils ********************************** */
// get_hostname.c
char *get_hostname(void);
#endif