added prompt header and made main
This commit is contained in:
parent
b67f3a20ab
commit
de6bb00acf
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
# 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
|
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"))
|
SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
|
||||||
|
|
||||||
OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))
|
OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))
|
||||||
|
|||||||
@ -1,16 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* :::::::: */
|
||||||
|
/* 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
|
#ifndef ENVIROMENT_H
|
||||||
# define ENVIROMENT_H
|
# define ENVIROMENT_H
|
||||||
|
|
||||||
typedef struct s_enviroment
|
typedef struct s_enviroment
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
char *value;
|
char *value;
|
||||||
struct s_enviroment *next;
|
struct s_enviroment *next;
|
||||||
} t_enviroment;
|
} t_enviroment;
|
||||||
|
|
||||||
void add_enviroment(t_enviroment **enviroment, char *name, char *value);
|
void add_enviroment(t_enviroment **enviroment, char *name, char *value);
|
||||||
void print_enviroment(t_enviroment *enviroment);
|
void print_enviroment(t_enviroment *enviroment);
|
||||||
char *get_enviroment(t_enviroment *enviroment, char *name);
|
char *get_enviroment(t_enviroment *enviroment, char *name);
|
||||||
void free_enviroment(t_enviroment *enviroment);
|
void free_enviroment(t_enviroment *enviroment);
|
||||||
|
int parse_enviroment(char **envp, t_enviroment **enviroment);
|
||||||
|
|
||||||
#endif
|
#endif // ENVIROMENT_H
|
||||||
|
|||||||
@ -6,13 +6,16 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */
|
/* 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
|
#ifndef MINISHELL_H
|
||||||
# define MINISHELL_H
|
# define MINISHELL_H
|
||||||
|
|
||||||
|
# define SUCCESS 1
|
||||||
|
# define FAILURE 0
|
||||||
|
|
||||||
# include "allowed.h"
|
# include "allowed.h"
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "enviroment.h"
|
# include "enviroment.h"
|
||||||
|
|||||||
18
inc/prompt.h
Normal file
18
inc/prompt.h
Normal 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
|
||||||
19
src/enviroment/parse_enviroment.c
Normal file
19
src/enviroment/parse_enviroment.c
Normal 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
26
src/main.c
Normal 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);
|
||||||
|
}
|
||||||
0
src/prompt/load_history.c
Normal file
0
src/prompt/load_history.c
Normal file
@ -6,40 +6,24 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
|
/* 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"
|
#include "minishell.h"
|
||||||
|
|
||||||
void print_prompt(void)
|
char *prompt(void)
|
||||||
{
|
{
|
||||||
|
char *line;
|
||||||
|
|
||||||
char *cwd = getcwd(NULL, 0);
|
char *cwd = getcwd(NULL, 0);
|
||||||
if (cwd == NULL)
|
if (cwd == NULL)
|
||||||
{
|
{
|
||||||
perror("getcwd");
|
perror("getcwd");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("%s$ ", cwd);
|
line = readline(cwd);
|
||||||
free(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;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user