🔨」 fix: fixed some things.

This commit is contained in:
2024-05-07 11:04:20 +02:00
parent cff9e40005
commit 44bcb15a33
7 changed files with 114 additions and 13 deletions

View File

@ -6,7 +6,11 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 09:38:51 by mmoussou #+# #+# */ /* Created: 2024/04/26 09:38:51 by mmoussou #+# #+# */
<<<<<<< HEAD
/* Updated: 2024/05/06 20:30:42 by mmoussou ### ########.fr */ /* Updated: 2024/05/06 20:30:42 by mmoussou ### ########.fr */
=======
/* Updated: 2024/05/03 10:24:15 by adjoly ### ########.fr */
>>>>>>> e1ba625 (🏗 wip: testing things, might broke.)
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,5 +30,6 @@ char set_env(char **env, const char *name, char *content);
char *get_hostname(void); char *get_hostname(void);
char *get_prompt(void); char *get_prompt(void);
char *get_pwd(void); char *get_pwd(void);
bool is_str(char *src, char *dst);
#endif #endif

35
include/minishell.h.orig Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 09:38:51 by mmoussou #+# #+# */
<<<<<<< HEAD
/* Updated: 2024/05/06 20:30:42 by mmoussou ### ########.fr */
=======
/* Updated: 2024/05/03 10:24:15 by adjoly ### ########.fr */
>>>>>>> e1ba625 (🏗 wip: testing things, might broke.)
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include <readline/readline.h>
# include <stdio.h>
# include <stdlib.h>
# include <stdint.h>
# include "libft.h"
# include "parsing.h"
# include "execution.h"
char set_env(char **env, const char *name, char *content);
char *get_hostname(void);
char *get_prompt(void);
char *get_pwd(void);
bool is_str(char *src, char *dst);
#endif

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */ /* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
/* Updated: 2024/04/25 14:30:50 by adjoly ### ########.fr */ /* Updated: 2024/05/04 13:54:02 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,4 +19,11 @@ typedef struct s_cmd
char **argv; char **argv;
} t_cmd; } t_cmd;
typedef struct s_parsing
{
} t_parsing;
t_cmd split_cmd(char *cmd_av);
#endif #endif

25
src/is_str.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 10:23:40 by adjoly #+# #+# */
/* Updated: 2024/05/03 10:23:55 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdbool.h>
bool is_str(char *src, char *dst)
{
while (*src && *dst && *src == *dst)
{
src++;
dst++;
}
if (*dst)
return (false);
return (true);
}

View File

@ -6,28 +6,25 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */ /* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/05/02 15:53:21 by adjoly ### ########.fr */ /* Updated: 2024/05/04 15:33:54 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <fcntl.h> #include <fcntl.h>
#include "minishell.h" #include "minishell.h"
bool is_str(char *src, char *dst) void print_cmd(t_cmd cmd)
{ {
while (*src && *dst && *src == *dst) ft_putendl_fd(cmd.cmd, 1);
while (*(cmd.argv))
{ {
src++; ft_putendl_fd(*(cmd.argv), 1);
dst++; (cmd.argv)++;
} }
if (*dst)
return (false);
return (true);
} }
int main(int ac, char **av, char **env) int main(int ac, char **av, char **env)
@ -35,6 +32,7 @@ int main(int ac, char **av, char **env)
char *test; char *test;
char **lll; char **lll;
char *prompt; char *prompt;
t_cmd *cmd;
(void)ac; (void)ac;
(void)av; (void)av;
@ -50,7 +48,11 @@ int main(int ac, char **av, char **env)
continue; continue;
if (is_str(test, "exit")) if (is_str(test, "exit"))
break; break;
cmd = ft_calloc(sizeof(t_cmd), 1);
*cmd = split_cmd(test);
print_cmd(*cmd);
ft_free("a", &lll);
} }
//ft_free("a", &lll); ft_free("a", &lll);
return (0); return (0);
} }

27
src/parsing/split_cmd.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* split_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */
/* Updated: 2024/05/04 15:20:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
#include "libft.h"
t_cmd split_cmd(char *cmd_av)
{
char **split;
char **tmp_split;
t_cmd cmd;
split = ft_split(cmd_av, 32);
tmp_split = split;
cmd.cmd = ft_strdup(*tmp_split);
cmd.argv = tmp_split;
return (cmd);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */ /* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */
/* Updated: 2024/05/02 13:42:24 by adjoly ### ########.fr */ /* Updated: 2024/05/03 10:32:07 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,7 +29,7 @@ char *get_hostname(void)
free(buf); free(buf);
return (buf); return (buf);
} }
hostname = ft_calloc(delimiter - buf, sizeof(char)); hostname = ft_calloc(delimiter - buf + 1, sizeof(char));
ft_strlcpy(hostname, buf, delimiter - buf + 1); ft_strlcpy(hostname, buf, delimiter - buf + 1);
free(buf); free(buf);
return (hostname); return (hostname);