start
This commit is contained in:
parent
f6e9c64b29
commit
33cccda0ad
4
Makefile
4
Makefile
@ -1,4 +1,5 @@
|
|||||||
SRCS = main.c
|
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_getstr.c filetester.c
|
||||||
|
SRCS = main.c ${UTILS_SRC}
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ 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:
|
||||||
|
BIN
argprinter
Executable file
BIN
argprinter
Executable file
Binary file not shown.
41
filetester.c
Normal file
41
filetester.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "minishell"
|
||||||
|
|
||||||
|
int ft_file_is_readable(char *path)
|
||||||
|
{
|
||||||
|
int readable;
|
||||||
|
|
||||||
|
fd = open(path, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: %s: No such file or directory\n", path);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
readable = read(fd, "", 0);
|
||||||
|
if (readable == -1)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_file_is_writeable(char *path)
|
||||||
|
{
|
||||||
|
int writeable;
|
||||||
|
|
||||||
|
fd = open(path, O_WRONLY | O_CREAT, 0644);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
ft_eprintf("bizarre l'erreur");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
writeable = write(fd, "", 0);
|
||||||
|
if (writeable == -1)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
return (1);
|
||||||
|
}
|
BIN
libftx/extra/extra.a
Normal file
BIN
libftx/extra/extra.a
Normal file
Binary file not shown.
BIN
libftx/extra/ft_contain_only.o
Normal file
BIN
libftx/extra/ft_contain_only.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_freer.o
Normal file
BIN
libftx/extra/ft_freer.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_is_in.o
Normal file
BIN
libftx/extra/ft_is_in.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_random_generator.o
Normal file
BIN
libftx/extra/ft_random_generator.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_strchri.o
Normal file
BIN
libftx/extra/ft_strchri.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_strcmp.o
Normal file
BIN
libftx/extra/ft_strcmp.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_strfjoin.o
Normal file
BIN
libftx/extra/ft_strfjoin.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_strgen.o
Normal file
BIN
libftx/extra/ft_strgen.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_strmerger.o
Normal file
BIN
libftx/extra/ft_strmerger.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_strndup.o
Normal file
BIN
libftx/extra/ft_strndup.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_tabrealloc.o
Normal file
BIN
libftx/extra/ft_tabrealloc.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_ultoa_base.o
Normal file
BIN
libftx/extra/ft_ultoa_base.o
Normal file
Binary file not shown.
BIN
libftx/gnl/get_next_line.a
Normal file
BIN
libftx/gnl/get_next_line.a
Normal file
Binary file not shown.
BIN
libftx/gnl/get_next_line.o
Normal file
BIN
libftx/gnl/get_next_line.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_atoi.o
Normal file
BIN
libftx/libft/ft_atoi.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_bzero.o
Normal file
BIN
libftx/libft/ft_bzero.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_calloc.o
Normal file
BIN
libftx/libft/ft_calloc.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_isalnum.o
Normal file
BIN
libftx/libft/ft_isalnum.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_isalpha.o
Normal file
BIN
libftx/libft/ft_isalpha.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_isascii.o
Normal file
BIN
libftx/libft/ft_isascii.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_isdigit.o
Normal file
BIN
libftx/libft/ft_isdigit.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_isprint.o
Normal file
BIN
libftx/libft/ft_isprint.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_itoa.o
Normal file
BIN
libftx/libft/ft_itoa.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_memchr.o
Normal file
BIN
libftx/libft/ft_memchr.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_memcmp.o
Normal file
BIN
libftx/libft/ft_memcmp.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_memcpy.o
Normal file
BIN
libftx/libft/ft_memcpy.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_memmove.o
Normal file
BIN
libftx/libft/ft_memmove.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_memset.o
Normal file
BIN
libftx/libft/ft_memset.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_putchar_fd.o
Normal file
BIN
libftx/libft/ft_putchar_fd.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_putendl_fd.o
Normal file
BIN
libftx/libft/ft_putendl_fd.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_putnbr_fd.o
Normal file
BIN
libftx/libft/ft_putnbr_fd.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_putstr_fd.o
Normal file
BIN
libftx/libft/ft_putstr_fd.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_split.o
Normal file
BIN
libftx/libft/ft_split.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strchr.o
Normal file
BIN
libftx/libft/ft_strchr.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strdup.o
Normal file
BIN
libftx/libft/ft_strdup.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_striteri.o
Normal file
BIN
libftx/libft/ft_striteri.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strjoin.o
Normal file
BIN
libftx/libft/ft_strjoin.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strlcat.o
Normal file
BIN
libftx/libft/ft_strlcat.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strlcpy.o
Normal file
BIN
libftx/libft/ft_strlcpy.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strlen.o
Normal file
BIN
libftx/libft/ft_strlen.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strmapi.o
Normal file
BIN
libftx/libft/ft_strmapi.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strncmp.o
Normal file
BIN
libftx/libft/ft_strncmp.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strnstr.o
Normal file
BIN
libftx/libft/ft_strnstr.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strrchr.o
Normal file
BIN
libftx/libft/ft_strrchr.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_strtrim.o
Normal file
BIN
libftx/libft/ft_strtrim.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_substr.o
Normal file
BIN
libftx/libft/ft_substr.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_tolower.o
Normal file
BIN
libftx/libft/ft_tolower.o
Normal file
Binary file not shown.
BIN
libftx/libft/ft_toupper.o
Normal file
BIN
libftx/libft/ft_toupper.o
Normal file
Binary file not shown.
BIN
libftx/libft/libft.a
Normal file
BIN
libftx/libft/libft.a
Normal file
Binary file not shown.
BIN
libftx/libftx.a
Normal file
BIN
libftx/libftx.a
Normal file
Binary file not shown.
@ -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/01/18 19:21:40 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/01 16:20:05 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
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, ...);
|
||||||
|
@ -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/01/05 18:25:05 by cchauvet ### ########.fr #
|
# Updated: 2023/02/01 16:19:19 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
|
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
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
BIN
libftx/printf/ft_dprintX.o
Normal file
BIN
libftx/printf/ft_dprintX.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintarg.o
Normal file
BIN
libftx/printf/ft_dprintarg.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintflag.o
Normal file
BIN
libftx/printf/ft_dprintflag.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintl_base.o
Normal file
BIN
libftx/printf/ft_dprintl_base.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintptr.o
Normal file
BIN
libftx/printf/ft_dprintptr.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintstrtab.o
Normal file
BIN
libftx/printf/ft_dprintstrtab.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintul.o
Normal file
BIN
libftx/printf/ft_dprintul.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintul_base.o
Normal file
BIN
libftx/printf/ft_dprintul_base.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_dprintx.o
Normal file
BIN
libftx/printf/ft_dprintx.o
Normal file
Binary file not shown.
24
libftx/printf/ft_eprintf.c
Normal file
24
libftx/printf/ft_eprintf.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
BIN
libftx/printf/ft_isarg.o
Normal file
BIN
libftx/printf/ft_isarg.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_isdigit.o
Normal file
BIN
libftx/printf/ft_isdigit.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_printf.a
Normal file
BIN
libftx/printf/ft_printf.a
Normal file
Binary file not shown.
@ -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/01/05 17:36:39 by cchauvet ### ########.fr */
|
/* Updated: 2023/02/01 16:19:38 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ 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);
|
||||||
|
|
||||||
|
BIN
libftx/printf/ft_printf.o
Normal file
BIN
libftx/printf/ft_printf.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_putchar_fd.o
Normal file
BIN
libftx/printf/ft_putchar_fd.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_putstr_fd.o
Normal file
BIN
libftx/printf/ft_putstr_fd.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_skipflag.o
Normal file
BIN
libftx/printf/ft_skipflag.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_strlen.o
Normal file
BIN
libftx/printf/ft_strlen.o
Normal file
Binary file not shown.
BIN
libftx/printf/ft_vdprintf.o
Normal file
BIN
libftx/printf/ft_vdprintf.o
Normal file
Binary file not shown.
47
main.c
47
main.c
@ -1,11 +1,56 @@
|
|||||||
#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)
|
||||||
{
|
{
|
||||||
ft_split()
|
char infile;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
12
minishell.h
12
minishell.h
@ -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>
|
||||||
|
|
||||||
typedef struct s_list
|
int ft_file_is_readable(char *path);
|
||||||
{
|
int ft_file_is_writeable(char *path);
|
||||||
void *content;
|
|
||||||
void *next;
|
|
||||||
int tag;
|
|
||||||
} t_list
|
|
||||||
|
|
||||||
typedef struct cmd
|
typedef struct cmd
|
||||||
{
|
{
|
||||||
|
BIN
utils/.ft_is_a_quote.c.swp
Normal file
BIN
utils/.ft_is_a_quote.c.swp
Normal file
Binary file not shown.
27
utils/ft_getstr.c
Normal file
27
utils/ft_getstr.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#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));
|
||||||
|
}
|
BIN
utils/ft_getstr.o
Normal file
BIN
utils/ft_getstr.o
Normal file
Binary file not shown.
29
utils/ft_is_in_quote.c
Normal file
29
utils/ft_is_in_quote.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#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);
|
||||||
|
}
|
BIN
utils/ft_is_in_quote.o
Normal file
BIN
utils/ft_is_in_quote.o
Normal file
Binary file not shown.
15
utils/ft_strnchr.c
Normal file
15
utils/ft_strnchr.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#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);
|
||||||
|
}
|
BIN
utils/ft_strnchr.o
Normal file
BIN
utils/ft_strnchr.o
Normal file
Binary file not shown.
14
utils/ft_strncpy.c
Normal file
14
utils/ft_strncpy.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#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);
|
||||||
|
}
|
BIN
utils/ft_strncpy.o
Normal file
BIN
utils/ft_strncpy.o
Normal file
Binary file not shown.
17
utils/ft_strreplace.c
Normal file
17
utils/ft_strreplace.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#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);
|
||||||
|
}
|
BIN
utils/ft_strreplace.o
Normal file
BIN
utils/ft_strreplace.o
Normal file
Binary file not shown.
12
utils/utils.h
Normal file
12
utils/utils.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#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
|
Loading…
Reference in New Issue
Block a user