Compare commits

..

No commits in common. "13d412ea7151fab3b5424f6d6538a8ae2c496304" and "f6e9c64b297ea5fdba21ab7655190ed6d7610b8d" have entirely different histories.

96 changed files with 14 additions and 460 deletions

Binary file not shown.

View File

@ -1,5 +1,4 @@
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_getstr.c SRCS = main.c
SRCS = env.c ${UTILS_SRC}
OBJS = ${SRCS:.c=.o} OBJS = ${SRCS:.c=.o}
@ -7,7 +6,7 @@ NAME = minishell
CC = clang CC = clang
CFLAGS = -g -Wall -Werror -Wextra CFLAGS = -Wall -Werror -Wextra
LIBS = libftx/libftx.a LIBS = libftx/libftx.a
@ -17,7 +16,6 @@ LIBS = libftx/libftx.a
all: ${NAME} all: ${NAME}
${NAME}: ${OBJS} ${NAME}: ${OBJS}
make -C libftx all
${CC} ${OBJS} -o ${NAME} ${LIBS} ${CC} ${OBJS} -o ${NAME} ${LIBS}
clean: clean:

Binary file not shown.

139
env.c
View File

@ -1,139 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/02/02 17:39:56 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "env.h"
#include "libftx/libftx.h"
void print_export(t_list **head, int fd)
{
t_list *current;
char *ctn;
current = *head;
while (current != NULL)
{
ctn = current->content;
if (*(ft_strchr(ctn, '=') - 1) != '_')
{
write(fd, "declare -x ", 11);
ft_putstr_fd(ctn, fd);
write(fd, "\n", 1);
}
current = current->next;
}
}
void print_env(t_list **head, int fd)
{
t_list *current;
current = *head;
while (current != NULL)
{
ft_putstr_fd(current->content, fd);
write(fd, "\n", 1);
current = current->next;
}
}
int strcmp_alphabet(char *s1, char *s2)
{
int i;
if (!s1 || !s2)
return (-2);
i = 0;
while (s1[i] && s2[i])
{
if (s1[i] < s2[i])
return (0);
else if (s1[i] > s2[i])
return (1);
i++;
}
return (-1);
}
void ft_double_swap(char **a, char **b)
{
void *c;
c = *a;
*a = *b;
*b = c;
}
void exchange(char **a, char **b, char **c)
{
void *d;
d = *a;
*a = *b;
*b = *c;
*c = d;
}
void add_sort(t_list **head, char *str)
{
t_list *current;
char *last;
current = *head;
while (current->next != NULL && strcmp_alphabet(str, current->content) != 0)
current = current->next;
if (strcmp_alphabet(str, current->content) == 1)
last = str;
else
exchange(&last, (char **)(&current->content), &str);
while (current != NULL)
{
if (current->next == NULL)
current->next = ft_calloc(1, sizeof(t_list));
if (current->next == NULL)
return ;
current = current->next;
if (current->content == NULL)
{
current->content = last;
return ;
}
else
ft_double_swap((char **)(&current->content), &last);
}
}
t_list **init_env(char **env)
{
t_list **head;
int i;
head = ft_calloc(1, sizeof(t_list *));
*head = ft_calloc(1, sizeof(t_list));
if (*head == NULL)
return (NULL);
i = -1;
while (env[++i])
{
if (ft_strnstr(env[i], "XMODIFIERS=@im=ibus", 200))
write(1, "", 0);
add_sort(head, env[i]);
}
return (head);
}
/*int main(int argc, char *argv[], char **env)
{
(void)argc;
(void)argv;
print_export(init_env(env));
return (0);
}*/

