diff options
| author | nass1pro <nass1pro@gmail.com> | 2020-06-12 13:52:58 +0200 |
|---|---|---|
| committer | nass1pro <nass1pro@gmail.com> | 2020-06-13 11:45:50 +0200 |
| commit | d971bd8d16608f316396aba7a579d0b1f1af5aeb (patch) | |
| tree | 98ec558582ed20a120e13b4a376fd206fb620da0 /test_mini/libft/src/io | |
| parent | 3136f59540a8dd29e2f096be5a8943e2ddd28431 (diff) | |
| download | minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.tar.gz minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.tar.bz2 minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.zip | |
Added e_token enum
Diffstat (limited to 'test_mini/libft/src/io')
36 files changed, 0 insertions, 1473 deletions
diff --git a/test_mini/libft/src/io/ft_getchar.c b/test_mini/libft/src/io/ft_getchar.c deleted file mode 100644 index 9d233c0..0000000 --- a/test_mini/libft/src/io/ft_getchar.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_getchar.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/18 10:29:54 by cacharle #+# #+# */ -/* Updated: 2020/02/14 02:24:56 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char ft_getchar(void) -{ - char c; - - if (read(STDIN_FILENO, &c, 1) < 0) - return (-1); - return (c); -} diff --git a/test_mini/libft/src/io/ft_next_line.c b/test_mini/libft/src/io/ft_next_line.c deleted file mode 100644 index 74afa71..0000000 --- a/test_mini/libft/src/io/ft_next_line.c +++ /dev/null @@ -1,113 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/31 10:39:38 by cacharle #+# #+# */ -/* Updated: 2020/02/28 12:11:35 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int st_find_newline(char *str) -{ - int i; - - i = -1; - while (str[++i]) - if (str[i] == '\n') - return (i); - return (-1); -} - -static int st_free_return(char **ptr, char **ptr2, int ret) -{ - if (ptr != NULL) - { - free(*ptr); - *ptr = NULL; - } - if (ptr2 != NULL) - { - free(*ptr2); - *ptr2 = NULL; - } - return (ret); -} - -static int st_read_line(int fd, char **line, char *rest) -{ - int ret; - int split_at; - char *buf; - - if ((buf = malloc(sizeof(char) * (FTNL_BUFFER_SIZE + 1))) == NULL) - return (st_free_return(line, NULL, FTNL_STATUS_ERROR)); - while ((ret = read(fd, buf, FTNL_BUFFER_SIZE)) > 0) - { - buf[ret] = '\0'; - if ((split_at = st_find_newline(buf)) != -1) - { - ft_strcpy(rest, buf + split_at + 1); - buf[split_at] = '\0'; - if ((*line = ft_strjoinf(*line, buf, FT_STRJOINF_FST)) == NULL) - return (st_free_return(&buf, NULL, FTNL_STATUS_ERROR)); - return (st_free_return(&buf, NULL, FTNL_STATUS_LINE)); - } - if ((*line = ft_strjoinf(*line, buf, FT_STRJOINF_FST)) == NULL) - return (st_free_return(&buf, NULL, FTNL_STATUS_ERROR)); - } - if (ret == -1) - return (st_free_return(&buf, line, FTNL_STATUS_ERROR)); - return (st_free_return(&buf, NULL, ret)); -} - -/* -** if has rest: -** if rest has newline: -** push rest until newline in line, shift rest -** return LINE_READ -** else: -** push rest in line -** -** while can read fd in buf -** if buf has newline: -** push buf until newline in line -** push buf after newline in rest -** return LINE_READ -** push buf in line -** -** return FTNL_EOF -*/ - -int ft_next_line(int fd, char **line) -{ - int split_at; - static char rest[OPEN_MAX][FTNL_BUFFER_SIZE + 1] = {{0}}; - - if (fd < 0 || fd > OPEN_MAX || line == NULL || FTNL_BUFFER_SIZE <= 0) - return (FTNL_STATUS_ERROR); - if ((*line = ft_strdup("")) == NULL) - return (FTNL_STATUS_ERROR); - if (rest[fd][0] == '\0') - return (st_read_line(fd, line, rest[fd])); - if ((split_at = st_find_newline(rest[fd])) != -1) - { - free(*line); - if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL) - return (FTNL_STATUS_ERROR); - ft_strncpy(*line, rest[fd], split_at); - (*line)[split_at] = '\0'; - ft_strcpy(rest[fd], rest[fd] + split_at + 1); - return (FTNL_STATUS_LINE); - } - free(*line); - if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1)))) - return (FTNL_STATUS_ERROR); - ft_strcpy(*line, rest[fd]); - rest[fd][0] = '\0'; - return (st_read_line(fd, line, rest[fd])); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_asprintf.c b/test_mini/libft/src/io/ft_printf/ft_asprintf.c deleted file mode 100644 index 5eb62d9..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_asprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_asprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:30:33 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:43:08 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_asprintf(char **ret, const char *format, ...) -{ - int vret; - va_list ap; - - va_start(ap, format); - vret = ft_vasprintf(ret, format, ap); - va_end(ap); - return (vret); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_dprintf.c b/test_mini/libft/src/io/ft_printf/ft_dprintf.c deleted file mode 100644 index 8e60970..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_dprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_dprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:29:11 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:42:05 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_dprintf(int fd, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vdprintf(fd, format, ap); - va_end(ap); - return (ret); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_printf.c b/test_mini/libft/src/io/ft_printf/ft_printf.c deleted file mode 100644 index 1b92bb2..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_printf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:31:32 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:41:54 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_printf(const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vprintf(format, ap); - va_end(ap); - return (ret); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_snprintf.c b/test_mini/libft/src/io/ft_printf/ft_snprintf.c deleted file mode 100644 index e1fdfbd..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_snprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_snprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:27:55 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:41:49 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_snprintf(char *str, size_t size, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vsnprintf(str, size, format, ap); - va_end(ap); - return (ret); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_sprintf.c b/test_mini/libft/src/io/ft_printf/ft_sprintf.c deleted file mode 100644 index 31da75e..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_sprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_sprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:17:21 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:42:28 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_sprintf(char *str, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vsprintf(str, format, ap); - va_end(ap); - return (ret); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_vasprintf.c b/test_mini/libft/src/io/ft_printf/ft_vasprintf.c deleted file mode 100644 index 85f66bc..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_vasprintf.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vasprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:49:56 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:45:39 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vasprintf(char **ret, const char *format, va_list ap) -{ - (void)ret; - (void)format; - (void)ap; - return (0); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_vasprintf.h b/test_mini/libft/src/io/ft_printf/ft_vasprintf.h deleted file mode 100644 index 2d364c8..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_vasprintf.h +++ /dev/null @@ -1,155 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* header.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/29 00:06:46 by cacharle #+# #+# */ -/* Updated: 2020/01/15 11:39:15 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_VASPRINTF_H -# define FT_VASPRINTF_H - -# include <unistd.h> -# include <stdlib.h> -# include <stdarg.h> -# include "libft.h" - -# define STATUS_ERROR -1 - -# define SPECIFIERS_STR "nfcspdiuxX%" -# define FLAGS_STR "#0- +'" - -# define IS_STANDALONE_FLAG(c) (ft_strchr(FLAGS_STR, c) != NULL) - -# define FLAG_MINUS (1 << 0) -# define FLAG_ZERO (1 << 1) -# define FLAG_SIGNED (1 << 2) -# define FLAG_SPACE (1 << 3) -# define FLAG_ALTERNATE (1 << 4) -# define FLAG_SHORT (1 << 5) -# define FLAG_SHORT_SHORT (1 << 6) -# define FLAG_LONG (1 << 7) -# define FLAG_LONG_LONG (1 << 8) -# define FLAG_WIDTH_WILDCARD (1 << 9) -# define FLAG_PRECISION_WILDCARD (1 << 10) -# define FLAG_WIDTH_OVERWRITE (1 << 11) - -# define ITOA_HEX_LOW(x) (ft_itoa_unsigned_base(x, "0123456789abcdef")) -# define ITOA_HEX_UP(x) (ft_itoa_unsigned_base(x, "0123456789ABCDEF")) -# define ITOA_DEC(x) (ft_itoa_base(x, "0123456789")) - -typedef int t_bool; -typedef short t_flags; -typedef long long int t_big_int; -typedef long long unsigned int t_big_uint; - -typedef struct -{ - int precision; - int width; - t_flags flags; - char specifier; - int fmt_len; - int size; - long long int *written; -} t_pformat; - -typedef struct s_flist -{ - struct s_flist *next; - t_pformat *content; -} t_flist; - -typedef struct s_printf_status -{ - va_list ap; - t_flist *flist; - const char *format; - char *out; - int out_size; -} t_printf_status; - -/* -** ft_printf.c -*/ - -int ft_printf(const char *format, ...); -const char *add_conversion(t_printf_status *status, - t_pformat *pformat); -const char *add_between(t_printf_status *status); -int destroy_status_error(t_printf_status *status); - -/* -** parse.c -*/ - -int parse(const char *format, t_flist **flist); -t_pformat *parse_reduced(const char *fmt); - -/* -** printer.c -*/ - -char *convert(t_pformat *pformat, va_list ap); -char *convert_specifier(va_list ap, t_pformat *pformat); -char *handle_width(t_pformat *pformat, char *str); -char *handle_precision(t_pformat *pformat, char *str); - -/* -** utils.c -*/ - -char *ft_itoa_base(long long int n, char *base); -char *ft_itoa_unsigned_base(long long unsigned int n, - char *base); -void *ft_memjoin_free(void *dst, int dst_size, void *src, - int src_size); - -/* -** extract.c -*/ - -const char *extract_flags(t_pformat *pformat, const char *fmt); -const char *extract_width(t_pformat *pformat, const char *fmt); -const char *extract_precision(t_pformat *pformat, const char *fmt); -const char *extract_length_modifier(t_pformat *pformat, - const char *fmt); - -/* -** list.c -*/ - -t_flist *list_new(t_pformat *content); -void *list_destroy(t_flist **lst); -void list_push_front(t_flist **lst, t_flist *new); -void list_pop_front(t_flist **lst); -t_flist *list_reverse(t_flist *lst); - -/* -** convert_*.c -*/ - -char *convert_char(va_list ap, t_pformat *pformat); -char *convert_str(va_list ap, t_pformat *pformat); -char *convert_ptr(va_list ap, t_pformat *pformat); -char *convert_int(va_list ap, t_pformat *pformat); -char *convert_uint(va_list ap, t_pformat *pformat); -char *convert_hex(va_list ap, t_pformat *pformat); -char *convert_percent(va_list ap, t_pformat *pformat); -char *convert_written(va_list ap, t_pformat *pformat); -char *convert_double(va_list ap, t_pformat *pformat); -char *convert_none(va_list ap, t_pformat *pformat); - -/* -** length_modifier.c -*/ - -t_big_uint length_modifier_unsigned_int( - va_list ap, t_pformat *pformat); -t_big_int length_modifier_int(va_list ap, t_pformat *pformat); - -#endif diff --git a/test_mini/libft/src/io/ft_printf/ft_vdprintf.c b/test_mini/libft/src/io/ft_printf/ft_vdprintf.c deleted file mode 100644 index a5e5ebf..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_vdprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vdprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:40:03 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:46:00 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vdprintf(int fd, const char *format, va_list ap) -{ - int out_len; - char *out; - - if ((out_len = ft_vasprintf(&out, format, ap)) == -1) - return (-1); - write(fd, out, out_len); - return (out_len); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_vprintf.c b/test_mini/libft/src/io/ft_printf/ft_vprintf.c deleted file mode 100644 index b98670b..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_vprintf.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:32:44 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:44:11 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vprintf(const char *format, va_list ap) -{ - return (ft_vdprintf(STDOUT_FILENO, format, ap)); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_vsnprintf.c b/test_mini/libft/src/io/ft_printf/ft_vsnprintf.c deleted file mode 100644 index 7db988c..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_vsnprintf.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vsnprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:36:32 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:45:14 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vsnprintf(char *str, size_t size, const char *format, va_list ap) -{ - int ret; - int full_out_len; - char *full_out; - - full_out_len = ft_vasprintf(&full_out, format, ap); - ft_strncpy(str, full_out, size); - ret = MIN((size_t)full_out_len, size); - free(full_out); - return (ret); -} diff --git a/test_mini/libft/src/io/ft_printf/ft_vsprintf.c b/test_mini/libft/src/io/ft_printf/ft_vsprintf.c deleted file mode 100644 index 91b4815..0000000 --- a/test_mini/libft/src/io/ft_printf/ft_vsprintf.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vsprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:34:17 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:44:24 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vsprintf(char *str, const char *format, va_list ap) -{ - return (ft_vsnprintf(str, INT_MAX + 1, format, ap)); -} diff --git a/test_mini/libft/src/io/ft_printf/internals/convert.c b/test_mini/libft/src/io/ft_printf/internals/convert.c deleted file mode 100644 index 398c754..0000000 --- a/test_mini/libft/src/io/ft_printf/internals/convert.c +++ /dev/null @@ -1,122 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* printer.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/28 23:19:24 by cacharle #+# #+# */ -/* Updated: 2019/11/14 10:22:04 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include <unistd.h> -#include <stdlib.h> -#include <stdarg.h> -#include "libft.h" -#include "ft_vasprintf.h" - -char *convert(t_pformat *pformat, va_list ap) -{ - char *str; - - if (pformat == NULL) - return (NULL); - if (pformat->flags & FLAG_WIDTH_WILDCARD) - { - if (pformat->flags & FLAG_WIDTH_OVERWRITE) - (void)va_arg(ap, int); - else - pformat->width = va_arg(ap, int); - if (pformat->width < 0) - { - pformat->flags |= FLAG_MINUS; - pformat->width *= -1; - } - } - if (pformat->flags & FLAG_PRECISION_WILDCARD) - pformat->precision = va_arg(ap, int); - if ((str = convert_specifier(ap, pformat)) == NULL) - return (NULL); - return (str); -} - -char *convert_specifier(va_list ap, t_pformat *pformat) -{ - if (pformat->specifier == 'c') - return (convert_char(ap, pformat)); - if (pformat->specifier == 's') - return (convert_str(ap, pformat)); - if (pformat->specifier == 'p') - return (convert_ptr(ap, pformat)); - if (pformat->specifier == 'd' || pformat->specifier == 'i') - return (convert_int(ap, pformat)); - if (pformat->specifier == 'u') - return (convert_uint(ap, pformat)); - if (pformat->specifier == 'x') - return (convert_hex(ap, pformat)); - if (pformat->specifier == 'X') - return (convert_hex(ap, pformat)); - if (pformat->specifier == '%') - return (convert_percent(ap, pformat)); - if (pformat->specifier == 'n') - return (convert_written(ap, pformat)); - else - return (convert_none(ap, pformat)); - return (NULL); -} - -char *handle_width(t_pformat *pformat, char *str) -{ - char *tmp; - int len; - int i; - - if ((len = ft_strlen(str)) >= pformat->width) - return (str); |
