added prompt header and made main

This commit is contained in:
whaffman 2025-02-04 16:42:55 +01:00
parent b67f3a20ab
commit de6bb00acf
8 changed files with 97 additions and 34 deletions

View File

@ -6,7 +6,7 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/02/04 16:13:00 by whaffman ######## odam.nl #
# Updated: 2025/02/04 16:40:44 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
@ -22,7 +22,7 @@ LIBFT = $(LIBFT_PATH)/libft.a
OBJ_PATH = obj
VPATH = src:src/enviroment
VPATH = src:src/enviroment:src/prompt
SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))

View File

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* enviroment.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:26:35 by whaffman #+# #+# */
/* Updated: 2025/02/04 16:28:59 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef ENVIROMENT_H
# define ENVIROMENT_H
@ -12,5 +24,6 @@ void add_enviroment(t_enviroment **enviroment, char *name, char *value);
void print_enviroment(t_enviroment *enviroment);
char *get_enviroment(t_enviroment *enviroment, char *name);
void free_enviroment(t_enviroment *enviroment);
int parse_enviroment(char **envp, t_enviroment **enviroment);
#endif
#endif // ENVIROMENT_H

View File

@ -6,13 +6,16 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */
/* Updated: 2025/02/04 16:13:14 by whaffman ######## odam.nl */
/* Updated: 2025/02/04 16:28:30 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# define SUCCESS 1
# define FAILURE 0
# include "allowed.h"
# include "libft.h"
# include "enviroment.h"

18
inc/prompt.h Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* prompt.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:35:35 by whaffman #+# #+# */
/* Updated: 2025/02/04 16:36:04 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef PROMPT_H
# define PROMPT_H
#endif // PROMPT_H

View File

@ -0,0 +1,19 @@
#include "minishell.h"
int parse_enviroment(char **envp, t_enviroment **enviroment)
{
char **env;
*enviroment = NULL;
if (envp == NULL)
return (FAILURE);
while (*envp != NULL)
{
env = ft_split(*envp, '=');
add_enviroment(enviroment, env[0], env[1]);
ft_free_arr(env);
envp++;
}
return (SUCCESS);
}

26
src/main.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
/* Updated: 2025/02/04 16:39:58 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
int main(int argc, char **argv, char **envp)
{
t_enviroment *enviroment;
char *line;
(void)argc;
(void)argv;
parse_enviroment(envp, &enviroment);
//print_enviroment(enviroment);
free_enviroment(enviroment);
return (EXIT_SUCCESS);
}

View File

View File

@ -6,40 +6,24 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
/* Updated: 2025/02/04 16:13:09 by whaffman ######## odam.nl */
/* Updated: 2025/02/04 16:39:39 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void print_prompt(void)
char *prompt(void)
{
char *line;
char *cwd = getcwd(NULL, 0);
if (cwd == NULL)
{
perror("getcwd");
return;
}
printf("%s$ ", cwd);
line = readline(cwd);
free(cwd);
return (line);
}
int main(int argc, char **argv, char **envp)
{
(void)argc;
(void)argv;
char **env;
t_enviroment *enviroment = NULL;
while (*envp != NULL)
{
env = ft_split(*envp, '=');
add_enviroment(&enviroment, env[0], env[1]);
ft_free_arr(env);
envp++;
}
print_enviroment(enviroment);
free_enviroment(enviroment);
return 0;
}