This commit is contained in:
Jeremy FLEURY
2019-07-17 11:22:24 +02:00
commit 748d10f4f3
174 changed files with 8953 additions and 0 deletions

108
Makefile Normal file
View File

@@ -0,0 +1,108 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/05/30 14:54:49 by jfleury #+# #+# #
# Updated: 2019/07/17 11:19:50 by jfleury ### ########.fr #
# #
# **************************************************************************** #
NAME1 = asm
NAME2 = corewar
CC = gcc
RM = rm -f
INCLUDE = -I ./include
IN_LIB = -I libft/include
IN_PRT = -I libft/printf
CFLAGS += -Wall -Wextra -Werror $(INCLUDE) $(IN_LIB) $(IN_PRT)
NCURS = -lncurses
SRC_ASM = srcs/srcs_asm/main_asm.c \
srcs/srcs_asm/op.c \
srcs/srcs_asm/convert/convert.c \
srcs/srcs_asm/convert/conv_instru.c \
srcs/srcs_asm/convert/conv_utils.c \
srcs/srcs_asm/lexer/src_variable/var_automaton.c \
srcs/srcs_asm/lexer/ft_lexer.c \
srcs/srcs_asm/lexer/ft_automaton.c \
srcs/srcs_asm/lexer/lib_lexer/ft_append_token_label.c \
srcs/srcs_asm/lexer/lib_lexer/ft_cut_line.c \
srcs/srcs_asm/lexer/lib_lexer/ft_line_strchr.c \
srcs/srcs_asm/lexer/lib_lexer/ft_create_string.c \
srcs/srcs_asm/lexer/lib_lexer/ft_check_line.c \
srcs/srcs_asm/lexer/lib_lexer/ft_append_lst_tk.c \
srcs/srcs_asm/lexer/lib_lexer/ft_empty_line.c \
srcs/srcs_asm/lexer/lib_lexer/ft_free_list.c \
srcs/srcs_asm/lexer/lib_lexer/ft_create_token_label.c \
srcs/srcs_asm/parser/ft_parser.c \
srcs/srcs_asm/parser/parse_utils.c \
srcs/srcs_asm/parser/ft_parse_command.c \
srcs/srcs_asm/parser/ft_parse_instruc.c \
srcs/srcs_asm/parser/ft_cal_progsize.c
SRC_VM = srcs/srcs_vm/cw_parser.c \
srcs/srcs_vm/cw_read_mem.c \
srcs/srcs_vm/cw_write_mem.c \
srcs/srcs_vm/cw_process.c \
srcs/srcs_vm/cw_vm.c \
srcs/srcs_vm/cw_live.c \
srcs/srcs_vm/cw_add_sub.c \
srcs/srcs_vm/cw_aff.c \
srcs/srcs_vm/cw_and_or_xor.c \
srcs/srcs_vm/cw_fork_lfork.c \
srcs/srcs_vm/cw_ld_lld.c \
srcs/srcs_vm/cw_ldi_lldi.c \
srcs/srcs_vm/cw_st.c \
srcs/srcs_vm/cw_sti.c \
srcs/srcs_vm/cw_zjump.c \
srcs/srcs_vm/check_args.c \
srcs/srcs_vm/main.c \
srcs/srcs_vm/cw_visual.c \
srcs/srcs_vm/cw_init_ncurs.c \
srcs/srcs_vm/cw_error.c \
srcs/srcs_vm/cw_print_usage.c \
srcs/srcs_vm/cw_ops_tools.c \
srcs/srcs_vm/cw_args.c \
srcs/srcs_vm/cw_visual_win.c
LIB = libft/libft.a
PRT = libft/printf/libftprintf.a
INCP = $(foreach dir, $(INCDIR), -I$(dir))
OBJ_ASM = $(SRC_ASM:.c=.o)
OBJ_VM = $(SRC_VM:.c=.o)
all: libft $(NAME1) $(NAME2)
libft :
make -C libft -f Makefile
make -C libft/printf -f Makefile
$(NAME1): $(OBJ_ASM)
make -C libft -f Makefile
make -C libft/printf -f Makefile
$(CC) -o $(NAME1) $(CFLAGS) $(OBJ_ASM) $(LIB) $(PRT)
$(NAME2): $(OBJ_VM)
make -C libft -f Makefile
make -C libft/printf -f Makefile
$(CC) -o $(NAME2) $(CFLAGS) $(OBJ_VM) $(LIB) $(PRT) -lncurses
clean:
make -C libft -f Makefile clean
make -C libft/printf -f Makefile clean
$(RM) $(OBJ_ASM) $(OBJ_VM)
fclean: clean
make -C libft -f Makefile fclean
make -C libft/printf -f Makefile fclean
$(RM) $(NAME1) $(NAME2)
re: fclean all
.PHONY: all clean fclean re

4
auteur Normal file
View File

@@ -0,0 +1,4 @@
jfleury
mdchane
tmaze
igarbuz

138
include/asm.h Normal file
View File

@@ -0,0 +1,138 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* asm.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/29 16:43:12 by jfleury #+# #+# */
/* Updated: 2019/07/16 11:40:38 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ASM_H
# define ASM_H
# define LABEL 1
# define INSTRUCTION 2
# define DIRECT 3
# define DIRECT_LABEL 4
# define INDIRECT 5
# define INDIRECT_LABEL 6
# define REGISTER 7
# define STRING 8
# define SEPERATOR 9
# define COMMENT 10
# define COMMAND 11
# include "libft.h"
# include "ft_printf.h"
# include "op.h"
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
/*
** Struct
*/
typedef struct s_token
{
int type;
char *contents;
int line;
struct s_token *next;
} t_token;
typedef struct s_label
{
char *contents;
int place;
struct s_label *next;
} t_label;
typedef struct s_lst_tk
{
t_token *token;
struct s_lst_tk *next;
} t_lst_tk;
typedef struct s_pos_lab
{
t_label *lab;
int pos;
} t_pos_lab;
typedef struct s_inst
{
char *name;
int nb_params;
char poss[3];
} t_inst;
/*
** Global
*/
extern int g_matrice_automaton[30][17];
extern char *g_string_automaton[16];
extern int g_nb_line;
extern int g_nb_char;
extern int g_nb_token;
extern int g_place;
extern t_op g_tab[17];
/*
** ASM
*/
t_label *get_label(t_token *tk, t_label *label);
void ft_convert(t_lst_tk *lst, t_header *head, char **argv,
t_label *list_lab);
void ft_free_all(t_lst_tk *list, t_label *label, t_header *head);
unsigned char *ft_conv_instru(t_token *tk, int *size_instru,
t_pos_lab pos_lab);
unsigned char *ft_strextend_nm(unsigned char *s1, char unsigned *s2,
int n, int m);
/*
** Lexer
*/
t_token *ft_lexer_token(char **line, t_label **list_label);
int ft_lexer(t_lst_tk **lst_tk, t_label **list_label,
char **argv);
int ft_automaton(char *line, t_token *token, t_label *label,
int *nb_char_token);
int ft_line_strchr(char *str, char c);
int ft_empty_line(char *line);
int ft_append_lst_tk(t_token *list_token, t_lst_tk **list);
char **ft_cut_line(char **line, int nb_char_token);
char *ft_create_string(char *line, int nb_char_token);
char *ft_check_line(char *line, int fd);
void ft_append_token_label(t_token *token, t_token **list_token,
t_label *label, t_label **list_label);
void ft_create_token_label(char *str, int type, t_token *token,
t_label *label);
void ft_free_list(t_lst_tk *list, t_label *label);
/*
** Parser
*/
int ft_tklen(t_token *tk);
int ft_parse_instruct(t_token *tk, t_label *label,
unsigned int *size);
int parse_header(t_lst_tk **lst, t_header *head);
int ft_parser(t_lst_tk *lst, t_label *label, t_header *head);
int is_inst(char *name);
char *ft_error(char *msg);
char *ft_parse_command(t_token *tk);
char *ft_parse_command2(t_token *tk, t_header *head);
char *ft_strnew_1(size_t size);
char *ft_strcpy_1(char *dest, const char *src);
unsigned char *ft_strcpy_n(unsigned char *dest, const unsigned char *src,
int n, int m);
unsigned char *ft_conv_hexa(int nbr, int size);
#endif

233
include/corewar.h Normal file
View File

@@ -0,0 +1,233 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* corewar.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/08 11:54:03 by tmaze #+# #+# */
/* Updated: 2019/07/15 19:02:57 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COREWAR_H
# define COREWAR_H
# include <unistd.h>
# include <stdlib.h>
# include <stdio.h>
# include <fcntl.h>
# include <errno.h>
# include "libft.h"
# include "ft_printf.h"
# include <ncurses.h>
# define IND_SIZE 2
# define REG_SIZE 4
# define DIR_SIZE REG_SIZE
# define REG_CODE 1
# define DIR_CODE 2
# define IND_CODE 3
# define MAX_ARGS_NUMBER 4
# define MAX_PLAYERS 4
# define MEM_SIZE (4*1024)
# define IDX_MOD (MEM_SIZE / 8)
# define CHAMP_MAX_SIZE (MEM_SIZE / 6)
/*
** Added MEM_SIZE overflow protection binary mask. MEM_SIZE must be 2^x number.
** MEM_SIZE_M must be MEM_SIZE - 1;
*/
# define MEM_SIZE_M MEM_SIZE - 1
# define COMMENT_CHAR '#'
# define LABEL_CHAR ':'
# define DIRECT_CHAR '%'
# define SEPARATOR_CHAR ','
# define LABEL_CHARS "abcdefghijklmnopqrstuvwxyz_0123456789"
# define NAME_CMD_STRING ".name"
# define COMMENT_CMD_STRING ".comment"
# define REG_NUMBER 16
# define CYCLE_TO_DIE 1536
# define CYCLE_DELTA 50
# define NBR_LIVE 21
# define MAX_CHECKS 10
# define T_REG 1
# define T_DIR 2
# define T_IND 4
# define PROG_NAME_LENGTH (128)
# define COMMENT_LENGTH (2048)
# define COREWAR_EXEC_MAGIC 0xea83f3
# define AG_VERB 0x0001
# define AG_DUMP32 0x0002
# define AG_DUMP64 0x0004
# define AG_VISUAL 0x0008
# define AG_AFF 0x0010
# define VB_LIVE 0x0001
# define VB_CYCLES 0x0002
# define VB_OPS 0x0004
# define VB_DEATH 0x0008
# define VB_PC 0x0010
# define ART_MAX_SIZE 1023
char g_buf[BUF_SIZE];
typedef struct s_player
{
unsigned int magic;
char prog_name[PROG_NAME_LENGTH + 1];
unsigned int prog_size;
char comment[COMMENT_LENGTH + 1];
int num;
char col;
unsigned int live_ct;
unsigned int lst_live;
unsigned char code[CHAMP_MAX_SIZE];
} t_player;
typedef struct s_process
{
size_t pid;
unsigned char op;
unsigned char carry;
char new;
unsigned int wait;
int regs[REG_NUMBER + 1];
int lst_live;
unsigned short int pc;
struct s_process *next;
} t_process;
typedef struct s_visual
{
WINDOW *arena;
WINDOW *stat;
bool paused;
int delay;
} t_visual;
typedef struct s_vm
{
unsigned char mem[MEM_SIZE];
unsigned char col[MEM_SIZE];
t_player pls[MAX_PLAYERS];
int args;
int dump;
int verb;
int live;
int live_ct;
int cycles;
int ctd_c;
int ctd;
short int nb_j;
size_t p_ct;
size_t pid_ct;
t_process *tl;
t_visual vis;
} t_vm;
typedef struct s_ops
{
unsigned int wait;
void (*func)(t_process*, t_vm*);
} t_ops;
typedef struct s_args
{
char t;
short int i;
} t_args;
typedef struct s_pargs
{
char *arg;
void (*func)(char**, t_vm*, int);
char nb_ag;
} t_pargs;
void cw_print_usage(void);
void clear_process(t_vm *vm);
void init_process(t_vm *vm);
void del_prcs(t_vm *vm);
void init_vm(t_vm *vm, int i);
int load_champ(t_vm *vm);
void mem_dump(t_vm *vm);
void arg_dump(char **av, t_vm *vm, int i);
void arg_verb(char **av, t_vm *vm, int i);
void arg_visual(char **av, t_vm *vm, int i);
void arg_aff(char **av, t_vm *vm, int i);
void fgqarg_aff(char **av, t_vm *vm, int i);
int cw_parser(int ac, char **av, t_vm *vm);
int check_file(char *path);
int read_four(t_vm *vm, size_t index);
short int read_two(t_vm *vm, size_t index);
unsigned char read_mem(t_vm *vm, int ind);
void write_mem(t_vm *vm, unsigned int index, char val
, unsigned short int pc);
void write_four(t_vm *vm, unsigned int index, int val
, unsigned short int pc);
unsigned int l2b_endian(unsigned int num);
void cw_move_pc(t_vm *vm, t_process *p, int jp);
void init_args(t_args *ag, t_process *p, t_vm *vm);
int check_reg(t_vm *vm, int ind);
int cw_ocp(char nb_ag, t_args *ag, char size_dir);
void cw_live(t_process *p, t_vm *vm);
void cw_ld(t_process *p, t_vm *vm);
void cw_st(t_process *p, t_vm *vm);
void cw_add(t_process *p, t_vm *vm);
void cw_sub(t_process *p, t_vm *vm);
void cw_and(t_process *p, t_vm *vm);
void cw_or(t_process *p, t_vm *vm);
void cw_xor(t_process *p, t_vm *vm);
void cw_zjump(t_process *p, t_vm *vm);
void cw_ldi(t_process *p, t_vm *vm);
void cw_sti(t_process *p, t_vm *vm);
void cw_fork(t_process *p, t_vm *vm);
void cw_lld(t_process *p, t_vm *vm);
void cw_lldi(t_process *p, t_vm *vm);
void cw_lfork(t_process *p, t_vm *vm);
void cw_aff(t_process *p, t_vm *vm);
int err_msg(int err, t_vm *vm);
void error(t_vm *vm, int err);
/*
** cw_visual.c
*/
void print_arena(t_vm *vm);
void print_pc(t_vm *vm, unsigned short int pc, char col);
void control_delay(t_vm *vm);
/*
** cw_init_ncurs.c
*/
void init_ncurses(t_vm *vm);
void destroy_ncurses(t_vm *vm);
void destroy_ncurses_exit(t_vm *vm);
void check_user_exit(t_vm *vm, int key);
/*
** cw_visual_win.c
*/
void visual_winners(t_vm *vm, int i);
void visual_delay_update(t_vm *vm);
#endif

69
include/op.h Normal file
View File

@@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* op.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/10/04 11:33:27 by zaz #+# #+# */
/* Updated: 2019/07/15 18:14:53 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef OP_H
# define OP_H
# define IND_SIZE 2
# define REG_SIZE 4
# define DIR_SIZE REG_SIZE
# define REG_CODE 1
# define DIR_CODE 2
# define IND_CODE 3
# define MAX_ARGS_NUMBER 4
# define MAX_PLAYERS 4
# define MEM_SIZE (4*1024)
# define IDX_MOD (MEM_SIZE / 8)
# define CHAMP_MAX_SIZE (MEM_SIZE / 6)
# define COMMENT_CHAR '#'
# define LABEL_CHAR ':'
# define DIRECT_CHAR '%'
# define SEPARATOR_CHAR ','
# define LABEL_CHARS "abcdefghijklmnopqrstuvwxyz_0123456789"
# define NAME_CMD_STRING ".name"
# define COMMENT_CMD_STRING ".comment"
# define REG_NUMBER 16
# define CYCLE_TO_DIE 1536
# define CYCLE_DELTA 50
# define NBR_LIVE 21
# define MAX_CHECKS 10
# define T_REG 1
# define T_DIR 2
# define T_IND 4
# define T_LAB 8
# define PROG_NAME_LENGTH (128)
# define COMMENT_LENGTH (2048)
# define COREWAR_EXEC_MAGIC 0xea83f3
typedef char t_arg_type;
typedef struct s_header
{
unsigned int magic;
char prog_name[PROG_NAME_LENGTH + 1];
unsigned int prog_size;
char comment[COMMENT_LENGTH + 1];
} t_header;
typedef struct s_op
{
char *name;
int nb_param;
char poss[3];
char op_code;
int cycle;
char *comp_name;
int byte;
int size;
} t_op;
#endif

124
libft/Makefile Normal file
View File

@@ -0,0 +1,124 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/11/14 20:22:58 by jfleury #+# #+# #
# Updated: 2019/07/17 11:13:16 by jfleury ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
AR = ar rc
CC = gcc
RL = ranlib
RM = rm -f
INCLUDE = -I ./include
CFLAGS = -Wall -Werror -Wextra -c $(INCLUDE)
SRC_LIBFT = libft/ft_memset.c \
libft/ft_bzero.c \
libft/ft_memcpy.c \
libft/ft_memccpy.c \
libft/ft_memmove.c \
libft/ft_memchr.c \
libft/ft_memcmp.c \
libft/ft_strlen.c \
libft/ft_strcmp.c \
libft/ft_strdup.c \
libft/ft_strcpy.c \
libft/ft_strncpy.c \
libft/ft_strcat.c \
libft/ft_strncat.c \
libft/ft_strlcat.c \
libft/ft_strchr.c \
libft/ft_strrchr.c \
libft/ft_atoi.c \
libft/ft_atoi_bin.c \
libft/ft_atoi_long.c \
libft/ft_isalpha.c \
libft/ft_isdigit.c \
libft/ft_isalnum.c \
libft/ft_strstr.c \
libft/ft_strnstr.c \
libft/ft_strncmp.c \
libft/ft_strnequ.c \
libft/ft_isascii.c \
libft/ft_isprint.c \
libft/ft_toupper.c \
libft/ft_tolower.c \
libft/ft_memalloc.c \
libft/ft_memdel.c \
libft/ft_strnew.c \
libft/ft_strdel.c \
libft/ft_strclr.c \
libft/ft_striter.c \
libft/ft_striteri.c \
libft/ft_strmap.c \
libft/ft_strmapi.c \
libft/ft_strequ.c \
libft/ft_strsub.c \
libft/ft_strtrim.c \
libft/ft_strsplit.c \
libft/ft_itoa.c \
libft/ft_strjoin.c \
libft/ft_putchar.c \
libft/ft_putstr.c \
libft/ft_putendl.c \
libft/ft_putnbr.c \
libft/ft_putchar_fd.c \
libft/ft_putstr_fd.c \
libft/ft_putendl_fd.c \
libft/ft_putnbr_fd.c \
libft/ft_lstnew.c \
libft/ft_lstdelone.c \
libft/ft_lstdel.c \
libft/ft_lstadd.c \
libft/ft_lstadd_end.c \
libft/ft_lstiter.c \
libft/ft_lstmap.c \
libft/ft_strextend.c \
libft/ft_strnextend.c \
libft/ft_sstrnew.c \
libft/ft_sstrcpy.c \
libft/ft_sstrdel.c \
libft/get_next_line.c \
libft/ft_memtab.c \
libft/ft_memint_tab.c \
libft/ft_sstrprint.c \
libft/ft_bubble_sort.c \
libft/ft_char_replace.c \
libft/ft_itoa_base.c \
libft/ft_itoa_double.c \
libft/ft_strnchr.c \
libft/ft_strrnchr.c \
libft/ft_strupcase.c \
libft/ft_strndup.c \
libft/ft_power.c \
libft/ft_itoa_base_int.c \
libft/ft_itoa_base_short.c \
libft/ft_strrev.c \
libft/ft_isnumb.c \
libft/ft_atois.c \
libft/ft_mod.c \
libft/ft_iswhitespace.c
OBJ_LIBFT = $(SRC_LIBFT:.c=.o)
all: $(NAME)
$(NAME): $(OBJ_LIBFT)
$(AR) $(NAME) $(OBJ_LIBFT)
$(RL) $(NAME)
clean:
$(RM) $(OBJ_LIBFT)
fclean: clean
$(RM) $(NAME)
re: fclean all
.SILENT: $(OBJ_LIBFT) $(NAME) all clean fclean re

199
libft/include/libft.h Normal file
View File

@@ -0,0 +1,199 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 15:35:42 by jfleury #+# #+# */
/* Updated: 2019/07/15 19:15:18 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <string.h>
# include <unistd.h>
# include <stdlib.h>
# include <stdarg.h>
# define BUFF_SIZE 32
# define CONV_ID_NB 13
# define FLAGS_NB 5
# define PRECI_GROUPS 3
# define RED "\x1B[31m"
# define GRN "\x1B[32m"
# define YEL "\x1B[33m"
# define BLU "\x1B[34m"
# define MAG "\x1B[35m"
# define CYN "\x1B[36m"
# define WHT "\x1B[37m"
# define RESET "\x1B[0m"
# define STRONG "\033[1m"
typedef struct s_list
{
void *content;
size_t content_size;
struct s_list *next;
} t_list;
typedef struct s_conv_spec
{
char conv_id;
int *flags;
int *modifier;
int field_width;
int precision;
char *converted;
} t_conv_spec;
typedef struct s_fptr_id
{
char *conv_id_tab;
char *(*fptr[CONV_ID_NB])(t_conv_spec c_s, va_list *list);
} t_fptr_id;
typedef struct s_fptr_flag
{
int *flags;
char *(*fptr[FLAGS_NB])(t_conv_spec c_s, char *str);
} t_fptr_flag;
typedef struct s_fptr_preci
{
char **preci_group;
char *(*fptr[PRECI_GROUPS])(t_conv_spec c_s, char *str);
} t_fptr_preci;
int ft_atoi(const char *str);
int ft_atoi_bin(char *str);
long long ft_atoi_long(const char *str);
void ft_bzero(void *s, size_t n);
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_isprint(int c);
char *ft_itoa(int n);
void *ft_memalloc(size_t size);
void *ft_memccpy(void *dest, const void *src, int c, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void ft_memdel(void **ap);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memset(void *s, int c, size_t n);
void ft_putchar(char c);
void ft_putchar_fd(char c, int fd);
void ft_putendl(char const *s);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr(int n);
void ft_putnbr_fd(int n, int fd);
void ft_putstr(char const *s);
void ft_putstr_fd(char const *s, int fd);
char *ft_strcat(char *dest, const char *src);
char *ft_strchr(const char *s, int c);
void ft_strclr(char *s);
int ft_strcmp(const char *s1, const char *s2);
char *ft_strcpy(char *dest, const char *src);
void ft_strdel(char **as);
char *ft_strdup(const char *src);
int ft_strequ(char const *s1, char const *s2);
void ft_striter(char *s, void (*f)(char*));
void ft_striteri(char *s, void (*f)(unsigned int, char*));
char *ft_strjoin(char const *s1, char const *s2);
size_t ft_strlcat(char *dest, const char *src, size_t n);
size_t ft_strlen(const char *str);
char *ft_strmap(char const *s, char (*f)(char));
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
char *ft_strncat(char *dest, const char *src, size_t n);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strncpy(char *dest, const char *src, size_t n);
int ft_strnequ(char const *s1, char const *s2, size_t n);
char *ft_strnew(size_t size);
char *ft_strnstr(const char *s1, const char *s2, size_t n);
char *ft_strrchr(const char *s, int c);
char **ft_strsplit(char const *s, char c);
char *ft_strstr(const char *str, const char *to_find);
char *ft_strsub(char const *s, unsigned int start, size_t len);
char *ft_strtrim(char const *s);
int ft_tolower(int c);
char *ft_itoa_base_int(unsigned int nb, int base);
char *ft_itoa_base_short(unsigned short nb, int base);
int ft_toupper(int c);
char *ft_strextend(char *s1, char const *s2);
char *ft_strnextend(char *s1, char const *s2, size_t len);
char **ft_sstrnew(size_t row, size_t col);
char **ft_sstrcpy(char **dest, char const **src);
char **ft_memtab(size_t y, size_t x);
int **ft_memint_tab(size_t y, size_t x);
void ft_sstrprint(char **str);
int *ft_bubble_sort(int *tab, int size);
t_list *ft_lstnew(void const *content, size_t content_size);
void ft_lstdelone(t_list **alst, void (*del)(void*, size_t));
void ft_lstdel(t_list **alst, void (*del)(void*, size_t));
void ft_lstadd(t_list **alst, t_list *new);
int ft_lstadd_end(t_list **alst, t_list *elem);
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
void ft_lstprint_str(t_list *lst);
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
int ft_sstrdel(char **str, int size);
int get_next_line(const int fd, char **line, char **tmp);
unsigned long long ft_power(unsigned long long nb, unsigned long long power);
char *ft_char_replace(char *str, char c, char r);
char *ft_strupcase(char *str);
char *ft_strnchr(const char *s, int c, int n);
char *ft_strrnchr(const char *s, int c, int n);
char *ft_strndup(const char *src, size_t n);
char *ft_itoa_base(unsigned long long n, int base);
char *ft_itoa_double(t_conv_spec conv_spec, long double nb);
char *ft_strrev(char *str);
char *ft_data_conv_id(void);
int ft_store_conv_id(t_conv_spec *c_s, char *format, int i);
void ft_store_modifier(t_conv_spec *c_s, char *f, int i, int l);
void ft_store_flag(t_conv_spec *c_s, char *format, int i, int l);
void ft_store_wc_field_width(t_conv_spec *c_s, va_list *ap);
void ft_store_wc_precision(t_conv_spec *c_s, va_list *ap);
void ft_store_field_width
(t_conv_spec *c_s, char *format, int i, int len);
void ft_store_precision(t_conv_spec *c_s, char *f, int i, int l);
void ft_struct_init(t_conv_spec *c_s);
void ft_struct_del(t_conv_spec *c_s);
char *ft_data_conv_ids(void);
char *ft_process_c(t_conv_spec c_s, va_list *ap);
char *ft_process_s(t_conv_spec c_s, va_list *ap);
char *ft_process_p(t_conv_spec c_s, va_list *ap);
char *ft_process_di(t_conv_spec c_s, va_list *ap);
char *ft_process_o(t_conv_spec c_s, va_list *ap);
char *ft_process_u(t_conv_spec c_s, va_list *ap);
char *ft_process_x(t_conv_spec c_s, va_list *ap);
char *ft_process_xx(t_conv_spec c_s, va_list *ap);
char *ft_process_f(t_conv_spec c_s, va_list *ap);
char *ft_process_b(t_conv_spec c_s, va_list *ap);
char *ft_process_dd(t_conv_spec c_s, va_list *ap);
char *ft_process_percent(t_conv_spec c_s, va_list *ap);
char *ft_process_id(t_conv_spec c_s, va_list *ap);
char *ft_process_flags(t_conv_spec c_s, char *str);
char *ft_process_hash(t_conv_spec c_s, char *str);
char *ft_hash_xx_preci(char *str, int i);
char *ft_hash_xx_zero(char *str, int i);
char *ft_hash_x_preci(char *str, int i);
char *ft_hash_x_zero(char *str, int i);
char *ft_process_plus(t_conv_spec c_s, char *str);
char *ft_process_zero(t_conv_spec c_s, char *str);
char *ft_process_minus(t_conv_spec c_s, char *str);
char *ft_process_space(t_conv_spec c_s, char *str);
char *ft_process_min_width(t_conv_spec c_s, char *str);
char *ft_precision_diouxx(t_conv_spec c_s, char *str);
char *ft_precision_s(t_conv_spec c_s, char *str);
char *ft_precision_p(t_conv_spec c_s, char *str);
char *ft_process_preci(t_conv_spec c_s, char *str);
int ft_atois(const char *str, int *nb);
int ft_isnumb(char *str);
int ft_mod(unsigned int val, unsigned int div);
int ft_iswhitespace(char c);
#endif

39
libft/libft/ft_atoi.c Normal file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:46:25 by jfleury #+# #+# */
/* Updated: 2019/03/07 13:38:37 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int number;
int c;
int signe;
number = 0;
c = 0;
signe = 0;
while (str[c] != '\0' && (str[c] == '\t' || str[c] == '\n'
|| str[c] == '\v' || str[c] == '\f' || str[c] == '\r' || str[c] == ' '))
c++;
if (str[c] == '-' || str[c] == '+')
{
if (str[c] == '-')
signe = 1;
c++;
}
while (str[c] != '\0' && (str[c] >= '0' && str[c] <= '9'))
{
number = ((number * 10) + (str[c] - 48));
c++;
}
if (signe == 1)
number = -number;
return (number);
}

32
libft/libft/ft_atoi_bin.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_bin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/01 15:48:50 by jfleury #+# #+# */
/* Updated: 2019/07/04 12:07:25 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi_bin(char *str)
{
int j;
int bin;
int result;
j = ft_strlen(str) - 1;
result = 0;
bin = 1;
while (j >= 0)
{
if (str[j] == '1')
result = result + bin;
bin = bin * 2;
j--;
}
return (result);
}

View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_long.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/04 17:51:43 by jfleury #+# #+# */
/* Updated: 2019/03/05 19:48:52 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
long long ft_atoi_long(const char *str)
{
long long number;
long long c;
long long signe;
number = 0;
c = 0;
signe = 0;
while (str[c] != '\0' && (str[c] == '\t' || str[c] == '\n'
|| str[c] == '\v' || str[c] == '\f' || str[c] == '\r' || str[c] == ' '))
c++;
if (str[c] == '-' || str[c] == '+')
{
if (str[c] == '-')
signe = 1;
c++;
}
while (str[c] != '\0' && (str[c] >= '0' && str[c] <= '9'))
{
number = ((number * 10) + (str[c] - 48));
c++;
}
if (signe == 1)
number = -number;
return (number);
}

32
libft/libft/ft_atois.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atois.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/27 11:58:44 by tmaze #+# #+# */
/* Updated: 2019/06/19 15:23:42 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atois(const char *str, int *nb)
{
int num;
num = 0;
while (ft_iswhitespace(str[num]))
num++;
if (str[num] == '+' || str[num] == '-')
num++;
if (ft_strlen(&(str[num])) < 10 || (num > 0 && str[num - 1] == '-'
&& ft_strcmp("2147483648", &(str[num])) >= 0)
|| ft_strcmp("2147483647", &(str[num])) >= 0)
{
*nb = ft_atoi(str);
return (0);
}
return (1);
}

View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bubble_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/28 13:37:01 by jfleury #+# #+# */
/* Updated: 2019/02/28 13:41:41 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int *ft_bubble_sort(int *tab, int size)
{
int temp;
int c;
int check;
c = 0;
check = 0;
while (check == 0)
{
check = 1;
while (c < size - 1)
{
if (tab[c] > tab[c + 1])
{
temp = tab[c];
tab[c] = tab[c + 1];
tab[c + 1] = temp;
check = 0;
}
c++;
}
c = 0;
}
return (tab);
}

19
libft/libft/ft_bzero.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 17:45:47 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:51 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
ft_memset(s, 0, n);
}

View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_char_replace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/16 18:50:02 by jfleury #+# #+# */
/* Updated: 2019/01/16 18:54:31 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_char_replace(char *str, char c, char r)
{
int i;
i = 0;
while (str[i] != 0)
{
if (str[i] == c)
str[i] = r;
i++;
}
return (str);
}

23
libft/libft/ft_isalnum.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 15:55:08 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:50 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalnum(int c)
{
if (c >= '0' && c <= '9')
return (1);
else if (c >= 'A' && c <= 'Z')
return (1);
else if (c >= 'a' && c <= 'z')
return (1);
else
return (0);
}

19
libft/libft/ft_isalpha.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 16:07:58 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:50 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
else
return (0);
}

19
libft/libft/ft_isascii.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 16:19:58 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:49 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
else
return (0);
}

19
libft/libft/ft_isdigit.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 16:22:16 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:48 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
else
return (0);
}

28
libft/libft/ft_isnumb.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnumb.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/17 15:00:23 by tmaze #+# #+# */
/* Updated: 2019/07/12 12:09:41 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isnumb(char *str)
{
int i;
i = 0;
while (str[i])
{
if ((i == 0 && str[i] != '-' && str[i] != '+' && !ft_isdigit(str[i]))
|| (i != 0 && !ft_isdigit(str[i])))
return (0);
i++;
}
return (1);
}

19
libft/libft/ft_isprint.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 16:25:39 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:47 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
else
return (0);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iswhitespace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 16:11:19 by tmaze #+# #+# */
/* Updated: 2019/02/25 16:13:25 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_iswhitespace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|| c == '\r');
}

62
libft/libft/ft_itoa.c Normal file
View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 11:06:12 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:48:02 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
static int ft_isneg(int n)
{
if (n >= 0)
return (0);
else
return (1);
}
static int ft_nbrlen(int n)
{
int i;
i = 0;
while (n / 10 != 0)
{
i++;
n = n / 10;
}
i++;
return (i);
}
char *ft_itoa(int n)
{
char *str;
int len;
int nb;
if (n == -2147483648)
return (ft_strdup("-2147483648"));
nb = n;
len = ft_nbrlen(n) + ft_isneg(n);
if (!(str = (char*)malloc(sizeof(char) * len + 1)))
return (NULL);
str[len] = '\0';
if (n < 0)
n = -n;
while (len > ft_isneg(nb))
{
len--;
str[len] = (n % 10) + 48;
n = n / 10;
}
if (ft_isneg(nb) == 1)
str[0] = '-';
return (str);
}

View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/23 15:05:04 by allefebv #+# #+# */
/* Updated: 2019/07/08 17:26:58 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <string.h>
static int ft_malloc_len(unsigned long long nb, int base)
{
int i;
i = 0;
while (nb != 0)
{
nb = nb / base;
i++;
}
return (i);
}
char *ft_itoa_base(unsigned long long nb, int base)
{
unsigned long long result;
int i;
char *str;
char *tab;
tab = ft_strdup("0123456789abcdef");
if (base < 2 || base > 16)
return (NULL);
i = ft_malloc_len(nb, base);
if (nb == 0)
i++;
if (!(str = (char*)malloc(sizeof(char*) * i + 1)))
return (NULL);
str[i] = '\0';
if (nb == 0)
str[0] = '0';
while (nb != 0)
{
i--;
result = nb % base;
str[i] = tab[result];
nb = nb / base;
}
free(tab);
return (str);
}

View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_base_int.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/23 15:05:04 by allefebv #+# #+# */
/* Updated: 2019/07/09 15:26:17 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <string.h>
static int ft_malloc_len(unsigned int nb, int base)
{
int i;
i = 0;
while (nb != 0)
{
nb = nb / base;
i++;
}
return (i);
}
char *ft_itoa_base_int(unsigned int nb, int base)
{
unsigned int result;
int i;
char *str;
char *tab;
tab = ft_strdup("0123456789abcdef");
if (base < 2 || base > 16)
return (NULL);
i = ft_malloc_len(nb, base);
if (nb == 0)
i++;
if (!(str = (char*)malloc(sizeof(char*) * i + 1)))
return (NULL);
str[i] = '\0';
if (nb == 0)
str[0] = '0';
while (nb != 0)
{
i--;
result = nb % base;
str[i] = tab[result];
nb = nb / base;
}
free(tab);
return (str);
}

View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_base_short.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/23 15:05:04 by allefebv #+# #+# */
/* Updated: 2019/07/13 17:27:38 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <string.h>
static int ft_malloc_len(unsigned short nb, int base)
{
short i;
i = 0;
while (nb != 0)
{
nb = nb / base;
i++;
}
return (i);
}
char *ft_itoa_base_short(unsigned short nb, int base)
{
unsigned short result;
short i;
char *str;
char *tab;
tab = ft_strdup("0123456789abcdef");
if (base < 2 || base > 16)
return (NULL);
i = ft_malloc_len(nb, base);
if (nb == 0)
i++;
if (!(str = (char*)malloc(sizeof(char*) * i + 1)))
return (NULL);
str[i] = '\0';
if (nb == 0)
str[0] = '0';
while (nb != 0)
{
i--;
result = nb % base;
str[i] = tab[result];
nb = nb / base;
}
free(tab);
return (str);
}

View File

@@ -0,0 +1,88 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_double.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/21 16:36:44 by jfleury #+# #+# */
/* Updated: 2019/04/02 12:07:30 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_zero(t_conv_spec conv_spec, char *str)
{
int i;
i = 2;
str = ft_strnew(conv_spec.precision + 2);
str[0] = '0';
str[1] = '.';
while (conv_spec.precision > 0)
{
str[i] = '0';
conv_spec.precision--;
i++;
}
return (str);
}
static char *ft_place_point(t_conv_spec conv_spec, char *str)
{
char *final_str;
int i;
if ((i = ft_strlen(str) - conv_spec.precision) <= 0)
{
free(str);
return (ft_strdup("(error)"));
}
final_str = ft_strnew(ft_strlen(str) + 1);
ft_strncpy(final_str, str, i);
final_str[i] = '.';
ft_strcat(final_str, str + i);
free(str);
return (final_str);
}
static char *ft_process(t_conv_spec conv_spec, char *str, int flag,
long double nb)
{
long long result;
unsigned long long power;
if (conv_spec.precision > 16)
conv_spec.precision = 16;
power = ft_power(10, conv_spec.precision);
result = nb * power;
if (((nb * power * 10) - (result * 10)) > 5)
result++;
if (flag == 1)
result = -result;
str = ft_itoa(result);
str = ft_place_point(conv_spec, str);
return (str);
}
char *ft_itoa_double(t_conv_spec conv_spec, long double nb)
{
char *str;
int flag;
flag = 0;
str = NULL;
if (conv_spec.precision == -1)
conv_spec.precision = 6;
if (nb < 0)
{
flag = 1;
nb = -nb;
}
if (nb == 0)
str = ft_zero(conv_spec, str);
else
str = ft_process(conv_spec, str, flag, nb);
return (str);
}

21
libft/libft/ft_lstadd.c Normal file
View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 16:31:08 by jfleury #+# #+# */
/* Updated: 2019/05/15 19:49:23 by allefebv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd(t_list **alst, t_list *new)
{
if (new == NULL)
return ;
new->next = *alst;
*alst = new;
}

View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_end.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: allefebv <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/15 17:26:04 by allefebv #+# #+# */
/* Updated: 2019/05/15 19:49:43 by allefebv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstadd_end(t_list **alst, t_list *elem)
{
t_list *end;
if (elem == NULL)
return (0);
if (*alst == NULL)
ft_lstadd(alst, elem);
else
{
end = *alst;
while (end->next != NULL)
end = end->next;
end->next = elem;
elem->next = NULL;
}
return (1);
}

30
libft/libft/ft_lstdel.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 15:54:50 by jfleury #+# #+# */
/* Updated: 2018/11/15 18:31:58 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void ft_lstdel(t_list **alst, void (*del)(void*, size_t))
{
t_list *temp_alst;
t_list *temp_next;
temp_alst = *alst;
while (temp_alst)
{
temp_next = temp_alst->next;
del(temp_alst->content, temp_alst->content_size);
free(temp_alst);
temp_alst = temp_next;
}
*alst = NULL;
}

View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 14:59:45 by jfleury #+# #+# */
/* Updated: 2018/11/14 16:02:18 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
#include <stdlib.h>
void ft_lstdelone(t_list **alst, void (*del)(void*, size_t))
{
del((*alst)->content, (*alst)->content_size);
free(*alst);
*alst = NULL;
}

27
libft/libft/ft_lstiter.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 17:11:41 by jfleury #+# #+# */
/* Updated: 2018/11/16 14:37:53 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
{
t_list *temp_lst;
t_list *temp_next;
temp_lst = lst;
while (temp_lst)
{
temp_next = temp_lst->next;
f(temp_lst);
temp_lst = temp_next;
}
}

38
libft/libft/ft_lstmap.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 18:20:50 by jfleury #+# #+# */
/* Updated: 2018/11/15 18:30:30 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *final_lst;
t_list *temp_lst;
t_list *new;
if (lst == NULL || f == NULL)
return (NULL);
temp_lst = f(lst);
if (!(new = ft_lstnew(temp_lst->content, temp_lst->content_size)))
return (NULL);
final_lst = new;
lst = lst->next;
while (lst)
{
temp_lst = f(lst);
if (!(new->next = ft_lstnew(temp_lst->content, temp_lst->content_size)))
return (NULL);
new = new->next;
lst = lst->next;
}
return (final_lst);
}

36
libft/libft/ft_lstnew.c Normal file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:54:39 by jfleury #+# #+# */
/* Updated: 2019/04/23 14:13:31 by allefebv ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *newlst;
if (!(newlst = (t_list*)malloc(sizeof(t_list))))
return (NULL);
if (content == NULL)
{
newlst->content = NULL;
newlst->content_size = 0;
}
else
{
if (!(newlst->content = (void*)malloc(sizeof(content) * content_size)))
return (NULL);
ft_memcpy((newlst->content), content, content_size);
newlst->content_size = content_size;
}
newlst->next = NULL;
return (newlst);
}

View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstprint_char.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: allefebv <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/02 12:18:10 by allefebv #+# #+# */
/* Updated: 2019/04/23 13:53:16 by allefebv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstprint_str(t_list *lst)
{
while (lst != NULL)
{
ft_printf("%s\n", (char*)(lst->content));
lst = lst->next;
}
}

24
libft/libft/ft_memalloc.c Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memalloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 09:59:49 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:41:04 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void *ft_memalloc(size_t size)
{
void *temp;
if (!(temp = (void*)malloc(size)))
return (NULL);
ft_memset(temp, 0, size);
return (temp);
}

33
libft/libft/ft_memccpy.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 11:09:19 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:00:31 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
char *temp_dest;
char *temp_src;
int i;
temp_dest = (char*)dest;
temp_src = (char*)src;
i = 0;
while (n > 0)
{
temp_dest[i] = temp_src[i];
if (temp_src[i] == (char)c)
return (dest + i + 1);
i++;
n--;
}
return (NULL);
}

32
libft/libft/ft_memchr.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 11:09:29 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:00:43 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *temp_s;
unsigned char temp_c;
int i;
temp_s = (unsigned char*)s;
temp_c = (unsigned char)c;
i = 0;
while (n > 0)
{
if (temp_s[i] == temp_c)
return (temp_s + i);
i++;
n--;
}
return (NULL);
}

35
libft/libft/ft_memcmp.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 11:09:06 by jfleury #+# #+# */
/* Updated: 2019/03/02 12:55:38 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *temp_s1;
unsigned char *temp_s2;
int i;
temp_s1 = (unsigned char*)s1;
temp_s2 = (unsigned char*)s2;
i = 0;
while (n > 0)
{
if (temp_s1[i] != temp_s2[i])
return (temp_s1[i] - temp_s2[i]);
else
{
i++;
n--;
}
}
return (0);
}

31
libft/libft/ft_memcpy.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 11:11:11 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:47 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memcpy(void *dest, const void *src, size_t n)
{
char *temp_dest;
char *temp_src;
int i;
temp_dest = (char*)dest;
temp_src = (char*)src;
i = 0;
while (n > 0)
{
temp_dest[i] = temp_src[i];
i++;
n--;
}
return (dest);
}

22
libft/libft/ft_memdel.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 09:59:57 by jfleury #+# #+# */
/* Updated: 2018/11/13 20:49:47 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
void ft_memdel(void **ap)
{
if (ap != NULL && *ap != NULL)
{
free(*ap);
*ap = NULL;
}
}

View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memint_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:54:49 by jfleury #+# #+# */
/* Updated: 2019/03/12 13:54:54 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
int **ft_memint_tab(size_t y, size_t x)
{
int **tab;
size_t i;
i = 0;
if (!(tab = (int**)ft_memalloc(sizeof(int*) * (y))))
return (NULL);
while (i < y)
{
if (!(tab[i] = (int*)ft_memalloc(sizeof(int) * x)))
{
i++;
while (i > 0)
{
free(tab[i - 2]);
i--;
}
free(tab);
return (NULL);
}
i++;
}
return (tab);
}

34
libft/libft/ft_memmove.c Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 09:55:12 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:45:16 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned char *temp_dest;
unsigned char *temp_src;
size_t i;
temp_dest = (unsigned char*)dest;
temp_src = (unsigned char*)src;
i = n;
if (temp_dest > temp_src)
while (n)
{
temp_dest[n - 1] = temp_src[n - 1];
n--;
}
else
ft_memcpy(temp_dest, temp_src, i);
return (dest);
}

29
libft/libft/ft_memset.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/06 15:17:24 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:45 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memset(void *s, int c, size_t n)
{
unsigned char *temp;
int i;
i = 0;
temp = (unsigned char*)s;
while (n > 0)
{
temp[i] = c;
i++;
n--;
}
return (s);
}

41
libft/libft/ft_memtab.c Normal file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memtab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:55:02 by jfleury #+# #+# */
/* Updated: 2019/03/12 13:55:07 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char **ft_memtab(size_t y, size_t x)
{
char **tab;
size_t i;
i = 0;
if (!(tab = (char**)ft_memalloc(sizeof(char*) * (y + 1))))
return (NULL);
while (i < y)
{
if (!(tab[i] = ft_strnew(x)))
{
i++;
while (i > 0)
{
free(tab[i - 1]);
i--;
}
free(tab);
return (NULL);
}
i++;
}
tab[y] = 0;
return (tab);
}

21
libft/libft/ft_mod.c Normal file
View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/21 00:51:09 by tmaze #+# #+# */
/* Updated: 2019/06/24 15:27:43 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_mod(unsigned int val, unsigned int div)
{
int r;
r = val % div;
return ((r < 0) ? r + div : r);
}

23
libft/libft/ft_power.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/21 17:34:08 by jfleury #+# #+# */
/* Updated: 2019/01/23 15:07:35 by allefebv ### ########.fr */
/* */
/* ************************************************************************** */
unsigned long long ft_power(unsigned long long nb, int power)
{
if (power == 0)
return (1);
if (power == 1)
return (nb);
if (power > 0)
return (nb * ft_power(nb, power - 1));
else
return (0);
}

18
libft/libft/ft_putchar.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:46:36 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:57:28 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:03:58 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:49:12 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

19
libft/libft/ft_putendl.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:03:39 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:43 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl(char const *s)
{
ft_putstr(s);
ft_putchar('\n');
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:03:45 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:51:53 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char const *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

35
libft/libft/ft_putnbr.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:47:14 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:42 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr(int n)
{
if (n == -2147483648)
{
ft_putchar('-');
ft_putchar('2');
n = 147483648;
}
if (n < 0)
{
ft_putchar('-');
n = -n;
}
if (n < 10)
ft_putchar(n + 48);
if (n > 9)
{
ft_putnbr(n / 10);
ft_putnbr(n % 10);
}
}

View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:47:14 by jfleury #+# #+# */
/* Updated: 2018/11/06 09:47:31 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
if (n == -2147483648)
{
ft_putchar_fd('-', fd);
ft_putchar_fd('2', fd);
n = 147483648;
}
if (n < 0)
{
ft_putchar_fd('-', fd);
n = -n;
}
if (n < 10)
ft_putchar_fd(n + 48, fd);
if (n > 9)
{
ft_putnbr_fd(n / 10, fd);
ft_putnbr_fd(n % 10, fd);
}
}

28
libft/libft/ft_putstr.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:47:33 by jfleury #+# #+# */
/* Updated: 2018/11/13 20:26:16 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr(char const *s)
{
int i;
i = 0;
if (s != NULL)
{
while (s[i] != 0)
{
ft_putchar(s[i]);
i++;
}
}
}

View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:04:05 by jfleury #+# #+# */
/* Updated: 2018/11/13 20:26:36 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
void ft_putstr_fd(char const *s, int fd)
{
size_t i;
i = 0;
if (s != NULL)
{
while (s[i] != '\0')
{
ft_putchar_fd(s[i], fd);
i++;
}
}
}

25
libft/libft/ft_sstrcpy.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:55:16 by jfleury #+# #+# */
/* Updated: 2019/03/12 13:55:19 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
char **ft_sstrcpy(char **dest, char const **src)
{
while (*src != 0 && *dest != 0)
{
ft_strcpy(*dest, *src);
src++;
dest++;
}
return (dest);
}

26
libft/libft/ft_sstrdel.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:50:51 by jfleury #+# #+# */
/* Updated: 2019/03/12 13:50:53 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
int ft_sstrdel(char **str, int size)
{
while (size >= 0)
{
free(str[size]);
size--;
}
free(str);
str = NULL;
return (0);
}

30
libft/libft/ft_sstrnew.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:51:04 by jfleury #+# #+# */
/* Updated: 2019/03/12 13:51:06 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_sstrnew(size_t y, size_t x)
{
char **str;
size_t i;
i = 0;
if (!(str = (char**)ft_memalloc(y + 1)))
return (NULL);
while (i < y)
{
str[i] = ft_strnew(x);
i++;
}
str[y] = 0;
return (str);
}

View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:51:14 by jfleury #+# #+# */
/* Updated: 2019/03/12 13:51:16 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_sstrprint(char **str)
{
size_t i;
i = 0;
while (str[i] != 0)
{
ft_putstr(str[i]);
ft_putchar('\n');
i++;
}
}

30
libft/libft/ft_strcat.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:47:58 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:46:03 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strcat(char *dest, const char *src)
{
int i;
int j;
j = 0;
i = ft_strlen(dest);
while (src[j] != '\0')
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}

23
libft/libft/ft_strchr.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 10:47:52 by jfleury #+# #+# */
/* Updated: 2019/06/07 13:49:03 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
while (*s != (char)c && *s != '\0')
s++;
if (*s == (char)c)
return ((char *)s);
return (NULL);
}

24
libft/libft/ft_strclr.c Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strclr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:00:22 by jfleury #+# #+# */
/* Updated: 2018/11/14 12:24:47 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_strclr(char *s)
{
size_t i;
if (s != NULL)
{
i = ft_strlen(s);
ft_bzero(s, i);
}
}

26
libft/libft/ft_strcmp.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:48:13 by jfleury #+# #+# */
/* Updated: 2019/03/04 14:38:51 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
size_t i;
size_t j;
i = ft_strlen(s1);
j = ft_strlen(s2);
if (i > j)
return (ft_memcmp(s1, s2, i));
else
return (ft_memcmp(s1, s2, j));
}

25
libft/libft/ft_strcpy.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:48:33 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:19:06 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcpy(char *dest, const char *src)
{
unsigned int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}

23
libft/libft/ft_strdel.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:07:18 by jfleury #+# #+# */
/* Updated: 2019/05/23 12:22:31 by allefebv ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <stdlib.h>
void ft_strdel(char **as)
{
if (as != NULL && *as != NULL)
{
free(*as);
*as = NULL;
}
}

36
libft/libft/ft_strdup.c Normal file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:48:56 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:45:44 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
char *ft_strdup(const char *src)
{
char *str;
int i;
int j;
i = 0;
j = 0;
while (src[j] != '\0')
j++;
str = (char*)malloc(sizeof(*str) * (j + 1));
if (str == NULL)
return (NULL);
while (src[i] != '\0')
{
str[i] = src[i];
i++;
}
str[i] = '\0';
return (str);
}

22
libft/libft/ft_strequ.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:01:11 by jfleury #+# #+# */
/* Updated: 2019/03/02 12:56:54 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strequ(char const *s1, char const *s2)
{
if (!(s1) || !(s2))
return (0);
if (!(ft_strcmp(s1, s2)))
return (1);
return (0);
}

View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strextend.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/21 11:15:30 by jfleury #+# #+# */
/* Updated: 2018/11/21 11:41:42 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strextend(char *s1, char const *s2)
{
char *str;
int i;
if (s1 == NULL || s2 == NULL)
return (NULL);
i = ft_strlen(s1) + ft_strlen(s2);
str = s1;
if (!(s1 = (char*)malloc(sizeof(s1) * i + 1)))
return (NULL);
ft_strcpy(s1, str);
ft_strcat(s1, s2);
free(str);
return (s1);
}

25
libft/libft/ft_striter.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:00:32 by jfleury #+# #+# */
/* Updated: 2018/11/15 17:25:51 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void ft_striter(char *s, void (*f)(char*))
{
if (s != NULL && f != NULL)
{
while (*s != '\0')
{
f(s);
s++;
}
}
}

29
libft/libft/ft_striteri.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:00:37 by jfleury #+# #+# */
/* Updated: 2018/11/15 17:26:01 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
unsigned int i;
i = 0;
if (s != NULL && f != NULL)
{
while (*s != '\0')
{
f(i, s);
i++;
s++;
}
}
}

30
libft/libft/ft_strjoin.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:01:42 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:48:27 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
int i;
if (s1 == NULL || s2 == NULL)
return (NULL);
i = ft_strlen(s1) + ft_strlen(s2);
if (!(str = (char*)malloc(sizeof(str) * i + 1)))
return (NULL);
ft_strcpy(str, s1);
ft_strcat(str, s2);
return (str);
}

35
libft/libft/ft_strlcat.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 09:55:24 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:30 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
size_t ft_strlcat(char *dest, const char *src, size_t n)
{
size_t i;
size_t j;
i = 0;
if (n == 0)
return (ft_strlen(src));
while (dest[i] && i < n)
i++;
j = i;
while (src[i - j] && i < n - 1)
{
dest[i] = src[i - j];
i++;
}
if (j < n)
dest[i] = '\0';
return (j + ft_strlen(src));
}

23
libft/libft/ft_strlen.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:49:21 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:25:34 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}

37
libft/libft/ft_strmap.c Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:00:49 by jfleury #+# #+# */
/* Updated: 2018/11/13 20:55:38 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <stdlib.h>
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
char *str;
int len;
int i;
if (!(s))
return (NULL);
len = ft_strlen((char*)s);
if (!(str = (char*)malloc(sizeof(char) * len + 1)))
return (NULL);
i = 0;
while (s[i] != '\0')
{
if (!(str[i] = f(s[i])))
return (NULL);
i++;
}
str[i] = '\0';
return (str);
}

37
libft/libft/ft_strmapi.c Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:00:59 by jfleury #+# #+# */
/* Updated: 2018/11/13 20:57:38 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <stdlib.h>
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int len;
int i;
if (!(s))
return (NULL);
len = ft_strlen((char*)s);
if (!(str = (char*)malloc(sizeof(char) * len + 1)))
return (NULL);
i = 0;
while (s[i] != '\0')
{
if (!(str[i] = f(i, s[i])))
return (NULL);
i++;
}
str[i] = '\0';
return (str);
}

31
libft/libft/ft_strncat.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:49:31 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:26:56 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
char *ft_strncat(char *dest, const char *src, size_t n)
{
size_t i;
size_t j;
j = 0;
i = ft_strlen(dest);
while (src[j] != '\0' && j < n)
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}

27
libft/libft/ft_strnchr.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/07 17:53:03 by jfleury #+# #+# */
/* Updated: 2019/04/02 12:08:05 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnchr(const char *s, int c, int n)
{
while (*s != (char)c && *s != '\0')
{
s++;
n--;
if (n == 0)
return (NULL);
}
if (*s == (char)c)
return ((char *)s);
return (NULL);
}

31
libft/libft/ft_strncmp.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:49:43 by jfleury #+# #+# */
/* Updated: 2018/11/15 16:46:42 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int i;
i = 0;
while (n > 0 && (s1[i] != '\0' || s2[i] != '\0'))
{
if (s1[i] != s2[i])
return ((unsigned char)s1[i] - s2[i]);
else
{
i++;
n--;
}
}
return (0);
}

31
libft/libft/ft_strncpy.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:49:53 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:27:16 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
char *ft_strncpy(char *dest, const char *src, size_t n)
{
unsigned int i;
i = 0;
while (i < n && src[i] != '\0')
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}

31
libft/libft/ft_strndup.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/15 17:33:47 by allefebv #+# #+# */
/* Updated: 2019/04/02 12:09:00 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strndup(const char *s, size_t len)
{
char *strcpy;
if (ft_strlen(s) > len)
{
if (!(strcpy = (char*)malloc(sizeof(char) * (len + 1))))
return (NULL);
ft_strncpy(strcpy, s, len);
}
else
{
if (!(strcpy = ft_strdup(s)))
return (NULL);
}
return (strcpy);
}

23
libft/libft/ft_strnequ.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:01:20 by jfleury #+# #+# */
/* Updated: 2018/11/15 17:23:25 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
int ft_strnequ(char const *s1, char const *s2, size_t n)
{
if (!(s1) || !(s2))
return (0);
if (!(ft_strncmp(s1, s2, (int)n)))
return (1);
return (0);
}

25
libft/libft/ft_strnew.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:00:08 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:28:06 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
#include "libft.h"
char *ft_strnew(size_t size)
{
char *str;
if (!(str = (char*)malloc(sizeof(char) * size + 1)))
return (NULL);
ft_bzero(str, size + 1);
return (str);
}

View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnextend.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/21 11:16:19 by jfleury #+# #+# */
/* Updated: 2018/11/21 11:42:05 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strnextend(char *s1, char const *s2, size_t len)
{
char *tmp;
int i;
if (!(s1) || !(s2))
return (NULL);
if (len < ft_strlen(s2))
i = ft_strlen(s1) + len;
else
i = ft_strlen(s1) + ft_strlen(s2);
tmp = s1;
if (!(s1 = (char*)malloc(sizeof(s1) * (i + 1))))
return (NULL);
ft_strcpy(s1, tmp);
ft_strncat(s1, s2, len);
free(tmp);
return (s1);
}

38
libft/libft/ft_strnstr.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 17:44:35 by jfleury #+# #+# */
/* Updated: 2018/11/15 17:19:56 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
char *ft_strnstr(const char *s1, const char *s2, size_t n)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (s1[i] != '\0' && i < n)
{
j = 0;
while (s1[i] == s2[j] && s2[j] != 0 && s1[i] != 0 && i < n)
{
i++;
j++;
}
if (s2[j] == 0)
return ((char*)s1 + i - j);
if (j == 0)
i++;
else
i = i - j + 1;
}
return (NULL);
}

28
libft/libft/ft_strrchr.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/08 14:47:08 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:28:35 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
char *ft_strrchr(const char *s, int c)
{
int i;
i = ft_strlen((char *)s);
while (i >= 0)
{
if (s[i] == c)
return ((char *)s + i);
i--;
}
return (NULL);
}

33
libft/libft/ft_strrev.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrev.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/09 17:12:12 by jfleury #+# #+# */
/* Updated: 2019/04/02 12:09:13 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrev(char *str)
{
char stra;
int start;
int end;
start = 0;
end = ft_strlen(str);
end--;
while (start < end)
{
stra = str[end];
str[end] = str[start];
str[start] = stra;
start++;
end--;
}
return (str);
}

23
libft/libft/ft_strrnchr.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrnchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/09 10:33:56 by allefebv #+# #+# */
/* Updated: 2019/04/02 12:08:23 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrnchr(const char *s, int c, int n)
{
while (s[n] != c)
n--;
if (s[n] == c)
return ((char*)s + n);
else
return (NULL);
}

80
libft/libft/ft_strsplit.c Normal file
View File

@@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:02:06 by jfleury #+# #+# */
/* Updated: 2019/03/02 12:36:51 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
static char *ft_strdup_split(char const *s, char c, int *i)
{
int j;
char *new;
j = 0;
while (s[j] != c && s[j] != '\0')
j++;
if (!(new = (char*)malloc(sizeof(char) * (j + 1))))
return (NULL);
j = 0;
while (s[j] != c && s[j] != '\0')
{
new[j] = s[j];
j++;
}
new[j] = '\0';
*i = *i + j;
return (new);
}
static int ft_size(char const *s, char c)
{
int i;
int j;
i = 0;
j = 0;
while (s[i] != '\0')
{
if (s[i] != c && (s[i + 1] == c || s[i + 1] == '\0'))
j++;
i++;
}
return (j);
}
char **ft_strsplit(char const *s, char c)
{
char **s_str;
int size_s_str;
int i;
int j;
if (s == NULL)
return (NULL);
size_s_str = ft_size(s, c);
if (!(s_str = (char**)malloc(sizeof(char*) * (size_s_str + 1))))
return (NULL);
s_str[size_s_str] = 0;
i = 0;
j = 0;
while (s[i] != '\0')
{
while (s[i] == c && s[i] != '\0')
i++;
if (s[i] == '\0')
return (s_str);
if (!(s_str[j] = ft_strdup_split((s + i), c, &i)))
return (NULL);
else
j++;
}
return (s_str);
}

38
libft/libft/ft_strstr.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 14:50:07 by jfleury #+# #+# */
/* Updated: 2018/11/13 19:37:48 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
char *ft_strstr(const char *str, const char *to_find)
{
int i;
int j;
i = 0;
j = 0;
if (to_find[0] == '\0')
return ((char *)str);
while (str[i] != '\0')
{
j = 0;
while (str[i + j] == to_find[j])
{
if (to_find[j + 1] == '\0')
{
return ((char *)str + i);
}
j++;
}
i++;
}
return (NULL);
}

35
libft/libft/ft_strsub.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:01:30 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:47:30 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
#include <stdlib.h>
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
i = 0;
if (s == NULL || ft_strlen(s) < start)
return (NULL);
if (!(str = (char*)malloc(sizeof(char) * (len + 1))))
return (NULL);
while (len > i && s[start] != 0)
{
str[i] = s[start];
start++;
i++;
}
str[i] = 0;
return (str);
}

34
libft/libft/ft_strtrim.c Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/13 10:01:56 by jfleury #+# #+# */
/* Updated: 2018/11/13 20:45:52 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
char *ft_strtrim(char const *s)
{
char *str;
int i;
int len;
if (s == NULL)
return (NULL);
i = 0;
len = ft_strlen(s) - 1;
while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t'))
i++;
if (s[i] == 0)
return (ft_strdup(s + i));
while ((s[len] == ' ' || s[len] == '\n' || s[len] == '\t') && len > 0)
len--;
str = (ft_strsub(s, i, len - i + 1));
return (str);
}

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strupcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/14 17:23:47 by jfleury #+# #+# */
/* Updated: 2019/04/02 12:08:35 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strupcase(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] - 32;
i++;
}
return (str);
}

22
libft/libft/ft_tolower.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 17:31:11 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:29:39 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
{
c = c + 32;
return (c);
}
else
return (c);
}

22
libft/libft/ft_toupper.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 17:37:05 by jfleury #+# #+# */
/* Updated: 2018/11/13 18:29:41 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
{
c = c - 32;
return (c);
}
else
return (c);
}

View File

@@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 13:50:20 by jfleury #+# #+# */
/* Updated: 2019/07/01 15:23:57 by jfleury ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_read(char *tmp, char **line, int fd, int *check_end)
{
char buf[BUFF_SIZE + 1];
int ret;
int i;
while ((ret = read(fd, buf, BUFF_SIZE)) != 0)
{
i = 0;
buf[ret] = '\0';
while (buf[i] != '\0' && buf[i] != '\n')
i++;
if (buf[i] == '\n')
{
if (!(*line = ft_strnextend(*line, buf, i)))
return (NULL);
ft_strcpy(tmp, buf + i + 1);
return (tmp);
}
if (!(*line = ft_strextend(*line, buf)))
return (NULL);
ft_bzero(buf, BUFF_SIZE + 1);
}
if (!ret && **line == '\0')
*check_end = 1;
return (tmp);
}
char *ft_checktmp(char *tmp, char **line, int *check_n)
{
int i;
int j;
i = 0;
if (tmp == NULL)
{
if (!(tmp = ft_strnew(BUFF_SIZE)))
return (NULL);
}
while (tmp[i] != '\0' && tmp[i] != '\n')
{
line[0][i] = tmp[i];
i++;
}
if (tmp[i] == '\n')
*check_n = 1;
j = 0;
while (tmp[i + j] != '\0')
j++;
ft_memmove(tmp, tmp + i + 1, j);
ft_bzero(tmp + j, i + 1);
return (tmp);
}
int get_next_line(const int fd, char **line, char **tmp)
{
char buf[1];
int check_n;
int check_end;
if (line == NULL || fd < 0 || read(fd, buf, 0) < 0)
return (-1);
if (!(*line = ft_strnew(BUFF_SIZE)))
*line = NULL;
check_n = 0;
check_end = 0;
if (!(*tmp = ft_checktmp(*tmp, line, &check_n)))
return (-1);
if (check_n == 1)
return (1);
if (!(*tmp = ft_read(*tmp, line, fd, &check_end)))
return (-1);
if (check_end == 0)
return (1);
return (0);
}

81
libft/printf/Makefile Normal file
View File

@@ -0,0 +1,81 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/12/14 16:59:10 by igarbuz #+# #+# #
# Updated: 2019/07/17 11:14:14 by jfleury ### ########.fr #
# #
# **************************************************************************** #
NAME = libftprintf.a
SRC = buf_cnt.c \
ft_argcast.c \
ft_arglen_f.c \
ft_arglen_oct.c \
ft_arglen.c \
ft_buf_print_db.c \
ft_buf_print_ldb.c \
ft_error.c \
ft_exp_dec.c \
ft_init_param.c \
ft_nd_div.c \
ft_nd_long_div.c \
ft_nd_long_mul.c \
ft_nd_long_round.c \
ft_nd_mul.c \
ft_nd_round.c \
ft_null.c \
ft_parse.c \
ft_printf_db.c \
ft_printf_ldb.c \
ft_printf.c \
ft_unicode.c \
libft_printf.c \
pow10.c \
print_buf_bit_float.c \
print_buf_num.c \
print_buf_prefix.c \
print_buf_unicode.c \
print_buf.c \
print_cs_pad.c \
print_num_pad.c
HEAD = ft_printf.h
OBJ = $(SRC:.c=.o)
CC = gcc
CFLAGS = -Wall -Werror -Wextra -O3
CPPFLAGS = -I .
all: $(NAME)
$(NAME): $(OBJ)
ar rcs $(NAME) $(OBJ) *.o
ranlib $(NAME)
%.o : %.c $(HEAD)
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
norm:
norminette $(SRC) $(HEAD) | grep -B1 "Error*"
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(NAME)
debug: CFLAGS += -g
debug: re
re: fclean all
.PHONY: all clean fclean re norm debug
.SILENT: $(OBJ) $(NAME) all clean fclean re

13
libft/printf/buf_cnt.c Normal file
View File

@@ -0,0 +1,13 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buf_cnt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/24 13:03:33 by igarbuz #+# #+# */
/* Updated: 2019/01/24 13:03:39 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
int g_bcn = 0;

66
libft/printf/ft_argcast.c Normal file
View File

@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_argcast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/24 13:03:50 by igarbuz #+# #+# */
/* Updated: 2019/01/24 13:03:56 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static intmax_t ft_arg_cast_c(va_list valist)
{
return (va_arg(valist, int));
}
static intmax_t ft_arg_cast_s(va_list valist)
{
return (va_arg(valist, intptr_t));
}
static intmax_t ft_arg_cast_i(va_list valist, int p)
{
if (p >> 8 & 1)
return (va_arg(valist, long long int));
else if (p >> 7 & 1)
return (va_arg(valist, long int));
else if (p >> 6 & 1)
return ((short int)va_arg(valist, int));
else if (p >> 5 & 1)
return ((signed char)va_arg(valist, int));
else
return (va_arg(valist, int));
}
static intmax_t ft_arg_cast_u(va_list valist, int p)
{
if (p >> 8 & 1)
return (va_arg(valist, unsigned long long int));
else if (p >> 7 & 1)
return (va_arg(valist, unsigned long int));
else if (p >> 6 & 1)
return ((unsigned short int)va_arg(valist, int));
else if (p >> 5 & 1)
return ((unsigned char)va_arg(valist, int));
else
return (va_arg(valist, unsigned int));
}
intmax_t ft_arg_cast(va_list valist, int p, const char c)
{
if (c == 'c')
return (ft_arg_cast_c(valist));
else if (c == 's')
return (ft_arg_cast_s(valist));
else if (c == 'd' || c == 'i')
return (ft_arg_cast_i(valist, p));
else if (c == 'u' || c == 'o' || c == 'x' || c == 'X')
return (ft_arg_cast_u(valist, p));
else if (c == 'p')
return (ft_arg_cast_u(valist, 0x100));
return (0);
}

74
libft/printf/ft_arglen.c Normal file
View File

@@ -0,0 +1,74 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arglen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/24 13:04:12 by igarbuz #+# #+# */
/* Updated: 2019/01/24 13:04:16 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_unbrlen(uintmax_t n)
{
int i;
i = 1;
while (n && n > 9)
{
n = n / 10;
i++;
}
return (i);
}
static int ft_snbrlen(intmax_t n)
{
if (n < 0)
return (ft_unbrlen(-n));
return (ft_unbrlen(n));
}
static int ft_hexlen(uintmax_t x)
{
int i;
i = 1;
while (x > 15)
{
x = (x >> 4);
i++;
}
return (i);
}
/*
** For string length, if an argument is an integer Zero, "(null)" is printed
** that corresponds to below returned precision of 6;
*/
int ft_arg_len(intmax_t arg, char c, t_param *prm)
{
if (c == 'c' || c == '%')
return (1);
else if (!arg && !prm->prc && c != 'o')
return (0);
else if (c == 'd' || c == 'i')
return (ft_snbrlen((intmax_t)arg));
else if (c == 'u')
return (ft_unbrlen((uintmax_t)arg));
else if (c == 'o')
return (ft_arg_len_oct(arg, prm));
else if (c == 'x' || c == 'X')
return (ft_hexlen((uintmax_t)arg));
else if (c == 'p')
return (ft_hexlen((uintmax_t)arg));
else if (c == 's' && prm->p >> 7 & 1)
return (ft_strlen_unicode((wchar_t *)arg));
else if (c == 's')
return (ft_strlen_printf((char *)arg));
return (0);
}

View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arglen_f.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/24 13:04:25 by igarbuz #+# #+# */
/* Updated: 2019/01/24 13:04:30 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_fract_len(const char *f)
{
const char *t;
t = f;
while (*t && *t != '.')
t++;
f = t + 1;
while (*t)
t++;
return (t - f);
}
int ft_arg_db_len(const char *s, int p, double *arg)
{
int len;
uintmax_t *ptr;
ptr = (uintmax_t *)arg;
len = ft_strlen_printf(s);
if ((p & 1) || (p >> 3 & 1) || (*ptr >> 63))
len += 1;
return (len);
}
int ft_arg_long_db_len(const char *s, int p, long double *arg)
{
int len;
uintmax_t *ptr;
ptr = (uintmax_t *)arg;
len = ft_strlen_printf(s);
if ((p & 1) || (p >> 3 & 1) || (ptr[1] >> 15) & 1)
len += 1;
return (len);
}
int ft_arg_flen(intmax_t arg, char c, int p, int len)
{
if ((c == 'i' || c == 'd')
&& (arg < 0 || (arg >= 0 && (p & 1 || p >> 3 & 1))))
return (len + 1);
if ((c == 'x' || c == 'X') && (p >> 2 & 1) && arg)
return (len + 2);
else if (c == 'p')
return (len + 2);
return (len);
}

View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arglen_oct.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/29 19:52:21 by igarbuz #+# #+# */
/* Updated: 2019/01/29 19:52:25 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_octlen(uintmax_t o)
{
int i;
i = 1;
while (o > 7)
{
o = (o >> 3);
i++;
}
return (i);
}
int ft_arg_len_oct(intmax_t arg, t_param *prm)
{
if (arg && prm->prc)
return (ft_octlen((uintmax_t)arg) + (prm->p >> 2 & 1));
else if (!arg && !prm->prc && !(prm->p >> 2 & 1))
return (0);
return (ft_octlen((uintmax_t)arg));
}

Some files were not shown because too many files have changed in this diff Show More