21
env.h
View File

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/31 14:39:05 by erey-bet #+# #+# */
/* Updated: 2023/01/31 14:56:16 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ENV_H
# define ENV_H
typedef struct s_env {
void *ctn;
void *next;
} t_env;
#endif

49
file1
View File

@ -1,49 +0,0 @@
COLORTERM=truecolor
DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/101231/bus,guid=2b19cb48c68a1a9a5df2465563da4d2b'
DBUS_STARTER_ADDRESS='unix:path=/run/user/101231/bus,guid=2b19cb48c68a1a9a5df2465563da4d2b'
DBUS_STARTER_BUS_TYPE=session
DESKTOP_SESSION=ubuntu
DISPLAY=:0
DOCKER_HOST=unix:///run/user/101231/docker.sock
GDMSESSION=ubuntu
GDM_LANG=en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/dd4e2769_33dd_4e18_81b2_70c233dc78ce
GNOME_TERMINAL_SERVICE=:1.96
GPG_AGENT_INFO=/run/user/101231/gnupg/S.gpg-agent:0:1
GTK_MODULES=gail:atk-bridge
HOME=/nfs/homes/erey-bet
IM_CONFIG_PHASE=1
INVOCATION_ID=4f6816c8fd9446809f7d454fd8bdc56a
JOURNAL_STREAM=9:166232
KRB5CCNAME=FILE:/tmp/krb5cc_101231_TfpJ05
LANG=en_US.UTF-8
LANGUAGE=en
LOGNAME=erey-bet
MANAGERPID=38750
OLDPWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell
PATH=/nfs/homes/erey-bet/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell
QT_ACCESSIBILITY=1
QT_IM_MODULE=ibus
SESSION_MANAGER=local/1C2.42angouleme.fr:@/tmp/.ICE-unix/39041,unix/1C2.42angouleme.fr:/tmp/.ICE-unix/39041
SHELL=/bin/zsh
SHLVL=1
SSH_AGENT_PID=39003
SSH_AUTH_SOCK=/run/user/101231/keyring/ssh
TERM=xterm-256color
USER=erey-bet
VTE_VERSION=6003
XAUTHORITY=/nfs/homes/erey-bet/.Xauthority
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
XDG_CURRENT_DESKTOP=ubuntu:GNOME
XDG_DATA_DIRS=/usr/share/gnome:/usr/share/ubuntu:/nfs/homes/erey-bet/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/erey-bet
XDG_MENU_PREFIX=gnome-
XDG_RUNTIME_DIR=/run/user/101231
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_CLASS=user
XDG_SESSION_DESKTOP=ubuntu
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_TYPE=x11
XMODIFIERS='@im=ibus'

50
file2
View File

@ -1,50 +0,0 @@
COLORTERM=truecolor
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/101231/bus,guid=2b19cb48c68a1a9a5df2465563da4d2b
DBUS_STARTER_ADDRESS=unix:path=/run/user/101231/bus,guid=2b19cb48c68a1a9a5df2465563da4d2b
DBUS_STARTER_BUS_TYPE=session
DESKTOP_SESSION=ubuntu
DISPLAY=:0
DOCKER_HOST=unix:///run/user/101231/docker.sock
GDMSESSION=ubuntu
GDM_LANG=en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/dd4e2769_33dd_4e18_81b2_70c233dc78ce
GNOME_TERMINAL_SERVICE=:1.96
GPG_AGENT_INFO=/run/user/101231/gnupg/S.gpg-agent:0:1
GTK_MODULES=gail:atk-bridge
HOME=/nfs/homes/erey-bet
IM_CONFIG_PHASE=1
INVOCATION_ID=4f6816c8fd9446809f7d454fd8bdc56a
JOURNAL_STREAM=9:166232
KRB5CCNAME=FILE:/tmp/krb5cc_101231_TfpJ05
LANG=en_US.UTF-8
LANGUAGE=en
LOGNAME=erey-bet
MANAGERPID=38750
OLDPWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell
PATH=/nfs/homes/erey-bet/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell
QT_ACCESSIBILITY=1
QT_IM_MODULE=ibus
SESSION_MANAGER=local/1C2.42angouleme.fr:@/tmp/.ICE-unix/39041,unix/1C2.42angouleme.fr:/tmp/.ICE-unix/39041
SHELL=/bin/zsh
SHLVL=1
SSH_AGENT_PID=39003
TERM=xterm-256color
USER=erey-bet
VTE_VERSION=6003
XAUTHORITY=/nfs/homes/erey-bet/.Xauthority
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
XDG_CURRENT_DESKTOP=ubuntu:GNOME
XDG_DATA_DIRS=/usr/share/gnome:/usr/share/ubuntu:/nfs/homes/erey-bet/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/erey-bet
XDG_MENU_PREFIX=gnome-
XDG_RUNTIME_DIR=/run/user/101231
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_CLASS=user
XDG_SESSION_DESKTOP=ubuntu
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_TYPE=x11
XMODIFIERS=@im=ibus
_=/nfs/homes/erey-bet/travaux/Cursus42/minishell/./minishell
SSH_AUTH_SOCK=/run/user/101231/keyring/ssh

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */ /* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/02/01 16:20:05 by cchauvet ### ########.fr */ /* Updated: 2023/01/18 19:21:40 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,6 @@
char *ft_ultoa_base(unsigned long long n, char *base); char *ft_ultoa_base(unsigned long long n, char *base);
int ft_printf(const char *format, ...); int ft_printf(const char *format, ...);
int ft_eprintf(const char *format, ...);
char *get_next_line(int fd); char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop); size_t ft_random_generator(size_t start, size_t stop);
void ft_freer_tab_ultimate(size_t len, ...); void ft_freer_tab_ultimate(size_t len, ...);

View File

@ -6,13 +6,13 @@
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ # # By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# # # Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
# Updated: 2023/02/01 16:19:19 by cchauvet ### ########.fr # # Updated: 2023/01/05 18:25:05 by cchauvet ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
CC = clang CC = clang
SRCS = ft_dprintarg.c ft_dprintflag.c ft_dprintl_base.c ft_dprintptr.c ft_dprintstrtab.c ft_dprintul_base.c ft_dprintul.c ft_dprintx.c ft_dprintX.c ft_isarg.c ft_isdigit.c ft_printf.c ft_putchar_fd.c ft_putstr_fd.c ft_skipflag.c ft_strlen.c ft_vdprintf.c ft_eprintf.c SRCS = ft_dprintarg.c ft_dprintflag.c ft_dprintl_base.c ft_dprintptr.c ft_dprintstrtab.c ft_dprintul_base.c ft_dprintul.c ft_dprintx.c ft_dprintX.c ft_isarg.c ft_isdigit.c ft_printf.c ft_putchar_fd.c ft_putstr_fd.c ft_skipflag.c ft_strlen.c ft_vdprintf.c
OBJS = ${SRCS:.c=.o} OBJS = ${SRCS:.c=.o}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_eprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 22:01:28 by cchauvet #+# #+# */
/* Updated: 2023/02/01 16:18:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_printf(const char *format, ...)
{
va_list va;
int i;
va_start(va, format);
i = ft_vdprintf(2, format, va);
va_end(va);
return (i);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */ /* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/02/01 16:19:38 by cchauvet ### ########.fr */ /* Updated: 2023/01/05 17:36:39 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,6 @@ int ft_dprintarg(int fd, int c, va_list va);
int ft_dprintstrtab(int fd, char **tab); int ft_dprintstrtab(int fd, char **tab);
int ft_printf(const char *format, ...); int ft_printf(const char *format, ...);
int ft_eprintf(const char *format, ...);
int ft_vdprintf(int fd, const char *format, va_list va); int ft_vdprintf(int fd, const char *format, va_list va);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

49
main.c
View File

@ -1,56 +1,11 @@
#include "minishell.h" #include "minishell.h"
int ft_get_infile(char **line)
{
size_t i;
char *path;
path = NULL;
i = 0;
while ((*line)[i] != '\0')
{
if ((*line)[i] == '<' && ft_is_in_quote(*line, i) == 0)
{
if (path != NULL)
free(path);
path = ft_getstr(*line, i);
if (path == NULL)
return (-1);
if (ft_file_is_readable(path) == 0)
{
free(path);
return (-1);
}
}
i++;
}
return (open(path, O_RDONLY));
}
t_list **ft_parse_cmd(char *line) t_list **ft_parse_cmd(char *line)
{ {
char infile; ft_split()
char outfile;
t_list **cmds;
size_t i;
(void) outfile;
(void) cmds;
i = 0;
while (line[i] != '\0')
{
i++;
}
} }
int main(int ac, char **av) int main(int ac, char **av)
{ {
int fd;
int i;
if (ac == 1)
return (1);
ft_parse_cmd(av[1]);
return (1);
} }

BIN
main.o

Binary file not shown.

View File

@ -1,13 +1,13 @@
#ifndef FT_MINISHELL #ifndef FT_MINISHELL
# define FT_MINISHELL # define FT_MINISHELL
# include "libftx/libftx.h" # include "libftx/libftx.h"
# include "utils/utils.h"
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
int ft_file_is_readable(char *path); typedef struct s_list
int ft_file_is_writeable(char *path); {
void *content;
void *next;
int tag;
} t_list
typedef struct cmd typedef struct cmd
{ {

Binary file not shown.

View File

@ -1,27 +0,0 @@
#include "utils.h"
char *ft_getstr(char *str, size_t n)
{
size_t start;
size_t stop;
char c;
int quote;
start = n;
stop = n;
quote = ft_is_in_quote(str, n);
if (quote == 0)
c = ' ';
else
{
if (quote == 1)
c = '\'';
else
c = '"';
}
while (str[start - 1] != c && start > 0)
start--;
while (str[stop] != c && str[stop] != '\0')
stop++;
return (ft_strndup(str + start, stop - start));
}

Binary file not shown.

View File

@ -1,29 +0,0 @@
#include "utils.h"
int ft_is_in_quote(char *str, size_t n)
{
size_t double_quoted;
size_t simple_quoted;
size_t i;
double_quoted = 0;
simple_quoted = 0;
i = 0;
while (str[i] != '\0' && i < n)
{
if (str[i] == '"')
{
if (simple_quoted == 0)
double_quoted = !double_quoted;
}
if (str[i] == '\'')
{
if (double_quoted == 0)
simple_quoted = !simple_quoted;
}
i++;
}
return (simple_quoted == 1 + (double_quoted == 1) * 2);
}

Binary file not shown.

View File

@ -1,15 +0,0 @@
#include "utils.h"
ssize_t ft_strnchr(char *str, char c)
{
size_t i;
i = 0;
while (str[i] != '\0')
{
if (str[i] == c)
return (i);
i++;
}
return (-1);
}

Binary file not shown.

View File

@ -1,14 +0,0 @@
#include "utils.h"
size_t ft_strncpy(char *dst, char *src, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
dst[i] = src[i];
i++;
}
return (i);
}

Binary file not shown.

View File

@ -1,17 +0,0 @@
#include "utils.h"
char *ft_strreplace(char *str, char *fill, size_t start, size_t stop)
{
char *out;
size_t sum;
out = malloc((ft_strlen(str) + ft_strlen(fill) - (stop - start) + 1 * sizeof(char)));
if (out == NULL)
return (NULL);
ft_strncpy(out, str, start);
ft_strncpy(out + start, fill, ft_strlen(fill));
sum = start + ft_strlen(fill);
ft_strncpy(out + sum, str + stop, ft_strlen(str) - stop);
out[sum + ft_strlen(str) - stop] = '\0';
return (out);
}

Binary file not shown.

View File

@ -1,12 +0,0 @@
#ifndef FT_UTILS
# define FT_UTILS
# include <stdlib.h>
# include "../libftx/libftx.h"
size_t ft_strncpy(char *dst, char *src, size_t n);
int ft_is_in_quote(char *str, size_t n);
char *ft_strreplace(char *str, char *fill, size_t start, size_t stop);
ssize_t ft_strnchr(char *str, char c);
char *ft_getstr(char *str, size_t n);
#endif