mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「✨」 feat(Prompt): prompt working
This commit is contained in:
0
.minishellrc
Normal file
0
.minishellrc
Normal file
BIN
.minishellrc.swp
Normal file
BIN
.minishellrc.swp
Normal file
Binary file not shown.
21
compile_commands.json
Normal file
21
compile_commands.json
Normal file
@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"directory": "/nfs/homes/adjoly/Documents/ft_minipowershell",
|
||||
"arguments": [
|
||||
"cc",
|
||||
"-I",
|
||||
"include/",
|
||||
"-I",
|
||||
"libft/",
|
||||
"-Werror",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-g",
|
||||
"src/main.c",
|
||||
"-c",
|
||||
"-o",
|
||||
"obj/src/main.o"
|
||||
],
|
||||
"file": "src/main.c"
|
||||
}
|
||||
]
|
@ -1,28 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.h :+: :+: :+: */
|
||||
/* parsing.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:24:21 by adjoly ### ########.fr */
|
||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/04/25 14:30:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GET_NEXT_LINE_H
|
||||
# define GET_NEXT_LINE_H
|
||||
#ifndef PARSING_H
|
||||
# define PARSING_H
|
||||
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 1
|
||||
# endif
|
||||
|
||||
char *get_next_line(int fd);
|
||||
char *ft_strjoin_gnl(char *s1, char *s2);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
size_t ft_strlen(const char *s);
|
||||
typedef struct s_cmd
|
||||
{
|
||||
char *cmd;
|
||||
char **argv;
|
||||
} t_cmd;
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
|
||||
# Updated: 2024/03/18 14:33:40 by adjoly ### ########.fr #
|
||||
# Updated: 2024/04/27 17:17:00 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -37,6 +37,7 @@ SRCS = is/ft_isalnum.c \
|
||||
mem/ft_memcpy.c \
|
||||
mem/ft_memmove.c \
|
||||
mem/ft_memset.c \
|
||||
mem/ft_freetab.c \
|
||||
print/ft_putchar.c \
|
||||
print/ft_putchar_fd.c \
|
||||
print/ft_putendl_fd.c \
|
||||
@ -70,16 +71,16 @@ SRCS = is/ft_isalnum.c \
|
||||
print/printf/ft_putnbrbase.c \
|
||||
print/printf/ft_putnbr.c \
|
||||
print/printf/ft_putstr.c \
|
||||
io/get_next_line/get_next_line.c \
|
||||
io/get_next_line/get_next_line_utils.c \
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR),$(SRCS:.c=.o))
|
||||
|
||||
FLAGS = -Werror -Wall -Wextra -g
|
||||
|
||||
LIB = io/get_next_line/get_next_line.a
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@make -s -C io/get_next_line/
|
||||
@ar -rcs $(NAME) $(OBJS) $(LIB)
|
||||
@ar -rcs $(NAME) $(OBJS)
|
||||
@echo "[✔] Libft compiled"
|
||||
|
||||
$(OBJSDIR)%.o: %.c
|
||||
@ -89,11 +90,9 @@ $(OBJSDIR)%.o: %.c
|
||||
all: $(NAME)
|
||||
|
||||
clean:
|
||||
@make -s -C io/get_next_line/ clean
|
||||
@rm -f $(OBJS)
|
||||
|
||||
fclean: clean
|
||||
@make -s -C io/get_next_line/ fclean
|
||||
@rm -f $(NAME)
|
||||
@echo "[X] Libft cleaned"
|
||||
|
||||
|
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:23:07 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:25:28 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
#include "../../libft.h"
|
||||
|
||||
char check_line(char *res, char *buf)
|
||||
{
|
||||
|
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:45:27 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:25:44 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strjoin_gnl(char *s1, char *s2)
|
||||
{
|
||||
|
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:45:08 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:27:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,13 +16,15 @@
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# include "print/printf/ft_printf.h"
|
||||
# include "io/get_next_line/get_next_line.h"
|
||||
# include <stdarg.h>
|
||||
|
||||
# define INT_MAX 2147483647
|
||||
# define INT_MIN -2147483648
|
||||
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 5
|
||||
# endif
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
@ -36,6 +38,7 @@ typedef enum s_boolean
|
||||
TRUE,
|
||||
} t_boolean;
|
||||
|
||||
char *ft_strjoinvaarg(char *src, ...);
|
||||
long long ft_atoll(const char *nptr);
|
||||
int ft_atoi(const char *nptr);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
@ -84,6 +87,10 @@ void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
|
||||
char *get_next_line(int fd);
|
||||
char *ft_strjoin_gnl(char *s1, char *s2);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char *s);
|
||||
void ft_putnbrbase_fd(int n, char *base, int fd);
|
||||
@ -95,10 +102,12 @@ int ft_printconversion(char conversion, va_list args);
|
||||
int ft_putnbrulong(unsigned int n);
|
||||
int ft_putaddr(void *ptr);
|
||||
int ft_putstr_p(char *s);
|
||||
int ft_putnbrbase_p(unsigned long int n, char *base);
|
||||
int ft_putnbrbasep(unsigned long int n, char *base);
|
||||
int ft_putnbrbase_pf(unsigned int n, char *base);
|
||||
int ft_putchar_p(char c);
|
||||
int ft_putnbr_p(int n);
|
||||
size_t ft_strlen(const char *s);
|
||||
|
||||
void ft_freearr(void **arr);
|
||||
|
||||
#endif
|
||||
|
@ -1,33 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.h :+: :+: :+: */
|
||||
/* ft_freetab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/17 16:50:36 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:47:28 by adjoly ### ########.fr */
|
||||
/* Created: 2024/04/27 15:33:20 by adjoly #+# #+# */
|
||||
/* Updated: 2024/04/27 17:20:24 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PRINTF_H
|
||||
# define FT_PRINTF_H
|
||||
#include <stdlib.h>
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
void ft_freearr(void **arr)
|
||||
{
|
||||
void **tmp;
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_printconversion(char conversion, va_list args);
|
||||
int ft_putnbrulong(unsigned int n);
|
||||
int ft_putaddr(void *ptr);
|
||||
|
||||
int ft_putstr_p(char *s);
|
||||
|
||||
int ft_putnbrbase_p(unsigned long int n, char *base);
|
||||
int ft_pputnbrbase(unsigned int n, char *base);
|
||||
int ft_putchar_p(char c);
|
||||
int ft_putnbr_p(int n);
|
||||
size_t ft_strlen(const char *s);
|
||||
|
||||
#endif
|
||||
tmp = arr;
|
||||
while (*tmp)
|
||||
{
|
||||
free(*tmp);
|
||||
tmp++;
|
||||
}
|
||||
free(arr);
|
||||
}
|
BIN
libft/obj/str/ft_strjoinvaarg.o
Normal file
BIN
libft/obj/str/ft_strjoinvaarg.o
Normal file
Binary file not shown.
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:46:36 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:27:13 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_putaddr(void *ptr)
|
||||
{
|
||||
@ -19,7 +19,7 @@ int ft_putaddr(void *ptr)
|
||||
if (ptr == NULL)
|
||||
return (write(1, "(nil)", 5));
|
||||
write(1, "0x", 2);
|
||||
r = ft_putnbrbase_p((long unsigned int)ptr, "0123456789abcdef");
|
||||
r = ft_putnbrbasep((long unsigned int)ptr, "0123456789abcdef");
|
||||
return (2 + r);
|
||||
}
|
||||
|
||||
@ -56,9 +56,9 @@ int ft_printconversion(char conversion, va_list args)
|
||||
else if (conversion == 'p')
|
||||
count = ft_putaddr(va_arg(args, void *));
|
||||
else if (conversion == 'x')
|
||||
count = ft_pputnbrbase(va_arg(args, unsigned long), "0123456789abcdef");
|
||||
count = ft_putnbrbasep(va_arg(args, unsigned long), "0123456789abcdef");
|
||||
else if (conversion == 'X')
|
||||
count = ft_pputnbrbase(va_arg(args, unsigned long), "0123456789ABCDEF");
|
||||
count = ft_putnbrbasep(va_arg(args, unsigned long), "0123456789ABCDEF");
|
||||
return (count);
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:17:42 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:22:30 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putchar_p(char c)
|
||||
{
|
||||
|
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:20:26 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:24:27 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_putnbr_p(int n)
|
||||
{
|
||||
|
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:21:56 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:29:04 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_putnbrbase_pf(unsigned int n, char *base)
|
||||
{
|
||||
@ -29,7 +29,7 @@ int ft_putnbrbase_pf(unsigned int n, char *base)
|
||||
return (len);
|
||||
}
|
||||
|
||||
int ft_putnbrbase_p(unsigned long int n, char *base)
|
||||
int ft_putnbrbasep(unsigned long int n, char *base)
|
||||
{
|
||||
unsigned long int base_len;
|
||||
int len;
|
||||
@ -40,7 +40,7 @@ int ft_putnbrbase_p(unsigned long int n, char *base)
|
||||
len += write(1, &base[n % base_len], 1);
|
||||
else
|
||||
{
|
||||
len += ft_putnbrbase_p(n / base_len, base);
|
||||
len += ft_putnbrbasep(n / base_len, base);
|
||||
len += write(1, &base[n % base_len], 1);
|
||||
}
|
||||
return (len);
|
||||
|
@ -6,11 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/12 15:05:16 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:24:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_putstr_p(char *s)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 09:14:19 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:43:50 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:21:29 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -38,7 +38,7 @@ static int ft_countletter(char const *s, char sep)
|
||||
return (i);
|
||||
}
|
||||
|
||||
static void *ft_freearr(char **arr)
|
||||
static void *ft_freearr_s(char **arr)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -67,7 +67,7 @@ char **ft_split_to_result(char **tab, char const *s, char c)
|
||||
k = 0;
|
||||
tab[j] = ft_calloc(ft_countletter(&s[i], c) + 1, sizeof(char));
|
||||
if (!tab[j])
|
||||
return (ft_freearr(tab));
|
||||
return (ft_freearr_s(tab));
|
||||
while (s[i] && s[i] != c)
|
||||
tab[j][k++] = s [i++];
|
||||
tab[j][k] = '\0';
|
||||
|
46
src/main.c
46
src/main.c
@ -6,23 +6,47 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||
/* Updated: 2024/04/25 11:30:17 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/04/27 17:34:52 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
t_boolean is_str(char *src, char *dst)
|
||||
{
|
||||
while (*src++ == *dst++)
|
||||
;
|
||||
while (*src && *dst && *src == *dst)
|
||||
{
|
||||
src++;
|
||||
dst++;
|
||||
}
|
||||
if (*src)
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
void get_prompt(void)
|
||||
{
|
||||
char *pwd;
|
||||
char *home;
|
||||
char *user;
|
||||
char *host;
|
||||
|
||||
pwd = getenv("PWD");
|
||||
home = getenv("HOME");
|
||||
host = getenv("HOST");
|
||||
user = getenv("USER");
|
||||
|
||||
if (!ft_strncmp(pwd, home, ft_strlen(home)))
|
||||
{
|
||||
ft_printf("%s@%s:~%s> ", user, host, pwd + ft_strlen(home));
|
||||
return ;
|
||||
}
|
||||
ft_printf("%s@%s:%s> ", user, host, pwd);
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **env)
|
||||
{
|
||||
char *test;
|
||||
@ -33,16 +57,14 @@ int main(int ac, char **av, char **env)
|
||||
(void)env;
|
||||
while (1)
|
||||
{
|
||||
test = readline("test>");
|
||||
get_prompt();
|
||||
test = readline(NULL);
|
||||
lll = ft_split(test, ' ');
|
||||
if (is_str(*lll, "exit") == TRUE)
|
||||
return (0);
|
||||
if (is_str(*lll, "uwu") == TRUE)
|
||||
{
|
||||
printf("go burn in hell\n");
|
||||
return (0);
|
||||
}
|
||||
printf("%s\n", test);
|
||||
if (!*lll)
|
||||
continue;
|
||||
if (is_str(test, "exit"))
|
||||
break;
|
||||
}
|
||||
ft_freearr((void **)lll);
|
||||
return (0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user