Merge nm-otool with full history
This commit is contained in:
commit
0b34a414c5
250 changed files with 9149 additions and 0 deletions
7
nm-otool/.gitignore
vendored
Normal file
7
nm-otool/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
ft_nm
|
||||||
|
ft_otool
|
||||||
|
srcs/mach_32
|
||||||
|
includes/mach_32.h
|
||||||
|
tests/*
|
||||||
|
!tests/*.c
|
||||||
|
!tests/*.sh
|
||||||
0
nm-otool/.gitmodules
vendored
Normal file
0
nm-otool/.gitmodules
vendored
Normal file
130
nm-otool/Makefile
Normal file
130
nm-otool/Makefile
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
|
# Updated: 2017/11/07 15:52:38 by jhalford ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = ft_nm ft_otool
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
W_FLAGS = -Wall -Wextra -Werror
|
||||||
|
D_FLAGS =
|
||||||
|
FLAGS = $(W_FLAGS) $(D_FLAGS)
|
||||||
|
|
||||||
|
LEN_NAME = `printf "%s" $(NAME) |wc -c`
|
||||||
|
DELTA = $$(echo "$$(tput cols)-31-$(LEN_NAME)"|bc)
|
||||||
|
|
||||||
|
LIBFT_DIR = libft/
|
||||||
|
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
||||||
|
LIBFT_INC = $(LIBFT_DIR)includes/
|
||||||
|
|
||||||
|
LIBS =
|
||||||
|
SRC_DIR = srcs/
|
||||||
|
INC_DIR = includes/
|
||||||
|
OBJ_DIR = objs/
|
||||||
|
|
||||||
|
NM_OBJ = $(OBJ_DIR)ft_nm.o
|
||||||
|
OTOOL_OBJ = $(OBJ_DIR)ft_otool.o
|
||||||
|
|
||||||
|
SRC_BASE = \
|
||||||
|
endianness.c\
|
||||||
|
fat.c\
|
||||||
|
ft_nm.c\
|
||||||
|
ft_otool.c\
|
||||||
|
mach/get_section.c\
|
||||||
|
mach/mach.c\
|
||||||
|
mach/otool_mach.c\
|
||||||
|
mach/symbol_filter.c\
|
||||||
|
mach/symbol_format.c\
|
||||||
|
mach/symbol_free.c\
|
||||||
|
mach/symbol_init.c\
|
||||||
|
mach/symbol_sort.c\
|
||||||
|
mach_64/get_section_64.c\
|
||||||
|
mach_64/mach_64.c\
|
||||||
|
mach_64/otool_mach_64.c\
|
||||||
|
mach_64/symbol_64_filter.c\
|
||||||
|
mach_64/symbol_64_format.c\
|
||||||
|
mach_64/symbol_64_free.c\
|
||||||
|
mach_64/symbol_64_init.c\
|
||||||
|
mach_64/symbol_64_sort.c\
|
||||||
|
memcheck.c\
|
||||||
|
ppc/otool_ppc.c
|
||||||
|
|
||||||
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
|
OBJS = $(addprefix $(OBJ_DIR), $($(notdir SRC_BASE):.c=.o))
|
||||||
|
OBJS := $(filter-out $(NM_OBJ), $(OBJS))
|
||||||
|
OBJS := $(filter-out $(OTOOL_OBJ), $(OBJS))
|
||||||
|
NB = $(words $(SRC_BASE))
|
||||||
|
INDEX = 0
|
||||||
|
|
||||||
|
SHELL := /bin/bash
|
||||||
|
|
||||||
|
all:
|
||||||
|
@make -C $(LIBFT_DIR)
|
||||||
|
@make -j $(NAME)
|
||||||
|
|
||||||
|
ft_nm: $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(NM_OBJ)
|
||||||
|
@$(CC) $(OBJS) -o $@ \
|
||||||
|
-I $(INC_DIR) \
|
||||||
|
-I $(LIBFT_INC) \
|
||||||
|
$(LIBS) $(LIBFT_LIB) $(NM_OBJ) $(FLAGS)
|
||||||
|
@printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n"
|
||||||
|
|
||||||
|
ft_otool: $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(OTOOL_OBJ)
|
||||||
|
@$(CC) $(OBJS) -o $@ \
|
||||||
|
-I $(INC_DIR) \
|
||||||
|
-I $(LIBFT_INC) \
|
||||||
|
$(LIBS) $(LIBFT_LIB) $(OTOOL_OBJ) $(FLAGS)
|
||||||
|
@printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n"
|
||||||
|
|
||||||
|
$(LIBFT_LIB):
|
||||||
|
@make -C $(LIBFT_DIR)
|
||||||
|
|
||||||
|
$(OBJ_DIR) :
|
||||||
|
@mkdir -p $@
|
||||||
|
@mkdir -p $(dir $(OBJS))
|
||||||
|
|
||||||
|
$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||||
|
@$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB)))))
|
||||||
|
@$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB)))))
|
||||||
|
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB) - 1))))
|
||||||
|
@$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}"))
|
||||||
|
@printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) nm/otool $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')"
|
||||||
|
@$(CC) $(FLAGS) $(OBJ_FLAG) -MMD -c $< -o $@\
|
||||||
|
-I $(INC_DIR)\
|
||||||
|
-I $(LIBFT_INC)
|
||||||
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
||||||
|
clean: cleanlib
|
||||||
|
@if [ -e $(OBJ_DIR) ]; then \
|
||||||
|
rm -rf $(OBJ_DIR); \
|
||||||
|
printf "\r\033[38;5;202m✗ clean $(NAME) \033[0m\033[K\n"; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
cleanlib:
|
||||||
|
@make -C $(LIBFT_DIR) clean
|
||||||
|
|
||||||
|
fclean: clean fcleanlib
|
||||||
|
@for file in $(NAME); do \
|
||||||
|
if [ -e $$file ]; then \
|
||||||
|
rm -f $$file ; \
|
||||||
|
printf "\r\033[38;5;196m✗ fclean $$file\033[0m\033[K\n"; \
|
||||||
|
fi; \
|
||||||
|
done;
|
||||||
|
|
||||||
|
fcleanlib: cleanlib
|
||||||
|
@make -C $(LIBFT_DIR) fclean
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
relib: fcleanlib $(LIBFT_LIB)
|
||||||
|
|
||||||
|
.PHONY : fclean clean re relib cleanlib fcleanlib
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
1
nm-otool/auteur
Normal file
1
nm-otool/auteur
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
jhalford
|
||||||
90
nm-otool/includes/ft_nm.h
Normal file
90
nm-otool/includes/ft_nm.h
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_nm.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/30 11:44:40 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/07 16:02:11 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_NM_H
|
||||||
|
# define FT_NM_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
** sorting flags
|
||||||
|
** -r reverse sort
|
||||||
|
** -n numerical sort (as opposed to alphabetical)
|
||||||
|
** -p don't sort
|
||||||
|
*/
|
||||||
|
|
||||||
|
# define NM_NOSORT (1 << 0)
|
||||||
|
# define NM_NSORT (1 << 1)
|
||||||
|
# define NM_ASORT (1 << 2)
|
||||||
|
# define NM_RSORT (1 << 3)
|
||||||
|
|
||||||
|
/*
|
||||||
|
** filtering flags
|
||||||
|
** -a show all symbols
|
||||||
|
** -g filter-out local symbols
|
||||||
|
** -U filter-out undefined symbols
|
||||||
|
** -u show only undefined symbols
|
||||||
|
*/
|
||||||
|
|
||||||
|
# define NM_ALL (1 << 4)
|
||||||
|
# define NM_NO_LOCAL (1 << 5)
|
||||||
|
# define NM_NO_UNDF (1 << 6)
|
||||||
|
# define NM_ONLY_UNDF (1 << 7)
|
||||||
|
|
||||||
|
/*
|
||||||
|
** formating flags
|
||||||
|
** -o prepend file name on each line
|
||||||
|
** -m Display the N_SECT type symbols (Mach-O symbols) as (segment_name,
|
||||||
|
** section_name) followed by either external or non-external and then
|
||||||
|
** the symbol name. Undefined, common, absolute and indirect symbols
|
||||||
|
** get displayed as (undefined), (common), (absolute), and (indirect),
|
||||||
|
** respectively.
|
||||||
|
*/
|
||||||
|
|
||||||
|
# define NM_FULL (1 << 8)
|
||||||
|
# define NM_OFORMAT (1 << 9)
|
||||||
|
# define NM_MFORMAT (1 << 10)
|
||||||
|
|
||||||
|
typedef struct s_fdata t_fdata;
|
||||||
|
typedef enum e_symtype t_symtype;
|
||||||
|
typedef struct s_symbolmap t_symbolmap;
|
||||||
|
typedef struct s_machodata t_machodata;
|
||||||
|
|
||||||
|
enum e_symtype
|
||||||
|
{
|
||||||
|
SYM_UNDF,
|
||||||
|
SYM_ABS,
|
||||||
|
SYM_TEXT,
|
||||||
|
SYM_DATA,
|
||||||
|
SYM_BSS,
|
||||||
|
SYM_COMMON,
|
||||||
|
SYM_STAB,
|
||||||
|
SYM_OTHER,
|
||||||
|
SYM_INDR,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_machodata
|
||||||
|
{
|
||||||
|
t_fdata *file;
|
||||||
|
t_list *sects;
|
||||||
|
t_list *symbols;
|
||||||
|
struct symtab_command *symtab;
|
||||||
|
struct dysymtab_command *dysymtab;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_symbolmap
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
char *s;
|
||||||
|
};
|
||||||
|
|
||||||
|
void nm_single_file(void *file, t_fdata *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
58
nm-otool/includes/ft_nm_otool.h
Normal file
58
nm-otool/includes/ft_nm_otool.h
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_nm_otool.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/20 14:36:10 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/07 16:02:32 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_NM_OTOOL_H
|
||||||
|
# define FT_NM_OTOOL_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <sys/mman.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
|
||||||
|
# include <mach/machine.h>
|
||||||
|
# include <mach-o/loader.h>
|
||||||
|
# include <mach-o/nlist.h>
|
||||||
|
# include <mach-o/fat.h>
|
||||||
|
# include <mach-o/arch.h>
|
||||||
|
|
||||||
|
# include "ft_nm.h"
|
||||||
|
# include "ft_otool.h"
|
||||||
|
|
||||||
|
# include "mach_64.h"
|
||||||
|
# include "mach.h"
|
||||||
|
# include "ppc.h"
|
||||||
|
|
||||||
|
typedef struct s_fdata t_fdata;
|
||||||
|
typedef unsigned int t_u;
|
||||||
|
|
||||||
|
# define IS_MACH_64(x) (*(t_u*)x == MH_MAGIC_64||*(t_u*)x == MH_CIGAM_64)
|
||||||
|
# define IS_MACH_32(x) (*(t_u*)x == MH_MAGIC||*(t_u*)x == MH_CIGAM)
|
||||||
|
# define IS_FAT(x) (*(t_u*)x == FAT_MAGIC||*(t_u*)x == FAT_CIGAM)
|
||||||
|
# define IS_REV(x) ({t_u m=*(t_u*)x;m==MH_CIGAM||m==MH_CIGAM_64||m==FAT_CIGAM;})
|
||||||
|
# define MC(ptr) memcheck(data->file, ptr, sizeof(ptr))
|
||||||
|
|
||||||
|
struct s_fdata
|
||||||
|
{
|
||||||
|
t_flag flag;
|
||||||
|
char **av_data;
|
||||||
|
void *file;
|
||||||
|
void *eof;
|
||||||
|
char *filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
void *fat_extract(struct fat_header *fat, char *aname);
|
||||||
|
uint64_t endian(uint64_t n, uint8_t size);
|
||||||
|
void memcheck(t_fdata *file, void *ptr, size_t size);
|
||||||
|
|
||||||
|
#endif
|
||||||
26
nm-otool/includes/ft_otool.h
Normal file
26
nm-otool/includes/ft_otool.h
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_otool.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/30 11:46:23 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/07 13:24:50 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_OTOOL_H
|
||||||
|
# define FT_OTOOL_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
** otool flags
|
||||||
|
** -t show text section
|
||||||
|
** -d show data section
|
||||||
|
*/
|
||||||
|
# define OTOOL_TEXT (1 << 0)
|
||||||
|
# define OTOOL_DATA (1 << 1)
|
||||||
|
|
||||||
|
void otool_single_file(void *file, t_fdata *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
43
nm-otool/includes/mach.h
Normal file
43
nm-otool/includes/mach.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mach.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/07 16:02:46 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MACH_H
|
||||||
|
# define MACH_H
|
||||||
|
|
||||||
|
typedef struct s_symbol t_symbol;
|
||||||
|
typedef struct s_fdata t_fdata;
|
||||||
|
|
||||||
|
struct s_symbol
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
t_symtype type;
|
||||||
|
char *string;
|
||||||
|
struct nlist nlist;
|
||||||
|
struct section *section;
|
||||||
|
};
|
||||||
|
|
||||||
|
int symbol_init(t_symbol *symbol,
|
||||||
|
char *stringtable, struct nlist *array, int i);
|
||||||
|
int symbol_set(t_symbol *symbol, t_machodata *data);
|
||||||
|
void symbol_free(void *data, size_t size);
|
||||||
|
int symbol_sort(t_list **syms, t_flag flag);
|
||||||
|
int symbol_filter(t_list **syms, t_flag flag);
|
||||||
|
int is_external(t_symbol *s);
|
||||||
|
int is_not_external(t_symbol *s);
|
||||||
|
int symbol_format(t_symbol *symbol, t_fdata *data);
|
||||||
|
void *get_section(t_machodata *data, char *lookup);
|
||||||
|
void mach_parse(t_machodata *data);
|
||||||
|
|
||||||
|
void nm_mach(t_fdata *data);
|
||||||
|
void otool_mach(t_fdata *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
43
nm-otool/includes/mach_64.h
Normal file
43
nm-otool/includes/mach_64.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mach_64.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/07 16:01:54 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MACH_64_H
|
||||||
|
# define MACH_64_H
|
||||||
|
|
||||||
|
typedef struct s_fdata t_fdata;
|
||||||
|
typedef struct s_symbol_64 t_symbol_64;
|
||||||
|
|
||||||
|
struct s_symbol_64
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
t_symtype type;
|
||||||
|
char *string;
|
||||||
|
struct nlist_64 nlist;
|
||||||
|
struct section_64 *section;
|
||||||
|
};
|
||||||
|
|
||||||
|
int symbol_64_init(t_symbol_64 *symbol,
|
||||||
|
char *stringtable, struct nlist_64 *array, int i);
|
||||||
|
int symbol_64_set(t_symbol_64 *symbol, t_machodata *data);
|
||||||
|
void symbol_64_free(void *data, size_t size);
|
||||||
|
int symbol_64_sort(t_list **syms, t_flag flag);
|
||||||
|
int symbol_64_filter(t_list **syms, t_flag flag);
|
||||||
|
int is_external_64(t_symbol_64 *s);
|
||||||
|
int is_not_external_64(t_symbol_64 *s);
|
||||||
|
int symbol_64_format(t_symbol_64 *symbol, t_fdata *data);
|
||||||
|
void *get_section_64(t_machodata *data, char *lookup);
|
||||||
|
void mach_64_parse(t_machodata *data);
|
||||||
|
|
||||||
|
void nm_mach_64(t_fdata *data);
|
||||||
|
void otool_mach_64(t_fdata *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
18
nm-otool/includes/ppc.h
Normal file
18
nm-otool/includes/ppc.h
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ppc.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/11/01 11:38:10 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/07 15:29:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef PPC_H
|
||||||
|
# define PPC_H
|
||||||
|
|
||||||
|
void otool_ppc(t_fdata *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
1
nm-otool/libft/.gitignore
vendored
Normal file
1
nm-otool/libft/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
libft.a
|
||||||
258
nm-otool/libft/Makefile
Normal file
258
nm-otool/libft/Makefile
Normal file
|
|
@ -0,0 +1,258 @@
|
||||||
|
#* ************************************************************************** *#
|
||||||
|
#* *#
|
||||||
|
#* ::: :::::::: *#
|
||||||
|
#* Makefile :+: :+: :+: *#
|
||||||
|
#* +:+ +:+ +:+ *#
|
||||||
|
#* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ *#
|
||||||
|
#* +#+#+#+#+#+ +#+ *#
|
||||||
|
#* Created: 2016/08/29 21:32:58 by wescande #+# #+# *#
|
||||||
|
#* Updated: 2016/12/24 02:14:21 by wescande ### ########.fr *#
|
||||||
|
#* *#
|
||||||
|
#* ************************************************************************** *#
|
||||||
|
|
||||||
|
NAME = libft.a
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
FLAGS = -Wall -Wextra -Werror -O3
|
||||||
|
|
||||||
|
LEN_NAME = `printf "%s" $(NAME) |wc -c`
|
||||||
|
DELTA = $$(echo "$$(tput cols)-31-$(LEN_NAME)"|bc)
|
||||||
|
|
||||||
|
SRC_DIR = srcs/
|
||||||
|
INC_DIR = includes/
|
||||||
|
OBJ_DIR = objs/
|
||||||
|
|
||||||
|
SRC_BASE = \
|
||||||
|
btree/btree_apply_by_level.c\
|
||||||
|
btree/btree_apply_infix.c\
|
||||||
|
btree/btree_apply_prefix.c\
|
||||||
|
btree/btree_apply_suffix.c\
|
||||||
|
btree/btree_create_node.c\
|
||||||
|
btree/btree_del.c\
|
||||||
|
btree/btree_delone.c\
|
||||||
|
btree/btree_insert_data.c\
|
||||||
|
btree/btree_level_count.c\
|
||||||
|
btree/btree_map.c\
|
||||||
|
btree/btree_print.c\
|
||||||
|
btree/btree_search_item.c\
|
||||||
|
char/ft_isalnum.c\
|
||||||
|
char/ft_isalpha.c\
|
||||||
|
char/ft_isascii.c\
|
||||||
|
char/ft_isdigit.c\
|
||||||
|
char/ft_isprint.c\
|
||||||
|
char/ft_tolower.c\
|
||||||
|
char/ft_toupper.c\
|
||||||
|
cliopts/cliopts_get.c\
|
||||||
|
cliopts/cliopts_getmap.c\
|
||||||
|
color/ft_color_mk.c\
|
||||||
|
color/ft_color_mkif.c\
|
||||||
|
color/ft_color_reset.c\
|
||||||
|
color/ft_color_set.c\
|
||||||
|
dlst/ft_dlstadd_after.c\
|
||||||
|
dlst/ft_dlstadd_before.c\
|
||||||
|
dlst/ft_dlstdel.c\
|
||||||
|
dlst/ft_dlstdelone.c\
|
||||||
|
dlst/ft_dlstlast.c\
|
||||||
|
dlst/ft_dlstnew.c\
|
||||||
|
dlst/ft_dlstrtostr.c\
|
||||||
|
dlst/ft_dlstsize.c\
|
||||||
|
error/error.c\
|
||||||
|
error/ft_usage.c\
|
||||||
|
ft_printf/ft_conversion.c\
|
||||||
|
ft_printf/ft_fmt_simplify.c\
|
||||||
|
ft_printf/ft_fmt_validate_conv.c\
|
||||||
|
ft_printf/ft_fmt_validate_flags.c\
|
||||||
|
ft_printf/ft_fmt_validate_mod.c\
|
||||||
|
ft_printf/ft_printf.c\
|
||||||
|
ft_printf/ft_printf_color.c\
|
||||||
|
ft_printf/ft_printf_parse.c\
|
||||||
|
ft_printf/ft_transform.c\
|
||||||
|
ft_printf/ft_vprintf.c\
|
||||||
|
ft_printf/lib_fmt.c\
|
||||||
|
ft_printf/lib_fmt_error.c\
|
||||||
|
ft_printf/lib_pad.c\
|
||||||
|
ft_printf/lib_pad_sharp.c\
|
||||||
|
get_next_line/get_next_line.c\
|
||||||
|
lst/ft_id.c\
|
||||||
|
lst/ft_lst2str.c\
|
||||||
|
lst/ft_lst_at.c\
|
||||||
|
lst/ft_lst_bfree.c\
|
||||||
|
lst/ft_lst_cfree.c\
|
||||||
|
lst/ft_lst_delif.c\
|
||||||
|
lst/ft_lst_delsub.c\
|
||||||
|
lst/ft_lst_filter.c\
|
||||||
|
lst/ft_lst_filterout.c\
|
||||||
|
lst/ft_lst_find.c\
|
||||||
|
lst/ft_lst_merge.c\
|
||||||
|
lst/ft_lst_order_delsub.c\
|
||||||
|
lst/ft_lst_pop.c\
|
||||||
|
lst/ft_lst_print.c\
|
||||||
|
lst/ft_lst_print2.c\
|
||||||
|
lst/ft_lst_removeif.c\
|
||||||
|
lst/ft_lst_reverse.c\
|
||||||
|
lst/ft_lst_size.c\
|
||||||
|
lst/ft_lst_sorted_insert.c\
|
||||||
|
lst/ft_lst_sorted_merge.c\
|
||||||
|
lst/ft_lstadd.c\
|
||||||
|
lst/ft_lstdel.c\
|
||||||
|
lst/ft_lstdelone.c\
|
||||||
|
lst/ft_lsteadd.c\
|
||||||
|
lst/ft_lstiter.c\
|
||||||
|
lst/ft_lstlast.c\
|
||||||
|
lst/ft_lstmap.c\
|
||||||
|
lst/ft_lstnadd.c\
|
||||||
|
lst/ft_lstnew.c\
|
||||||
|
lst/ft_lstnew_range.c\
|
||||||
|
lst/ft_lstsort.c\
|
||||||
|
lst/lst_insert_sort.c\
|
||||||
|
lst/pop.c\
|
||||||
|
lst/push.c\
|
||||||
|
lst/top.c\
|
||||||
|
math/bswap.c\
|
||||||
|
math/ft_addrcmp.c\
|
||||||
|
math/ft_ilen.c\
|
||||||
|
math/ft_ilen_base.c\
|
||||||
|
math/ft_itoa.c\
|
||||||
|
math/ft_itoa_base.c\
|
||||||
|
math/ft_lllen.c\
|
||||||
|
math/ft_lllen_base.c\
|
||||||
|
math/ft_lltoa_base.c\
|
||||||
|
math/ft_uilen.c\
|
||||||
|
math/ft_uitoa_base.c\
|
||||||
|
math/ft_ulltoa_base.c\
|
||||||
|
math/id.c\
|
||||||
|
mem/ft_bzero.c\
|
||||||
|
mem/ft_malloc.c\
|
||||||
|
mem/ft_memalloc.c\
|
||||||
|
mem/ft_memccpy.c\
|
||||||
|
mem/ft_memchr.c\
|
||||||
|
mem/ft_memcmp.c\
|
||||||
|
mem/ft_memcpy.c\
|
||||||
|
mem/ft_memdel.c\
|
||||||
|
mem/ft_memmove.c\
|
||||||
|
mem/ft_memset.c\
|
||||||
|
mem/ft_realloc.c\
|
||||||
|
net/create_client.c\
|
||||||
|
net/create_server.c\
|
||||||
|
net/forge_ip.c\
|
||||||
|
net/forge_tcp.c\
|
||||||
|
net/net_get.c\
|
||||||
|
net/net_send.c\
|
||||||
|
net/reserve_port.c\
|
||||||
|
path/ft_path_notdir.c\
|
||||||
|
printing/ft_putchar.c\
|
||||||
|
printing/ft_putendl.c\
|
||||||
|
printing/ft_putnbr.c\
|
||||||
|
printing/ft_putstr.c\
|
||||||
|
printing/hexdump.c\
|
||||||
|
printing/hexdump_int.c\
|
||||||
|
rs/rs.c\
|
||||||
|
sstr/ft_sstradd.c\
|
||||||
|
sstr/ft_sstrcat.c\
|
||||||
|
sstr/ft_sstrdel.c\
|
||||||
|
sstr/ft_sstrdup.c\
|
||||||
|
sstr/ft_sstrfree.c\
|
||||||
|
sstr/ft_sstrmerge.c\
|
||||||
|
sstr/ft_sstrprint.c\
|
||||||
|
sstr/ft_sstrprint_fd.c\
|
||||||
|
sstr/ft_sstrsort.c\
|
||||||
|
sstr/ft_sstrstr.c\
|
||||||
|
str/ft_atoi.c\
|
||||||
|
str/ft_convert_base.c\
|
||||||
|
str/ft_putaddr_fd.c\
|
||||||
|
str/ft_split_whitespaces.c\
|
||||||
|
str/ft_str3join.c\
|
||||||
|
str/ft_strappend.c\
|
||||||
|
str/ft_strbetween.c\
|
||||||
|
str/ft_strcat.c\
|
||||||
|
str/ft_strcatf.c\
|
||||||
|
str/ft_strchr.c\
|
||||||
|
str/ft_strchrcpy.c\
|
||||||
|
str/ft_strclr.c\
|
||||||
|
str/ft_strcmp.c\
|
||||||
|
str/ft_strcpy.c\
|
||||||
|
str/ft_strcspn.c\
|
||||||
|
str/ft_strcut.c\
|
||||||
|
str/ft_strdel.c\
|
||||||
|
str/ft_strdup.c\
|
||||||
|
str/ft_strdupchr.c\
|
||||||
|
str/ft_strduptr.c\
|
||||||
|
str/ft_strequ.c\
|
||||||
|
str/ft_strinsert.c\
|
||||||
|
str/ft_stris.c\
|
||||||
|
str/ft_striter.c\
|
||||||
|
str/ft_striteri.c\
|
||||||
|
str/ft_strjoin.c\
|
||||||
|
str/ft_strlcat.c\
|
||||||
|
str/ft_strlen.c\
|
||||||
|
str/ft_strlenchr.c\
|
||||||
|
str/ft_strmap.c\
|
||||||
|
str/ft_strmapi.c\
|
||||||
|
str/ft_strncat.c\
|
||||||
|
str/ft_strncmp.c\
|
||||||
|
str/ft_strncpy.c\
|
||||||
|
str/ft_strndup.c\
|
||||||
|
str/ft_strnequ.c\
|
||||||
|
str/ft_strnew.c\
|
||||||
|
str/ft_strnstr.c\
|
||||||
|
str/ft_strrchr.c\
|
||||||
|
str/ft_strreplace.c\
|
||||||
|
str/ft_strrev.c\
|
||||||
|
str/ft_strsepjoin.c\
|
||||||
|
str/ft_strsplit.c\
|
||||||
|
str/ft_strstr.c\
|
||||||
|
str/ft_strsub.c\
|
||||||
|
str/ft_strtok.c\
|
||||||
|
str/ft_strtrim.c\
|
||||||
|
sys/open_new.c\
|
||||||
|
time/epoch.c\
|
||||||
|
time/ft_mytime_free.c\
|
||||||
|
time/ft_mytime_get.c\
|
||||||
|
time/ft_time_isrecent.c
|
||||||
|
|
||||||
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
|
NB = $(words $(SRC_BASE))
|
||||||
|
INDEX = 0
|
||||||
|
SHELL := /bin/bash
|
||||||
|
|
||||||
|
all :
|
||||||
|
@$(MAKE) -j $(NAME)
|
||||||
|
|
||||||
|
$(NAME) : $(OBJ_DIR) $(OBJS)
|
||||||
|
@ar rcs $(NAME) $(OBJS)
|
||||||
|
@printf "\r\033[38;5;117m✓ MAKE $(NAME)\033[0m\033[K\n"
|
||||||
|
|
||||||
|
$(OBJ_DIR) :
|
||||||
|
@mkdir -p $(OBJ_DIR)
|
||||||
|
@mkdir -p $(dir $(OBJS))
|
||||||
|
|
||||||
|
$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||||
|
@$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB)))))
|
||||||
|
@$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB)))))
|
||||||
|
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB) - 1))))
|
||||||
|
@$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}"))
|
||||||
|
@printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) $(NAME) $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')"
|
||||||
|
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||||
|
-I $(INC_DIR)
|
||||||
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
||||||
|
clean :
|
||||||
|
@if [ -e $(OBJ_DIR) ]; \
|
||||||
|
then \
|
||||||
|
rm -rf $(OBJ_DIR); \
|
||||||
|
printf "\r\033[38;5;202m✗ clean $(NAME).\033[0m\033[K\n"; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
fclean : clean
|
||||||
|
@if [ -e $(NAME) ]; \
|
||||||
|
then \
|
||||||
|
rm -rf $(NAME); \
|
||||||
|
printf "\r\033[38;5;196m✗ fclean $(NAME).\033[0m\033[K\n"; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
re : fclean all
|
||||||
|
|
||||||
|
.PHONY : fclean clean re
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
22
nm-otool/libft/README.md
Normal file
22
nm-otool/libft/README.md
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# libft
|
||||||
|
|
||||||
|
## libc
|
||||||
|
|
||||||
|
malloc interface functions, string manipulation
|
||||||
|
|
||||||
|
## data structures
|
||||||
|
|
||||||
|
- string anipulation (`char *`)
|
||||||
|
- string array manipulation (`char **`)
|
||||||
|
- linked list (`t_list`)
|
||||||
|
- double linked list (`t_dlist`)
|
||||||
|
- binary trees (`t_btree`)
|
||||||
|
- time struct (`t_mytime`)
|
||||||
|
|
||||||
|
## ft_printf
|
||||||
|
|
||||||
|
printf rewrite
|
||||||
|
|
||||||
|
## get_next_line
|
||||||
|
|
||||||
|
read one line from a file descriptor, supports calls between multiple file descriptors.
|
||||||
55
nm-otool/libft/includes/btree.h
Normal file
55
nm-otool/libft/includes/btree.h
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/16 17:31:13 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BTREE_H
|
||||||
|
# define BTREE_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
struct s_btree
|
||||||
|
{
|
||||||
|
void *item;
|
||||||
|
size_t content_size;
|
||||||
|
struct s_btree *left;
|
||||||
|
struct s_btree *right;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_printdata
|
||||||
|
{
|
||||||
|
int is_left;
|
||||||
|
int offset;
|
||||||
|
int depth;
|
||||||
|
int left;
|
||||||
|
int right;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_btree t_btree;
|
||||||
|
typedef struct s_printdata t_printdata;
|
||||||
|
|
||||||
|
t_btree *btree_create_node(void const *item, size_t content_size);
|
||||||
|
t_btree *btree_map(t_btree *root, void *(*f)(void *));
|
||||||
|
void btree_insert_data(
|
||||||
|
t_btree **root,
|
||||||
|
void *item,
|
||||||
|
size_t content_size,
|
||||||
|
int (*cmpf)(void *, void *));
|
||||||
|
void *btree_search_item(t_btree *root,
|
||||||
|
void *data_ref, int (*cmpf)(void *, void *));
|
||||||
|
int btree_level_count(t_btree *root);
|
||||||
|
void btree_apply_prefix(t_btree *root, void (*applyf)(void *));
|
||||||
|
void btree_apply_infix(t_btree *root, void (*applyf)(void *));
|
||||||
|
void btree_apply_suffix(t_btree *root, void (*applyf)(void *));
|
||||||
|
void btree_print(int fd, t_btree *tree, char *(*printer)(void *));
|
||||||
|
void btree_del(t_btree **root, void (*del)(void *, size_t));
|
||||||
|
void btree_delone(t_btree **root, void (*del)(void *, size_t));
|
||||||
|
|
||||||
|
#endif
|
||||||
44
nm-otool/libft/includes/cliopts.h
Normal file
44
nm-otool/libft/includes/cliopts.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cliopts.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/30 11:54:42 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CLIOPTS_H
|
||||||
|
# define CLIOPTS_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include "error.h"
|
||||||
|
|
||||||
|
typedef struct s_cliopts t_cliopts;
|
||||||
|
typedef struct s_data_template t_data_template;
|
||||||
|
typedef long long t_flag;
|
||||||
|
|
||||||
|
struct s_cliopts
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
char *str;
|
||||||
|
t_flag flag_on;
|
||||||
|
t_flag flag_off;
|
||||||
|
int (*get)();
|
||||||
|
int arg_required:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_data_template
|
||||||
|
{
|
||||||
|
t_flag flag;
|
||||||
|
char **av_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
int cliopts_get(char **av, t_cliopts opt_map[], void *data);
|
||||||
|
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg);
|
||||||
|
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg);
|
||||||
|
int cliopts_has(char **av, char c);
|
||||||
|
|
||||||
|
#endif
|
||||||
56
nm-otool/libft/includes/color.h
Normal file
56
nm-otool/libft/includes/color.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* color.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 13:36:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/02/18 20:01:33 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef COLOR_H
|
||||||
|
# define COLOR_H
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
struct s_color
|
||||||
|
{
|
||||||
|
char fg[7];
|
||||||
|
char bg[7];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_color t_color;
|
||||||
|
|
||||||
|
# define FG_DEFAULT "\e[0m"
|
||||||
|
# define ON_BOLD "\e[1m"
|
||||||
|
|
||||||
|
# define ON_UNDERLINED "\e[4m"
|
||||||
|
# define ON_INVERTED "\e[7m"
|
||||||
|
|
||||||
|
# define FG_BLACK "\e[30m"
|
||||||
|
# define FG_RED "\e[31m"
|
||||||
|
# define FG_GREEN "\e[32m"
|
||||||
|
# define FG_YELLOW "\e[33m"
|
||||||
|
# define FG_BLUE "\e[34m"
|
||||||
|
# define FG_MAGENTA "\e[35m"
|
||||||
|
# define FG_CYAN "\e[36m"
|
||||||
|
|
||||||
|
# define BG_BLACK "\e[40m"
|
||||||
|
# define BG_RED "\e[41m"
|
||||||
|
# define BG_GREEN "\e[42m"
|
||||||
|
# define BG_YELLOW "\e[43m"
|
||||||
|
# define BG_BLUE "\e[44m"
|
||||||
|
# define BG_MAGENTA "\e[45m"
|
||||||
|
# define BG_CYAN "\e[46m"
|
||||||
|
# define BG_DEFAULT "\e[49m"
|
||||||
|
|
||||||
|
# define FBG_DEFAULT FG_DEFAULT BG_DEFAULT
|
||||||
|
|
||||||
|
void ft_color_reset(void);
|
||||||
|
void ft_color_set(t_color color);
|
||||||
|
|
||||||
|
void ft_color_mk(t_color *color, char fg[7], char bg[7]);
|
||||||
|
void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7]);
|
||||||
|
|
||||||
|
#endif
|
||||||
35
nm-otool/libft/includes/dlst.h
Normal file
35
nm-otool/libft/includes/dlst.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* dlst.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/16 17:30:42 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef DLST_H
|
||||||
|
# define DLST_H
|
||||||
|
|
||||||
|
struct s_dlist
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
size_t content_size;
|
||||||
|
struct s_dlist *next;
|
||||||
|
struct s_dlist *prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_dlist t_dlist;
|
||||||
|
|
||||||
|
void ft_dlstadd_after(t_dlist **alst, t_dlist *new);
|
||||||
|
void ft_dlstadd_before(t_dlist **alst, t_dlist *new);
|
||||||
|
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t));
|
||||||
|
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t));
|
||||||
|
int ft_dlstsize(t_dlist *list);
|
||||||
|
t_dlist *ft_dlstnew(void const *content, size_t content_size);
|
||||||
|
t_dlist *ft_dlstlast(t_dlist *list);
|
||||||
|
char *ft_dlsttostr(t_dlist *list);
|
||||||
|
|
||||||
|
#endif
|
||||||
63
nm-otool/libft/includes/error.h
Normal file
63
nm-otool/libft/includes/error.h
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* error.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/30 10:06:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef ERROR_H
|
||||||
|
# define ERROR_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
** DEBUG with malloc
|
||||||
|
*/
|
||||||
|
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||||
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
|
# define DG(s, ...) ft_dprintf(STDERR,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
** DEBUG with no malloc
|
||||||
|
*/
|
||||||
|
# define DG2 ft_putstr(__FILE__"\t");ft_putnbr(__LINE__)
|
||||||
|
# define DGW(d) DG2;d;ft_putchar('\n')
|
||||||
|
# define DGS(s) DGW(ft_putstr(": "s"="))
|
||||||
|
# define DGSN(s, n) DGW(ft_putstr(": "s"=");ft_putnbr(n))
|
||||||
|
# define DGSH(s, n) DGW(ft_putstr(": "s"=");ft_putnbr_hex(n))
|
||||||
|
|
||||||
|
# define ERR_PROTO(u, m) "{red}%s: %s{eoc}\n", u, m
|
||||||
|
# define ERR_MSG(u, m) ft_dprintf(2, ERR_PROTO(u, m))
|
||||||
|
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
|
||||||
|
# define ERRMSG_MAX_SIZE 150
|
||||||
|
|
||||||
|
enum e_errors
|
||||||
|
{
|
||||||
|
E_NOERR,
|
||||||
|
E_CO_INV,
|
||||||
|
E_CO_INVL,
|
||||||
|
E_CO_MULT,
|
||||||
|
E_CO_MISS,
|
||||||
|
E_CO_MISSL,
|
||||||
|
E_SYS_NOFILE,
|
||||||
|
E_SYS_ISDIR,
|
||||||
|
E_SYS_NOPERM,
|
||||||
|
E_MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern char g_error_msg[E_MAX][ERRMSG_MAX_SIZE];
|
||||||
|
extern char *g_errmsg;
|
||||||
|
extern int g_errnum;
|
||||||
|
extern char **g_argv;
|
||||||
|
|
||||||
|
int error_set(int n, ...);
|
||||||
|
int ft_perror(char *utility);
|
||||||
|
void ft_usage(char *format, ...);
|
||||||
|
|
||||||
|
#endif
|
||||||
80
nm-otool/libft/includes/ft_printf.h
Normal file
80
nm-otool/libft/includes/ft_printf.h
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ftprintf.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 09:23:06 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_PRINTF_H
|
||||||
|
# define FT_PRINTF_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
# define ALL_FLAGS "#0- +"
|
||||||
|
# define ALL_CONVERSIONS "sSpdDioOuUxXcCb"
|
||||||
|
|
||||||
|
typedef struct s_fmt t_fmt;
|
||||||
|
typedef struct s_conv t_conv;
|
||||||
|
typedef char *(t_converter)(t_fmt *fmt, va_list ap);
|
||||||
|
typedef void (t_pad_func)(char *str, t_fmt *fmt);
|
||||||
|
|
||||||
|
struct s_conv
|
||||||
|
{
|
||||||
|
char id;
|
||||||
|
char allowed_flags[6];
|
||||||
|
char base[20];
|
||||||
|
t_converter *converter;
|
||||||
|
t_pad_func *sharp_func;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_fmt
|
||||||
|
{
|
||||||
|
char flags[6];
|
||||||
|
int width;
|
||||||
|
int precision;
|
||||||
|
char modifier[3];
|
||||||
|
char conversion;
|
||||||
|
int valid;
|
||||||
|
t_conv conv;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_vdprintf(int fd, const char *format, va_list ap);
|
||||||
|
int ft_fmtcalc(char **final, char **str, va_list ap);
|
||||||
|
|
||||||
|
extern t_conv g_convs[];
|
||||||
|
|
||||||
|
t_fmt *ft_fmt_init(void);
|
||||||
|
void ft_fmt_print(t_fmt *fmt);
|
||||||
|
void ft_printf_color(char **final, char **str, va_list ap);
|
||||||
|
t_fmt *ft_printf_parse(char **format, va_list ap);
|
||||||
|
|
||||||
|
char *ft_transform(t_fmt *fmt, va_list ap);
|
||||||
|
|
||||||
|
void ft_fmt_error_conv(char conv);
|
||||||
|
void ft_fmt_error_mod_conv(char *mod, char conv);
|
||||||
|
void ft_fmt_error_flag_conv(char flag, char conv);
|
||||||
|
void ft_fmt_error_flag_flag(char flag1, char flag2);
|
||||||
|
|
||||||
|
void ft_fmt_simplify(t_fmt *fmt);
|
||||||
|
int ft_fmt_validate_conv(t_fmt *fmt);
|
||||||
|
void ft_fmt_validate_flags(t_fmt *fmt);
|
||||||
|
void ft_fmt_validate_mod(t_fmt *fmt);
|
||||||
|
|
||||||
|
char *ft_signed_conversion(t_fmt *fmt, va_list ap);
|
||||||
|
char *ft_unsigned_conversion(t_fmt *fmt, va_list ap);
|
||||||
|
char *ft_str_conversion(t_fmt *fmt, va_list ap);
|
||||||
|
char *ft_char_conversion(t_fmt *fmt, va_list ap);
|
||||||
|
|
||||||
|
void ft_pad_sharp_o(char *str, t_fmt *fmt);
|
||||||
|
void ft_pad_sharp_xb(char *str, t_fmt *fmt);
|
||||||
|
void ft_pad_left(char *str, t_fmt *fmt);
|
||||||
|
void ft_pad_right(char *str, t_fmt *fmt);
|
||||||
|
|
||||||
|
#endif
|
||||||
22
nm-otool/libft/includes/ft_types.h
Normal file
22
nm-otool/libft/includes/ft_types.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_types.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/25 01:56:58 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/23 15:58:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_TYPES_H
|
||||||
|
# define FT_TYPES_H
|
||||||
|
|
||||||
|
typedef struct s_stos t_stos;
|
||||||
|
typedef struct s_stof t_stof;
|
||||||
|
typedef struct s_itof t_itof;
|
||||||
|
typedef long long int t_flag;
|
||||||
|
typedef long long int t_type;
|
||||||
|
|
||||||
|
#endif
|
||||||
31
nm-otool/libft/includes/get_next_line.h
Normal file
31
nm-otool/libft/includes/get_next_line.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/05 12:21:36 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 13:07:58 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GET_NEXT_LINE_H
|
||||||
|
# define GET_NEXT_LINE_H
|
||||||
|
# define BUFF_SIZE 32
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/uio.h>
|
||||||
|
|
||||||
|
typedef struct s_save t_save;
|
||||||
|
|
||||||
|
struct s_save
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char *str;
|
||||||
|
};
|
||||||
|
|
||||||
|
int get_next_line(int const fd, char **line);
|
||||||
|
|
||||||
|
#endif
|
||||||
100
nm-otool/libft/includes/libft.h
Normal file
100
nm-otool/libft/includes/libft.h
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/01 12:58:06 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
|
||||||
|
# define FT_TRY(a,b) ((a) ? (a) : (b))
|
||||||
|
|
||||||
|
# include <string.h>
|
||||||
|
# include <errno.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <time.h>
|
||||||
|
|
||||||
|
# include "ft_types.h"
|
||||||
|
# include "error.h"
|
||||||
|
# include "color.h"
|
||||||
|
# include "cliopts.h"
|
||||||
|
# include "rs.h"
|
||||||
|
|
||||||
|
# include "lst.h"
|
||||||
|
# include "dlst.h"
|
||||||
|
# include "btree.h"
|
||||||
|
|
||||||
|
# include "str.h"
|
||||||
|
# include "sstr.h"
|
||||||
|
# include "math.h"
|
||||||
|
# include "mytime.h"
|
||||||
|
# include "get_next_line.h"
|
||||||
|
# include "net.h"
|
||||||
|
# include "sys.h"
|
||||||
|
|
||||||
|
struct s_stos
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
char *val;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_stof
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
int (*f)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_itof
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
int (*f)();
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_printf(const char *format, ...);
|
||||||
|
int ft_dprintf(int fd, const char *format, ...);
|
||||||
|
int ft_vdprintf(int fd, const char *format, va_list ap);
|
||||||
|
int ft_asprintf(char **ret, const char *format, ...);
|
||||||
|
int ft_vasprintf(char **ret, const char *format, va_list ap);
|
||||||
|
|
||||||
|
void *ft_malloc(size_t size);
|
||||||
|
void *ft_memset(void *b, int c, size_t len);
|
||||||
|
void ft_bzero(void *s, size_t n);
|
||||||
|
void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||||
|
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
||||||
|
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||||
|
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_memalloc(size_t size);
|
||||||
|
void ft_memdel(void **ap);
|
||||||
|
|
||||||
|
int ft_putchar(int c);
|
||||||
|
int ft_putstr(char const *s);
|
||||||
|
int ft_putendl(char const *s);
|
||||||
|
int ft_putnbr(long n);
|
||||||
|
int ft_putnbr_hex(long n);
|
||||||
|
|
||||||
|
int ft_error_message(char *message);
|
||||||
|
|
||||||
|
int ft_putchar_fd(int c, int fd);
|
||||||
|
int ft_putstr_fd(char const *s, int fd);
|
||||||
|
int ft_putendl_fd(char const *s, int fd);
|
||||||
|
int ft_putnbr_fd(long n, int fd);
|
||||||
|
int ft_putnbr_hex_fd(long n, int fd);
|
||||||
|
|
||||||
|
void *hexdump(void *addr, uint32_t offset, uint32_t size, int swap);
|
||||||
|
void *hexdump_64(void *addr, uint64_t offset, uint64_t size, int swap);
|
||||||
|
|
||||||
|
void *hexdump_int(void *addr, uint32_t offset, uint32_t size, int swap);
|
||||||
|
void *hexdump_64_int(void *addr, uint64_t offset, uint64_t size, int swap);
|
||||||
|
|
||||||
|
void *ft_realloc(void *data, int size);
|
||||||
|
|
||||||
|
#endif
|
||||||
94
nm-otool/libft/includes/lst.h
Normal file
94
nm-otool/libft/includes/lst.h
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lst.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/20 20:01:20 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LST_H
|
||||||
|
# define LST_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
size_t content_size;
|
||||||
|
struct s_list *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_list t_list;
|
||||||
|
|
||||||
|
int pop(t_list **lst);
|
||||||
|
t_list *push(t_list **stack, int elem);
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||||
|
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||||
|
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||||
|
void ft_lstadd(t_list **alst, t_list *new);
|
||||||
|
int ft_lstiter(t_list *lst, int (*f)(), void *data);
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *));
|
||||||
|
|
||||||
|
t_list *ft_lstnew_range(int a, int b);
|
||||||
|
void ft_lsteadd(t_list **alst, t_list *new);
|
||||||
|
void ft_lstnadd(t_list **alst, t_list *new, int n);
|
||||||
|
void ft_lstsort(t_list **begin_list, int (*cmp)());
|
||||||
|
void ft_lst_print(t_list *list, void (*printer)());
|
||||||
|
int ft_lstsize(t_list *lst);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
void ft_lst_sorted_merge(
|
||||||
|
t_list **begin_list1,
|
||||||
|
t_list *begin_list2,
|
||||||
|
int (*cmp)());
|
||||||
|
void ft_lst_sorted_insert(
|
||||||
|
t_list **begin_list,
|
||||||
|
t_list *insert,
|
||||||
|
int (*cmp)());
|
||||||
|
void ft_lst_delif(
|
||||||
|
t_list **alist,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t));
|
||||||
|
void ft_lst_delsub(
|
||||||
|
t_list **alst,
|
||||||
|
t_list *sub, int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t));
|
||||||
|
void ft_lst_cfree(void *ptr, size_t size);
|
||||||
|
void ft_lst_bfree(void *ptr, size_t size);
|
||||||
|
t_list *ft_lst_filter(
|
||||||
|
t_list *lst,
|
||||||
|
void const *data_ref,
|
||||||
|
t_list *(*f)(t_list *elem, void const *));
|
||||||
|
t_list *ft_lst_removeif(
|
||||||
|
t_list **alst,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)());
|
||||||
|
t_list *ft_lst_find(
|
||||||
|
t_list *begin_list,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)());
|
||||||
|
t_list *ft_lstpop(t_list **lst);
|
||||||
|
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2);
|
||||||
|
void ft_lst_reverse(t_list **begin_list);
|
||||||
|
void ft_lst_filterout(
|
||||||
|
t_list **alst,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t));
|
||||||
|
|
||||||
|
int ft_diff(void *a, void *b);
|
||||||
|
t_list *ft_id(t_list *a);
|
||||||
|
t_list *ft_lst_at(t_list *list, unsigned int nbr);
|
||||||
|
|
||||||
|
void lst_insert_sort(t_list **head,
|
||||||
|
int (cmp)());
|
||||||
|
|
||||||
|
t_list *ft_lst_pop(t_list **lst);
|
||||||
|
char *ft_lst2str(t_list *list);
|
||||||
|
|
||||||
|
#endif
|
||||||
43
nm-otool/libft/includes/math.h
Normal file
43
nm-otool/libft/includes/math.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* math.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/11/01 11:53:22 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MATH_H
|
||||||
|
# define MATH_H
|
||||||
|
|
||||||
|
# define FT_WS(x) (x == ' ' || x == '\t' || x == '\n')
|
||||||
|
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
|
||||||
|
# define FT_NEG(x) ((x) < 0)
|
||||||
|
# define FT_POS(x) ((x) > 0)
|
||||||
|
# define FT_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
# define FT_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
# define FT_DIST(a, b) FT_ABS((a) - (b))
|
||||||
|
|
||||||
|
char *ft_itoa(int n);
|
||||||
|
char *ft_itoa_base(int nbr, char *base, char *flags);
|
||||||
|
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
||||||
|
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
||||||
|
char *ft_uitoa_base(unsigned int nbr, char *base);
|
||||||
|
size_t ft_ilen(int n);
|
||||||
|
size_t ft_ilen_base(int n, int base);
|
||||||
|
size_t ft_uilen(unsigned int n);
|
||||||
|
size_t ft_lllen(long long n);
|
||||||
|
size_t ft_lllen_base(long long n, int base);
|
||||||
|
|
||||||
|
int ft_addrcmp(void *a, void *b);
|
||||||
|
void *id(void *data);
|
||||||
|
|
||||||
|
uint8_t bswap_8(uint8_t x);
|
||||||
|
uint16_t bswap_16(uint16_t x);
|
||||||
|
uint32_t bswap_32(uint32_t x);
|
||||||
|
uint64_t bswap_64(uint64_t x);
|
||||||
|
|
||||||
|
#endif
|
||||||
37
nm-otool/libft/includes/mytime.h
Normal file
37
nm-otool/libft/includes/mytime.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mytime.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 11:43:12 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/02/18 13:11:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MYTIME_H
|
||||||
|
# define MYTIME_H
|
||||||
|
|
||||||
|
# include <sys/time.h>
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
struct s_mytime
|
||||||
|
{
|
||||||
|
char *year;
|
||||||
|
char *month;
|
||||||
|
char *day;
|
||||||
|
char *hour;
|
||||||
|
char *min;
|
||||||
|
char *sec;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_mytime t_mytime;
|
||||||
|
|
||||||
|
int ft_time_isrecent(time_t event);
|
||||||
|
t_mytime *ft_mytime_get(time_t epoch);
|
||||||
|
void ft_mytime_free(t_mytime **time);
|
||||||
|
size_t epoch_micro(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
47
nm-otool/libft/includes/net.h
Normal file
47
nm-otool/libft/includes/net.h
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* net.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/07 18:06:12 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/07 18:14:42 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef NET_H
|
||||||
|
# define NET_H
|
||||||
|
|
||||||
|
# define ACK 2
|
||||||
|
# define NACK 3
|
||||||
|
# define NET_MAXSIZE 512
|
||||||
|
|
||||||
|
# include <sys/socket.h>
|
||||||
|
# include <netdb.h>
|
||||||
|
# include <net/if.h>
|
||||||
|
# include <netinet/in.h>
|
||||||
|
# include <netinet/ip.h>
|
||||||
|
# include <netinet/tcp.h>
|
||||||
|
# include <netinet/ip_icmp.h>
|
||||||
|
# include <arpa/inet.h>
|
||||||
|
|
||||||
|
# include "mytime.h"
|
||||||
|
|
||||||
|
int create_server(int port, int backlog, char *protoname);
|
||||||
|
int create_client(char *addr, int port, char *protoname);
|
||||||
|
void listener(int domain, int sock, int proto,
|
||||||
|
void (*handler)(void *buf, int bytes, struct sockaddr_in *addr));
|
||||||
|
|
||||||
|
int net_send(int sock, char *msg, int size);
|
||||||
|
int net_send_large(int sock, char *msg, int size);
|
||||||
|
int net_get(int sock, char *msg, int size);
|
||||||
|
int net_get_fd(int sock, int fd, int size);
|
||||||
|
int net_get_large(int sock, int fd);
|
||||||
|
|
||||||
|
int reserve_port(int *port);
|
||||||
|
|
||||||
|
void tcphdr_init(struct tcphdr *header);
|
||||||
|
void iphdr_init(struct ip *header);
|
||||||
|
|
||||||
|
#endif
|
||||||
34
nm-otool/libft/includes/rs.h
Normal file
34
nm-otool/libft/includes/rs.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* rs.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/07 18:05:30 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/07 18:18:16 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_RS_H
|
||||||
|
# define LIBFT_RS_H
|
||||||
|
|
||||||
|
# include <float.h>
|
||||||
|
# include <dlfcn.h>
|
||||||
|
# include <math.h>
|
||||||
|
|
||||||
|
extern struct s_stats {
|
||||||
|
int count;
|
||||||
|
double min;
|
||||||
|
double max;
|
||||||
|
double avg;
|
||||||
|
double m;
|
||||||
|
double stdev;
|
||||||
|
double var;
|
||||||
|
} g_rs;
|
||||||
|
|
||||||
|
void rs_clear();
|
||||||
|
void rs_push(double n);
|
||||||
|
void rs_calcmore();
|
||||||
|
|
||||||
|
#endif
|
||||||
27
nm-otool/libft/includes/sstr.h
Normal file
27
nm-otool/libft/includes/sstr.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sstr.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/24 17:46:36 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef SSTR_H
|
||||||
|
# define SSTR_H
|
||||||
|
|
||||||
|
char **ft_sstradd(char **list, char *new);
|
||||||
|
void ft_sstrsort(char **list, int (*cmp)());
|
||||||
|
void ft_sstrprint(char **list, char sep);
|
||||||
|
void ft_sstrprint_fd(int fd, char **list, char sep);
|
||||||
|
char **ft_sstrdup(char **list);
|
||||||
|
char **ft_sstrmerge(char **s1, char **s2);
|
||||||
|
void ft_sstrdel(char **sstr, int index);
|
||||||
|
void ft_sstrfree(char **sstr);
|
||||||
|
char *ft_sstrcat(char **sstr, char sep);
|
||||||
|
char *ft_sstrstr(char **sstr, char *find);
|
||||||
|
|
||||||
|
#endif
|
||||||
78
nm-otool/libft/includes/str.h
Normal file
78
nm-otool/libft/includes/str.h
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* str.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/18 13:05:53 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 11:36:58 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef STR_H
|
||||||
|
# define STR_H
|
||||||
|
|
||||||
|
int ft_isalpha(int c);
|
||||||
|
int ft_isdigit(int c);
|
||||||
|
int ft_isalnum(int c);
|
||||||
|
int ft_isascii(int c);
|
||||||
|
int ft_isprint(int c);
|
||||||
|
int ft_toupper(int c);
|
||||||
|
int ft_tolower(int c);
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *s);
|
||||||
|
size_t ft_strlenchr(const char *s, char c);
|
||||||
|
char *ft_strdup(const char *s1);
|
||||||
|
char *ft_strdupchr(const char *str, char c);
|
||||||
|
char *ft_strduptr(char *str, int (*is)(int c));
|
||||||
|
char *ft_strcpy(char *dst, const char *src);
|
||||||
|
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||||
|
char *ft_strchrcpy(char *dst, const char *str, char c);
|
||||||
|
char *ft_strcat(char *s1, const char *s2);
|
||||||
|
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||||
|
char *ft_strchr(const char *s, int c);
|
||||||
|
char *ft_strrchr(const char *s, int c);
|
||||||
|
char *ft_strstr(const char *big, const char *little);
|
||||||
|
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||||
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
int ft_atoi(const char *str);
|
||||||
|
|
||||||
|
char *ft_strnew(size_t size);
|
||||||
|
void ft_strdel(char **as);
|
||||||
|
void ft_strclr(char *s);
|
||||||
|
void ft_striter(char *s, void (*f)(char *));
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||||
|
char *ft_strmap(char const *s, char (*f)(char));
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||||
|
int ft_strequ(char const *s1, char const *s2);
|
||||||
|
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||||
|
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
char *ft_strsepjoin(char **tab, char sep);
|
||||||
|
char *ft_strtrim(char const *s);
|
||||||
|
char **ft_strsplit(char const *s, char c);
|
||||||
|
|
||||||
|
char *ft_strrev(char *str);
|
||||||
|
char **ft_strsplit(char const *s, char c);
|
||||||
|
char *ft_str3join(char const *s1, char const *s2, char const *s3);
|
||||||
|
char *ft_strcut(char *str, char *cut);
|
||||||
|
char **ft_split_whitespaces(char const *str);
|
||||||
|
char *ft_convert_base(
|
||||||
|
char *str, char *base_from, char *base_to, char *flags);
|
||||||
|
char *ft_strcatf(char *s1, const char *s2);
|
||||||
|
char *ft_strinsert(char *str, char c, int n);
|
||||||
|
int ft_strappend(char **dst, char *src);
|
||||||
|
char *ft_strbetween(char *start, char *end);
|
||||||
|
char *ft_strreplace(char **str, char *start, char *end, char *new);
|
||||||
|
char *ft_strtok(char *s, const char *delim);
|
||||||
|
size_t ft_strcspn(char *s, const char *delim);
|
||||||
|
|
||||||
|
char *ft_path_notdir(char *path);
|
||||||
|
int ft_stris(char *str, int (*f)());
|
||||||
|
|
||||||
|
char *ft_strndup(const char *s1, size_t n);
|
||||||
|
|
||||||
|
#endif
|
||||||
32
nm-otool/libft/includes/sys.h
Normal file
32
nm-otool/libft/includes/sys.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sys.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/07 18:10:34 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef SYS_H
|
||||||
|
# define SYS_H
|
||||||
|
|
||||||
|
# define FT_XATTR_SIZE 10000
|
||||||
|
# define STDIN STDIN_FILENO
|
||||||
|
# define STDOUT STDOUT_FILENO
|
||||||
|
# define STDERR STDERR_FILENO
|
||||||
|
# define STDBUG 9
|
||||||
|
|
||||||
|
# define PIPE_READ 0
|
||||||
|
# define PIPE_WRITE 1
|
||||||
|
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/xattr.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
|
||||||
|
int open_new(char *filename, int oflag);
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
nm-otool/libft/pdf/ft_printf.pdf
Normal file
BIN
nm-otool/libft/pdf/ft_printf.pdf
Normal file
Binary file not shown.
BIN
nm-otool/libft/pdf/get_next_line.fr.pdf
Normal file
BIN
nm-otool/libft/pdf/get_next_line.fr.pdf
Normal file
Binary file not shown.
BIN
nm-otool/libft/pdf/libft.fr.pdf
Normal file
BIN
nm-otool/libft/pdf/libft.fr.pdf
Normal file
Binary file not shown.
46
nm-otool/libft/srcs/btree/btree_apply_by_level.c
Normal file
46
nm-otool/libft/srcs/btree/btree_apply_by_level.c
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_apply_by_level.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/14 17:25:46 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
int g_level = 0;
|
||||||
|
|
||||||
|
static void btree_apply_to_level(
|
||||||
|
t_btree *root,
|
||||||
|
int level,
|
||||||
|
int is_first_elem,
|
||||||
|
void (*applyf)(void *item, int current_level, int is_first_elem))
|
||||||
|
{
|
||||||
|
if (level == g_level)
|
||||||
|
{
|
||||||
|
(*applyf)(root->item, level, is_first_elem);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_to_level(root->left, level + 1, is_first_elem, applyf);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_to_level(root->right, level + 1, 0, applyf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void btree_apply_by_level(
|
||||||
|
t_btree *root,
|
||||||
|
void (*applyf)(void *item, int current_level, int is_first_elem))
|
||||||
|
{
|
||||||
|
int height;
|
||||||
|
|
||||||
|
height = btree_level_count(root);
|
||||||
|
while (g_level < height)
|
||||||
|
{
|
||||||
|
btree_apply_to_level(root, 0, 1, applyf);
|
||||||
|
g_level++;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
nm-otool/libft/srcs/btree/btree_apply_infix.c
Normal file
23
nm-otool/libft/srcs/btree/btree_apply_infix.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/06 18:22:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_apply_infix(t_btree *root, void (*applyf)(void *))
|
||||||
|
{
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_infix(root->left, applyf);
|
||||||
|
(*applyf)(root->item);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_infix(root->right, applyf);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
22
nm-otool/libft/srcs/btree/btree_apply_prefix.c
Normal file
22
nm-otool/libft/srcs/btree/btree_apply_prefix.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/18 21:06:44 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_apply_prefix(t_btree *root, void (*applyf)(void *))
|
||||||
|
{
|
||||||
|
(*applyf)(root->item);
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_prefix(root->left, applyf);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_prefix(root->right, applyf);
|
||||||
|
}
|
||||||
23
nm-otool/libft/srcs/btree/btree_apply_suffix.c
Normal file
23
nm-otool/libft/srcs/btree/btree_apply_suffix.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_apply_suffix.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/05 11:43:08 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/05 11:43:13 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_apply_suffix(t_btree *root, void (*applyf)(void *))
|
||||||
|
{
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_suffix(root->left, applyf);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_suffix(root->right, applyf);
|
||||||
|
(*applyf)(root->item);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
35
nm-otool/libft/srcs/btree/btree_create_node.c
Normal file
35
nm-otool/libft/srcs/btree/btree_create_node.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
t_btree *btree_create_node(void const *item, size_t content_size)
|
||||||
|
{
|
||||||
|
t_btree *new;
|
||||||
|
|
||||||
|
if (!(new = (t_btree *)ft_malloc(sizeof(t_btree))))
|
||||||
|
return (NULL);
|
||||||
|
new->left = 0;
|
||||||
|
new->right = 0;
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
new->content_size = 0;
|
||||||
|
new->item = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new->content_size = content_size;
|
||||||
|
new->item = ft_memalloc(content_size + 1);
|
||||||
|
ft_memcpy(new->item, item, content_size);
|
||||||
|
}
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
23
nm-otool/libft/srcs/btree/btree_del.c
Normal file
23
nm-otool/libft/srcs/btree/btree_del.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_del.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 19:43:51 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_del(t_btree **root, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (root && *root && del)
|
||||||
|
{
|
||||||
|
btree_del(&(*root)->left, del);
|
||||||
|
btree_del(&(*root)->right, del);
|
||||||
|
btree_delone(root, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
nm-otool/libft/srcs/btree/btree_delone.c
Normal file
24
nm-otool/libft/srcs/btree/btree_delone.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_delone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/05 11:45:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 12:48:55 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_delone(t_btree **root, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (root && *root)
|
||||||
|
{
|
||||||
|
if (del)
|
||||||
|
(*del)((*root)->item, (*root)->content_size);
|
||||||
|
free(*root);
|
||||||
|
*root = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
nm-otool/libft/srcs/btree/btree_insert_data.c
Normal file
43
nm-otool/libft/srcs/btree/btree_insert_data.c
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/14 16:12:47 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_insert_data(
|
||||||
|
t_btree **root,
|
||||||
|
void *item,
|
||||||
|
size_t content_size,
|
||||||
|
int (*cmpf)(void *, void *))
|
||||||
|
{
|
||||||
|
t_btree *node;
|
||||||
|
|
||||||
|
if (!*root)
|
||||||
|
{
|
||||||
|
*root = btree_create_node(item, content_size);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
node = *root;
|
||||||
|
if ((*cmpf)(item, node->item) < 0)
|
||||||
|
{
|
||||||
|
if (node->left)
|
||||||
|
btree_insert_data(&node->left, item, content_size, cmpf);
|
||||||
|
else
|
||||||
|
node->left = btree_create_node(item, content_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (node->right)
|
||||||
|
btree_insert_data(&node->right, item, content_size, cmpf);
|
||||||
|
else
|
||||||
|
node->right = btree_create_node(item, content_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
nm-otool/libft/srcs/btree/btree_level_count.c
Normal file
21
nm-otool/libft/srcs/btree/btree_level_count.c
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/25 17:46:00 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
int btree_level_count(t_btree *root)
|
||||||
|
{
|
||||||
|
return (root
|
||||||
|
? 1 + FT_MAX(btree_level_count(root->left),
|
||||||
|
btree_level_count(root->right))
|
||||||
|
: 0);
|
||||||
|
}
|
||||||
27
nm-otool/libft/srcs/btree/btree_map.c
Normal file
27
nm-otool/libft/srcs/btree/btree_map.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_map.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/24 15:49:42 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
t_btree *btree_map(t_btree *root, void *(*f)(void *))
|
||||||
|
{
|
||||||
|
t_btree *new;
|
||||||
|
|
||||||
|
if (!root)
|
||||||
|
return (NULL);
|
||||||
|
if (!(new = (t_btree *)ft_malloc(sizeof(*new))))
|
||||||
|
return (NULL);
|
||||||
|
new->item = (*f)(root->item);
|
||||||
|
new->left = btree_map(root->left, f);
|
||||||
|
new->right = btree_map(root->right, f);
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
82
nm-otool/libft/srcs/btree/btree_print.c
Normal file
82
nm-otool/libft/srcs/btree/btree_print.c
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/15 19:08:35 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
static int print_t2(t_printdata data, char s[20][255], char b[20])
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
width = 5;
|
||||||
|
i = -1;
|
||||||
|
while (++i < width)
|
||||||
|
s[2 * data.depth][data.offset + data.left + i] = b[i];
|
||||||
|
i = -1;
|
||||||
|
if (data.depth && data.is_left)
|
||||||
|
{
|
||||||
|
while (++i < width + data.right)
|
||||||
|
s[2 * data.depth - 1]
|
||||||
|
[data.offset + data.left + width / 2 + i] = '-';
|
||||||
|
s[2 * data.depth - 1][data.offset + data.left + width / 2] = '+';
|
||||||
|
s[2 * data.depth - 1]
|
||||||
|
[data.offset + data.left + data.right + 3 * width / 2] = '+';
|
||||||
|
}
|
||||||
|
else if (data.depth && !data.is_left)
|
||||||
|
{
|
||||||
|
while (++i < width + data.left)
|
||||||
|
s[2 * data.depth - 1][data.offset - width / 2 + i] = '-';
|
||||||
|
s[2 * data.depth - 1][data.offset + data.left + width / 2] = '+';
|
||||||
|
s[2 * data.depth - 1][data.offset - width / 2 - 1] = '+';
|
||||||
|
}
|
||||||
|
return (data.left + width + data.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int print_t(t_btree *tree,
|
||||||
|
t_printdata data, char s[20][255], char *(*printer)(void *))
|
||||||
|
{
|
||||||
|
char b[20];
|
||||||
|
int width;
|
||||||
|
|
||||||
|
width = 5;
|
||||||
|
if (!tree)
|
||||||
|
return (0);
|
||||||
|
sprintf(b, "%5s", printer(tree->item));
|
||||||
|
data.left = print_t(tree->left, (t_printdata){
|
||||||
|
1, data.offset, data.depth + 1, data.left, data.right}, s, printer);
|
||||||
|
data.right = print_t(tree->right, (t_printdata){
|
||||||
|
0, data.offset + data.left + width, data.depth + 1,
|
||||||
|
data.left, data.right}, s, printer);
|
||||||
|
return (print_t2(data, s, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
void btree_print(int fd, t_btree *tree, char *(*printer)(void *))
|
||||||
|
{
|
||||||
|
char s[20][255];
|
||||||
|
char empty[255];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (++i < 20)
|
||||||
|
sprintf(s[i], "%80s", " ");
|
||||||
|
sprintf(empty, "%80s", " ");
|
||||||
|
print_t(tree, (t_printdata){0, 0, 0, 0, 0}, s, printer);
|
||||||
|
i = -1;
|
||||||
|
while (++i < 20)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(s[i], empty) == 0)
|
||||||
|
break ;
|
||||||
|
if (i == 0 && ft_strcmp(s[1], empty) == 0)
|
||||||
|
break ;
|
||||||
|
ft_dprintf(fd, "%s\n", s[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
nm-otool/libft/srcs/btree/btree_search_item.c
Normal file
30
nm-otool/libft/srcs/btree/btree_search_item.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/23 19:04:56 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void *btree_search_item(t_btree *root,
|
||||||
|
void *data_ref, int (*cmpf)(void *, void *))
|
||||||
|
{
|
||||||
|
void *out;
|
||||||
|
|
||||||
|
out = NULL;
|
||||||
|
if (root)
|
||||||
|
{
|
||||||
|
out = btree_search_item(root->left, data_ref, cmpf);
|
||||||
|
if (!out && ((*cmpf)(root->item, data_ref) == 0))
|
||||||
|
out = root->item;
|
||||||
|
if (!out)
|
||||||
|
out = btree_search_item(root->right, data_ref, cmpf);
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
22
nm-otool/libft/srcs/char/ft_isalnum.c
Normal file
22
nm-otool/libft/srcs/char/ft_isalnum.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:31:33 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalnum(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 'a' && c <= 'z')
|
||||||
|
|| (c >= 'A' && c <= 'Z')
|
||||||
|
|| (c >= '0' && c <= '9'))
|
||||||
|
return (c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/char/ft_isalpha.c
Normal file
20
nm-otool/libft/srcs/char/ft_isalpha.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 11:59:16 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalpha(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||||
|
return (c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/char/ft_isascii.c
Normal file
20
nm-otool/libft/srcs/char/ft_isascii.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:28 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:35:42 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isascii(int c)
|
||||||
|
{
|
||||||
|
if (c >= 0 && c <= 127)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
23
nm-otool/libft/srcs/char/ft_isdigit.c
Normal file
23
nm-otool/libft/srcs/char/ft_isdigit.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:33 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 14:56:34 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isdigit(int c)
|
||||||
|
{
|
||||||
|
unsigned char a;
|
||||||
|
|
||||||
|
a = (unsigned char)c;
|
||||||
|
if (a >= '0' && a <= '9')
|
||||||
|
return (a);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/char/ft_isprint.c
Normal file
20
nm-otool/libft/srcs/char/ft_isprint.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isprint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:38 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:32:40 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isprint(int c)
|
||||||
|
{
|
||||||
|
if (c >= 32 && c <= 126)
|
||||||
|
return (c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/char/ft_tolower.c
Normal file
20
nm-otool/libft/srcs/char/ft_tolower.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tolower.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:58:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:24:09 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_tolower(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'A' && c <= 'Z')
|
||||||
|
return (c + 32);
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/char/ft_toupper.c
Normal file
20
nm-otool/libft/srcs/char/ft_toupper.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_toupper.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:53:58 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:24:40 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_toupper(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'a' && c <= 'z')
|
||||||
|
return (c - 32);
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
110
nm-otool/libft/srcs/cliopts/cliopts_get.c
Normal file
110
nm-otool/libft/srcs/cliopts/cliopts_get.c
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cliopts_get.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/04/02 20:45:11 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** void *data must be a structure starting with `int flag`
|
||||||
|
** to do polymorphism with t_data_template !
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cliopts.h"
|
||||||
|
|
||||||
|
static char *check_required(char ***av, char *arg)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
if (!av || !*av)
|
||||||
|
return (NULL);
|
||||||
|
if (!arg || !*arg || !*(arg + 1))
|
||||||
|
return (*++(*av));
|
||||||
|
ret = arg + 1;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cliopts_parse_short(
|
||||||
|
char ***av, t_cliopts opt_map[], void *data)
|
||||||
|
{
|
||||||
|
t_cliopts *map;
|
||||||
|
char *arg;
|
||||||
|
int i;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
arg = **av + 1;
|
||||||
|
i = -1;
|
||||||
|
while (arg[++i] && !(tmp = NULL))
|
||||||
|
{
|
||||||
|
if (!(map = cliopts_getmap_short(opt_map, arg[i])))
|
||||||
|
return (ERR_SET(E_CO_INV, arg[i]));
|
||||||
|
((t_data_template*)data)->flag |= map->flag_on;
|
||||||
|
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||||
|
if (map->get)
|
||||||
|
{
|
||||||
|
if (map->arg_required && !(tmp = check_required(av, arg + i)))
|
||||||
|
return (ERR_SET(E_CO_MISS, *arg));
|
||||||
|
tmp = tmp ? tmp : **av;
|
||||||
|
if ((map->get)(tmp, data))
|
||||||
|
return (ERR_SET(E_CO_MISS, *arg));
|
||||||
|
if (map->arg_required)
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (++(*av) ? 0 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cliopts_parse_long(
|
||||||
|
char ***av, t_cliopts opt_map[], void *data)
|
||||||
|
{
|
||||||
|
t_cliopts *map;
|
||||||
|
char *arg;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
arg = **av + 2;
|
||||||
|
tmp = NULL;
|
||||||
|
if (!(map = cliopts_getmap_long(opt_map, arg)))
|
||||||
|
return (ERR_SET(E_CO_INVL, arg));
|
||||||
|
((t_data_template*)data)->flag |= map->flag_on;
|
||||||
|
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||||
|
if (map->get)
|
||||||
|
{
|
||||||
|
if (map->arg_required && !(tmp = check_required(av, NULL)))
|
||||||
|
return (ERR_SET(E_CO_MISS, *arg));
|
||||||
|
if ((map->get)(tmp, data))
|
||||||
|
return (ERR_SET(E_CO_MISSL, arg));
|
||||||
|
}
|
||||||
|
++(*av);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cliopts_get(char **av, t_cliopts opt_map[], void *data)
|
||||||
|
{
|
||||||
|
if (!av)
|
||||||
|
return (1);
|
||||||
|
av++;
|
||||||
|
while (av && *av)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(*av, "-") == 0 || (ft_strcmp(*av, "--") == 0 && av++))
|
||||||
|
break ;
|
||||||
|
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
||||||
|
{
|
||||||
|
if (cliopts_parse_long(&av, opt_map, data))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else if ((*av)[0] == '-')
|
||||||
|
{
|
||||||
|
if (cliopts_parse_short(&av, opt_map, data))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
((t_data_template*)data)->av_data = av;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
35
nm-otool/libft/srcs/cliopts/cliopts_getmap.c
Normal file
35
nm-otool/libft/srcs/cliopts/cliopts_getmap.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cliopts_getmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/25 14:59:03 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 15:01:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cliopts.h"
|
||||||
|
|
||||||
|
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (opt_map[++i].c)
|
||||||
|
if (!ft_strcmp(opt_map[i].str, arg))
|
||||||
|
return (&opt_map[i]);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (opt_map[++i].c)
|
||||||
|
if (opt_map[i].c == arg)
|
||||||
|
return (&opt_map[i]);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
19
nm-otool/libft/srcs/color/ft_color_mk.c
Normal file
19
nm-otool/libft/srcs/color/ft_color_mk.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_mk.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/12 11:54:49 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_mk(t_color *color, char fg[7], char bg[7])
|
||||||
|
{
|
||||||
|
ft_strcpy(color->fg, fg);
|
||||||
|
ft_strcpy(color->bg, bg);
|
||||||
|
}
|
||||||
19
nm-otool/libft/srcs/color/ft_color_mkif.c
Normal file
19
nm-otool/libft/srcs/color/ft_color_mkif.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_mk.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/03 12:17:14 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7])
|
||||||
|
{
|
||||||
|
if (cond)
|
||||||
|
ft_color_mk(color, fg, bg);
|
||||||
|
}
|
||||||
19
nm-otool/libft/srcs/color/ft_color_reset.c
Normal file
19
nm-otool/libft/srcs/color/ft_color_reset.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_reset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 13:48:05 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/25 14:06:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_reset(void)
|
||||||
|
{
|
||||||
|
ft_putstr(FG_DEFAULT);
|
||||||
|
ft_putstr(BG_DEFAULT);
|
||||||
|
}
|
||||||
22
nm-otool/libft/srcs/color/ft_color_set.c
Normal file
22
nm-otool/libft/srcs/color/ft_color_set.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_set.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 13:53:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/12 11:55:03 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_set(t_color color)
|
||||||
|
{
|
||||||
|
char out[20];
|
||||||
|
|
||||||
|
ft_strcpy(out, color.fg);
|
||||||
|
ft_strcat(out, color.bg);
|
||||||
|
ft_putstr(out);
|
||||||
|
}
|
||||||
30
nm-otool/libft/srcs/dlst/ft_dlstadd_after.c
Normal file
30
nm-otool/libft/srcs/dlst/ft_dlstadd_after.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_add_after.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:36 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_dlstadd_after(t_dlist **alst, t_dlist *new)
|
||||||
|
{
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
new->prev = (*alst);
|
||||||
|
if (*alst)
|
||||||
|
new->next = (*alst)->next;
|
||||||
|
else
|
||||||
|
new->next = NULL;
|
||||||
|
if (new->next)
|
||||||
|
new->next->prev = new;
|
||||||
|
if (new->prev)
|
||||||
|
new->prev->next = new;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
nm-otool/libft/srcs/dlst/ft_dlstadd_before.c
Normal file
28
nm-otool/libft/srcs/dlst/ft_dlstadd_before.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_add_before.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:09 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_dlstadd_before(t_dlist **alst, t_dlist *new)
|
||||||
|
{
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
new->next = (*alst);
|
||||||
|
if (*alst)
|
||||||
|
new->prev = (*alst)->prev;
|
||||||
|
if (new->next)
|
||||||
|
new->next->prev = new;
|
||||||
|
if (new->prev)
|
||||||
|
new->prev->next = new;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
nm-otool/libft/srcs/dlst/ft_dlstdel.c
Normal file
41
nm-otool/libft/srcs/dlst/ft_dlstdel.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlstdel.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/07 17:29:54 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static void ft_dlstdelback(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (alst && *alst && del)
|
||||||
|
{
|
||||||
|
ft_dlstdelback(&(*alst)->prev, del);
|
||||||
|
ft_dlstdelone(alst, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_dlstdelfront(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (alst && *alst && del)
|
||||||
|
{
|
||||||
|
ft_dlstdelfront(&(*alst)->next, del);
|
||||||
|
ft_dlstdelone(alst, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (alst && *alst && del)
|
||||||
|
{
|
||||||
|
ft_dlstdelback(&(*alst)->prev, del);
|
||||||
|
ft_dlstdelfront(&(*alst)->next, del);
|
||||||
|
ft_dlstdelone(alst, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
nm-otool/libft/srcs/dlst/ft_dlstdelone.c
Normal file
34
nm-otool/libft/srcs/dlst/ft_dlstdelone.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_delone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:13 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/14 17:52:58 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_dlist *tmp;
|
||||||
|
|
||||||
|
tmp = *alst;
|
||||||
|
if (tmp)
|
||||||
|
{
|
||||||
|
if (del)
|
||||||
|
(*del)(tmp->content, tmp->content_size);
|
||||||
|
if (tmp->next)
|
||||||
|
tmp->next->prev = tmp->prev;
|
||||||
|
if (tmp->prev)
|
||||||
|
tmp->prev->next = tmp->next;
|
||||||
|
if (tmp->prev)
|
||||||
|
*alst = tmp->prev;
|
||||||
|
else
|
||||||
|
*alst = tmp->next;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/dlst/ft_dlstlast.c
Normal file
20
nm-otool/libft/srcs/dlst/ft_dlstlast.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_last.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:15 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_dlist *ft_dlstlast(t_dlist *list)
|
||||||
|
{
|
||||||
|
while (list && list->next)
|
||||||
|
list = list->next;
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
39
nm-otool/libft/srcs/dlst/ft_dlstnew.c
Normal file
39
nm-otool/libft/srcs/dlst/ft_dlstnew.c
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_new.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_dlist *ft_dlstnew(void const *content, size_t content_size)
|
||||||
|
{
|
||||||
|
t_dlist *new;
|
||||||
|
|
||||||
|
if (!content)
|
||||||
|
{
|
||||||
|
new = ft_malloc(sizeof(*new));
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
new->content_size = 0;
|
||||||
|
new->content = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new = (t_dlist *)ft_malloc(sizeof(*new));
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
new->content_size = content_size;
|
||||||
|
new->content = ft_memalloc(content_size + 1);
|
||||||
|
ft_memcpy(new->content, content, content_size);
|
||||||
|
}
|
||||||
|
new->next = NULL;
|
||||||
|
new->prev = NULL;
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
30
nm-otool/libft/srcs/dlst/ft_dlstrtostr.c
Normal file
30
nm-otool/libft/srcs/dlst/ft_dlstrtostr.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlstrtostr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:29 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/14 16:13:24 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_dlsttostr(t_dlist *list)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return (NULL);
|
||||||
|
while (list->prev)
|
||||||
|
list = list->prev;
|
||||||
|
str = (char *)ft_strnew(sizeof(char) * (ft_dlstsize(list) + 2));
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
ft_strcat(str, (char *)list->content);
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
36
nm-otool/libft/srcs/dlst/ft_dlstsize.c
Normal file
36
nm-otool/libft/srcs/dlst/ft_dlstsize.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_size.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:23 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:23 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_dlstsize(t_dlist *list)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
t_dlist *tmp;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
if (list)
|
||||||
|
size++;
|
||||||
|
tmp = list;
|
||||||
|
while (tmp->next)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
tmp = list;
|
||||||
|
while (tmp->prev)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
tmp = tmp->prev;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
48
nm-otool/libft/srcs/error/error.c
Normal file
48
nm-otool/libft/srcs/error/error.c
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 01:53:25 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] =
|
||||||
|
{
|
||||||
|
"unknown error 0",
|
||||||
|
"invalid option -%c",
|
||||||
|
"invalid option --%s",
|
||||||
|
"option '%c' awaits argument(s): please don't combine",
|
||||||
|
"option '%c': missing argument",
|
||||||
|
"option '%s': missing argument",
|
||||||
|
"%s: no such file or directory",
|
||||||
|
"%s: Is a directory",
|
||||||
|
"%s: Permission denied",
|
||||||
|
};
|
||||||
|
|
||||||
|
int g_errnum = 0;
|
||||||
|
char *g_errmsg = NULL;
|
||||||
|
char **g_argv;
|
||||||
|
|
||||||
|
int error_set(int n, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
g_errnum = n;
|
||||||
|
va_start(ap, n);
|
||||||
|
ft_strdel(&g_errmsg);
|
||||||
|
ft_vasprintf(&g_errmsg, g_error_msglist[n], ap);
|
||||||
|
return (g_errnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_perror(char *utility)
|
||||||
|
{
|
||||||
|
utility = utility ? utility : g_argv[0];
|
||||||
|
ERR_MSG(utility, g_errmsg);
|
||||||
|
return (g_errnum);
|
||||||
|
}
|
||||||
26
nm-otool/libft/srcs/error/ft_usage.c
Normal file
26
nm-otool/libft/srcs/error/ft_usage.c
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_usage.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/04/02 15:08:56 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/04/02 20:05:28 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_usage(char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *usage;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
usage = NULL;
|
||||||
|
ft_vasprintf(&usage, format, ap);
|
||||||
|
ft_dprintf(2, "usage: %s\n", usage);
|
||||||
|
ft_strdel(&usage);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
69
nm-otool/libft/srcs/ft_printf/ft_conversion.c
Normal file
69
nm-otool/libft/srcs/ft_printf/ft_conversion.c
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_conversion.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
static char base10[] = "0123456789";
|
||||||
|
long long arg;
|
||||||
|
|
||||||
|
arg = va_arg(ap, int);
|
||||||
|
(void)fmt;
|
||||||
|
return (ft_lltoa_base(arg, base10, fmt->flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_unsigned_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
unsigned int uiarg;
|
||||||
|
unsigned long long ullarg;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
if (!*fmt->modifier
|
||||||
|
|| ft_strequ(fmt->modifier, "hh")
|
||||||
|
|| ft_strequ(fmt->modifier, "h")
|
||||||
|
|| ft_strequ(fmt->modifier, "z"))
|
||||||
|
{
|
||||||
|
uiarg = va_arg(ap, int);
|
||||||
|
return (ft_uitoa_base(uiarg, g_convs[i].base));
|
||||||
|
}
|
||||||
|
ullarg = va_arg(ap, long long);
|
||||||
|
return (ft_ulltoa_base(ullarg, g_convs[i].base));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_char_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
(void)fmt;
|
||||||
|
ret = (char *)ft_malloc(sizeof(char) + 1);
|
||||||
|
ret[0] = (char)va_arg(ap, int);
|
||||||
|
ret[1] = '\0';
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_str_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
(void)fmt;
|
||||||
|
ret = va_arg(ap, char *);
|
||||||
|
if (ret == NULL)
|
||||||
|
return (ft_strdup("NULL"));
|
||||||
|
ret = ft_strdup(ret);
|
||||||
|
if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
|
||||||
|
ret[fmt->precision] = '\0';
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
31
nm-otool/libft/srcs/ft_printf/ft_fmt_simplify.c
Normal file
31
nm-otool/libft/srcs/ft_printf/ft_fmt_simplify.c
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt_validate.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:53:54 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_simplify(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char hashtag;
|
||||||
|
|
||||||
|
hashtag = '#';
|
||||||
|
if (fmt->conversion == 'p')
|
||||||
|
{
|
||||||
|
fmt->conversion = 'x';
|
||||||
|
if (!ft_strchr(fmt->flags, '#'))
|
||||||
|
ft_strncat(fmt->flags, &hashtag, 1);
|
||||||
|
}
|
||||||
|
if (ft_strchr("DOUCS", fmt->conversion))
|
||||||
|
{
|
||||||
|
fmt->conversion += 32;
|
||||||
|
ft_strcpy(fmt->modifier, "l");
|
||||||
|
}
|
||||||
|
}
|
||||||
24
nm-otool/libft/srcs/ft_printf/ft_fmt_validate_conv.c
Normal file
24
nm-otool/libft/srcs/ft_printf/ft_fmt_validate_conv.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:55:36 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:55:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_fmt_validate_conv(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion))
|
||||||
|
{
|
||||||
|
if (fmt->conversion != '%')
|
||||||
|
ft_fmt_error_conv(fmt->conversion);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
60
nm-otool/libft/srcs/ft_printf/ft_fmt_validate_flags.c
Normal file
60
nm-otool/libft/srcs/ft_printf/ft_fmt_validate_flags.c
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_flags.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/05 15:19:35 by wescande ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
static void ft_fmt_validate_flag_flag(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char *flag_ptr;
|
||||||
|
|
||||||
|
if (ft_strchr(fmt->flags, '+') && (flag_ptr = ft_strchr(fmt->flags, ' ')))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_flag(' ', '+');
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
if (ft_strchr(fmt->flags, '-') && (flag_ptr = ft_strchr(fmt->flags, '0')))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_flag('0', '-');
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
if (fmt->precision && (flag_ptr = ft_strchr(fmt->flags, '0')))
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_fmt_validate_flag_conv(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char *flag_ptr;
|
||||||
|
char flag;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
flag_ptr = fmt->flags;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
while (*flag_ptr)
|
||||||
|
{
|
||||||
|
flag = *flag_ptr;
|
||||||
|
if (!ft_strchr(g_convs[i].allowed_flags, flag))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_conv(flag, fmt->conversion);
|
||||||
|
if (flag == '#')
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
flag_ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_validate_flags(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
ft_fmt_validate_flag_conv(fmt);
|
||||||
|
ft_fmt_validate_flag_flag(fmt);
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/ft_printf/ft_fmt_validate_mod.c
Normal file
20
nm-otool/libft/srcs/ft_printf/ft_fmt_validate_mod.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:53:42 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:53:52 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_validate_mod(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (fmt->conversion == 's' || fmt->conversion == 'c')
|
||||||
|
if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l"))
|
||||||
|
ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion);
|
||||||
|
}
|
||||||
37
nm-otool/libft/srcs/ft_printf/ft_printf.c
Normal file
37
nm-otool/libft/srcs/ft_printf/ft_printf.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/04/02 15:22:13 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_printf(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
return (ft_vdprintf(1, format, ap));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_dprintf(int fd, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
return (ft_vdprintf(fd, format, ap));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_asprintf(char **ret, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
return (ft_vasprintf(ret, format, ap));
|
||||||
|
}
|
||||||
53
nm-otool/libft/srcs/ft_printf/ft_printf_color.c
Normal file
53
nm-otool/libft/srcs/ft_printf/ft_printf_color.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf_color.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_stos g_colors[] =
|
||||||
|
{
|
||||||
|
{"{red}", FG_RED},
|
||||||
|
{"{gre}", FG_GREEN},
|
||||||
|
{"{yel}", FG_YELLOW},
|
||||||
|
{"{blu}", FG_BLUE},
|
||||||
|
{"{mag}", FG_MAGENTA},
|
||||||
|
{"{cya}", FG_CYAN},
|
||||||
|
{"{bla}", FG_BLACK},
|
||||||
|
{"{eoc}", FG_DEFAULT},
|
||||||
|
{"{bol}", ON_BOLD},
|
||||||
|
{"{und}", ON_UNDERLINED},
|
||||||
|
{"{inv}", ON_INVERTED},
|
||||||
|
{NULL, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
void ft_printf_color(char **final, char **str, va_list ap)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (ft_strncmp(*str, "{ran}", 5) == 0)
|
||||||
|
{
|
||||||
|
i = va_arg(ap, int) % 6;
|
||||||
|
*final = ft_strjoin(*final, g_colors[i].val);
|
||||||
|
*str += 5;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
while (g_colors[i].key)
|
||||||
|
{
|
||||||
|
if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
|
||||||
|
{
|
||||||
|
*final = ft_strjoin(*final, g_colors[i].val);
|
||||||
|
*str += 5;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
123
nm-otool/libft/srcs/ft_printf/ft_printf_parse.c
Normal file
123
nm-otool/libft/srcs/ft_printf/ft_printf_parse.c
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_parse.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
static void ft_printf_parse_flags(t_fmt *fmt, char **format)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = *format;
|
||||||
|
while (str[i])
|
||||||
|
{
|
||||||
|
if (ft_strchr(ALL_FLAGS, (int)str[i]))
|
||||||
|
{
|
||||||
|
if (!ft_strchr(fmt->flags, (int)str[i]))
|
||||||
|
ft_strncat(fmt->flags, str + i, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
*format += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buf[10];
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = *format;
|
||||||
|
if (str[i] == '*')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
fmt->width = va_arg(ap, int);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_strcpy(buf, "0");
|
||||||
|
while (ft_isdigit((int)(str[i])))
|
||||||
|
ft_strncat(buf, str + i++, 1);
|
||||||
|
fmt->width = ft_atoi(buf);
|
||||||
|
}
|
||||||
|
*format += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buf[10];
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = *format;
|
||||||
|
if (str[i] == '.')
|
||||||
|
{
|
||||||
|
if (str[++i] == '*')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
fmt->precision = va_arg(ap, int);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_strcpy(buf, "0");
|
||||||
|
while (ft_isdigit(str[i]))
|
||||||
|
ft_strncat(buf, str + i++, 1);
|
||||||
|
fmt->precision = ft_atoi(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*format += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_printf_parse_modifiers(t_fmt *fmt, char **format)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = *format;
|
||||||
|
if (str[0] == 'h' && str[1] == 'h')
|
||||||
|
ft_strcpy(fmt->modifier, "hh");
|
||||||
|
else if (str[0] == 'h' && str[1] != 'h')
|
||||||
|
ft_strcpy(fmt->modifier, "h");
|
||||||
|
else if (str[0] == 'l' && str[1] == 'l')
|
||||||
|
ft_strcpy(fmt->modifier, "ll");
|
||||||
|
else if (str[0] == 'l' && str[1] != 'l')
|
||||||
|
ft_strcpy(fmt->modifier, "l");
|
||||||
|
else if (str[0] == 'j')
|
||||||
|
ft_strcpy(fmt->modifier, "j");
|
||||||
|
else if (str[0] == 'z')
|
||||||
|
ft_strcpy(fmt->modifier, "z");
|
||||||
|
else
|
||||||
|
ft_strcpy(fmt->modifier, "");
|
||||||
|
*format += ft_strlen(fmt->modifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_fmt *ft_printf_parse(char **format, va_list ap)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
|
||||||
|
fmt = ft_fmt_init();
|
||||||
|
ft_printf_parse_flags(fmt, format);
|
||||||
|
ft_printf_parse_width(fmt, format, ap);
|
||||||
|
ft_printf_parse_precision(fmt, format, ap);
|
||||||
|
ft_printf_parse_modifiers(fmt, format);
|
||||||
|
fmt->conversion = **format;
|
||||||
|
(*format)++;
|
||||||
|
ft_fmt_validate_mod(fmt);
|
||||||
|
ft_fmt_validate_flags(fmt);
|
||||||
|
ft_fmt_simplify(fmt);
|
||||||
|
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
|
||||||
|
return (fmt);
|
||||||
|
}
|
||||||
34
nm-otool/libft/srcs/ft_printf/ft_transform.c
Normal file
34
nm-otool/libft/srcs/ft_printf/ft_transform.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_transform.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 10:26:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
char *ft_transform(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
fmt->conv = g_convs[i];
|
||||||
|
ret = (*fmt->conv.converter)(fmt, ap);
|
||||||
|
if (fmt->width > (int)ft_strlen(ret))
|
||||||
|
ret = ft_realloc(ret, fmt->width + 5);
|
||||||
|
else
|
||||||
|
ret = ft_realloc(ret, ft_strlen(ret) + 3);
|
||||||
|
if (ft_strchr(fmt->flags, '-'))
|
||||||
|
ft_pad_right(ret, fmt);
|
||||||
|
else
|
||||||
|
ft_pad_left(ret, fmt);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
85
nm-otool/libft/srcs/ft_printf/ft_vprintf.c
Normal file
85
nm-otool/libft/srcs/ft_printf/ft_vprintf.c
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_vprintf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/04/02 15:22:20 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_conv g_convs[] =
|
||||||
|
{
|
||||||
|
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
||||||
|
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
||||||
|
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
|
||||||
|
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
|
||||||
|
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'s', "-", "", &ft_str_conversion, NULL},
|
||||||
|
{'c', "-", "", &ft_char_conversion, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_vdprintf(int fd, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
char size;
|
||||||
|
|
||||||
|
ret = NULL;
|
||||||
|
size = ft_vasprintf(&ret, format, ap);
|
||||||
|
if (size != -1)
|
||||||
|
ft_putstr_fd(ret, fd);
|
||||||
|
ft_strdel(&ret);
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_vasprintf(char **ret, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
char *tmp;
|
||||||
|
char *final;
|
||||||
|
|
||||||
|
str = (char *)format;
|
||||||
|
final = ft_strnew(1);
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
tmp = final;
|
||||||
|
if (*str == '{')
|
||||||
|
ft_printf_color(&final, &str, ap);
|
||||||
|
else if (*str == '%')
|
||||||
|
{
|
||||||
|
if (ft_fmtcalc(&final, &str, ap))
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
else if (!(final = ft_strjoin(final, (char[]){*str++, 0})))
|
||||||
|
return (-1);
|
||||||
|
ft_strdel(&tmp);
|
||||||
|
}
|
||||||
|
*ret = final;
|
||||||
|
return (ft_strlen(final));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_fmtcalc(char **final, char **str, va_list ap)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
char *transform;
|
||||||
|
|
||||||
|
*str += 1;
|
||||||
|
if (!(fmt = ft_printf_parse(str, ap)))
|
||||||
|
return (1);
|
||||||
|
if (!fmt->valid)
|
||||||
|
ft_strncat(*final, &fmt->conversion, 1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transform = ft_transform(fmt, ap);
|
||||||
|
*final = ft_strjoin(*final, transform);
|
||||||
|
ft_strdel(&transform);
|
||||||
|
}
|
||||||
|
free(fmt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
49
nm-otool/libft/srcs/ft_printf/lib_fmt.c
Normal file
49
nm-otool/libft/srcs/ft_printf/lib_fmt.c
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_fmt *ft_fmt_init(void)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
|
||||||
|
fmt = (t_fmt *)ft_malloc(sizeof(t_fmt) + 1);
|
||||||
|
ft_bzero(fmt->flags, 6);
|
||||||
|
ft_bzero(fmt->modifier, 3);
|
||||||
|
fmt->conversion = '\0';
|
||||||
|
fmt->width = 0;
|
||||||
|
fmt->precision = 0;
|
||||||
|
fmt->valid = 0;
|
||||||
|
return (fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_print(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
ft_putendl("\n---");
|
||||||
|
ft_putstr("valid: ");
|
||||||
|
ft_putnbr(fmt->valid);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("conv.: ");
|
||||||
|
ft_putchar(fmt->conversion);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("flags: ");
|
||||||
|
ft_putendl(fmt->flags);
|
||||||
|
ft_putstr("width: ");
|
||||||
|
ft_putnbr(fmt->width);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("prec.: ");
|
||||||
|
ft_putnbr(fmt->precision);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("modifier: ");
|
||||||
|
ft_putendl(fmt->modifier);
|
||||||
|
ft_putendl("---");
|
||||||
|
}
|
||||||
47
nm-otool/libft/srcs/ft_printf/lib_fmt_error.c
Normal file
47
nm-otool/libft/srcs/ft_printf/lib_fmt_error.c
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt_error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:38 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 17:22:41 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_error_conv(char conv)
|
||||||
|
{
|
||||||
|
ft_putstr("Warning: invalid or unsupported conversion specifier '");
|
||||||
|
ft_putchar(conv);
|
||||||
|
ft_putendl("'");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_error_mod_conv(char *mod, char conv)
|
||||||
|
{
|
||||||
|
ft_putstr("warning: length modifier '");
|
||||||
|
ft_putstr(mod);
|
||||||
|
ft_putstr("' results in undefined behaviour or no effect with '");
|
||||||
|
ft_putchar(conv);
|
||||||
|
ft_putendl("' conversion specifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_error_flag_conv(char flag, char conv)
|
||||||
|
{
|
||||||
|
ft_putstr("warning: flag '");
|
||||||
|
ft_putchar(flag);
|
||||||
|
ft_putstr("' results in undefined behaviour with '");
|
||||||
|
ft_putchar(conv);
|
||||||
|
ft_putendl("' conversion specifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_error_flag_flag(char flag1, char flag2)
|
||||||
|
{
|
||||||
|
ft_putstr("warning: flag '");
|
||||||
|
ft_putchar(flag1);
|
||||||
|
ft_putstr("' is ignored when flag '");
|
||||||
|
ft_putchar(flag2);
|
||||||
|
ft_putendl("' is present");
|
||||||
|
}
|
||||||
42
nm-otool/libft/srcs/ft_printf/lib_pad.c
Normal file
42
nm-otool/libft/srcs/ft_printf/lib_pad.c
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_pad.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/02/18 13:14:30 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_pad_right(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (ft_strchr(fmt->flags, '#'))
|
||||||
|
(fmt->conv.sharp_func)(str, fmt);
|
||||||
|
while ((int)ft_strlen(str) < fmt->width)
|
||||||
|
ft_strcat(str, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_pad_left(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char sign;
|
||||||
|
|
||||||
|
sign = 0;
|
||||||
|
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
|
||||||
|
{
|
||||||
|
sign = str[0];
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
if (ft_strchr(fmt->flags, '0'))
|
||||||
|
while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0))
|
||||||
|
ft_strcatf(str, "0");
|
||||||
|
if (sign)
|
||||||
|
str--;
|
||||||
|
if (ft_strchr(fmt->flags, '#'))
|
||||||
|
(fmt->conv.sharp_func)(str, fmt);
|
||||||
|
while ((int)ft_strlen(str) < fmt->width)
|
||||||
|
ft_strcatf(str, " ");
|
||||||
|
}
|
||||||
44
nm-otool/libft/srcs/ft_printf/lib_pad_sharp.c
Normal file
44
nm-otool/libft/srcs/ft_printf/lib_pad_sharp.c
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_pad_sharp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
|
(void)fmt;
|
||||||
|
ft_bzero(buf, 100);
|
||||||
|
if (str[0] != '0')
|
||||||
|
ft_strcatf(buf, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char start[3];
|
||||||
|
|
||||||
|
start[0] = '0';
|
||||||
|
start[1] = fmt->conversion;
|
||||||
|
start[2] = 0;
|
||||||
|
if (str[0] == '0')
|
||||||
|
{
|
||||||
|
if (str[1] == '0')
|
||||||
|
str[1] = fmt->conversion;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str[0] = fmt->conversion;
|
||||||
|
ft_strcatf(str, "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_strcatf(str, start);
|
||||||
|
}
|
||||||
89
nm-otool/libft/srcs/get_next_line/get_next_line.c
Normal file
89
nm-otool/libft/srcs/get_next_line/get_next_line.c
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "get_next_line.h"
|
||||||
|
|
||||||
|
static int ft_fdcmp(t_save *a, int *b)
|
||||||
|
{
|
||||||
|
return (a->fd - *b);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_gnlfree(void *a, size_t size)
|
||||||
|
{
|
||||||
|
(void)size;
|
||||||
|
ft_strdel(&((t_save*)a)->str);
|
||||||
|
free(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static t_list *ft_newfd(t_list **head, int fd)
|
||||||
|
{
|
||||||
|
t_save new;
|
||||||
|
|
||||||
|
new.fd = fd;
|
||||||
|
new.str = ft_memalloc((BUFF_SIZE > 0 ? BUFF_SIZE : 0) + 1);
|
||||||
|
ft_lstadd(head, ft_lstnew(&new, sizeof(t_save)));
|
||||||
|
return (*head);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_loop_read(int fd, char **line, char *save)
|
||||||
|
{
|
||||||
|
char buf[BUFF_SIZE + 1];
|
||||||
|
char *pos;
|
||||||
|
char *tmp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
|
||||||
|
{
|
||||||
|
buf[ret] = 0;
|
||||||
|
tmp = *line;
|
||||||
|
if ((pos = ft_strchr(buf, '\n')))
|
||||||
|
{
|
||||||
|
ft_strcpy(save, pos + 1);
|
||||||
|
*pos = 0;
|
||||||
|
}
|
||||||
|
if (!(*line = ft_strjoin(*line, buf)))
|
||||||
|
return (-1);
|
||||||
|
ft_strdel(&tmp);
|
||||||
|
if (pos)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (ret < 0)
|
||||||
|
return (-1);
|
||||||
|
return (**line ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_next_line(int const fd, char **line)
|
||||||
|
{
|
||||||
|
static t_list *head;
|
||||||
|
t_list *tmp;
|
||||||
|
char *pos;
|
||||||
|
char *save;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (fd < 0 || !line)
|
||||||
|
return (-1);
|
||||||
|
if (!(tmp = ft_lst_find(head, (void *)&fd, &ft_fdcmp)))
|
||||||
|
tmp = ft_newfd(&head, fd);
|
||||||
|
save = ((t_save*)tmp->content)->str;
|
||||||
|
if (!(*line = ft_strdup(save)))
|
||||||
|
return (-1);
|
||||||
|
ft_bzero(save, BUFF_SIZE + 1);
|
||||||
|
if ((pos = ft_strchr(*line, '\n')))
|
||||||
|
{
|
||||||
|
ft_strcpy(save, pos + 1);
|
||||||
|
*pos = 0;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (!(ret = ft_loop_read(fd, line, save)))
|
||||||
|
ft_lst_delif(&head, (int *)&fd, ft_fdcmp, &ft_gnlfree);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
18
nm-otool/libft/srcs/lst/ft_id.c
Normal file
18
nm-otool/libft/srcs/lst/ft_id.c
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_id.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:08:55 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 22:43:40 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_id(t_list *a)
|
||||||
|
{
|
||||||
|
return (a);
|
||||||
|
}
|
||||||
37
nm-otool/libft/srcs/lst/ft_lst2str.c
Normal file
37
nm-otool/libft/srcs/lst/ft_lst2str.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst2str.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/07 17:53:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/07 17:53:19 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_lst2str(t_list *list)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
t_list *tmp;
|
||||||
|
char *new;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
tmp = list;
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
size += ft_strlen((char *)tmp->content) + 1;
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
new = ft_memalloc(size);
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
ft_strcat(new, (char *)list->content);
|
||||||
|
if (list->next)
|
||||||
|
ft_strcat(new, " ");
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
28
nm-otool/libft/srcs/lst/ft_lst_at.c
Normal file
28
nm-otool/libft/srcs/lst/ft_lst_at.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_at.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:18:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/06/21 18:33:52 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "lst.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_at(t_list *list, unsigned int nbr)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (i < nbr && list)
|
||||||
|
{
|
||||||
|
list = list->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
26
nm-otool/libft/srcs/lst/ft_lst_bfree.c
Normal file
26
nm-otool/libft/srcs/lst/ft_lst_bfree.c
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_bfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/07 16:55:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/15 21:35:59 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_bfree(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
t_list *lst;
|
||||||
|
|
||||||
|
lst = ptr;
|
||||||
|
(void)size;
|
||||||
|
if (lst)
|
||||||
|
{
|
||||||
|
ft_strdel((char **)&lst->content);
|
||||||
|
free(lst);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
nm-otool/libft/srcs/lst/ft_lst_cfree.c
Normal file
20
nm-otool/libft/srcs/lst/ft_lst_cfree.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_cfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/15 21:36:03 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_cfree(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
(void)size;
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
36
nm-otool/libft/srcs/lst/ft_lst_delif.c
Normal file
36
nm-otool/libft/srcs/lst/ft_lst_delif.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_delif.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/06/22 17:16:50 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_delif(
|
||||||
|
t_list **alst,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
|
{
|
||||||
|
tmp = (*indirect);
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
nm-otool/libft/srcs/lst/ft_lst_delsub.c
Normal file
36
nm-otool/libft/srcs/lst/ft_lst_delsub.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_delsub.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/01/12 14:33:28 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_delsub(
|
||||||
|
t_list **alst,
|
||||||
|
t_list *sub,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, sub->content) == 0)
|
||||||
|
{
|
||||||
|
tmp = *indirect;
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
sub = sub->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
}
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
nm-otool/libft/srcs/lst/ft_lst_filter.c
Normal file
35
nm-otool/libft/srcs/lst/ft_lst_filter.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_filter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/23 16:28:53 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_filter(
|
||||||
|
t_list *lst,
|
||||||
|
void const *data_ref,
|
||||||
|
t_list *(*f)(t_list *elem, void const *))
|
||||||
|
{
|
||||||
|
t_list *out;
|
||||||
|
t_list *elem;
|
||||||
|
|
||||||
|
out = NULL;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
if (f)
|
||||||
|
elem = (*f)(lst, data_ref);
|
||||||
|
else
|
||||||
|
elem = lst;
|
||||||
|
elem = ft_lstnew(elem->content, elem->content_size);
|
||||||
|
ft_lsteadd(&out, elem);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
36
nm-otool/libft/srcs/lst/ft_lst_filterout.c
Normal file
36
nm-otool/libft/srcs/lst/ft_lst_filterout.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_filterout.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/26 16:56:02 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/23 16:29:21 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_filterout(
|
||||||
|
t_list **alst,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
|
{
|
||||||
|
tmp = *indirect;
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
nm-otool/libft/srcs/lst/ft_lst_find.c
Normal file
27
nm-otool/libft/srcs/lst/ft_lst_find.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_find.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:20 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/06/21 18:20:30 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)())
|
||||||
|
{
|
||||||
|
t_list *list_ptr;
|
||||||
|
|
||||||
|
list_ptr = begin_list;
|
||||||
|
while (list_ptr)
|
||||||
|
{
|
||||||
|
if ((cmp)(list_ptr->content, data_ref) == 0)
|
||||||
|
return (list_ptr);
|
||||||
|
list_ptr = list_ptr->next;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
28
nm-otool/libft/srcs/lst/ft_lst_merge.c
Normal file
28
nm-otool/libft/srcs/lst/ft_lst_merge.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_merge.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:50:32 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/04 11:09:24 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2)
|
||||||
|
{
|
||||||
|
t_list *list_ptr;
|
||||||
|
|
||||||
|
if (*begin_list1)
|
||||||
|
{
|
||||||
|
list_ptr = *begin_list1;
|
||||||
|
while (list_ptr->next)
|
||||||
|
list_ptr = list_ptr->next;
|
||||||
|
list_ptr->next = begin_list2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*begin_list1 = begin_list2;
|
||||||
|
}
|
||||||
41
nm-otool/libft/srcs/lst/ft_lst_order_delsub.c
Normal file
41
nm-otool/libft/srcs/lst/ft_lst_order_delsub.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_order_delsub.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/04 12:01:47 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_order_delsub(
|
||||||
|
t_list **alst,
|
||||||
|
t_list *sub,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, sub->content) > 0)
|
||||||
|
{
|
||||||
|
sub = sub->next;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
if ((*cmp)((*indirect)->content, sub->content) == 0)
|
||||||
|
{
|
||||||
|
tmp = *indirect;
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
sub = sub->next;
|
||||||
|
}
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
nm-otool/libft/srcs/lst/ft_lst_pop.c
Normal file
23
nm-otool/libft/srcs/lst/ft_lst_pop.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_pop.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/10/07 17:53:30 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/10/07 17:53:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_pop(t_list **lst)
|
||||||
|
{
|
||||||
|
t_list *top;
|
||||||
|
|
||||||
|
top = *lst;
|
||||||
|
if (lst && *lst)
|
||||||
|
*lst = (*lst)->next;
|
||||||
|
return (top);
|
||||||
|
}
|
||||||
25
nm-otool/libft/srcs/lst/ft_lst_print.c
Normal file
25
nm-otool/libft/srcs/lst/ft_lst_print.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/16 21:00:09 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_print(t_list *list, void (*printer)())
|
||||||
|
{
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
ft_putstr("[");
|
||||||
|
(*printer)(list->content);
|
||||||
|
ft_putstr("]->");
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
ft_putendl("X\n");
|
||||||
|
}
|
||||||
37
nm-otool/libft/srcs/lst/ft_lst_print2.c
Normal file
37
nm-otool/libft/srcs/lst/ft_lst_print2.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_print2.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:29 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/05/16 21:00:19 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_print2(t_list *list, void (*printer)())
|
||||||
|
{
|
||||||
|
t_list *list2;
|
||||||
|
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
ft_putendl("---");
|
||||||
|
list2 = *(t_list**)list->content;
|
||||||
|
while (list2)
|
||||||
|
{
|
||||||
|
ft_putstr("[");
|
||||||
|
(*printer)(*(int *)list2->content);
|
||||||
|
ft_putstr("]->");
|
||||||
|
list2 = list2->next;
|
||||||
|
}
|
||||||
|
ft_putendl("X");
|
||||||
|
ft_putendl("---");
|
||||||
|
ft_putendl(" |");
|
||||||
|
ft_putendl(" V");
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
ft_putendl(" X\n");
|
||||||
|
}
|
||||||
33
nm-otool/libft/srcs/lst/ft_lst_removeif.c
Normal file
33
nm-otool/libft/srcs/lst/ft_lst_removeif.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_removeif.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/06/22 22:04:23 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)())
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
|
{
|
||||||
|
tmp = (*indirect);
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
tmp->next = NULL;
|
||||||
|
return (tmp);
|
||||||
|
}
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
29
nm-otool/libft/srcs/lst/ft_lst_reverse.c
Normal file
29
nm-otool/libft/srcs/lst/ft_lst_reverse.c
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_reverse.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@43.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:20:13 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/08 00:31:33 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_reverse(t_list **begin_list)
|
||||||
|
{
|
||||||
|
t_list *new_start;
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
new_start = NULL;
|
||||||
|
while (*begin_list)
|
||||||
|
{
|
||||||
|
tmp = (*begin_list)->next;
|
||||||
|
(*begin_list)->next = new_start;
|
||||||
|
new_start = *begin_list;
|
||||||
|
*begin_list = tmp;
|
||||||
|
}
|
||||||
|
*begin_list = new_start;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue