From 377ee48fad342c32c3ce1677f5537eb35565c074 Mon Sep 17 00:00:00 2001 From: zael-mab Date: Tue, 23 Feb 2021 19:00:32 +0100 Subject: [PATCH] s_7:00 --- Makefile | 52 +++++++++ abs.s | 9 ++ args.c | 98 ++++++++++++++++ asm.h | 94 ++++++++++++++++ bee_gees.s | 32 ++++++ bigzork.s | 90 +++++++++++++++ corwiki | 31 ++++++ libft/Makefile | 121 ++++++++++++++++++++ libft/bo.c | 121 ++++++++++++++++++++ libft/check_ad.c | 18 +++ libft/dioux0.c | 112 +++++++++++++++++++ libft/dioux1.c | 144 ++++++++++++++++++++++++ libft/dioux1p.c | 88 +++++++++++++++ libft/f_loat0.c | 137 +++++++++++++++++++++++ libft/f_loat1.c | 108 ++++++++++++++++++ libft/ft_atoi.c | 39 +++++++ libft/ft_bzero.c | 18 +++ libft/ft_isalnum.c | 20 ++++ libft/ft_isalpha.c | 20 ++++ libft/ft_isascii.c | 20 ++++ libft/ft_isdigit.c | 20 ++++ libft/ft_isprint.c | 20 ++++ libft/ft_ispunct.c | 26 +++++ libft/ft_itoa.c | 54 +++++++++ libft/ft_itoa_u.c | 45 ++++++++ libft/ft_memalloc.c | 29 +++++ libft/ft_memccpy.c | 34 ++++++ libft/ft_memchr.c | 29 +++++ libft/ft_memcmp.c | 31 ++++++ libft/ft_memcpy.c | 26 +++++ libft/ft_memdel.c | 22 ++++ libft/ft_memmove.c | 26 +++++ libft/ft_memset.c | 23 ++++ libft/ft_putchar.c | 18 +++ libft/ft_putchar_fd.c | 18 +++ libft/ft_putendl.c | 19 ++++ libft/ft_putendl_fd.c | 19 ++++ libft/ft_putnbr.c | 29 +++++ libft/ft_putnbr_fd.c | 29 +++++ libft/ft_putstr.c | 25 +++++ libft/ft_putstr_fd.c | 25 +++++ libft/ft_strcat.c | 32 ++++++ libft/ft_strchr.c | 31 ++++++ libft/ft_strclr.c | 25 +++++ libft/ft_strcmp.c | 33 ++++++ libft/ft_strcpy.c | 27 +++++ libft/ft_strdel.c | 22 ++++ libft/ft_strdup.c | 30 +++++ libft/ft_strequ.c | 31 ++++++ libft/ft_striter.c | 25 +++++ libft/ft_striteri.c | 28 +++++ libft/ft_strjoin.c | 42 +++++++ libft/ft_strlcat.c | 36 ++++++ libft/ft_strlen.c | 33 ++++++ libft/ft_strmap.c | 30 +++++ libft/ft_strmapi.c | 34 ++++++ libft/ft_strncat.c | 32 ++++++ libft/ft_strncmp.c | 42 +++++++ libft/ft_strncpy.c | 28 +++++ libft/ft_strnequ.c | 31 ++++++ libft/ft_strnew.c | 26 +++++ libft/ft_strnjoin.c | 26 +++++ libft/ft_strnnn.c | 106 ++++++++++++++++++ libft/ft_strnstr.c | 36 ++++++ libft/ft_strrchr.c | 33 ++++++ libft/ft_strscpy.c | 29 +++++ libft/ft_strsplit.c | 78 +++++++++++++ libft/ft_strstr.c | 36 ++++++ libft/ft_strsub.c | 30 +++++ libft/ft_strtrim.c | 31 ++++++ libft/ft_tolower.c | 20 ++++ libft/ft_toupper.c | 20 ++++ libft/get_next_line.c | 62 +++++++++++ libft/libft.h | 253 ++++++++++++++++++++++++++++++++++++++++++ libft/lolot.c | 125 +++++++++++++++++++++ libft/main.c | 15 +++ libft/opert.c | 95 ++++++++++++++++ libft/opert2.c | 110 ++++++++++++++++++ libft/popac.c | 105 ++++++++++++++++++ libft/stdarg0.c | 131 ++++++++++++++++++++++ libft/xxp.c | 115 +++++++++++++++++++ libft/xxp0.c | 59 ++++++++++ link_lst.c | 126 +++++++++++++++++++++ main.c | 108 ++++++++++++++++++ nodes.c | 225 +++++++++++++++++++++++++++++++++++++ op.c | 51 +++++++++ op.h | 78 +++++++++++++ pars.c | 178 +++++++++++++++++++++++++++++ run.sh | 11 ++ set_op.c | 13 +++ test.sm | 8 ++ test1.s | 18 +++ toto.s | 93 ++++++++++++++++ turtle.s | 98 ++++++++++++++++ 94 files changed, 5079 insertions(+) create mode 100644 Makefile create mode 100644 abs.s create mode 100644 args.c create mode 100644 asm.h create mode 100644 bee_gees.s create mode 100644 bigzork.s create mode 100644 corwiki create mode 100755 libft/Makefile create mode 100755 libft/bo.c create mode 100755 libft/check_ad.c create mode 100755 libft/dioux0.c create mode 100755 libft/dioux1.c create mode 100755 libft/dioux1p.c create mode 100755 libft/f_loat0.c create mode 100755 libft/f_loat1.c create mode 100755 libft/ft_atoi.c create mode 100755 libft/ft_bzero.c create mode 100755 libft/ft_isalnum.c create mode 100755 libft/ft_isalpha.c create mode 100755 libft/ft_isascii.c create mode 100755 libft/ft_isdigit.c create mode 100755 libft/ft_isprint.c create mode 100755 libft/ft_ispunct.c create mode 100755 libft/ft_itoa.c create mode 100755 libft/ft_itoa_u.c create mode 100755 libft/ft_memalloc.c create mode 100755 libft/ft_memccpy.c create mode 100755 libft/ft_memchr.c create mode 100755 libft/ft_memcmp.c create mode 100755 libft/ft_memcpy.c create mode 100755 libft/ft_memdel.c create mode 100755 libft/ft_memmove.c create mode 100755 libft/ft_memset.c create mode 100755 libft/ft_putchar.c create mode 100755 libft/ft_putchar_fd.c create mode 100755 libft/ft_putendl.c create mode 100755 libft/ft_putendl_fd.c create mode 100755 libft/ft_putnbr.c create mode 100755 libft/ft_putnbr_fd.c create mode 100755 libft/ft_putstr.c create mode 100755 libft/ft_putstr_fd.c create mode 100755 libft/ft_strcat.c create mode 100755 libft/ft_strchr.c create mode 100755 libft/ft_strclr.c create mode 100755 libft/ft_strcmp.c create mode 100755 libft/ft_strcpy.c create mode 100755 libft/ft_strdel.c create mode 100755 libft/ft_strdup.c create mode 100755 libft/ft_strequ.c create mode 100755 libft/ft_striter.c create mode 100755 libft/ft_striteri.c create mode 100755 libft/ft_strjoin.c create mode 100755 libft/ft_strlcat.c create mode 100755 libft/ft_strlen.c create mode 100755 libft/ft_strmap.c create mode 100755 libft/ft_strmapi.c create mode 100755 libft/ft_strncat.c create mode 100755 libft/ft_strncmp.c create mode 100755 libft/ft_strncpy.c create mode 100755 libft/ft_strnequ.c create mode 100755 libft/ft_strnew.c create mode 100755 libft/ft_strnjoin.c create mode 100755 libft/ft_strnnn.c create mode 100755 libft/ft_strnstr.c create mode 100755 libft/ft_strrchr.c create mode 100644 libft/ft_strscpy.c create mode 100755 libft/ft_strsplit.c create mode 100755 libft/ft_strstr.c create mode 100755 libft/ft_strsub.c create mode 100755 libft/ft_strtrim.c create mode 100755 libft/ft_tolower.c create mode 100755 libft/ft_toupper.c create mode 100755 libft/get_next_line.c create mode 100755 libft/libft.h create mode 100755 libft/lolot.c create mode 100755 libft/main.c create mode 100755 libft/opert.c create mode 100755 libft/opert2.c create mode 100755 libft/popac.c create mode 100755 libft/stdarg0.c create mode 100755 libft/xxp.c create mode 100755 libft/xxp0.c create mode 100644 link_lst.c create mode 100644 main.c create mode 100755 nodes.c create mode 100644 op.c create mode 100644 op.h create mode 100644 pars.c create mode 100644 run.sh create mode 100644 set_op.c create mode 100644 test.sm create mode 100644 test1.s create mode 100644 toto.s create mode 100644 turtle.s diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c4f63f7 --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: zael-mab +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/02/14 05:40:09 by zael-mab #+# #+# # +# Updated: 2021/02/03 14:17:43 by zael-mab ### ########.fr # +# # +# **************************************************************************** # + +NAME = asm + +SRC = main.c\ + link_lst.c\ + op.c\ + pars.c\ + set_op.c\ + args.c +OBJ = $(SRC:.c=.o) + +HEADER = asm.h +LIBFT_DIR = ./libft +LIBFT = $(LIBFT_DIR)/libft.a + +CC = gcc +CFLAGS = -Wall -Wextra -Werror +LDFLAGS = -L$(LIBFT_DIR) +LDLIBS = -lft + +# =========================================================================== # + +all: depbuild $(NAME) + +depbuild: + @make -C $(LIBFT_DIR) + +$(NAME): $(OBJ) $(HEADER) + $(CC) $(OBJ) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $(NAME) + + +clean: + @rm -f $(OBJ) + @make -C $(LIBFT_DIR) clean + +fclean: clean + @rm -f $(NAME) + @make -C $(LIBFT_DIR) fclean + @echo "done\033[0m" + +re: fclean all diff --git a/abs.s b/abs.s new file mode 100644 index 0000000..8dd7717 --- /dev/null +++ b/abs.s @@ -0,0 +1,9 @@ +.name "Batman" +.comment "This city needs me" + +loop: + sti r1, %:live, %1 # <-- На эту операцию указывает метка loop +live: + live %0 # <-- На эту операцию указывает метка live + ld %0, r2 # <-- А на эту операцию никакая метка не указывает + zjmp %:loop diff --git a/args.c b/args.c new file mode 100644 index 0000000..87a724c --- /dev/null +++ b/args.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* args.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/02/21 17:44:27 by zael-mab #+# #+# */ +/* Updated: 2021/02/21 17:44:35 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "asm.h" + + +int check_reg(char *line, int arg); + + +int pars_args(char *instruction, t_asmdata *sdata, int y) +{ + int j; + int x; + int w; + + j = -1; + w = y; + x = 0; + int cnt = -1; // + char **tab = ft_strsplit(instruction, ','); + + ft_printf ("-_-_-_-_-_-_-_-_-_-%s-_-_-_-_-_-\n", sdata->name); + while (tab[++j]) + { + x = -1; + // cnt = op_tab[x].args[j]; + while (tab[j][++x]) + { + + if (tab[j][x] == 'r' && ft_isdigit(tab[j][x + 1])) + { + // if (ft_atoi(x + 1 + tab[j]) < 1 || ft_atoi(x + 1 + tab[j]) > 16) + // ft_printf ("Error! %d \n", ft_atoi(x + 1 + tab[j])); + ft_putchar ('R'); + // check_reg(tab[j], cnt); + break ; + } + if (tab[j][x] == 'r' && !ft_isdigit(tab[j][x + 1])) + ft_printf("!Error\n"); + else if (tab[j][x] == '%') //DIRECT_CHAR (%) and a number or label (LABEL_CHAR (:) in front of it) + { + //check_dir(); + ft_putchar ('D'); + break ; + } + else if (ft_isdigit(tab[j][x])) + { + ft_putchar ('I'); + // check_ind(); + break ; + } + } + ft_printf("-%s-\n", tab[j]); + + } + return (1); +} + +int check_reg(char *line, int arg) +{ + char *tmp = ft_strtrim(line); + int i; + + i = -1; + while (tmp[++i]) + { + if (tmp[i] == 'r' && ft_atoi( 1 + tmp) > 0 && ft_atoi( 1 + tmp) > 0) + { + if (!(arg & T_REG)) + { + ft_printf ("arg number [%s] wrrong\n", tmp); + break ; + } + else + { + ft_putstr ("(r) are good"); + break; + } + } + else + { + ft_printf ("Error [%s] \n", tmp); + break ; + } + } + + free(tmp); + return (1); +} \ No newline at end of file diff --git a/asm.h b/asm.h new file mode 100644 index 0000000..defc57c --- /dev/null +++ b/asm.h @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* asm.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/01/28 10:48:45 by zael-mab #+# #+# */ +/* Updated: 2021/02/03 14:22:25 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + + +// fix the ft_printf macros ! +#ifndef ASM_H +#define ASM_H + +#include "libft/libft.h" +#include "op.h" +#include +#include + +typedef enum {F , T} boolean; + +typedef struct s_node +{ + char *data; + size_t position; + int operation_num; //labels -pointes operation- + int op_code; + int op_arg1; + int op_arg2; + int op_arg3; + char *op_args[3]; + struct s_node *next; +} t_node; + +typedef struct s_head +{ + size_t l_size; + struct s_node *first; +} t_head; + + +typedef struct s_op +{ + char name[5]; + int args_numb; + int args[3]; + int op_code; + int wait_to_run; + char des[60]; + int x; + int dir_size; +} t_op; + + +typedef struct s_asmdata +{ + char *name; + char *comment; + int n; + int c; + int s; + int e; + int error; + int p_ex_code; +} t_asmdata; + +t_op op_tab[17]; + + + + +t_node *insert_node(t_head *head, void *data, int pos); +void display_nodes(t_head *head); // +void init_head(t_head *head); +char *avoid_comment (char *line); +boolean check_champion (char *line, t_asmdata *sdata); +boolean join (char *line, t_asmdata *sdata, char **cmd, int v); +t_node *search(t_node *l, char* x); + + +t_node *save_labels(t_head *labels, char *lin, t_head *head); +// void creat_op_table(t_hop *op, int i); + +void pars_instructions(t_head *head, t_head *labels, t_asmdata *sdata); + +void operations(char **operat, int i); + +int pars_args(char *instruction, t_asmdata *sdata, int y); + + +# endif diff --git a/bee_gees.s b/bee_gees.s new file mode 100644 index 0000000..7810928 --- /dev/null +++ b/bee_gees.s @@ -0,0 +1,32 @@ +.name"one +#two +three" +.comment"Ha, Ha, Ha, +stayiiiiin' +aliiiiiiiiiive" + + sti r1, %:live, %1 ;change live by the right value + + sti r1, %:live2, %1 ;change live by the right value + + + ld %1, r3 + ld %33, r6 +#While (r2 < 10) +forks: + add r2, r3, r2 ;increment r2 + xor r2, %15, r4 ;if (r4) {carry = 0} +live2: live %4 + zjmp %:endwhile ;if (carry) + fork %:forks + ld %0, r4 ;carry = 1 + zjmp %:forks + ld :forks ,r1 +#EndWhile +endwhile: + ld %0, r4 ;carry = 1 + +live: live %4 + zjmp %:live +xxm: + diff --git a/bigzork.s b/bigzork.s new file mode 100644 index 0000000..d750230 --- /dev/null +++ b/bigzork.s @@ -0,0 +1,90 @@ +.name "bigzork" +.comment "I know i cant win" + +ld %0, r2 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +st r1, 211 +loop: +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +live %1 +zjmp %:loop diff --git a/corwiki b/corwiki new file mode 100644 index 0000000..e1bd4c9 --- /dev/null +++ b/corwiki @@ -0,0 +1,31 @@ +Russian wiki + https://github.com/VBrazhnik/Corewar/wiki +English wiki + https://github.com/k-off/Corewar/wiki/Introduction +coreware operations resume + https://docs.google.com/spreadsheets/d/1tmSm8VH4mhIQPYQXae9quYiQSMRiSo809LEuSHMnOlA/edit#gid=0 +original corewar, if you wanna read more about it: + - corewars king of the hill + ttp://www.koth.org/ + - the Beginners guide to Redcode + http://vyznev.net/corewar/guide.html + - Core War + https://www.corewars.org/index.html + - creating a virtual machine/registre VM in C + https://en.wikibooks.org/wiki/Creating_a_Virtual_Machine/Register_VM_in_C +corewar correction page: + https://github.com/rizky/42-corrections/blob/master/corewar.pdf +a nice visualizer and GUI + https://github.com/conanwu777/corewar +rizky's corewar unit-tests + https://github.com/rizky/corewar/tree/unit-tests +rizky's coreware, (he have a nice resource folder) + https://github.com/rizky/corewar +corewar operations by jyeo + https://github.com/rizky/corewar/blob/master/resources/corewar_operations_by_jyeo.pdf +corewar cheat sheet by Ewen_ + https://github.com/rizky/corewar/blob/master/resources/Corewar_Cheat_Sheet.pdf +last thing: + - don't be afraid to ask the others, me included. + - and take your time reading through the resources, (I didn't do this, bcs of the lake of knowledge, and resources, but it's good thing if you have an idea of what's happening before you start the code) + diff --git a/libft/Makefile b/libft/Makefile new file mode 100755 index 0000000..81233d1 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,121 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: zael-mab +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/03/29 22:23:38 by zael-mab #+# #+# # +# Updated: 2020/03/02 23:38:32 by zael-mab ### ########.fr # +# # +# **************************************************************************** # + +NAME = libft.a +SRC_PATH= . +SRC_NAME=popac.c\ + stdarg0.c\ + ft_strscpy.c\ + bo.c\ + dioux0.c\ + dioux1.c\ + lolot.c\ + ft_strnnn.c\ + opert.c\ + opert2.c\ + f_loat0.c\ + f_loat1.c\ + dioux1.c\ + dioux1p.c\ + xxp.c\ + xxp0.c\ + ft_atoi.c\ + ft_itoa_u.c\ + ft_bzero.c\ + ft_isalnum.c\ + ft_isalpha.c\ + ft_isascii.c\ + ft_isdigit.c\ + ft_isprint.c\ + ft_itoa.c\ + ft_memalloc.c\ + ft_memccpy.c\ + ft_memchr.c\ + ft_memcmp.c\ + ft_memcpy.c\ + ft_memdel.c\ + ft_memmove.c\ + ft_memset.c\ + ft_putchar.c\ + ft_putchar_fd.c\ + ft_putendl.c\ + ft_putendl_fd.c\ + ft_putnbr.c\ + ft_putnbr_fd.c\ + ft_putstr.c\ + ft_putstr_fd.c\ + ft_strcat.c\ + ft_strchr.c\ + ft_strclr.c\ + ft_strcmp.c\ + ft_strcpy.c\ + ft_strdel.c\ + ft_strdup.c\ + ft_strequ.c\ + ft_striter.c\ + ft_striteri.c\ + ft_strjoin.c\ + ft_strlcat.c\ + ft_strlen.c\ + ft_strmap.c\ + ft_strmapi.c\ + ft_strncat.c\ + ft_strncmp.c\ + ft_strncpy.c\ + ft_strnequ.c\ + ft_strnjoin.c\ + ft_strnew.c\ + ft_strnstr.c\ + ft_strrchr.c\ + ft_strsplit.c\ + ft_strstr.c\ + ft_strsub.c\ + ft_strtrim.c\ + ft_tolower.c\ + ft_toupper.c\ + get_next_line.c +SRC= $(addprefix $(SRC_PATH)/, $(SRC_NAME)) + + +OBJ_PATH= obj +OBJ_NAME= $(SRC_NAME:.c=.o) +OBJ= $(addprefix $(OBJ_PATH)/, $(OBJ_NAME)) + + +CFLAGS= -Wall -Wextra -Werror +CC= gcc +HDR_FLAGS= -I. + + +all: $(NAME) + +$(NAME): $(OBJ) + @ar rc $(NAME) $(OBJ) + @ranlib $(NAME) + @echo "libft: library compilled" + +$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c + @mkdir $(OBJ_PATH) 2> /dev/null || true + @$(CC) $(CFLAGS) $(HDR_FLAGS) -o $@ -c $< + + +clean: + @rm -fr $(OBJ) + @rmdir $(OBJ_PATH) 2> /dev/null || true + @echo "libft: object files deleted" + +fclean: clean + @rm -f $(NAME) + @echo "libft: library deleted" + +re: fclean all + diff --git a/libft/bo.c b/libft/bo.c new file mode 100755 index 0000000..cc234c5 --- /dev/null +++ b/libft/bo.c @@ -0,0 +1,121 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bo.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/14 05:18:14 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:45:49 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_printf(const char *f, ...) +{ + t_cnt cnt; + t_lol lol; + va_list vl; + + lol.x = 0; + cnt.total = 0; + va_start(vl, f); + while (f[lol.x] != '\0') + { + if (f[lol.x] != '%') + { + cnt.total += ft_printf("%c", f[lol.x]); + lol.x++; + } + else if (f[lol.x] == '%') + { + if (!trt(&cnt, &lol, f, vl)) + return (cnt.total); + } + else + lol.x++; + } + va_end(vl); + return (cnt.total); +} + +int trt(t_cnt *cnt, t_lol *lol, const char *f, va_list vl) +{ + t_data data; + + data.f_lags = ft_strdup("-+# 0"); + data.types = ft_strdup("cpdeiosuxX%f"); + data.flg = 0; + a02(&data, *lol, f); + z_data_huck(&data, *lol, f); + z_data_fw(&data, *lol, f); + z_data_hl(&data, *lol, f); + if (data.ps == 0) + lol->x++; + else + { + print_typs(data, f, cnt, vl); + lol->x = data.ps + 1; + free(data.f_lags); + free(data.types); + } + return (1); +} + +void print_typs(t_data data, const char *f, t_cnt *cnt, va_list vl) +{ + if (f[data.ps] == 'c' || f[data.ps] == '%') + a04_prim(data, cnt, vl, f); + if (f[data.ps] == 's') + { + cnt->arr = va_arg(vl, char *); + a06_prim(data, cnt); + } + if (f[data.ps] == 'p') + a10prim(data, cnt, f, vl); + if (f[data.ps] == 'd' || f[data.ps] == 'i') + { + f_lags1(data, cnt, vl); + a11d_prim(data, f, cnt); + } + if (f[data.ps] == 'o' || f[data.ps] == 'u' || + f[data.ps] == 'x' || f[data.ps] == 'X') + f_lags0(data, cnt, vl); + if (f[data.ps] == 'o') + a10prim0(data, cnt, f); + if (f[data.ps] == 'u') + a11d_prim(data, f, cnt); + if (f[data.ps] == 'x' || f[data.ps] == 'X') + a10prim(data, cnt, f, vl); + if (f[data.ps] == 'f') + f_loat(f, data, cnt, vl); +} + +void f_lags0(t_data data, t_cnt *cnt, va_list vl) +{ + if (data.h_flags == 1) + cnt->c = (unsigned short int)va_arg(vl, unsigned int); + if (data.h_flags == 2) + cnt->c = (unsigned char)va_arg(vl, int); + if (data.l_flags == 1) + cnt->c = va_arg(vl, unsigned long int); + if (data.l_flags == 2) + cnt->c = va_arg(vl, unsigned long long int); + if (data.l_flags == -1 && data.h_flags == -1) + cnt->c = va_arg(vl, unsigned int); +} + +void f_lags1(t_data data, t_cnt *cnt, va_list vl) +{ + if (data.h_flags == 1) + cnt->c = (short int)va_arg(vl, int); + if (data.h_flags == 2) + cnt->c = (signed char)va_arg(vl, int); + if (data.l_flags == 1) + cnt->c = va_arg(vl, long int); + if (data.l_flags == 2) + cnt->c = va_arg(vl, long long int); + if (data.l_flags == -1 && data.h_flags == -1) + cnt->c = va_arg(vl, int); +} diff --git a/libft/check_ad.c b/libft/check_ad.c new file mode 100755 index 0000000..f9b2593 --- /dev/null +++ b/libft/check_ad.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* check_ad.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/05 10:33:59 by zael-mab #+# #+# */ +/* Updated: 2020/02/05 10:38:51 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int check_ad(void *p) +{ + if (p == NULL) + return (0); + return (1); +} diff --git a/libft/dioux0.c b/libft/dioux0.c new file mode 100755 index 0000000..09bf02e --- /dev/null +++ b/libft/dioux0.c @@ -0,0 +1,112 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dioux0.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/24 06:36:09 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:31:09 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void a10prim0(t_data data, t_cnt *cnt, const char *ar) +{ + t_ayy ayy; + + it_b09(cnt->c, 8, &ayy); + if (!cnt->c && data.fw0 <= 0 && ar[data.pres] == '.') + ayy.rar[0] = '\0'; + ayy.y0 = ft_strlen(ayy.rar); + cnt->x = (data.flg & HASH ? 1 : 0); + if (data.fw1 > (ayy.y0 + cnt->x) && data.fw0 <= ayy.y0) + { + if (cnt->c || cnt->x != 1) + ayy.w1 = data.fw1 - ayy.y0 - cnt->x; + else + ayy.w1 = data.fw1 - cnt->x; + o_01(ayy, data, cnt, ar); + } + o_02(ayy, data, cnt); + if (data.fw0 > ayy.y0 && data.fw1 > data.fw0) + o_03(ayy, data, cnt); + free(ayy.rar); +} + +void o_01(t_ayy ayy, t_data data, t_cnt *cnt, const char *ar) +{ + if (!(data.flg & MINES)) + { + if (data.flg & ZERO && ar[data.pres] != '.') + dd(ayy.w1, 0, '0'); + else + dd(ayy.w1, 0, ' '); + if (cnt->x == 1) + cnt->total += ft_printf("%c", '0'); + if (cnt->c || cnt->x != 1) + cnt->total += ft_printf("%s", ayy.rar); + cnt->total += (ayy.w1 > 0 ? ayy.w1 : 0); + } + else if (data.flg & MINES) + { + if (cnt->x == 1) + cnt->total += ft_printf("%c", '0'); + if (cnt->c || cnt->x != 1) + cnt->total += ft_printf("%s", ayy.rar); + dd(ayy.w1, 0, ' '); + cnt->total += (ayy.w1 > 0 ? ayy.w1 : 0); + } +} + +void o_02(t_ayy ayy, t_data data, t_cnt *cnt) +{ + if (data.fw1 <= data.fw0 && data.fw0 > ayy.y0) + { + ayy.w0 = data.fw0 - ayy.y0; + if (data.huck == 1 || data.huck == 3) + { + cnt->total += ft_printf("%s", ayy.rar) + (ayy.w0 > 0 ? ayy.w0 : 0); + dd(ayy.w0, 0, ' '); + } + else if (data.huck == 2 || data.huck == 0) + { + dd(ayy.w0, 0, '0'); + cnt->total += ft_printf("%s", ayy.rar) + (ayy.w0 > 0 ? ayy.w0 : 0); + } + } + else if ((data.fw0 <= ayy.y0 && data.fw1 <= ayy.y0 + cnt->x)) + { + if (cnt->x == 1) + cnt->total += ft_printf("%c", '0'); + if (cnt->c || cnt->x != 1) + cnt->total += ft_printf("%s", ayy.rar); + } +} + +void o_03(t_ayy ayy, t_data data, t_cnt *cnt) +{ + ayy.w0 = data.fw0 - ayy.y0; + ayy.w1 = data.fw1 - data.fw0; + if (!(data.flg & MINES)) + { + dd(ayy.w1, 0, ' '); + dd(ayy.w0, 0, 48); + cnt->total += ft_printf("%s", ayy.rar); + cnt->total += (ayy.w0 > 0 ? ayy.w0 : 0) + (ayy.w1 > 0 ? ayy.w1 : 0); + } + else if ((data.flg & MINES) && (data.huck == 2 || data.huck == 0)) + { + dd(ayy.w0, 0, 48); + cnt->total += ft_printf("%s", ayy.rar); + cnt->total += (ayy.w0 > 0 ? ayy.w0 : 0) + (ayy.w1 > 0 ? ayy.w1 : 0); + dd(ayy.w1, 0, ' '); + } + else if (data.huck == 1 || data.huck == 3) + { + ayy.w0 = data.fw0 - ayy.y1; + cnt->total += ft_printf("%s", ayy.rar) + (ayy.w0 > 0 ? ayy.w0 : 0); + dd(ayy.w0, 0, ' '); + } +} diff --git a/libft/dioux1.c b/libft/dioux1.c new file mode 100755 index 0000000..1edb2cb --- /dev/null +++ b/libft/dioux1.c @@ -0,0 +1,144 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dioux1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/24 06:36:09 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:31:23 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void a11d_prim(t_data data, const char *ar, t_cnt *cnt) +{ + t_ayy ayy; + + ayy.n = cnt->c; + ayy.looper = 0; + if (!cnt->c) + cnt->c = 0; + if (ar[data.ps] == 'u') + { + cnt->c = (!(pn_u(cnt->c)) ? -ayy.n : ayy.n); + ayy.rar = ft_itoa_u(cnt->c); + } + else + { + ayy.a = (((data.flg & PLUS) && pn(cnt->c)) ? '+' : '-'); + if ((data.flg & SPACE) && pn(cnt->c) && !(data.flg & PLUS)) + ayy.a = ' '; + if (!(pn(cnt->c)) || ((data.flg & PLUS || data.flg & SPACE))) + ayy.looper = 1; + cnt->c = (!(pn(cnt->c)) ? -ayy.n : ayy.n); + ayy.rar = ft_itoa(cnt->c); + } + diu_0(data, ar, cnt, &ayy); + free(ayy.rar); +} + +void diu_0(t_data data, const char *ar, t_cnt *cnt, t_ayy *ayy) +{ + ayy->y2 = ft_strlen(ayy->rar); + ayy->y1 = ayy->y2 + ayy->looper; + ayy->w1 = 0; + ayy->w0 = 0; + if ((ar[data.pres] == '.') && (data.fw0 <= 0 && cnt->c == 0)) + { + ayy->y1 -= 1; + *ayy->rar = '\0'; + } + if (data.fw1 > ayy->y1 && data.fw0 <= ayy->y2) + { + ayy->w1 = data.fw1 - ayy->y1; + if (!(MINES & data.flg) && !(data.flg & ZERO)) + { + dd(ayy->w1, 0, ' '); + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + cnt->total += ft_printf("%s", ayy->rar) + + (ayy->w1 > 0 ? ayy->w1 : 0); + } + diu_11(data, ar, cnt, ayy); + } + diu_1(data, cnt, ayy); + diu_2(data, cnt, ayy); +} + +void diu_11(t_data data, const char *ar, t_cnt *cnt, t_ayy *ayy) +{ + if (data.flg & ZERO && !(data.flg & MINES)) + { + if (ar[data.pres] != '.') + { + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + dd(ayy->w1, 0, '0'); + } + else + { + dd(ayy->w1, 0, ' '); + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + } + cnt->total += ft_printf("%s", ayy->rar) + (ayy->w1 > 0 ? ayy->w1 : 0); + } + else if (data.flg & MINES) + { + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + cnt->total += ft_printf("%s", ayy->rar) + (ayy->w1 > 0 ? ayy->w1 : 0); + dd(ayy->w1, 0, ' '); + } +} + +void diu_1(t_data data, t_cnt *cnt, t_ayy *ayy) +{ + if (data.fw1 <= (data.fw0 + ayy->looper) && data.fw0 > ayy->y2) + { + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + if (data.huck == 1 || data.huck == 3) + { + ayy->w0 = data.fw0 - ayy->y1; + cnt->total += ft_printf("%s", ayy->rar) + + (ayy->w1 > 0 ? ayy->w1 : 0); + dd(ayy->w1, 0, ' '); + } + else if (data.huck == 2 || data.huck == 0) + { + ayy->w0 = data.fw0 - ayy->y2; + dd(ayy->w0, 0, '0'); + cnt->total += ft_printf("%s", ayy->rar) + + (ayy->w0 > 0 ? ayy->w0 : 0); + } + } + else if (data.fw0 <= ayy->y1 && data.fw1 <= ayy->y1) + { + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + cnt->total += ft_printf("%s", ayy->rar); + } +} + +void diu_2(t_data data, t_cnt *cnt, t_ayy *ayy) +{ + if (data.fw0 > ayy->y2 && data.fw1 > (data.fw0 + ayy->looper)) + { + ayy->w1 = data.fw1 - (data.fw0 + ayy->looper); + ayy->w0 = data.fw0 - ayy->y2; + if (!(MINES & data.flg)) + { + dd(ayy->w1, 0, ' '); + cnt->total += (ayy->w1 > 0 ? ayy->w1 : 0); + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + dd(ayy->w0, 0, '0'); + cnt->total += ft_printf("%s", ayy->rar) + + (ayy->w0 > 0 ? ayy->w0 : 0); + } + diu_3(data, cnt, ayy); + } +} diff --git a/libft/dioux1p.c b/libft/dioux1p.c new file mode 100755 index 0000000..72461d3 --- /dev/null +++ b/libft/dioux1p.c @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dioux1p.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/22 01:03:48 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:31:34 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void it_b09(unsigned long long vl, int base, t_ayy *ayy) +{ + int x; + + ayy->n = vl; + x = 1; + while ((ayy->n = ayy->n / base) >= 1) + x++; + ayy->rar = ft_strnew(x); + ayy->n = (vl > 0 ? vl : -vl); + while (x--) + { + if (ayy->n % base < 10) + ayy->rar[x] = ayy->n % base + '0'; + else + ayy->rar[x] = ayy->n % base + 'a' - 10; + ayy->n = ayy->n / base; + } + ayy->rar[x] = ((x == 0) ? '-' : '0'); +} + +int pn_u(unsigned long long cnt) +{ + int i; + + i = 0; + if (cnt > 0) + i = 1; + return (i); +} + +int pn(long long cnt) +{ + int i; + + i = 0; + if (cnt >= 0) + i = 1; + return (i); +} + +void a04_prim(t_data data, t_cnt *cnt, va_list vl, const char *f) +{ + if (f[data.ps] == 'c') + cnt->c = (char)va_arg(vl, int); + else + cnt->c = '%'; + if (!(data.flg & MINES)) + { + cnt->total += ft_abs(data.fw1); + if (data.flg & ZERO) + dd(data.fw1, 1, '0'); + else + dd(data.fw1, 1, ' '); + ft_putchar(cnt->c); + } + a04_p(data, cnt); +} + +void a04_p(t_data data, t_cnt *cnt) +{ + if ((data.flg & MINES) && (data.huck == 2 || data.huck == 0)) + { + cnt->total += ft_abs(data.fw1); + ft_putchar(cnt->c); + dd(data.fw1, 1, ' '); + } + else if (data.huck == 1 || data.huck == 3) + { + cnt->total += ft_abs(data.fw0); + ft_putchar(cnt->c); + dd(data.fw0, 1, ' '); + } +} diff --git a/libft/f_loat0.c b/libft/f_loat0.c new file mode 100755 index 0000000..5924563 --- /dev/null +++ b/libft/f_loat0.c @@ -0,0 +1,137 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* f_loat0.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/24 09:10:59 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:31:44 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void f_loat(const char *ar, t_data data, t_cnt *cnt, va_list vl) +{ + t_lol lol; + + if (data.l_flags == 3) + cnt->c = va_arg(vl, long double); + if (data.l_flags == -1 || data.l_flags == 1) + cnt->c = (long double)va_arg(vl, double); + cnt->z = get_bits((char*)&cnt->c, sizeof(cnt->c)); + cnt->a = 64; + cnt->b = 15; + cnt->u = 16383; + cnt->sign = (int)cnt->z[0 + 48] - '0'; + cnt->mantissa = ft_strsub(cnt->z, cnt->b + 2 + 48, cnt->a); + cnt->exp = ft_strsub(cnt->z, 1 + 48, cnt->b); + f_loat0(cnt, &lol); + if (f_loat11(data, cnt, &lol) && f_loatp(ar, data, cnt, &lol)) + { + f_loat1(data, cnt, &lol); + f_loat2(ar, data, cnt, &lol); + free(lol.vf); + free(cnt->arr); + } + else + free(cnt->res); + free(cnt->mantissa); + free(cnt->exp); +} + +void f_loat0(t_cnt *cnt, t_lol *lol) +{ + char *flt; + char *tmp; + char *str; + char *tp; + + free(cnt->z); + lol->z = 0; + lol->k = 0; + cnt->res = ft_memset(ft_strnew(100), '0', 100); + while (cnt->mantissa[lol->z]) + { + if (cnt->mantissa[lol->z] == '1') + { + lol->k = lol->z + 1; + tmp = ft_powx(ft_strdup("5"), lol->k); + flt = ft_powx(ft_strdup("10"), (cnt->a - (lol->z + 1))); + str = ft_multi(flt, tmp); + tp = ft_sum(cnt->res, str); + cnt->res = tp; + } + lol->z++; + } +} + +int f_loat11(t_data data, t_cnt *cnt, t_lol *lol) +{ + if (ft_strcmp(cnt->exp, "111111111111111") == 0) + { + data.fw0 = (data.fw0 < 4 ? 4 : data.fw0); + if (lol->k == 0) + { + if ((data.flg & SPACE) && data.fw1 < data.fw0 && + !(cnt->sign == 1) && !(data.flg & PLUS)) + { + data.fw1 -= 1; + cnt->total += ft_printf(" "); + } + if (cnt->sign == 1) + cnt->arr = "-inf"; + if (data.flg & PLUS && !(cnt->sign == 1)) + cnt->arr = "+inf"; + if (!(data.flg & PLUS) && !(cnt->sign == 1)) + cnt->arr = "inf"; + } + if (lol->k != 0) + cnt->arr = "nan"; + a06_prim(data, cnt); + return (0); + } + return (1); +} + +void flgas(t_data data, t_cnt *cnt) +{ + data.fw0 = (data.fw0 == -1 ? 0 : data.fw0); + if ((data.flg & SPACE) && cnt->sign != 1 && !(data.flg & PLUS) + && (data.flg & MINES)) + { + cnt->total += ft_printf(" "); + cnt->x += 1; + } + if (cnt->sign == 1 && (data.flg & MINES)) + cnt->total += ft_printf("-"); + if ((data.flg & PLUS) && (cnt->sign != 1) && (data.flg & MINES)) + cnt->total += ft_printf("+"); +} + +int f_loatp(const char *ar, t_data data, t_cnt *cnt, t_lol *lol) +{ + if (ft_strcmp(cnt->exp, "000000000000000") == 0 && lol->k == 0) + { + cnt->x = 0; + if (ar[data.pres] != '.' && data.fw0 == -1) + data.fw0 = 6; + f_3bita(data, cnt); + if (!(data.flg & MINES)) + f_4bita(data, cnt); + flgas(data, cnt); + cnt->total += ft_printf("0"); + if (data.fw0 > 0 || (data.flg & HASH)) + cnt->total += ft_printf("."); + if (ar[data.ps] != '.' && data.fw0 > 0) + { + cnt->total += data.fw0; + dd(data.fw0, 0, '0'); + } + if ((data.flg & MINES)) + f_4bita(data, cnt); + return (0); + } + return (1); +} diff --git a/libft/f_loat1.c b/libft/f_loat1.c new file mode 100755 index 0000000..4d8fca4 --- /dev/null +++ b/libft/f_loat1.c @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* f_loat1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/29 03:08:32 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:31:57 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void f_3bita(t_data data, t_cnt *cnt) +{ + cnt->x = 1; + cnt->lg = ' '; + data.fw0 = (data.fw0 == -1 ? 0 : data.fw0); + if (cnt->sign == 1) + cnt->x += 1; + if ((data.flg & PLUS) && (cnt->sign != 1)) + cnt->x += 1; + if (data.fw0 > 0 || data.flg & HASH) + cnt->x += 1; + if ((data.flg & ZERO) && !(data.flg & MINES)) + cnt->lg = '0'; +} + +void f_4bita(t_data data, t_cnt *cnt) +{ + if ((data.fw0 + cnt->x) < data.fw1 && cnt->lg != '0') + { + cnt->x = data.fw1 - (cnt->x + data.fw0); + cnt->total += (cnt->x > 0 ? cnt->x : 0); + dd(cnt->x, 0, cnt->lg); + } + if (cnt->sign == 1 && !(data.flg & MINES)) + cnt->total += ft_printf("-"); + if ((data.flg & PLUS) && (cnt->sign != 1) && !(data.flg & MINES)) + cnt->total += ft_printf("+"); + if (data.flg & SPACE && cnt->sign != 1 && !(data.flg & PLUS) + && (data.fw0 + cnt->x >= data.fw1 || cnt->lg == '0') && !(data.flg & MINES)) + { + cnt->total += ft_printf(" "); + cnt->x += 1; + } + if ((data.fw0 + cnt->x) < data.fw1 && cnt->lg == '0' && !(data.flg & MINES)) + { + cnt->x = data.fw1 - (cnt->x + data.fw0); + cnt->total += (cnt->x > 0 ? cnt->x : 0); + dd(cnt->x, 0, cnt->lg); + } +} + +void f_loat3(const char *vf, t_data data, t_cnt *cnt, t_lol *lol) +{ + if (lol->d <= data.fw0) + lol->tp = data.fw0 - lol->d; + else + lol->tp = lol->d; + f_loat00(lol->tp, lol, cnt, cnt->arr); + f_3bita(data, cnt); + if (!(data.flg & MINES)) + f_4bita(data, cnt); + flgas(data, cnt); + if (ft_strlen(vf) < ft_strlen(cnt->arr)) + { + lol->d -= 1; + if (ft_strlen(vf) == 65) + lol->d = 0; + if (ft_strlen(vf) == 65) + cnt->total += ft_printf("1"); + else + cnt->total += ft_printf("0"); + } + else + cnt->total += ft_printf("0"); + f_loat3p(vf, data, cnt, lol); +} + +void f_loat3p(const char *vf, t_data data, t_cnt *cnt, t_lol *lol) +{ + if (data.fw0 > 0 || data.flg & HASH) + cnt->total += ft_printf("."); + if (data.fw0 < lol->d) + lol->d = data.fw0; + if (lol->d > 0) + { + cnt->total += lol->d; + dd(lol->d, 0, '0'); + } + if (ft_strlen(vf) < ft_strlen(cnt->arr)) + lol->tmp = ft_strsub(cnt->arr, + (ft_strlen(vf) == 65), data.fw0 - lol->d); + else + lol->tmp = ft_strsub(cnt->arr, 0, (data.fw0 - lol->d)); + cnt->total += ft_printf("%s", lol->tmp); + free(lol->tmp); + if (data.fw0 > 0) + { + if (data.fw0 > lol->d + ft_strlen(cnt->arr)) + cnt->total += (data.fw0 - lol->d) - ft_strlen(cnt->arr); + dd(((data.fw0 - lol->d) - ft_strlen(cnt->arr)), 0, '0'); + } + if (data.flg & MINES) + f_4bita(data, cnt); +} diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100755 index 0000000..bc97cd6 --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/03 22:27:59 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:40:45 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_atoi(const char *str) +{ + int a; + int b; + int c; + + a = 0; + b = 0; + c = 0; + while ((str[a] >= 9 && str[a] <= 13) || str[a] == 32) + a++; + if (str[a] == '-') + c = 1; + if (str[a] == '+' || str[a] == '-') + a++; + while (str[a] >= '0' && str[a] <= '9' && str[a] != '\0') + { + b = b * 10 + (str[a] - 48); + a++; + } + if (c == 1) + return (-b); + else + return (b); +} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100755 index 0000000..b089e62 --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/30 15:31:52 by zael-mab #+# #+# */ +/* Updated: 2019/04/19 02:34:24 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, '\0', n); +} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c new file mode 100755 index 0000000..14f80ad --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/04 00:57:46 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:42:18 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + if (ft_isalpha(c) || ft_isdigit(c)) + return (1); + return (0); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100755 index 0000000..a635bf7 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/03 23:27:53 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:41:17 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + return (1); + return (0); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100755 index 0000000..3916a44 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/04 01:05:42 by zael-mab #+# #+# */ +/* Updated: 2019/04/05 04:54:49 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + return (0); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100755 index 0000000..19a8229 --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/04 00:20:11 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:41:44 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (1); + return (0); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100755 index 0000000..bb63787 --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/04 01:19:32 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:43:53 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (1); + return (0); +} diff --git a/libft/ft_ispunct.c b/libft/ft_ispunct.c new file mode 100755 index 0000000..4c96b98 --- /dev/null +++ b/libft/ft_ispunct.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ispunct.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/24 12:40:04 by zael-mab #+# #+# */ +/* Updated: 2020/02/03 02:59:42 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_ispunct(int x) +{ + unsigned char c; + + c = (unsigned char)x; + if ((c >= 41 && c <= 47) || (c >= 50 && c <= 57) || (c >= 72 && c <= 77) + || c == 100 || (c >= 133 && c <= 137) || c == 140 || + (c >= 173 && c <= 176)) + return (1); + else + return (0); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100755 index 0000000..c0c5308 --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/12 09:16:45 by zael-mab #+# #+# */ +/* Updated: 2020/02/03 02:58:14 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static long long ft_x(long long nb) +{ + size_t j; + + j = 1; + while (nb / 10) + { + nb = nb / 10; + j++; + } + return (j); +} + +long long ft_llabs(long long n) +{ + return (n > 0 ? n : -n); +} + +char *ft_itoa(long long n) +{ + char *str; + int y; + int z; + unsigned long long nb; + + nb = n; + y = ft_x(n); + z = (n < 0 ? 1 : 0); + if (!(str = ft_strnew(y + z))) + return (NULL); + if (z) + n = ft_llabs(n); + while (y > 0) + { + str[y - 1] = nb % 10 + 48; + nb = nb / 10; + y--; + } + return (str); +} diff --git a/libft/ft_itoa_u.c b/libft/ft_itoa_u.c new file mode 100755 index 0000000..09822e5 --- /dev/null +++ b/libft/ft_itoa_u.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa_u.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/10 06:30:28 by zael-mab #+# #+# */ +/* Updated: 2020/02/05 13:01:39 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static unsigned long long ft_x(unsigned long long nb) +{ + size_t j; + + j = 1; + while (nb / 10) + { + nb = nb / 10; + j++; + } + return (j); +} + +char *ft_itoa_u(unsigned long long n) +{ + char *str; + int y; + unsigned long long nb; + + nb = n; + y = ft_x(n); + if (!(str = ft_strnew(y))) + return (NULL); + while (y > 0) + { + str[y - 1] = nb % 10 + 48; + nb = nb / 10; + y--; + } + return (str); +} diff --git a/libft/ft_memalloc.c b/libft/ft_memalloc.c new file mode 100755 index 0000000..bbbfdc5 --- /dev/null +++ b/libft/ft_memalloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memalloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 06:05:28 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:46:56 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memalloc(size_t size) +{ + char *r; + size_t j; + + j = 0; + if (!(r = (char *)malloc(size * sizeof(*r)))) + return (NULL); + while (j < size) + { + r[j] = '\0'; + j++; + } + return (r); +} diff --git a/libft/ft_memccpy.c b/libft/ft_memccpy.c new file mode 100755 index 0000000..6c9edde --- /dev/null +++ b/libft/ft_memccpy.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memccpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/31 06:40:24 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:12:00 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memccpy(void *dst, const void *src, int c, size_t n) +{ + unsigned char *r; + size_t j; + unsigned char *d; + unsigned char *s; + + r = 0; + j = 0; + d = (unsigned char *)dst; + s = (unsigned char *)src; + while (j < n && r == 0) + { + d[j] = s[j]; + if (s[j] == (unsigned char)c) + r = d + j + 1; + j++; + } + return (r); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100755 index 0000000..31c636d --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/31 07:29:04 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 22:45:58 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + unsigned char *str; + size_t j; + + j = 0; + str = (unsigned char*)s; + while (j < n) + { + if (str[j] == (unsigned char)c) + return (&str[j]); + j++; + } + return (NULL); +} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100755 index 0000000..ec0acb7 --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 00:14:47 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:47:16 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *str0; + unsigned char *str1; + size_t j; + + str0 = (unsigned char *)s1; + str1 = (unsigned char *)s2; + j = 0; + while (j < n) + { + if (str0[j] != str1[j]) + return (str0[j] - str1[j]); + j++; + } + return (0); +} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100755 index 0000000..a972e9a --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/30 21:03:09 by zael-mab #+# #+# */ +/* Updated: 2019/04/19 02:34:43 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + ((unsigned char *)dst)[i] = ((unsigned char *)src)[i]; + i++; + } + return (dst); +} diff --git a/libft/ft_memdel.c b/libft/ft_memdel.c new file mode 100755 index 0000000..c6a466d --- /dev/null +++ b/libft/ft_memdel.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 06:42:40 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:48:09 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_memdel(void **ap) +{ + if (ap) + { + free(*ap); + *ap = NULL; + } +} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100755 index 0000000..ba3003a --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/31 07:08:47 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:38:52 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + char *ls; + + if ((ls = (char *)malloc(sizeof(char) * (len)))) + { + ls = ft_memcpy(ls, src, len); + dst = ft_memcpy(dst, ls, len); + free(ls); + } + return (dst); +} diff --git a/libft/ft_memset.c b/libft/ft_memset.c new file mode 100755 index 0000000..b24f73d --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/29 23:31:55 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 19:05:30 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *b, int c, size_t len) +{ + size_t i; + + i = 0; + while (i < len) + ((unsigned char *)b)[i++] = (unsigned char)c; + return (b); +} diff --git a/libft/ft_putchar.c b/libft/ft_putchar.c new file mode 100755 index 0000000..260d4cb --- /dev/null +++ b/libft/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/31 21:33:21 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:07:01 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100755 index 0000000..05484c4 --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/21 18:42:57 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:37:05 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/ft_putendl.c b/libft/ft_putendl.c new file mode 100755 index 0000000..87fb699 --- /dev/null +++ b/libft/ft_putendl.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/06 01:11:51 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:08:58 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl(char const *s) +{ + ft_putstr(s); + write(1, "\n", 1); +} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100755 index 0000000..ef4a284 --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/06 06:01:40 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:14:03 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char const *s, int fd) +{ + ft_putstr_fd(s, fd); + write(fd, "\n", 1); +} diff --git a/libft/ft_putnbr.c b/libft/ft_putnbr.c new file mode 100755 index 0000000..d90fd69 --- /dev/null +++ b/libft/ft_putnbr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 23:25:29 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:10:10 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr(int n) +{ + unsigned int nb; + + if (n < 0) + { + nb = -n; + ft_putchar('-'); + } + else + nb = n; + if (nb >= 10) + ft_putnbr(nb / 10); + ft_putchar(nb % 10 + '0'); +} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100755 index 0000000..1b35ab4 --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/06 06:09:02 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:12:44 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + unsigned int nb; + + if (n < 0) + { + nb = -n; + ft_putchar_fd('-', fd); + } + else + nb = n; + if (nb >= 10) + ft_putnbr_fd(nb / 10, fd); + ft_putchar_fd(nb % 10 + '0', fd); +} diff --git a/libft/ft_putstr.c b/libft/ft_putstr.c new file mode 100755 index 0000000..51ad46a --- /dev/null +++ b/libft/ft_putstr.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 23:00:23 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:08:08 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr(char const *s) +{ + size_t j; + + j = 0; + if (s) + { + while (s[j]) + write(1, &s[j++], 1); + } +} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100755 index 0000000..d205770 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/06 05:58:31 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:11:42 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char const *s, int fd) +{ + size_t j; + + j = 0; + if (s) + { + while (s[j]) + write(fd, &s[j++], 1); + } +} diff --git a/libft/ft_strcat.c b/libft/ft_strcat.c new file mode 100755 index 0000000..3e287be --- /dev/null +++ b/libft/ft_strcat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 06:33:30 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 22:49:51 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strcat(char *s1, const char *s2) +{ + size_t j; + size_t i; + + j = 0; + i = 0; + while (s1[j]) + j++; + while (s2[i] != '\0') + { + s1[j] = s2[i]; + j++; + i++; + } + s1[j] = '\0'; + return (s1); +} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100755 index 0000000..b4d77fb --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 07:20:12 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:47:44 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + char *n; + int j; + + j = 0; + n = (char *)s; + while (n[j]) + { + if (n[j] == (char)c) + return (n + j); + j++; + } + if (n[j] == c) + return (&n[j]); + return (0); +} diff --git a/libft/ft_strclr.c b/libft/ft_strclr.c new file mode 100755 index 0000000..b6cfce2 --- /dev/null +++ b/libft/ft_strclr.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strclr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 08:32:20 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 02:00:49 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_strclr(char *s) +{ + size_t j; + + j = 0; + if (s) + { + while (s[j]) + s[j++] = '\0'; + } +} diff --git a/libft/ft_strcmp.c b/libft/ft_strcmp.c new file mode 100755 index 0000000..10794ab --- /dev/null +++ b/libft/ft_strcmp.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/02 02:05:25 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:39:07 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strcmp(const char *s1, const char *s2) +{ + size_t i; + + i = 0; + if (!s1 || !s2) + { + if (!s1 && !s2) + return (0); + return (!s1 ? (unsigned char)s2 : (unsigned char)s1 ); + } + while ((unsigned char)s1[i] || (unsigned char)s2[i]) + { + if ((unsigned char)s1[i] != (unsigned char)s2[i]) + return ((unsigned char)s1[i] - (unsigned char)s2[i]); + i++; + } + return (0); +} diff --git a/libft/ft_strcpy.c b/libft/ft_strcpy.c new file mode 100755 index 0000000..2cc5f3e --- /dev/null +++ b/libft/ft_strcpy.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 05:07:34 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 22:49:22 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strcpy(char *dst, const char *src) +{ + int j; + + j = 0; + while (src[j]) + { + dst[j] = src[j]; + j++; + } + dst[j] = '\0'; + return (dst); +} diff --git a/libft/ft_strdel.c b/libft/ft_strdel.c new file mode 100755 index 0000000..6c314ec --- /dev/null +++ b/libft/ft_strdel.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 07:54:51 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:50:14 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_strdel(char **as) +{ + if (as) + { + free(*as); + *as = NULL; + } +} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100755 index 0000000..9031f27 --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 02:32:51 by zael-mab #+# #+# */ +/* Updated: 2020/02/03 04:30:25 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(char *s1) +{ + char *str0; + size_t j; + + if (!(str0 = (char *)malloc(ft_strlen(s1) + 1))) + return (NULL); + j = 0; + while (s1[j]) + { + str0[j] = s1[j]; + j++; + } + str0[j] = '\0'; + return (str0); +} diff --git a/libft/ft_strequ.c b/libft/ft_strequ.c new file mode 100755 index 0000000..c58b49d --- /dev/null +++ b/libft/ft_strequ.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/07 00:05:45 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:00:44 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strequ(char const *s1, char const *s2) +{ + size_t j; + + j = 0; + if (s1 && s2) + { + while (s1[j] || s2[j]) + { + if (s1[j] != s2[j]) + return (0); + j++; + } + return (1); + } + return (0); +} diff --git a/libft/ft_striter.c b/libft/ft_striter.c new file mode 100755 index 0000000..e96a6f2 --- /dev/null +++ b/libft/ft_striter.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 08:49:19 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:50:45 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striter(char *s, void (*f)(char *)) +{ + size_t j; + + j = 0; + if (s) + { + while (s[j]) + f(&s[j++]); + } +} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100755 index 0000000..366a884 --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 22:08:17 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:51:24 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + size_t j; + + j = 0; + if (s) + { + while (s[j]) + { + f(j, &s[j]); + j++; + } + } +} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100755 index 0000000..3eb9d25 --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/07 06:13:32 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:02:33 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + size_t i; + size_t t; + char *s0; + + i = 0; + t = 0; + if (s1 && s2) + { + if ((s0 = ft_strnew(ft_strlen(s1) + ft_strlen(s2)))) + { + while (s1[i]) + { + s0[i] = s1[i]; + i++; + } + while (s2[t]) + { + s0[i] = s2[t]; + t++; + i++; + } + return (s0); + } + } + return (NULL); +} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100755 index 0000000..a9b1964 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 07:14:02 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 23:41:31 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t ld; + size_t ls; + size_t ln; + + ln = 0; + ld = ft_strlen(dst); + ls = ft_strlen(src); + if (ld >= size) + ls = ls + size; + else + ls = ls + ld; + while (src[ln] && ld + 1 < size) + { + dst[ld] = src[ln]; + ln++; + ld++; + } + dst[ld] = '\0'; + return (ls); +} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100755 index 0000000..6b60a87 --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 02:01:43 by zael-mab #+# #+# */ +/* Updated: 2019/04/19 00:05:39 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strlen(const char *str) +{ + int j; + + j = 0; + while (str[j]) + j++; + return (j); +} + +size_t ft_strlenp(const char *str) +{ + size_t j; + + j = 0; + while (str[j]) + j++; + return (j); +} diff --git a/libft/ft_strmap.c b/libft/ft_strmap.c new file mode 100755 index 0000000..43a0b55 --- /dev/null +++ b/libft/ft_strmap.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/06 04:42:43 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 15:59:13 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmap(char const *s, char (*f)(char)) +{ + char *str; + size_t j; + + if (!s || !(str = (char *)malloc((ft_strlen(s) + 1) * sizeof(*str)))) + return (NULL); + j = 0; + while (s[j]) + { + str[j] = f(s[j]); + j++; + } + str[j] = '\0'; + return (str); +} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100755 index 0000000..94c4c8c --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/06 05:30:25 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:00:02 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + size_t j; + char *str; + + j = 0; + if (s) + { + if ((str = ft_strnew(ft_strlen(s)))) + { + while (s[j]) + { + str[j] = f(j, s[j]); + j++; + } + return (str); + } + } + return (NULL); +} diff --git a/libft/ft_strncat.c b/libft/ft_strncat.c new file mode 100755 index 0000000..7676512 --- /dev/null +++ b/libft/ft_strncat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 04:03:38 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 22:50:01 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strncat(char *s1, const char *s2, size_t n) +{ + size_t j; + size_t i; + + j = 0; + i = 0; + while (s1[j]) + j++; + while (s2[i] != '\0' && i < n) + { + s1[j] = s2[i]; + j++; + i++; + } + s1[j] = '\0'; + return (s1); +} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c new file mode 100755 index 0000000..6689d6b --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/03 21:50:04 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:39:58 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + + i = 0; + while ((((unsigned char)s1[i] || (unsigned char)s2[i])) && i < n) + { + if ((unsigned char)s1[i] != (unsigned char)s2[i]) + return ((unsigned char)s1[i] - (unsigned char)s2[i]); + i++; + } + return (0); +} + +int ft_strscmp(const char *s1, const char *s2, size_t s, size_t n) +{ + size_t i; + + i = 0; + while ((((unsigned char)s1[i] || (unsigned char)s2[s])) && i < n) + { + if ((unsigned char)s1[i] != (unsigned char)s2[s]) + return ((unsigned char)s1[i] - (unsigned char)s2[s]); + i++; + s++; + } + return (0); +} diff --git a/libft/ft_strncpy.c b/libft/ft_strncpy.c new file mode 100755 index 0000000..8806937 --- /dev/null +++ b/libft/ft_strncpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 05:52:25 by zael-mab #+# #+# */ +/* Updated: 2019/04/21 22:49:37 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strncpy(char *dst, const char *src, size_t len) +{ + size_t j; + + j = 0; + while (src[j] && j < len) + { + dst[j] = src[j]; + j++; + } + while (j < len) + dst[j++] = '\0'; + return (dst); +} diff --git a/libft/ft_strnequ.c b/libft/ft_strnequ.c new file mode 100755 index 0000000..a4fbf75 --- /dev/null +++ b/libft/ft_strnequ.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/07 05:41:07 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:01:09 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strnequ(char const *s1, char const *s2, size_t n) +{ + size_t j; + + j = 0; + if (s1 && s2) + { + while ((s1[j] || s2[j]) && j < n) + { + if (s1[j] != s2[j]) + return (0); + j++; + } + return (1); + } + return (0); +} diff --git a/libft/ft_strnew.c b/libft/ft_strnew.c new file mode 100755 index 0000000..650bdd6 --- /dev/null +++ b/libft/ft_strnew.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 07:28:17 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:49:20 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnew(size_t size) +{ + char *r; + size_t j; + + j = 0; + if (!(r = (char *)malloc(size + 1 * sizeof(*r)))) + return (NULL); + while (j <= size) + r[j++] = '\0'; + return (r); +} diff --git a/libft/ft_strnjoin.c b/libft/ft_strnjoin.c new file mode 100755 index 0000000..5d1b107 --- /dev/null +++ b/libft/ft_strnjoin.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 21:41:57 by zael-mab #+# #+# */ +/* Updated: 2020/02/14 21:42:00 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnjoin(char const *s1, char const *s2, size_t n) +{ + char *result; + size_t t_length; + + if (!s1 || !s2) + return (NULL); + t_length = ft_strlen((char *)s1) + n + 1; + if (!(result = (char *)malloc(sizeof(char) * t_length))) + return (NULL); + return (ft_strncat(ft_strcpy(result, (char *)s1), (char *)s2, n)); +} diff --git a/libft/ft_strnnn.c b/libft/ft_strnnn.c new file mode 100755 index 0000000..d537ed1 --- /dev/null +++ b/libft/ft_strnnn.c @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnnn.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/30 10:10:52 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:32:40 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void f_loat1(t_data data, t_cnt *cnt, t_lol *lol) +{ + char *tst; + char *ten; + + tst = l_exponnt(cnt->exp, cnt->u, lol); + ten = ft_powx(ft_strdup("10"), cnt->a); + lol->vf = ft_multi(ft_sum(ten, cnt->res), tst); + cnt->arr = ft_strsub(lol->vf, 0, ft_strlen(lol->vf)); + lol->d = ft_strlen(lol->vf) - cnt->a - ft_abs(lol->y); + lol->d = ft_abs(lol->d); + lol->r = ft_strlen(lol->vf) - cnt->a; + data.fw0 = (data.fw0 == -1 ? 0 : data.fw0); +} + +void f_loat2(const char *ar, t_data data, t_cnt *cnt, t_lol *lol) +{ + if (ar[data.pres] != '.' && data.fw0 == -1) + data.fw0 = 6; + if (lol->y < 0) + f_loat3(lol->vf, data, cnt, lol); + if (lol->y == 0) + f_loat5(data, cnt, lol); + if (lol->y > 0) + { + f_loat6(lol->vf, data, cnt, lol); + if (data.fw1 > data.fw0 && (data.flg & MINES)) + f_4bita(data, cnt); + } +} + +void f_loat6(const char *vf, t_data data, t_cnt *cnt, t_lol *lol) +{ + data.fw0 = (data.fw0 == -1 ? 0 : data.fw0); + f_loat00((lol->r + data.fw0), lol, cnt, lol->vf); + f_3bita(data, cnt); + cnt->x += lol->r - 1 + (ft_strlen(vf) < ft_strlen(cnt->arr)); + if (!(data.flg & MINES)) + f_4bita(data, cnt); + flgas(data, cnt); + lol->tmp = ft_strsub(cnt->arr, 0, lol->r + + (ft_strlen(vf) < ft_strlen(cnt->arr))); + cnt->total += ft_printf("%s", lol->tmp); + free(lol->tmp); + if (data.fw0 > 0 || data.flg & HASH) + cnt->total += ft_printf("."); + if (data.fw0 > 0) + { + lol->tmp = ft_strsub(cnt->arr, lol->r, data.fw0); + cnt->total += ft_printf("%s", lol->tmp); + free(lol->tmp); + if (data.fw0 > ft_strlen(cnt->arr) - lol->r) + { + cnt->total += (data.fw0 - ft_strlen(cnt->arr) + lol->r); + dd((data.fw0 - ft_strlen(cnt->arr) + lol->r), 0, '0'); + } + } +} + +void f_loat5(t_data data, t_cnt *cnt, t_lol *lol) +{ + data.fw0 = (data.fw0 >= 0 ? data.fw0 : 0); + f_loat00(data.fw0 + 1, lol, cnt, lol->vf); + f_3bita(data, cnt); + if (!(data.flg & MINES)) + f_4bita(data, cnt); + flgas(data, cnt); + lol->tmp = ft_strsub(cnt->arr, 0, 1); + cnt->total += ft_printf("%s", lol->tmp); + free(lol->tmp); + if (data.fw0 > 0 || (data.flg & HASH)) + cnt->total += ft_printf("."); + if (data.fw0 > 0) + { + lol->tmp = ft_strsub(cnt->arr, 1, data.fw0); + cnt->total += ft_printf("%s", lol->tmp); + free(lol->tmp); + } + if (data.fw0 > ft_strlen(cnt->arr) - lol->r) + { + cnt->total += (data.fw0 - ft_strlen(cnt->arr) + lol->r); + dd((data.fw0 - ft_strlen(cnt->arr) + lol->r), 0, '0'); + } + if ((data.flg & MINES)) + f_4bita(data, cnt); +} + +void dd(int i, int j, char b) +{ + while (i-- > j) + ft_putchar(b); +} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100755 index 0000000..eab33b3 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/02 01:38:01 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:54:08 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *str, const char *srh, size_t len) +{ + size_t j0; + size_t j1; + + j0 = 0; + j1 = 0; + while (str[j0] && j0 < len) + { + j1 = 0; + while (str[j0 + j1] == srh[j1] && j0 + j1 < len) + { + j1++; + if (srh[j1] == '\0') + return ((char *)str + j0); + } + j0++; + } + if (srh[j1] == '\0') + return ((char *)str); + return (0); +} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100755 index 0000000..693911e --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 21:37:35 by zael-mab #+# #+# */ +/* Updated: 2019/04/19 02:31:38 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int j0; + int j1; + char *n; + + j0 = 0; + j1 = 0; + n = (char *)s; + while (n[j0]) + j0++; + while (j0 >= 0) + { + if (n[j0] == c) + return (&n[j0++]); + j0--; + } + return (0); +} diff --git a/libft/ft_strscpy.c b/libft/ft_strscpy.c new file mode 100644 index 0000000..f391564 --- /dev/null +++ b/libft/ft_strscpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strscpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/02/03 15:40:31 by zael-mab #+# #+# */ +/* Updated: 2021/02/03 15:42:49 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strscpy(char *dst, const char *src, size_t s, size_t len) +{ + size_t j; + + j = -1; + while (src[s] && s < len) + { + dst[++j] = src[s]; + s++; + } + while (j < len) + dst[j++] = '\0'; + return (dst); +} + diff --git a/libft/ft_strsplit.c b/libft/ft_strsplit.c new file mode 100755 index 0000000..4bb39de --- /dev/null +++ b/libft/ft_strsplit.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsplit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/13 14:04:26 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 02:27:48 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_cc(char const *s, char c, int i) +{ + int j; + + j = 0; + while (s[i] && s[i] != c) + { + j++; + i++; + } + return (j); +} + +static int ft_wc(char const *s, char c) +{ + int j; + int i; + int f; + + i = 0; + j = 0; + f = 0; + while (s[i]) + { + if (s[i] != c && f == 0) + { + j++; + f = 1; + } + else if (s[i] == c) + f = 0; + i++; + } + return (j); +} + +char **ft_strsplit(char const *s, char c) +{ + int j; + int i; + int k; + char **str; + + i = 0; + j = 0; + if (!s || !(str = (char **)malloc(sizeof(char*) * (ft_wc(s, c) + 1)))) + return (NULL); + while (s[i]) + { + while (s[i] == c && s[i]) + i++; + if (s[i]) + { + k = 0; + if (!(str[j] = ft_strnew(ft_cc(s, c, i)))) + return (NULL); + while (s[i] != c && s[i]) + str[j][k++] = s[i++]; + str[j++][k] = '\0'; + } + } + str[j] = NULL; + return (str); +} diff --git a/libft/ft_strstr.c b/libft/ft_strstr.c new file mode 100755 index 0000000..c1b871d --- /dev/null +++ b/libft/ft_strstr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/01 22:58:40 by zael-mab #+# #+# */ +/* Updated: 2019/04/22 01:52:40 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strstr(const char *str, const char *srh) +{ + int j0; + int j1; + + j0 = 0; + j1 = 0; + while (str[j0]) + { + j1 = 0; + while (str[j0 + j1] == srh[j1]) + { + j1++; + if (srh[j1] == '\0') + return ((char *)str + j0); + } + j0++; + } + if (srh[j1] == '\0') + return ((char *)str); + return (0); +} diff --git a/libft/ft_strsub.c b/libft/ft_strsub.c new file mode 100755 index 0000000..d4349ec --- /dev/null +++ b/libft/ft_strsub.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsub.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/07 05:53:27 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 16:01:56 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strsub(char const *s1, unsigned int start, size_t len) +{ + char *s0; + size_t j; + + j = 0; + if (!s1 || !(s0 = (char *)malloc(len + 1 * sizeof(*s0)))) + return (NULL); + while (j < len) + { + s0[j] = s1[j + start]; + j++; + } + s0[j] = '\0'; + return (s0); +} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100755 index 0000000..c1a92f1 --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/08 03:46:53 by zael-mab #+# #+# */ +/* Updated: 2019/04/19 03:12:07 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s) +{ + int i; + int j; + + i = 0; + if (s) + { + j = ft_strlen(s) - 1; + while (s[i] && (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')) + i++; + while (j > i && (s[j] == ' ' || s[j] == '\n' || s[j] == '\t')) + j--; + return (ft_strsub(s, i, j - i + 1)); + } + return (NULL); +} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100755 index 0000000..eeed701 --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/04 02:21:59 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:45:53 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + return (c); +} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100755 index 0000000..9ee2ef2 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/04 01:52:20 by zael-mab #+# #+# */ +/* Updated: 2019/04/12 14:45:14 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + return (c); +} diff --git a/libft/get_next_line.c b/libft/get_next_line.c new file mode 100755 index 0000000..7d51e03 --- /dev/null +++ b/libft/get_next_line.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/05 22:08:17 by zael-mab #+# #+# */ +/* Updated: 2020/10/17 18:27:26 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static unsigned int ft_linelen(char *tab) +{ + unsigned int i; + + i = 0; + while (tab[i] != '\n' && tab[i] != '\0') + i++; + return (i); +} + +static char *ft_line(char *tab) +{ + if (ft_strchr(tab, '\n')) + { + ft_strcpy(tab, ft_strchr(tab, '\n') + 1); + return (tab); + } + if (ft_linelen(tab) > 0) + { + ft_strcpy(tab, ft_strchr(tab, '\0')); + return (tab); + } + return (NULL); +} + +int get_next_line(int const fd, char **line) +{ + char *tmp; + char buff[BUFF_SIZE + 1]; + static char *tab[256]; + int ret; + + if (fd < 0 || BUFF_SIZE < 1 || !line || read(fd, buff, 0) < 0) + return (-1); + if (!(tab[fd]) && (tab[fd] = ft_strnew(0)) == NULL) + return (-1); + while (!(ft_strchr(tab[fd], '\n')) && (ret = read(fd, buff, BUFF_SIZE)) > 0) + { + buff[ret] = '\0'; + tmp = tab[fd]; + tab[fd] = ft_strnjoin(tmp, buff, ret); + free(tmp); + } + *line = ft_strsub(tab[fd], 0, ft_linelen(tab[fd])); + if (ft_line(tab[fd]) == NULL) + return (0); + return (1); +} diff --git a/libft/libft.h b/libft/libft.h new file mode 100755 index 0000000..110b400 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,253 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/29 22:22:07 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:53:31 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include + +# define NOTHING 0b000000000 +# define MINES 0b000000001 +# define PLUS 0b000000010 +# define HASH 0b000000100 +# define SPACE 0b000001000 +# define ZERO 0b000010000 +# define BUFF_SIZE 100 + +# define MNS(c) (c - '0') +# define PLS(c) (c + '0') + +typedef struct s_data +{ + int jumper; + int ps; + int flg; + int pres; + int h_flags; + int l_flags; + int fw0; + int fw1; + int huck; + char *f_lags; + char *types; + char *ar; +} t_data; + +typedef struct s_cnt +{ + char *arr; + long double c; + double s; + int i; + int total; + int x; + int a; + int b; + char *res; + char *z; + char *mantissa; + char *exp; + int sign; + char lg; + int u; +} t_cnt; + +typedef struct s_lol +{ + int y; + int x; + int d; + int tp; + int z; + int k; + int r; + int p; + char *vf; + char *res; + char *tmp; +} t_lol; + +typedef struct s_ayy +{ + char *rar; + char *tmp; + char a; + unsigned long long n; + int w0; + int w1; + int y0; + int y1; + int y2; + int carry; + int looper; + long long sum; +} t_ayy; + +int ft_strscmp(const char *s1, const char *s2, size_t s, + size_t n); +char *ft_strscpy(char *dst, const char *src, size_t s, + size_t len); +int get_next_line(int const fd, char **line); +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); +void ft_putchar(char c); +int ft_memcmp(const void *s1, const void *s2, size_t n); +int ft_strlen(const char *str); +size_t ft_strlenp(const char *str); +char *ft_strdup(char *s1); +char *ft_strcpy(char *dst, const char *src); +char *ft_strnjoin(char const *s1, char const *s2, size_t n); +char *ft_strncpy(char *dst, const char *src, size_t len); +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 *str, const char *srh); +char *ft_strnstr(const char *str, const char *srh, + 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); +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); +void *ft_memalloc(size_t size); +void ft_memdel(void **ap); +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_putstr(char const *s); +void ft_striteri(char *s, void(*f)(unsigned int, char *)); +void ft_putendl(char const *s); +void ft_putnbr(int n); +char *ft_strmap(char const *s, char (*f)(char)); +char *ft_strmapi(char const *s, + char (*f)(unsigned int, char)); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char const *s, int fd); +void ft_putendl_fd(char const *s, int fd); +void ft_putnbr_fd(int n, int fd); +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 *s1, unsigned int start, + size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s); +char **ft_strsplit(char const *s, char c); +char *ft_itoa_u(unsigned long long n); +char *ft_itoa(long long n); +int check_ad(void *p); +void z_data_flg(t_data *data, t_lol lol, const char *ar); +void a01_prim(t_data *data, t_cnt *cnt, t_lol *lol, + const char *ar); +void a04_prim(t_data data, t_cnt *cnt, va_list vl, + const char *f); +void a04_p(t_data data, t_cnt *cnt); +void a02(t_data *data, t_lol lol, const char *ar); +void it_b09(unsigned long long value, int base, t_ayy *ayy); +void dd(int i, int j, char b); +void a06_prim(t_data data, t_cnt *cnt); +void a10prim(t_data data, t_cnt *cnt, const char *ar, + va_list vl); +void a11d_prim(t_data data, const char *ar, t_cnt *cnt); +void a10prim0(t_data data, t_cnt *cnt, const char *ar); +void z_data_huck(t_data *data, t_lol lol, const char *ar); +void z_data_fw(t_data *data, t_lol lol, const char *ar); +void z_data_hl(t_data *data, t_lol lol, const char *ar); +void z_06_str1(t_data data, t_cnt *cnt, t_ayy *ayy); +void z_06_str2(t_data data, t_cnt *cnt, t_ayy *ayy); +void a10primp(t_ayy ayy, t_data data, t_cnt *cnt, + const char *ar); +int pn(long long cnt); +int pn_u(unsigned long long cnt); +void f_loat(const char *ar, t_data data, t_cnt *cnt, + va_list vl); +long double c_onvert(const char *bnr); +long long ft_pow(long long x, long long y); +char *get_bits(char *ptr, size_t size); +char *ft_sum(char *ar, char *ax); +void ft_sump(char *ax, char *ar, t_ayy *ayy); +char *ft_powx(char *x, int y); +char *ft_multi(char *ar, char *ax); +void ft_multi0(char *ar, char *ax, t_ayy *ayy); +char *ft_strev (char *x); +char *ignor(char *r); +char *l_exponnt(char *ar, int x, t_lol *lol); +int ft_printf (const char *f, ...); +void xxp_0(t_ayy ayy, t_data data, t_cnt *cnt, + const char *ar); +void xxp_1(t_ayy ayy, t_data data, t_cnt *cnt, + const char *ar); +void xxp_2(t_ayy ayy, t_data data, t_cnt *cnt); +void xxp_3(t_ayy ayy, t_data data, t_cnt *cnt); +void xxp_1p(t_ayy ayy, t_data data, t_cnt *cnt, + const char *ar); +void xxp2_p(t_ayy ayy, t_data data, t_cnt *cnt); +void xxp3_p(t_ayy ayy, t_data data, t_cnt *cnt, + const char *ar); +void z_06_sp(t_data data, t_cnt *cnt, t_ayy *ayy); +void diu_0(t_data data, const char *ar, t_cnt *cnt, + t_ayy *ayy); +void diu_1(t_data data, t_cnt *cnt, t_ayy *ayy); +void diu_2(t_data data, t_cnt *cnt, t_ayy *ayy); +void diu_11(t_data data, const char *ar, t_cnt *cnt, + t_ayy *ayy); +void diu_3(t_data data, t_cnt *cnt, + t_ayy *ayy); +void o_01(t_ayy ayy, t_data data, t_cnt *cnt, + const char *ar); +void o_02(t_ayy ayy, t_data data, t_cnt *cnt); +void o_03(t_ayy ayy, t_data data, t_cnt *cnt); +int ft_abs(int x); +void f_loat0(t_cnt *cnt, t_lol *lol); +void f_loat2(const char *ar, t_data data, t_cnt *cnt, + t_lol *lol); +void f_loat1(t_data data, t_cnt *cnt, t_lol *lol); +void f_loat3(const char *ar, t_data data, t_cnt *cnt, + t_lol *lol); +void f_loat4(const char *ar, t_data data, t_cnt *cnt, + t_lol *lol); +void f_loat5(t_data data, t_cnt *cnt, t_lol *lol); +void f_loat6(const char *ar, t_data data, t_cnt *cnt, + t_lol *lol); +void f_loat3p(const char *vf, t_data data, t_cnt *cnt, + t_lol *lol); +int f_loat11(t_data data, t_cnt *cnt, t_lol *lol); +void f_loat00(int a, t_lol *lol, t_cnt *cnt, char *vf); +void float_p0(const char *ar, t_data data, t_cnt *cnt, + t_lol *lol); +char *powx0(char *w, int y, char *x, char *str); +void f_lags0(t_data data, t_cnt *cnt, va_list vl); +void f_lags1(t_data data, t_cnt *cnt, va_list vl); +void print_typs(t_data data, const char *f, t_cnt *cnt, + va_list vl); +int trt(t_cnt *cnt, t_lol *lol, const char *f, va_list vl); +void f_3bita(t_data data, t_cnt *cnt); +int f_loatp(const char *ar, t_data data, + t_cnt *cnt, t_lol *lol); +void flgas(t_data data, t_cnt *cnt); +void f_4bita(t_data data, t_cnt *cnt); +#endif diff --git a/libft/lolot.c b/libft/lolot.c new file mode 100755 index 0000000..d26dcae --- /dev/null +++ b/libft/lolot.c @@ -0,0 +1,125 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lolot.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/02 01:35:56 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:32:52 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ignor(char *r) +{ + t_ayy ayy; + + ayy.w0 = 0; + ayy.looper = 0; + while (r[ayy.looper]) + { + if (r[ayy.looper] == '0') + ayy.looper++; + else + { + ayy.rar = ft_strnew(ft_strlen(r) - ayy.looper); + while (r[ayy.looper]) + { + ayy.rar[ayy.w0] = r[ayy.looper]; + ayy.w0++; + ayy.looper++; + } + if (ayy.w0 != 0) + { + free(r); + return (ayy.rar); + } + } + } + return (r); +} + +char *expennt(char *str, int a) +{ + int len; + int j; + char *res; + + len = ft_strlen(str); + j = len; + res = ft_memset(ft_strnew(a), '0', a); + while (j >= 0) + { + if (str[j] == '1') + res = ft_sum(res, ft_powx(ft_strdup("2"), (len - j - 1))); + j--; + } + return (ignor(res)); +} + +char *l_exponnt(char *ar, int x, t_lol *lol) +{ + int len; + int j; + char *tab; + long long res; + + len = ft_strlen(ar); + j = len; + res = 0; + while (j >= 0) + { + if (ar[j] == '1') + res += ft_pow(2, (len - j - 1)); + j--; + } + res = (res == 0 ? (1 - x) : (res - x)); + lol->y = res; + if (res < 0) + tab = ft_powx(ft_strdup("5"), ft_abs(res)); + else + tab = ft_powx(ft_strdup("2"), res); + return (ignor(tab)); +} + +int ft_iszero(char *str) +{ + int i; + + i = 0; + while (str[i]) + { + if (str[i] != '0') + return (0); + i++; + } + return (1); +} + +void f_loat00(int a, t_lol *lol, t_cnt *cnt, char *vf) +{ + char *x; + char *tp; + int y; + + lol->p = 0; + y = (int)vf[a]; + if (y < '5') + y = -1; + else if (y == '5' && ft_iszero(vf + a + 1)) + y = 0; + else + y = 1; + if (a <= ft_strlen(vf) && (y == 1 || + (y == 0 && ((int)vf[a - 1] % 2 == 1)))) + { + lol->p = 1; + a = ft_strlen(vf) - a; + x = ft_powx(ft_strdup("10"), a); + tp = ft_strdup(lol->vf); + free(cnt->arr); + cnt->arr = ft_sum(tp, x); + } +} diff --git a/libft/main.c b/libft/main.c new file mode 100755 index 0000000..6a3e1dd --- /dev/null +++ b/libft/main.c @@ -0,0 +1,15 @@ +#include "libft.h" +#include +int main (void) +{ + int i; + int tab[5] = {213213, -21, 0, 531, 100000}; + + i = 0; + while (i < 5) + { + ft_printf ("M%s\n", ft_itoa(tab[i])); + printf ("S%s\n", ft_itoa(tab[i++])); + } + +} \ No newline at end of file diff --git a/libft/opert.c b/libft/opert.c new file mode 100755 index 0000000..720916f --- /dev/null +++ b/libft/opert.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* opert.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/19 14:22:37 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:33:14 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_multi(char *ar, char *ax) +{ + t_ayy ayy; + + ayy.y0 = ft_strlen(ax); + ayy.y1 = ft_strlen(ar); + ayy.rar = ft_memset(ft_strnew(ayy.y0 + ayy.y1), '0', (ayy.y0 + ayy.y1)); + ayy.sum = 0; + ayy.w0 = -1; + if (ayy.y1 == 0 || ayy.y0 == 0) + { + if (ft_strcmp(ax, ar)) + free(ar); + free(ax); + return (ayy.rar); + } + ft_multi0(ar, ax, &ayy); + if (ft_strcmp(ax, ar)) + free(ar); + free(ax); + return (ignor(ft_strev(ayy.rar))); +} + +void ft_multi0(char *ar, char *ax, t_ayy *ayy) +{ + while (--ayy->y1 >= 0) + { + ayy->looper = ++ayy->w0; + ayy->carry = 0; + ayy->y0 = ft_strlen(ax); + while (--ayy->y0 >= 0) + { + ayy->sum = MNS(ar[ayy->y1]) * MNS(ax[ayy->y0]) + + MNS(ayy->rar[ayy->looper]) + ayy->carry; + ayy->rar[ayy->looper++] = PLS(ayy->sum % 10); + ayy->carry = ayy->sum / 10; + } + ayy->rar[ayy->looper] += (ayy->carry > 0 ? ayy->carry : 0); + } +} + +char *ft_sum(char *ar, char *ax) +{ + t_ayy ayy; + + if (ft_strlen(ax) > ft_strlen(ar)) + { + ayy.tmp = ax; + ax = ar; + ar = ayy.tmp; + } + ar = ft_strev(ar); + ax = ft_strev(ax); + ft_sump(ax, ar, &ayy); + while (++ayy.looper < ayy.w0) + { + ayy.y0 = MNS(ar[ayy.looper]) + + (ayy.looper < ayy.w1 ? MNS(ax[ayy.looper]) : 0) + ayy.carry; + ayy.rar[ayy.looper] = PLS(ayy.y0 % 10); + ayy.carry = ayy.y0 / 10; + } + free(ar); + free(ax); + if (ayy.carry) + ayy.rar[ayy.looper++] = '1'; + return (ignor(ft_strev(ayy.rar))); +} + +void ft_sump(char *ax, char *ar, t_ayy *ayy) +{ + ayy->w0 = ft_strlen(ar); + ayy->w1 = ft_strlen(ax); + ayy->rar = ft_strnew(ayy->w0 + ayy->w1); + ayy->looper = -1; + ayy->carry = 0; +} + +int ft_abs(int x) +{ + return (x < 0 ? -x : x); +} diff --git a/libft/opert2.c b/libft/opert2.c new file mode 100755 index 0000000..394e5e3 --- /dev/null +++ b/libft/opert2.c @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* opert2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/21 08:58:41 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:33:23 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *get_bits(char *ptr, size_t size) +{ + int i; + size_t jumper; + char *x; + + jumper = -1; + x = ft_strnew(size * 8); + ptr += size - 1; + while (size--) + { + i = 8; + while (i--) + x[++jumper] = ((((*ptr) >> i) & 1) ? '1' : '0'); + ptr--; + } + return (x); +} + +long long ft_pow(long long x, long long y) +{ + long long w; + + w = 1; + while (y--) + w *= x; + return (w); +} + +char *ft_powx(char *x, int y) +{ + char *w; + char *str; + + str = NULL; + w = ft_memset(ft_strnew(y + 1), '0', y + 1); + if (y == 0) + { + w[y] = '1'; + free(x); + return (w); + } + if (ft_atoi(x) == 10) + { + w[0] = '1'; + free(x); + return (w); + } + else + return (powx0(w, y, x, str)); +} + +char *powx0(char *w, int y, char *x, char *str) +{ + char *str0; + + w[y] = '1'; + while (y > 1) + { + if (y % 2 == 0) + { + str = ft_multi(x, x); + x = str; + str = NULL; + y /= 2; + } + else + { + str0 = ft_strdup(x); + str = ft_multi(x, w); + w = ft_strdup(str); + x = ft_multi(str0, str0); + free(str); + y = (y - 1) / 2; + } + } + return (ft_multi(x, w)); +} + +char *ft_strev(char *x) +{ + int i; + int j; + char *ax; + + j = 0; + i = ft_strlen(x); + ax = ft_strnew(i + 1); + while (i--) + { + ax[j] = x[i]; + j++; + } + free(x); + return (ax); +} diff --git a/libft/popac.c b/libft/popac.c new file mode 100755 index 0000000..5a7be74 --- /dev/null +++ b/libft/popac.c @@ -0,0 +1,105 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* popac.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/14 05:06:25 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:33:34 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void a06_prim(t_data data, t_cnt *cnt) +{ + t_ayy ayy; + + if (!cnt->arr) + cnt->arr = "(null)"; + ayy.y0 = ft_strlen(cnt->arr); + if (data.ps != data.pres) + { + if (data.fw0 >= ayy.y0) + ayy.w1 = data.fw1 - ayy.y0; + else if (data.fw0 < 0) + ayy.w1 = data.fw1; + else if (data.fw0 < ayy.y0) + ayy.w1 = data.fw1 - data.fw0; + if (data.huck == 1 || data.huck == 3) + { + cnt->total += (data.fw0 > 0 ? data.fw0 : 0); + dd(data.fw0, 0, ' '); + } + z_06_str1(data, cnt, &ayy); + } + z_06_str2(data, cnt, &ayy); +} + +void z_06_str1(t_data data, t_cnt *cnt, t_ayy *ayy) +{ + if (data.huck == 0 && !(data.flg & MINES)) + { + if (data.fw0 > 0) + cnt->total += (data.fw0 > ayy->y0 ? ayy->y0 : data.fw0); + cnt->total += (ayy->w1 > 0 ? ayy->w1 : 0); + dd(ayy->w1, 0, ' '); + while (data.fw0-- > 0 && *cnt->arr != '\0') + ft_putchar(*cnt->arr++); + } + z_06_sp(data, cnt, ayy); +} + +void z_06_sp(t_data data, t_cnt *cnt, t_ayy *ayy) +{ + if ((data.huck == 2 || data.huck == 0) && (data.flg & MINES)) + { + if (data.fw0 > 0) + cnt->total += (data.fw0 > ayy->y0 ? ayy->y0 : data.fw0); + cnt->total += (ayy->w1 > 0 ? ayy->w1 : 0); + while (data.fw0-- > 0 && *cnt->arr != '\0') + ft_putchar(*cnt->arr++); + dd(ayy->w1, 0, ' '); + } +} + +void z_06_str2(t_data data, t_cnt *cnt, t_ayy *ayy) +{ + if (data.pres == data.ps) + { + ayy->w1 = (data.fw1 > ayy->y0) ? (data.fw1 - ayy->y0) : 0; + cnt->total += ayy->w1 + ayy->y0; + if (!(data.flg & MINES)) + { + dd(ayy->w1, 0, ' '); + ft_putstr(cnt->arr); + } + else if (data.flg & MINES) + { + ft_putstr(cnt->arr); + dd(ayy->w1, 0, ' '); + } + } +} + +void diu_3(t_data data, t_cnt *cnt, t_ayy *ayy) +{ + if ((data.flg & MINES) && (data.huck == 2 || data.huck == 0)) + { + cnt->total += (ayy->w0 > 0 ? ayy->w0 : 0) + (ayy->w1 > 0 ? ayy->w1 : 0); + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + dd(ayy->w0, 0, '0'); + cnt->total += ft_printf("%s", ayy->rar); + dd(ayy->w1, 0, ' '); + } + else if (data.huck == 1 || data.huck == 3) + { + if (ayy->looper == 1) + cnt->total += ft_printf("%c", ayy->a); + ayy->w0 = data.fw0 - ayy->y1; + cnt->total += ft_printf("%s", ayy->rar) + (ayy->w0 > 0 ? ayy->w0 : 0); + dd(ayy->w0, 0, ' '); + } +} diff --git a/libft/stdarg0.c b/libft/stdarg0.c new file mode 100755 index 0000000..24c06ac --- /dev/null +++ b/libft/stdarg0.c @@ -0,0 +1,131 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stdarg0.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/05 17:13:24 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:33:48 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void a02(t_data *data, t_lol lol, const char *ar) +{ + int q; + + data->jumper = lol.x; + data->ps = 0; + data->pres = 0; + while (ar[++data->jumper] && data->ps == 0) + { + lol.z = -1; + q = 0; + while (data->types[++lol.z]) + { + if (data->types[lol.z] == ar[data->jumper]) + { + data->ps = data->jumper; + q = (data->jumper) - (lol.x + 1); + } + else if (data->ps > 0) + break ; + } + if (q < 1) + z_data_flg(data, lol, ar); + } +} + +void z_data_flg(t_data *data, t_lol lol, const char *ar) +{ + lol.z = -1; + while (data->f_lags[++lol.z]) + if (data->f_lags[lol.z] == ar[data->jumper]) + { + if (lol.z == 0 && !(data->flg & MINES)) + data->flg = data->flg + (1 << lol.z); + if ((ar[data->jumper] == '.') && ar[data->jumper + 1] == '0' && + (ar[data->jumper + 2] == '-')) + data->huck = 1; + else if (lol.z == 1 && !(data->flg & PLUS)) + data->flg = data->flg + (1 << lol.z); + else if (lol.z == 2 && !(data->flg & HASH)) + data->flg = data->flg + (1 << lol.z); + else if (lol.z == 3 && !(data->flg & SPACE)) + data->flg = data->flg + (1 << lol.z); + else if (lol.z == 4 && !(data->flg & ZERO)) + { + if (!(ft_isdigit(ar[data->jumper - 1])) && + (ar[data->jumper - 1] != '.') && !(data->flg & MINES)) + data->flg = data->flg + (1 << lol.z); + } + } +} + +void z_data_huck(t_data *data, t_lol lol, const char *ar) +{ + data->huck = 0; + data->pres = data->ps; + data->jumper = lol.x - 1; + while (ar[++data->jumper] && data->jumper < data->ps) + { + if ((ar[data->jumper] == '.') && (ar[data->jumper + 1] == '-')) + data->huck = 1; + if ((ar[data->jumper] == '.') && (ar[data->ps - 1] == '-')) + data->huck = 2; + if ((ar[data->jumper] == '.') && (ar[data->ps - 1] == '-') && + (ar[data->jumper + 1] == '-')) + data->huck = 3; + if (ar[data->jumper] == '.') + data->pres = data->jumper; + } +} + +void z_data_fw(t_data *data, t_lol lol, const char *ar) +{ + data->jumper = lol.x - 1; + data->fw1 = -1; + data->fw0 = -1; + while (ar[++data->jumper] && data->jumper < data->ps) + { + if (data->fw1 <= 0 && ft_isdigit(ar[data->jumper]) == 1 && + data->jumper < data->pres) + { + data->fw1 = ft_atoi(ar + data->jumper); + while (ft_isdigit(ar[data->jumper])) + data->jumper++; + } + else if (data->fw0 <= 0 && ft_isdigit(ar[data->jumper]) == 1 && + data->jumper > data->pres) + { + data->fw0 = ft_atoi(ar + data->jumper); + while (ft_isdigit(ar[data->jumper])) + data->jumper++; + } + } + data->fw0 = (data->fw0 < -1 ? 6 : data->fw0); +} + +void z_data_hl(t_data *data, t_lol lol, const char *ar) +{ + data->h_flags = -1; + data->l_flags = -1; + data->jumper = lol.x - 1; + while (ar[++data->jumper] && data->jumper < data->ps) + { + if (ar[data->jumper] == 'h') + data->h_flags = (ar[data->jumper] == 'h' ? 1 : -1); + if (ar[data->jumper] == 'h' && ar[data->jumper - 1] == 'h' && + data->h_flags == 1) + data->h_flags = 2; + if (ar[data->jumper] == 'l') + data->l_flags = 1; + if (ar[data->jumper] == 'l' && ar[data->jumper - 1] == 'l' && + data->l_flags == 1) + data->l_flags = 2; + if (ar[data->jumper] == 'L') + data->l_flags = 3; + } +} diff --git a/libft/xxp.c b/libft/xxp.c new file mode 100755 index 0000000..c8ff257 --- /dev/null +++ b/libft/xxp.c @@ -0,0 +1,115 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* xxp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/29 03:10:20 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:33:59 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void a10prim(t_data data, t_cnt *cnt, const char *ar, va_list vl) +{ + t_ayy ayy; + + if (ar[data.ps] == 'p') + { + cnt->c = va_arg(vl, unsigned long); + it_b09(cnt->c, 16, &ayy); + cnt->x = 2; + if (!cnt->c && data.fw0 <= 0 && ar[data.pres] == '.') + ayy.rar[0] = '\0'; + } + it_b09(cnt->c, 16, &ayy); + cnt->arr = "0x"; + if (ar[data.ps] != 'p') + xxp_0(ayy, data, cnt, ar); + xxp_1(ayy, data, cnt, ar); + free(ayy.rar); +} + +void xxp_0(t_ayy ayy, t_data data, t_cnt *cnt, const char *ar) +{ + cnt->i = -1; + cnt->x = 0; + if (!cnt->c && data.fw1 < 0 && data.fw0 <= 0 && ar[data.pres] == '.') + ayy.rar[0] = '\0'; + if (cnt->c == 0 && data.fw0 <= 0 && ar[data.pres] == '.' && data.fw1 <= 0) + ayy.rar[0] = '\0'; + if (cnt->c == 0 && data.fw0 <= 0 && ar[data.pres] == '.' && data.fw1 > 0) + ayy.rar[0] = ' '; + if (ar[data.ps] == 'X') + { + cnt->arr = "0X"; + while (ayy.rar[++cnt->i]) + { + if (ayy.rar[cnt->i] >= 'a' && ayy.rar[cnt->i] <= 'f') + ayy.rar[cnt->i] = ayy.rar[cnt->i] - 32; + } + } + if (cnt->c != 0) + cnt->x = (data.flg & HASH ? 2 : 0); +} + +void xxp_1(t_ayy ayy, t_data data, t_cnt *cnt, const char *ar) +{ + ayy.y0 = ft_strlen(ayy.rar); + cnt->total += ayy.y0 + cnt->x; + if (data.fw1 > (ayy.y0 + cnt->x) && data.fw0 <= ayy.y0) + { + ayy.w1 = data.fw1 - ayy.y0 - cnt->x; + cnt->total += ayy.w1; + xxp_1p(ayy, data, cnt, ar); + } + xxp_2(ayy, data, cnt); +} + +void xxp_1p(t_ayy ayy, t_data data, t_cnt *cnt, const char *ar) +{ + if (!(data.flg & MINES)) + { + if (data.flg & ZERO && ar[data.pres] != '.') + { + if (cnt->x == 2) + ft_putstr(cnt->arr); + dd(ayy.w1, 0, '0'); + } + else + { + dd(ayy.w1, 0, ' '); + if (cnt->x == 2) + ft_putstr(cnt->arr); + } + ft_putstr(ayy.rar); + } + else + { + if (cnt->x == 2) + ft_putstr(cnt->arr); + ft_putstr(ayy.rar); + dd(ayy.w1, 0, ' '); + } +} + +void xxp_2(t_ayy ayy, t_data data, t_cnt *cnt) +{ + if (data.fw1 <= (data.fw0 + cnt->x) && data.fw0 > ayy.y0) + xxp2_p(ayy, data, cnt); + else if (data.fw0 <= ayy.y0 && data.fw1 <= ayy.y0 + cnt->x) + { + if (cnt->x == 2) + ft_putstr(cnt->arr); + ft_putstr(ayy.rar); + } + else if (data.fw0 > ayy.y0 && data.fw1 > (data.fw0 + cnt->x)) + { + ayy.w0 = data.fw0 - ayy.y0; + ayy.w1 = data.fw1 - data.fw0 - cnt->x; + cnt->total += ayy.w1 + ayy.w0; + xxp_3(ayy, data, cnt); + } +} diff --git a/libft/xxp0.c b/libft/xxp0.c new file mode 100755 index 0000000..259d243 --- /dev/null +++ b/libft/xxp0.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* xxp0.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/29 03:10:30 by zael-mab #+# #+# */ +/* Updated: 2020/03/02 23:34:11 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void xxp2_p(t_ayy ayy, t_data data, t_cnt *cnt) +{ + if (cnt->x == 2) + ft_putstr(cnt->arr); + if (data.huck == 1 || data.huck == 3) + { + ayy.w0 = data.fw0 - ayy.y0 - cnt->x; + ft_putstr(ayy.rar); + dd(ayy.w0, 0, ' '); + } + else if (data.huck == 2 || data.huck == 0) + { + ayy.w0 = data.fw0 - ayy.y0; + dd(ayy.w0, 0, 48); + ft_putstr(ayy.rar); + } + cnt->total += ayy.w0; +} + +void xxp_3(t_ayy ayy, t_data data, t_cnt *cnt) +{ + if (!(data.flg & MINES)) + { + dd(ayy.w1, 0, ' '); + if (cnt->x == 2) + ft_putstr(cnt->arr); + dd(ayy.w0, 0, 48); + ft_putstr(ayy.rar); + } + else if ((data.flg & MINES) && (data.huck == 2 || data.huck == 0)) + { + if (cnt->x == 2) + ft_putstr(cnt->arr); + dd(ayy.w0, 0, '0'); + ft_putstr(ayy.rar); + dd(ayy.w1, 0, ' '); + } + else if (data.huck == 1 || data.huck == 3) + { + if (cnt->x == 2) + ft_putstr(cnt->arr); + ft_putstr(ayy.rar); + dd(ayy.w0, 0, ' '); + } +} diff --git a/link_lst.c b/link_lst.c new file mode 100644 index 0000000..32fab6c --- /dev/null +++ b/link_lst.c @@ -0,0 +1,126 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* link_lst.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/02/02 15:32:58 by zael-mab #+# #+# */ +/* Updated: 2021/02/02 18:25:05 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + + +#include "asm.h" + +void init_head(t_head *head) +{ + head = ft_memalloc (sizeof (t_head)); + head->first = NULL; + head->l_size = 0; +} +/////////////////////////////////// + + +t_node *insert_node(t_head *head, void *data, int pos) +{ + t_node *new_node; + t_node *p; + + new_node = ft_memalloc (sizeof (t_node)); + new_node->data = data; + new_node->operation_num = pos > -1 ? pos : -1; + new_node->next = NULL; + if (head->first == NULL) + { + head->first = new_node; + new_node->position = head->l_size++; + } + else + { + p = head->first; + while (p->next != NULL) + p = p->next; + p->next = new_node; + new_node->position = head->l_size++; + } + return (new_node->position + 1 == head->l_size ? new_node : NULL); +} + + +t_node *search(t_node *l, char* x) +{ + if (l == NULL) + return NULL; + if (!ft_strcmp(l->data, x)) + return (l); + else + return (search(l->next, x)); + +} + + +void display_nodes(t_head *head) +{ + t_node *l; + + l = head->first; + while (l) + { + ft_printf("_|%d|\t[%s]\t", l->position, l->data); + if (l->operation_num > -1) + ft_printf ("-%d-", l->operation_num); + ft_putchar ('\n'); + l = l->next; + } +} + + + +t_node *save_labels(t_head *labels, char *line, t_head *head) +{ + int j; + int i; + char *tmp; + static int tmp_post; + t_node p; //[ marker: + t_node t; // # End of file ] if a label didn't followed by '\n' at the end of file it's an error fix it . + + ft_bzero(&p, sizeof (t_node)); + ft_bzero(&t, sizeof (t_node)); + j = -1; + while (line[++j]) + if (line[j] == LABEL_CHAR) + break ; + +/////////////////////// + if (ft_strlen(line) > j) + { + tmp = ft_strncpy(ft_strnew(j), line, j); + i = -1; + while (++i <= j) + if (ft_isdigit(tmp[i]) || tmp[i] == 95 || (tmp[i] >= 97 && tmp[i] <= 122)); + else + break ; + +///////////////// + ft_printf ("*****%c***\n", line[i]); + if (j == i) + { + if (ft_strlen(line) > j + 1) + { + p = *insert_node (head, ft_strtrim (j + 1 +line), -1); // insert eash line + t = *insert_node(labels, tmp, p.position); + } + else + t = *insert_node(labels, tmp, tmp_post); + return (NULL); + } + free (tmp); + } + p = *insert_node (head, line, -1); + tmp_post = p.position + 1; + return (NULL); +} + +////////////////////////////////// \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..4e139ac --- /dev/null +++ b/main.c @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/01/28 10:48:04 by zael-mab #+# #+# */ +/* Updated: 2021/02/03 14:22:00 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "asm.h" + +// repeat. +// read the next Assembly command +// break it into the different fields it is composed of . +// lookup the binary code for each field. +// combine these code into a single machine language command. +// output this machine language command. + + +int main(int ac, char **av) +{ + if (ac == 2) + { + char *line; + int fd; + int ln; + // char *tmp; + t_head head; + // t_hop op; + t_head labels; + t_asmdata sdata; + + ft_bzero (&head, sizeof (t_head)); + // ft_bzero (&op, sizeof (t_hop)); + ft_bzero (&labels, sizeof (t_head)); + ft_bzero (&sdata, sizeof (t_asmdata)); + init_head (&head); + init_head (&labels); + // init_op(&op); + +// ///////////////////////////////////// + fd = open(av[1], O_RDONLY); + sdata.error = -1; + + // set_op_table(&op); + + ln = 0; + while (get_next_line(fd, &line) > 0) + { + // tmp = ft_strtrim(line); + // free (line); + // line = tmp; + + if (sdata.n == -1 && sdata.c == -1) + line = avoid_comment(line); // avoid comment + + // ft_printf("-------%s\n", line); + + if (sdata.n == -1 && sdata.c == -1) // avoid empty lines + save_labels(&labels, ft_strtrim(line), &head); + + check_champion(line, &sdata); // check and save the name & the comment + + free (line); + ln++; // I'll need ya later. + } + +///////////////***********/////////// + ft_printf ("\t[%s] | [%s]\t %d\n", sdata.name, sdata.comment, sdata.p_ex_code); + ft_printf ("\t----------\n"); + // display_nodes (&labels); + ft_printf ("\t----------\n"); + // display_nodes (&head); + ft_printf ("\t-----*----\n\n"); +/////////////***********/////////// + + pars_instructions(&head, &labels, &sdata); + + close (fd); + } + + if (ac == 1) + ft_printf ("No file detected!\n"); + if (ac > 2) + ft_printf ("Too many files!\n"); +} + + +char *avoid_comment (char *line) // deal with the comments !!! +{ + int i; + char *str; + + i = -1; + while (line[++i]) + { + if (line[i] == COMMENT_CHAR || line[i] == ALT_COMMENT_CHAR) + { + str = ft_strncpy(ft_strnew (i), line, i); + free (line); + return (str); + } + } + return (line); +} diff --git a/nodes.c b/nodes.c new file mode 100755 index 0000000..6f88721 --- /dev/null +++ b/nodes.c @@ -0,0 +1,225 @@ +#include "lem_in.h" + + +t_node *add_first(t_head *head, void* data) +{ + t_node *new_node; + + new_node = ft_memalloc (sizeof (t_node)); + new_node->data = data; + new_node->next = head->first; + head->first = new_node; + head->size +=1; + return (new_node); +} + +t_node *search(t_node *l, void* x) +{ + if (l == NULL) + return NULL; + if (l->data == x) + return (l); + else + return (search(l->next, x)); + +} + +t_node *push_list (t_head *head, void * data) +{ + t_node *new_node; + + new_node = ft_memalloc (sizeof (t_node)); + new_node->data = ft_strdup(data); + new_node->next = NULL; + + if (head->first == NULL) + { + head->size +=1; + head->first = new_node; + } + else + { + ////////////////////////////////////// + t_node *p = head->first; + int d = -1; + + if (ft_strcmp(head->first->data , data) > 0) + { + new_node->next = head->first; + head->first = new_node; + } + else + { + while (p->next != NULL) + { + if (ft_strcmp(p->next->data , data) > 0) + { + d = 0; + new_node->next = p->next; + p->next = new_node; + break ; + } + if (ft_strcmp(p->next->data, data) == 0) + { + free (new_node); + return NULL; + } + p = p->next; + } + ///////////////////////////////////////// + if (d == -1) + p->next = new_node; + } + head->size += 1; + } + return (new_node); +} + +/////////////////////////// + +void display (t_head *head) +{ + t_node *p; + + p = head->first; + while (p != NULL) + { + ft_printf (" *[%s]P(%d) ", p->data, p->pos); + p = p->next; + } + ft_printf ("\n"); +} + +///////////////////// + +void init_list_table (t_table **table, int size) +{ + int i; + + i =-1; + while (++i < size) + table[i]->head = ft_memalloc (sizeof (t_head)); +} + +boolean insert_graph (t_head *head, void *x, int y) +{ + t_node *new_node; + + new_node = ft_memalloc (sizeof (t_node)); + new_node->data = ft_strdup(x); + // ft_printf ("\t[data = %s] -- [data.x = %d]\n", x, data.y); + new_node->pos = y; + new_node->state = 0; + new_node->next = NULL; + if (head->first == NULL) + { + head->first = new_node; + head->size += 1; + return (1); + } + else + { + /////////////////////////// + t_node *p; + p = head->first; + while (p->next != NULL) + { + if (ft_strcmp(x, p->data) == 0) + { + free (new_node); + return (0); + } + p = p->next; + } + if (ft_strcmp (x, p->data) == 0) + { + free(new_node); + return (0); + } + p->next = new_node; + head->size += 1; + return (1); + } + return (0); +} +///////////////////// + +void init_table(t_table **table, int size) +{ + int i; + + i = -1; + while (++i < size) + table[i] = NULL; +} + + +void print_table (t_table **table, int size) +{ + int i; + + i = -1; + while (++i < size) + { + if (table[i] == NULL) + ft_printf ("\t%d\t-------\n", i); + else + { + ft_printf ("\t%d==>[%s]", i, table[i]->data); + display (table[i]->head); + } + } +} + +boolean insert_table (t_table **table, t_head *head, t_data0 data) +{ + t_table *p; + t_node *pt; + size_t l; + + pt = head->first; + l = 0; + while (l < data.table_size) + { + p = ft_memalloc (sizeof (t_table)); + if (pt->data == NULL) + return 0; + p->data = ft_strdup(pt->data); + if (table[l] != NULL) + return 0; + table[l] = p; + pt = pt->next; + l++; + } + return 1; +} + + +//////////////////////////// + +void *list_get (t_head *head) +{ + t_node *tmp; + void *data; + + if (head->first == NULL) + return (NULL); + tmp = head->first; + data = tmp->data; + head->first = head->first->next; + head->size--; + free(tmp); + return (data); +} + +void list_del_all (t_head *head) +{ + while (head->first != NULL) + list_get(head); +} + + +// try new sort & search methods ; +// minimize the error parts and the loops for each line; +// free ****; +// norme \ No newline at end of file diff --git a/op.c b/op.c new file mode 100644 index 0000000..0b4e808 --- /dev/null +++ b/op.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* op.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/01/26 11:27:59 by zael-mab #+# #+# */ +/* Updated: 2021/01/26 11:28:05 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "op.h" +#include "asm.h" + +t_op op_tab[17] = +{ + {"live", 1, {T_DIR}, 1, 10, "alive", 0, 0}, + {"ld", 2, {T_DIR | T_IND, T_REG}, 2, 5, "load", 1, 0}, + {"st", 2, {T_REG, T_IND | T_REG}, 3, 5, "store", 1, 0}, + {"add", 3, {T_REG, T_REG, T_REG}, 4, 10, "addition", 1, 0}, + {"sub", 3, {T_REG, T_REG, T_REG}, 5, 10, "soustraction", 1, 0}, + {"and", 3, {T_REG | T_DIR | T_IND, T_REG | T_IND | T_DIR, T_REG}, 6, 6, + "et (and r1, r2, r3 r1&r2 -> r3", 1, 0}, + {"or", 3, {T_REG | T_IND | T_DIR, T_REG | T_IND | T_DIR, T_REG}, 7, 6, + "ou (or r1, r2, r3 r1 | r2 -> r3", 1, 0}, + {"xor", 3, {T_REG | T_IND | T_DIR, T_REG | T_IND | T_DIR, T_REG}, 8, 6, + "ou (xor r1, r2, r3 r1^r2 -> r3", 1, 0}, + {"zjmp", 1, {T_DIR}, 9, 20, "jump if zero", 0, 1}, + {"ldi", 3, {T_REG | T_DIR | T_IND, T_DIR | T_REG, T_REG}, 10, 25, + "load index", 1, 1}, + {"sti", 3, {T_REG, T_REG | T_DIR | T_IND, T_DIR | T_REG}, 11, 25, + "store index", 1, 1}, + {"fork", 1, {T_DIR}, 12, 800, "fork", 0, 1}, + {"lld", 2, {T_DIR | T_IND, T_REG}, 13, 10, "long load", 1, 0}, + {"lldi", 3, {T_REG | T_DIR | T_IND, T_DIR | T_REG, T_REG}, 14, 50, + "long load index", 1, 1}, + {"lfork", 1, {T_DIR}, 15, 1000, "long fork", 0, 1}, + {"aff", 1, {T_REG}, 16, 2, "aff", 1, 0}, + {"", 0, {0}, 0, 0, "", 0, 0} +}; + +// #include +// int main(void) { +// int i = -1; +// while (++i < 16) { + +// puts(op_tab[i].name); +// } +// return 0; +// } \ No newline at end of file diff --git a/op.h b/op.h new file mode 100644 index 0000000..aa76efd --- /dev/null +++ b/op.h @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* op.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/01/26 11:27:59 by zael-mab #+# #+# */ +/* Updated: 2021/01/26 11:28:05 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +# ifndef OP_H +# define OP_H + + +#define IND_SIZE 2 +#define REG_SIZE 4 +#define DIR_SIZE REG_SIZE + + +# define REG_CODE 1 +# define DIR_CODE 2 +# define IND_CODE 3 + + +#define MAX_ARGS_NUMBER 4 +#define MAX_PLAYERS 4 +#define MEM_SIZE (4*1024) +#define IDX_MOD (MEM_SIZE / 8) +#define CHAMP_MAX_SIZE (MEM_SIZE / 6) + +#define COMMENT_CHAR '#' // Indicates the beginning of the comment +#define ALT_COMMENT_CHAR ';' +#define LABEL_CHAR ':' +#define DIRECT_CHAR '%' +#define SEPARATOR_CHAR ',' + +#define LABEL_CHARS "abcdefghijklmnopqrstuvwxyz_0123456789" + +#define NAME_CMD_STRING ".name" // The length of the name must not exceed 128 +#define COMMENT_CMD_STRING ".comment" // must not exceed 2048 + +#define REG_NUMBER 16 + +#define CYCLE_TO_DIE 1536 +#define CYCLE_DELTA 50 +#define NBR_LIVE 21 +#define MAX_CHECKS 10 + +/* +** +*/ + +typedef char t_arg_type; + +#define T_REG 1 +#define T_DIR 2 +#define T_IND 4 +#define T_LAB 8 + +/* +** +*/ + +# define PROG_NAME_LENGTH (128) +# define COMMENT_LENGTH (2048) +# define COREWAR_EXEC_MAGIC 0xea83f3 + +typedef struct header_s +{ + unsigned int magic; + char prog_name[PROG_NAME_LENGTH + 1]; + unsigned int prog_size; + char comment[COMMENT_LENGTH + 1]; +} header_t; + +#endif \ No newline at end of file diff --git a/pars.c b/pars.c new file mode 100644 index 0000000..3d8f8fa --- /dev/null +++ b/pars.c @@ -0,0 +1,178 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pars.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/01/26 11:48:24 by zael-mab #+# #+# */ +/* Updated: 2021/02/03 14:22:42 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "asm.h" + +// name; +// Comment; +// Executable code; +// + +// FOR PARS: +// in one line - one instruction. "sequence of instructions" +// Empty lines, comments, as well as extra tabs or spaces are ignored. + +// verything between the character '#' and the end of the line is considered a comment. + +// An empty string is a valid champion name : [ .name "" ] +// but But lack of the string is an error: [ .name ] (same case for the comment) + +// Also, in the file .s must be present champion's comment. + +// the command " .extend " -and all other commands excepting '.name' and '.comment'- detected as an error + + +// FOR EXUECUTABLE CODE: +// Assembly language has a rule one instruction per line. The new line character \n means both end +// of line and end of instruction. So instead of ; as for C language, we will use \n. + +// Each redcode instruction contains 3 parts : Opcode itself, the source address A-field +// and the destination address B-field. + + + + + +boolean check_champion (char *line, t_asmdata *sdata) +{ + int j; + + if (ft_strscmp(NAME_CMD_STRING, line, 0, 5) == 0) + sdata->n = 1; + if (ft_strscmp(COMMENT_CMD_STRING, line, 0, 8) == 0) + sdata->c = 1; + + if (ft_strscmp(NAME_CMD_STRING, line, 0, 5) == 0 || ft_strscmp(COMMENT_CMD_STRING, line, 0, 8) == 0) + { + sdata->error = -1; + sdata->e = 0; + sdata->s = 0; + } + +///////////////////// + j = -1; + while (line[++j]) + { + if (line[j] == '"' && sdata->s && !sdata->e) + sdata->e = j + 1; + if (line[j] == '"' && !sdata->s) + sdata->s = j + 1; + } + +///////////////////// + if (sdata->n == 1 && sdata->s && sdata->e && sdata->error == -1) + if ((sdata->name = ft_strscpy(ft_strnew(PROG_NAME_LENGTH), line, sdata->s, sdata->e))) + sdata->n = -1; + + if (sdata->c == 1 && sdata->s && sdata->e && sdata->error == -1) + if((sdata->comment = ft_strscpy(ft_strnew(COMMENT_LENGTH), line, sdata->s, sdata->e))) + sdata->c = -1; + +///////////////////// + if (sdata->s && (sdata->c == 1 || sdata->n == 1)) + { + + sdata->error++; + if (sdata->n == 1) + join(line, sdata, &sdata->name, PROG_NAME_LENGTH); + if (sdata->c == 1) + join (line, sdata, &sdata->comment, COMMENT_LENGTH); + return (1); + } + + return (1); +} + + +boolean join (char *line, t_asmdata *sdata, char **cmd, int v) +{ + char *tmp; + + tmp = ft_strnew(ft_strlen(line)); + if (sdata->error == 0) + *cmd = ft_strjoin (ft_strnew(v), line + sdata->s); + if (sdata->error > 0 && !sdata->e) + *cmd = ft_strjoin (*cmd, line); + if (sdata->error > 0 && sdata->e) + { + *cmd = ft_strjoin(*cmd, ft_strscpy(tmp, line, 0, sdata->e)); + sdata->c = (sdata->c == 1 ? -1 : sdata->c); + sdata->n = (sdata->n == 1 ? -1 : sdata->n); + } + free (tmp); + return (1); +} + +////////////////////////////////////////////////// + + +void pars_instructions(t_head *head, t_head *labels, t_asmdata *sdata) //REG_NUMBER +{ + t_node *instruct; + t_node *lbl; + char *tmp; + int i; + + instruct = NULL; + lbl = NULL; + instruct = head->first; + sdata->p_ex_code = -1; + + while (instruct != NULL) + { + // ft_printf ("instructions.%d= %s\n", instruct->position, instruct->data); + i = -1; + while (instruct->data[++i]) + if (instruct->data[i] < 'a' || instruct->data[i] > 'z') + break; + ///////////////// + if (i > 0) + { + tmp = ft_strncpy(ft_strnew(5), instruct->data, i); + int x = -1; + while (++x < 17) + { + if (!ft_strcmp(tmp, op_tab[x].name) && pars_args(instruct->data + i, sdata, x)) + { + ft_printf ("mutch %s ==> [%s]\n", op_tab[x].name, tmp); + pars_args(instruct->data + i, sdata, x); + break ; + } + } + ft_printf("%d", sdata->error); + // ft_printf ("list[%s] ===> tmp[%s]\n", op_list->name, instruct->data); + free (tmp); + } + ////////////////////// + // while (op_list) + // { + // if ( i > 0 && !ft_strcmp(op_list->name, tmp)) + // { + // ft_printf("[%d]_%s |\t %s \n", op_list->code, instruct->data, op_list->name); + // pars_args(instruct->data + i, op_list); + + // instruct->op_code = op_list->code; + // instruct->op_arg1 = op_list->arg1; + // instruct->op_arg2 = op_list->arg2; + // instruct->op_arg3 = op_list->arg3; + // } + + lbl = labels->first; + // while (lbl) use the searsh(); !!! + // lbl = lbl->next; + // } + //////// + instruct = instruct->next; + } +} + + diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..7f65761 --- /dev/null +++ b/run.sh @@ -0,0 +1,11 @@ +#!/bin/bash +SRC=./champs/*.s + +for f in $SRC +do + echo "----------------------------------------------------------------------------" + echo "$f" + ./asm $f + ./test $f +done +rm -f ./champs/*.cor diff --git a/set_op.c b/set_op.c new file mode 100644 index 0000000..12cb1e4 --- /dev/null +++ b/set_op.c @@ -0,0 +1,13 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set_op.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zael-mab +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/02/21 15:10:31 by zael-mab #+# #+# */ +/* Updated: 2021/02/21 15:10:47 by zael-mab ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "asm.h" diff --git a/test.sm b/test.sm new file mode 100644 index 0000000..78527ba --- /dev/null +++ b/test.sm @@ -0,0 +1,8 @@ +.name "zork" +.comment "just a basic living prog" + +l2: sti r1, \%:live,\%1 + and r1, \%0,r1 + +live: live \%1 + zjmp \%:live diff --git a/test1.s b/test1.s new file mode 100644 index 0000000..c132e2e --- /dev/null +++ b/test1.s @@ -0,0 +1,18 @@ +.name "zork x" +.comment "Zork zork zork" + + +x1: +l2: sti r1, \%:live,\%1 + and r00012, \%0,r1 + +live: + live \%21 + zjmp \%:live + +# Executable co,pilation: +# +# 0x0b,0x68,0x01,0x00,0x0f,0x00,0x01 +# 0x06,0x64,0x01,0x00,0x00,0x00,0x00,0x01 +# 0x01,0x00,0x00,0x00,0x01 +# 0x09,0xff,0xfb diff --git a/toto.s b/toto.s new file mode 100644 index 0000000..c20b47f --- /dev/null +++ b/toto.s @@ -0,0 +1,93 @@ +# +# Warrior qui a gagne +# l'annee derniere +# VOALA +# +.name"Celebration Funebre v0.99pl42" +.comment "Jour +J +" + + + + + + + + + + ld %0,r13 + + + + + +label:zjmp %:avantdebt + zjmp %0 # pour eviter ecrasement + # de l'instruction suivante +titi: +toto: +code:live 42 # 5 + sti r15,%0,r14 # 6 + zjmp %-200 # 3 + live %42 # 5 + sti r15,%0,r14 # 6 + zjmp %-200 # 3 + live %42 # 5 + sti r15,%0,r14 # 6 + zjmp %-200 # 3 + live %42 # 5 + sti r15,%0,r14 # 6 + zjmp %-200 # 3 + sti r15,%0,r14 # 6 + zjmp %-200 # 3 + sti r15,%0,r14 # 6 + zjmp %-200 + +avantdebt: sti r1,%:code,%1 # # mets a jour le live + sti r1,%:code,%15 # # mets a jour le live + sti r1,%:code,%29 # # mets a jour le live + sti r1,%:code,%43 # # mets a jour le live + sti r1,%:code,%57 # # mets a jour le live + sti r1,%:code,%71 # # mets a jour le live +init:ld %393216,r4 #7 + ld %917504,r12 #7 + ld %1,r11 #7 + ld %6,r10 #7 +debt: live %42 #5 + sti r4,%:label,%1 #7 + add r4,r12,r4 #5 + sub r10,r11,r10 #5 + zjmp %:init #3 + fork %:debt + live %3 +level0: fork %:level10 +level11: live %4 + fork %:level111 + +level110: live %42 + ldi %8,%:code,r15 #set des octets 9-12 + ld %-186,r14 #=$A-6-8 + ld %0,r2 + zjmp %:label + +level10: live %42 + fork %:level100 +level101: live %42 + ldi %4,%:code,r15 #set des octets 5-8 + ld %-190,r14 #=$A-6-4 + ld %0,r2 + zjmp %:label + +level111: live %42 + ldi %12,%:code,r15 #set des octets 13-16 + ld %-182,r14 # $A -6 -12 + ld %0,r2 + zjmp %:label + +level100: live %42 + ldi %0,%:code,r15 #set des octets 1-4 + ld %-194,r14 # $A -6 -0 + ld %0,r2 # + zjmp %:label # + diff --git a/turtle.s b/turtle.s new file mode 100644 index 0000000..42da39d --- /dev/null +++ b/turtle.s @@ -0,0 +1,98 @@ +.name "turtle" +.comment "TURTLE FFS U LAMA" + +entry: + sti r1, %:zork, %1 + sti r1, %:ardef, %1 + sti r1, %:avdef, %1 + sti r1, %:entry_l1, %1 + ld %0, r16 + fork %:zork + +entry_l1: + live %42 + ld %439025904, r2 + ld %0, r16 + fork %:avdef + +################################################################################ + +ardef: + live %42 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + st r2, -400 + zjmp %:ardef + +################################################################################ + +zork: + live %42 + zjmp %:zork + +################################################################################ + +avdef: + live %42 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + st r2, 400 + zjmp %:avdef + +################################################################################