Merge branch 'willem'

This commit is contained in:
whaffman 2025-02-04 14:01:57 +01:00
commit 1545e4af99
7 changed files with 173 additions and 2 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
minishell
a.out
*.d
*.o
obj/

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/libft"]
path = lib/libft
url = https://gitea.duinvoetje.nl/willem/libft.git

75
Makefile Normal file
View File

@ -0,0 +1,75 @@
# **************************************************************************** #
# #
# ::: o_ :::::: ::: #
# Makefile :+: / :+::+: :+: #
# +:+ > +:++:+ +:+ #
# By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ #
# +#+ +#+#+ +#++#+ +#+ \o/ #
# Created: 2024/10/15 11:48:46 by whaffman #+#+# #+#+# #+# #+# | #
# Updated: 2024/11/07 15:28:08 by whaffman ### ### ### ### / \ #
# #
# **************************************************************************** #
NAME = minishell
SRC_PATH = src
INC_PATH = inc
LIB_PATH = lib
LIBFT_PATH = $(LIB_PATH)/libft
LIBFT_INC_PATH = $(LIBFT_PATH)/inc
LIBFT = $(LIBFT_PATH)/libft.a
OBJ_PATH = obj
VPATH = src
SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))
DEPENDS = ${OBJECTS:.o=.d}
CC = cc
RM = rm -rf
INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH)
CFLAGS = -Wall -Wextra -Werror -MMD
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDLIBS := -L$(LIBFT_PATH) -lft
endif
all: $(NAME)
$(NAME): $(LIBFT) $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) $(LDLIBS) -o $(NAME)
-include ${DEPENDS}
$(LIBFT): $(LIBFT_PATH)
$(MAKE) -C $(LIBFT_PATH)
$(LIBFT_PATH):
git submodule add https://gitea.duinvoetje.nl/willem/libft.git $(LIBFT_PATH)
$(OBJ_PATH):
mkdir -p $@
$(OBJ_PATH)/%.o: %.c $(LIBFT) | $(OBJ_PATH)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) $(OBJECTS) $(OBJ_PATH)
$(MAKE) -C $(LIBFT_PATH) clean
$(MAKE) -C $(MLX42_PATH)/build clean
fclean: clean
$(RM) $(NAME)
$(MAKE) -C $(LIBFT_PATH) fclean
re: fclean all
run: all
./$(NAME)
.PHONY: all clean fclean re run

View File

@ -84,7 +84,7 @@
* `ssize_t read(int fd, void *buf, size_t count);`
* Reads up to count bytes from file descriptor fd into the buffer starting at buf.
* `close`
* `int close(int fd);`
* `int close(int fd);`q
* Closes the file descriptor fd.
* `fork`
* `pid_t fork(void);`

View File

@ -156,7 +156,6 @@
# include <fcntl.h>
# include <errno.h>
# include <signal.h>
# include <readline/readline.h>
# include <dirent.h>
# include <sys/stat.h>
# include <sys/ioctl.h>

1
lib/libft Submodule

@ -0,0 +1 @@
Subproject commit 27f7d3e9e02cccf7092f3101b939d381198a595b

88
src/prompt.c Normal file
View File

@ -0,0 +1,88 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "libft.h"
// /**
// * @brief Prints the prompt for the Minishell.
// *
// * This function prints the prompt for the Minishell, which is the current working directory followed by a dollar sign.
// *
// * @param void
// * @return void
// */
typedef struct s_enviroment
{
char *name;
char *value;
struct s_enviroment *next;
} t_enviroment;
void add_enviroment(t_enviroment **enviroment, char *name, char *value)
{
t_enviroment *new_enviroment = malloc(sizeof(t_enviroment));
if (new_enviroment == NULL)
{
perror("malloc");
return;
}
new_enviroment->name = name;
new_enviroment->value = value;
new_enviroment->next = *enviroment;
*enviroment = new_enviroment;
}
void print_enviroment(t_enviroment *enviroment)
{
while (enviroment != NULL)
{
printf("%s=%s\n", enviroment->name, enviroment->value);
enviroment = enviroment->next;
}
}
char *get_enviroment(t_enviroment *enviroment, char *name)
{
while (enviroment != NULL)
{
if (ft_strcmp(enviroment->name, name) == 0)
{
return enviroment->value;
}
enviroment = enviroment->next;
}
return NULL;
}
void print_prompt(void)
{
char *cwd = getcwd(NULL, 0);
if (cwd == NULL)
{
perror("getcwd");
return;
}
printf("%s$ ", cwd);
free(cwd);
}
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]);
envp++;
}
print_enviroment(enviroment);
return 0;
}