├── test └── libc │ ├── .gitignore │ ├── error │ └── .gitignore │ ├── README.md │ ├── configure │ ├── timer │ └── src │ │ └── main.c │ ├── unit │ └── src │ │ └── main.c │ ├── getopt │ └── src │ │ └── main.c │ ├── vector │ └── src │ │ └── main.c │ ├── queue │ └── src │ │ └── main.c │ ├── stack │ └── src │ │ └── main.c │ ├── string │ └── src │ │ └── main.c │ ├── rbtree │ └── src │ │ └── main.c │ └── f_math │ └── src │ └── main.c ├── examples ├── libc │ ├── error │ │ ├── .gitignore │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── array │ │ └── README.md │ ├── ldata │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── rand │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── list │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── matrix │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── queue │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── rbtree │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── stack │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── timer │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── unit │ │ └── README.md │ ├── arqueue │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── f_math │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── getopt │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── htable │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── string │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── vector │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── f_crypto │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── f_sort │ │ └── README.md │ ├── fdnotify │ │ └── README.md │ ├── threadpool │ │ └── README.md │ ├── f_error │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── f_memory │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── f_string │ │ ├── README.md │ │ └── src │ │ │ └── main.c │ ├── README.md │ ├── configure │ ├── lock │ │ └── src │ │ │ └── main.c │ └── Makefile └── makefile │ ├── print │ └── f_print.c │ ├── includes │ └── f_print.h │ └── srcs │ └── main.c ├── doc ├── images │ ├── logo-42.png │ ├── syntax.png │ ├── header-42.png │ └── generator-h.png └── misc │ ├── Makefile_part1.txt │ └── Makefile_part2.txt ├── .gitmodules ├── .travis.yml ├── srcs ├── README.md ├── libc │ ├── ldata │ │ ├── README.md │ │ └── include │ │ │ └── s_ldata.h │ ├── fdnotify │ │ ├── README.md │ │ ├── include │ │ │ ├── s_fdnotify_event.h │ │ │ └── s_fdnotify_cell.h │ │ └── src │ │ │ └── s_fdnotify_cell.c │ ├── f_secure │ │ └── README.md │ ├── reverse │ ├── f_error │ │ └── README.md │ ├── error │ │ └── README.md │ ├── threadpool │ │ ├── README.md │ │ └── include │ │ │ └── s_barrier.h │ ├── rand │ │ └── README.md │ ├── f_math │ │ ├── README.md │ │ ├── include │ │ │ ├── f_convert.h │ │ │ ├── f_math.h │ │ │ └── d_math.h │ │ └── src │ │ │ ├── f_abs.c │ │ │ ├── f_convert_angle.c │ │ │ └── f_minmax.c │ ├── lock │ │ └── README.md │ ├── arqueue │ │ └── README.md │ ├── getopt │ │ └── README.md │ ├── timer │ │ ├── README.md │ │ └── src │ │ │ └── s_timer_access.c │ ├── f_crypto │ │ ├── README.md │ │ └── include │ │ │ └── f_crypto.h │ ├── unit │ │ ├── README.md │ │ └── include │ │ │ ├── s_unit_params.h │ │ │ ├── s_unit_context.h │ │ │ └── s_unit_test.h │ ├── f_memory │ │ ├── README.md │ │ ├── include │ │ │ ├── f_free.h │ │ │ └── f_memory.h │ │ └── src │ │ │ └── f_free.c │ ├── matrix │ │ └── README.md │ ├── htable │ │ └── README.md │ ├── f_sort │ │ ├── README.md │ │ ├── include │ │ │ └── f_sort.h │ │ └── src │ │ │ ├── f_sort_bubble.c │ │ │ └── f_sort_shell.c │ ├── stack │ │ ├── README.md │ │ └── src │ │ │ ├── s_stack_access.c │ │ │ ├── s_stack_capacity.c │ │ │ └── s_stack_operator.c │ ├── queue │ │ ├── README.md │ │ └── src │ │ │ ├── s_queue_capacity.c │ │ │ ├── s_queue_operator.c │ │ │ └── s_queue_access.c │ ├── f_string │ │ ├── src │ │ │ ├── f_print_nstr.c │ │ │ ├── f_mapfile.c │ │ │ ├── f_print_color.c │ │ │ ├── f_space.c │ │ │ ├── f_char_alnum.c │ │ │ ├── f_print_bool.c │ │ │ ├── f_strdup.c │ │ │ └── f_str_tools.c │ │ └── include │ │ │ ├── f_space.h │ │ │ ├── f_str_tools.h │ │ │ └── f_char.h │ ├── rbtree │ │ ├── README.md │ │ └── src │ │ │ ├── s_rbtree_delete.c │ │ │ └── s_rbtree_access.c │ ├── array │ │ ├── README.md │ │ └── src │ │ │ ├── s_array_capacity.c │ │ │ ├── s_array_access.c │ │ │ └── s_array_operator.c │ ├── vector │ │ ├── README.md │ │ └── src │ │ │ └── s_vector_capacity.c │ ├── README.md │ ├── list │ │ └── src │ │ │ ├── s_list_capacity.c │ │ │ ├── s_list_find.c │ │ │ ├── s_list_interval.c │ │ │ └── s_list_cell_count.c │ └── string │ │ └── src │ │ └── s_string_add_color.c ├── vim │ ├── syntax │ │ ├── README.md │ │ └── c.vim │ ├── README.md │ ├── generator-h │ │ ├── README.md │ │ └── generator_h.vim │ ├── install │ ├── speed_open │ │ ├── README.md │ │ └── speed_open.vim │ └── header │ │ └── README.md └── Makefile │ └── README.md ├── .gitignore ├── Dockerfile ├── update ├── .HEADER ├── RELEASE.md └── README.md /test/libc/.gitignore: -------------------------------------------------------------------------------- 1 | file.txt 2 | -------------------------------------------------------------------------------- /examples/libc/error/.gitignore: -------------------------------------------------------------------------------- 1 | file.txt 2 | -------------------------------------------------------------------------------- /test/libc/error/.gitignore: -------------------------------------------------------------------------------- 1 | file.txt 2 | -------------------------------------------------------------------------------- /doc/images/logo-42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinPerez/42-toolkit/HEAD/doc/images/logo-42.png -------------------------------------------------------------------------------- /doc/images/syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinPerez/42-toolkit/HEAD/doc/images/syntax.png -------------------------------------------------------------------------------- /doc/images/header-42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinPerez/42-toolkit/HEAD/doc/images/header-42.png -------------------------------------------------------------------------------- /doc/images/generator-h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinPerez/42-toolkit/HEAD/doc/images/generator-h.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "test/libc/cmocka"] 2 | path = test/libc/cmocka 3 | url = git://git.cryptomilk.org/projects/cmocka.git 4 | -------------------------------------------------------------------------------- /examples/libc/array/README.md: -------------------------------------------------------------------------------- 1 | Array 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/error/README.md: -------------------------------------------------------------------------------- 1 | Error 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/ldata/README.md: -------------------------------------------------------------------------------- 1 | Ldata 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/rand/README.md: -------------------------------------------------------------------------------- 1 | Rand 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/list/README.md: -------------------------------------------------------------------------------- 1 | List 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/matrix/README.md: -------------------------------------------------------------------------------- 1 | Matrix 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/queue/README.md: -------------------------------------------------------------------------------- 1 | Queue 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/rbtree/README.md: -------------------------------------------------------------------------------- 1 | Rbtree 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/stack/README.md: -------------------------------------------------------------------------------- 1 | Stack 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/timer/README.md: -------------------------------------------------------------------------------- 1 | Timer 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/unit/README.md: -------------------------------------------------------------------------------- 1 | Unit 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/arqueue/README.md: -------------------------------------------------------------------------------- 1 | Arqueue 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/f_math/README.md: -------------------------------------------------------------------------------- 1 | MATH - Function 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/getopt/README.md: -------------------------------------------------------------------------------- 1 | Getopt 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/htable/README.md: -------------------------------------------------------------------------------- 1 | Htable 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/string/README.md: -------------------------------------------------------------------------------- 1 | String 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/vector/README.md: -------------------------------------------------------------------------------- 1 | Vector 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/f_crypto/README.md: -------------------------------------------------------------------------------- 1 | Crypto Function 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | === 8 | ## License 9 | 10 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 11 | -------------------------------------------------------------------------------- /examples/libc/f_sort/README.md: -------------------------------------------------------------------------------- 1 | Sort Function 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/fdnotify/README.md: -------------------------------------------------------------------------------- 1 | Fdnotify 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/threadpool/README.md: -------------------------------------------------------------------------------- 1 | Threapool 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/f_error/README.md: -------------------------------------------------------------------------------- 1 | ERROR Function 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/f_memory/README.md: -------------------------------------------------------------------------------- 1 | MEMORY Function 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /examples/libc/f_string/README.md: -------------------------------------------------------------------------------- 1 | String Function 2 | ======= 3 | 4 | 5 | #####This directory is an example. 6 | 7 | 8 | === 9 | ## License 10 | 11 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 12 | -------------------------------------------------------------------------------- /test/libc/README.md: -------------------------------------------------------------------------------- 1 | Test 2 | ======= 3 | 4 | ### How to test ? 5 | 6 | - make 7 | - cd 8 | - ./a.out 9 | 10 | === 11 | ## License 12 | 13 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - cc 5 | - clang 6 | 7 | script: 8 | - make -C examples/libc 9 | - make -C test/libc 10 | - make -C examples/libc travis 11 | # - make -C test/libc travis 12 | - make -C srcs/libc/lib42/ analyze 13 | -------------------------------------------------------------------------------- /srcs/README.md: -------------------------------------------------------------------------------- 1 | 42-toolkit 2 | ========== 3 | 4 | ## Tools list 5 | 6 | - libc/ "Lib42 in C" 7 | - Makefile/ "Template" 8 | - vim/ "Vim plugins" 9 | === 10 | 11 | ## License 12 | 13 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | # lib42 20 | lib42 21 | examples/libc/file.txt 22 | .build 23 | *.d 24 | -------------------------------------------------------------------------------- /examples/libc/README.md: -------------------------------------------------------------------------------- 1 | Example 2 | ======= 3 | 4 | 5 | ### How to generate all test ? 6 | 7 | - make 8 | 9 | ### How to execute ? 10 | 11 | - cd 12 | - ./a.out 13 | 14 | === 15 | ## License 16 | 17 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 18 | -------------------------------------------------------------------------------- /srcs/libc/ldata/README.md: -------------------------------------------------------------------------------- 1 | Ldata 2 | ========== 3 | 4 | ## Function 5 | 6 | 7 | === 8 | ### How to use ? 9 | 10 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/ldata). 11 | 12 | === 13 | ## License 14 | 15 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 16 | -------------------------------------------------------------------------------- /srcs/libc/fdnotify/README.md: -------------------------------------------------------------------------------- 1 | Fdnotify 2 | ========== 3 | 4 | ## Function 5 | 6 | 7 | === 8 | ### How to use ? 9 | 10 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/fdnotify). 11 | 12 | === 13 | ## License 14 | 15 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 16 | -------------------------------------------------------------------------------- /srcs/libc/f_secure/README.md: -------------------------------------------------------------------------------- 1 | F_secure Function 2 | ========== 3 | 4 | ## Function 5 | 6 | Not yet 7 | 8 | === 9 | ### How to use ? 10 | 11 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/f_secure). 12 | 13 | === 14 | ## License 15 | 16 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 17 | -------------------------------------------------------------------------------- /test/libc/configure: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Please don't use 4 | 5 | LIB=lib42 6 | 7 | printf "\e[36mGenerating %s \e[0m\t...\t" $LIB 8 | 9 | if [ -e $LIB ]; 10 | then 11 | rm -fr $LIB 12 | fi 13 | 14 | cd ../../srcs/libc > /dev/null 15 | ./make_lib > /dev/null 16 | cd - > /dev/null 17 | ln -s ../../srcs/libc/lib42 > /dev/null 18 | 19 | printf "\e[32mDone\e[0m\n" 20 | -------------------------------------------------------------------------------- /examples/libc/configure: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Please don't use 4 | 5 | LIB=lib42 6 | 7 | printf "\e[36mGenerating %s \e[0m\t...\t" $LIB 8 | 9 | if [ -e $LIB ]; 10 | then 11 | rm -fr $LIB 12 | fi 13 | 14 | cd ../../srcs/libc > /dev/null 15 | ./make_lib > /dev/null 16 | cd - > /dev/null 17 | ln -s ../../srcs/libc/lib42 > /dev/null 18 | 19 | printf "\e[32mDone\e[0m\n" 20 | -------------------------------------------------------------------------------- /srcs/vim/syntax/README.md: -------------------------------------------------------------------------------- 1 | 42-toolkit syntax 2 | ========== 3 | 4 | ## Preview 5 | 6 |

7 | syntax 8 |

9 | 10 | ## Description 11 | 12 | This file highlight `lib42` type 13 | 14 | ## License 15 | 16 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 17 | -------------------------------------------------------------------------------- /srcs/libc/reverse: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LIB=lib42 4 | 5 | function move_file 6 | { 7 | while [ ! -z "$1" ]; 8 | do 9 | ORIG=$(find . -name `basename $1` | grep -v $LIB) 10 | diff $1 $ORIG > /dev/null 2>&1 11 | if [ $? -eq 1 ] 12 | then 13 | cp $1 $ORIG 14 | echo $1 "->" $ORIG 15 | fi 16 | shift 17 | done 18 | } 19 | 20 | move_file $(find $LIB -type f -name "*.c") 21 | move_file $(find $LIB -type f -name "*.h") 22 | -------------------------------------------------------------------------------- /srcs/vim/README.md: -------------------------------------------------------------------------------- 1 | Vim 2 | ========== 3 | 4 | ## How to install or update the plugins? 5 | 6 | ```console 7 | ./install 8 | ``` 9 | 10 | ## Plugins 11 | 12 | - header "Make header like 42" 13 | - generator-h "Make .h like 42" 14 | - speed_open "Switch between .c and .h" 15 | - syntax "Highlight lib42 keyword" 16 | 17 | ## License 18 | 19 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 20 | -------------------------------------------------------------------------------- /srcs/vim/generator-h/README.md: -------------------------------------------------------------------------------- 1 | 42-toolkit generator-h 2 | ========== 3 | 4 | ## Preview 5 | 6 |

7 | generator-h 8 |

9 | 10 | ## Description 11 | 12 | This plugin generate will generate your header file 13 | 14 | ## License 15 | 16 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 17 | -------------------------------------------------------------------------------- /srcs/Makefile/README.md: -------------------------------------------------------------------------------- 1 | Makefile 2 | ========== 3 | 4 | ## Rules 5 | 6 | - clean Cleaning all objects 7 | - fclean Cleaning all objects and executable 8 | - debug Add debug flags 9 | - re Deleting all objects and build 10 | 11 | - analyze Analyze code but compile nothing 12 | - every God code 13 | - help Verbose arguments 14 | === 15 | 16 | ## License 17 | 18 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 19 | -------------------------------------------------------------------------------- /srcs/vim/syntax/c.vim: -------------------------------------------------------------------------------- 1 | syntax keyword lib42type uc ui ul t_error t_list t_vector t_stack t_queue t_array t_htable t_timer t_string t_getopt t_unit t_matrix t_rbtree 2 | highlight link lib42type Type 3 | 4 | syntax keyword v_thistype v_this 5 | highlight link v_thistype Exception 6 | 7 | syntax keyword unitfunct D_UNIT_FUNCT 8 | highlight link unitfunct String 9 | 10 | syntax keyword lib42define D_ERROR D_LIST D_VECTOR D_STACK D_QUEUE D_ARRAY D_HTABLE D_TIMER D_STRING D_GETOPT D_UNIT D_MATRIX D_RBTREE 11 | highlight link lib42define define 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | 3 | RUN apt-get install -y software-properties-common \ 4 | && add-apt-repository ppa:ubuntu-toolchain-r/test \ 5 | && apt-get update \ 6 | && apt-get -y upgrade 7 | 8 | RUN apt-get -y install \ 9 | build-essential \ 10 | gcc-5 \ 11 | g++-5 \ 12 | vim 13 | 14 | RUN ln -fs /usr/bin/gcc-5 /usr/bin/gcc \ 15 | && ln -fs /usr/bin/g++-5 /usr/bin/g++ 16 | 17 | RUN gcc --version \ 18 | && g++ --version 19 | 20 | RUN mkdir -p /usr/root/42-toolkit 21 | WORKDIR /usr/root/42-toolkit 22 | 23 | RUN apt-get clean 24 | -------------------------------------------------------------------------------- /srcs/vim/install: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | 4 | /bin/mkdir -p $HOME/.vim/plugin 5 | /bin/mkdir -p $HOME/.vim/syntax 6 | 7 | DIR_FILE=("syntax" "header" "speed_open" "generator-h") 8 | VIM_FILE="c.vim make_header.vim speed_open.vim generator_h.vim" 9 | DIRECTORY=("syntax" "plugin" "plugin" "plugin") 10 | INDEX=0 11 | 12 | for FILE in $VIM_FILE 13 | do 14 | if [ ! -f $HOME/.vim/${DIRECTORY[$INDEX]}/$FILE ]; then 15 | cp ${DIR_FILE[$INDEX]}/$FILE $HOME/.vim/${DIRECTORY[$INDEX]} 16 | printf "Plugin $FILE \e[32minstalled.\e[0m\n" 17 | fi 18 | INDEX=$((INDEX + 1)) 19 | done 20 | -------------------------------------------------------------------------------- /srcs/vim/speed_open/README.md: -------------------------------------------------------------------------------- 1 | 42-toolkit speed_open 2 | ========== 3 | 4 | # Description 5 | 6 | This plugin switch between your `header` file and your `c` file 7 | 8 | # How to install ? 9 | 10 | Append the following line into `~/.vimrc` 11 | 12 | ```vimscript 13 | let mapleader = "," 14 | nnoremap h :call Speed_open("vs") 15 | nnoremap H :call Speed_open("sp") 16 | ``` 17 | 18 | And now open a file, press on `ESC` and `,h` or `ESC` and `,H` 19 | ## License 20 | 21 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 22 | -------------------------------------------------------------------------------- /srcs/libc/f_error/README.md: -------------------------------------------------------------------------------- 1 | Error Function 2 | ========== 3 | 4 | ## Function 5 | 6 | - m_error(const char *str_err, size_t ret_val) 7 | /* This function print str_err on stderr and return ret_val */ 8 | 9 | - m_error_v(const char *str_err) 10 | /* This function print str_err on stderr */ 11 | 12 | - m_error_infos(const char *infos) 13 | /* This function print infos on stdout */ 14 | 15 | === 16 | ### How to use ? 17 | 18 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/f_error). 19 | 20 | === 21 | ## License 22 | 23 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 24 | -------------------------------------------------------------------------------- /srcs/libc/error/README.md: -------------------------------------------------------------------------------- 1 | Error 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_error *v_this, const char *file) 7 | /* This function initialize t_error */ 8 | 9 | - add(t_error *v_this, const char *error, bool ret) 10 | /* This function append error to file or if file was NULL print on screen */ 11 | /* And return ret */ 12 | 13 | - destroy(t_error *v_this) 14 | /* This function free t_error */ 15 | 16 | === 17 | ### How to use ? 18 | 19 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/error). 20 | 21 | === 22 | ## License 23 | 24 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 25 | -------------------------------------------------------------------------------- /update: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function usage 4 | { 5 | printf "./release \n\n" 6 | printf "example: ./release \"0.0\" \"first releases\"\n" 7 | } 8 | 9 | function sed_fix 10 | { 11 | local tmp_file="$(mktemp -t temp.XXXXX)" 12 | 13 | sed "$2$3/$4" $1 > ${tmp_file} && mv ${tmp_file} $1 14 | cp $1 ${tmp_file} 15 | } 16 | 17 | if [ "$#" -ne 2 ]; then 18 | usage 19 | else 20 | sed_fix RELEASE.md "s/####Current release :.*/" "####Current release : $1" g 21 | TMP=$(tail -n+6 RELEASE.md) 22 | sed_fix RELEASE.md "6,/" "-End" d 23 | printf "\t-V$1 " >> RELEASE.md 24 | date +%m-%d-%Y >> RELEASE.md 25 | printf "\t\t$2\n\n" >> RELEASE.md 26 | printf "$TMP" >> RELEASE.md 27 | fi 28 | -------------------------------------------------------------------------------- /srcs/libc/threadpool/README.md: -------------------------------------------------------------------------------- 1 | Threadpool 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_threadpool *v_this, size_t nb_threads); 7 | /* This function initialize t_threadpool and create nb thread */ 8 | 9 | - add_task(t_threadpool *v_this, t_threadpool_task *task); 10 | /* This function add function to tasks queue */ 11 | 12 | - destroy(t_threadpool *v_this) 13 | /* This function free t_threadpool and delete all thread */ 14 | 15 | === 16 | ### How to use ? 17 | 18 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/threadpool). 19 | 20 | === 21 | ## License 22 | 23 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 24 | -------------------------------------------------------------------------------- /srcs/libc/rand/README.md: -------------------------------------------------------------------------------- 1 | Rand 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_rand *v_this, t_type_rand style) 7 | /* This function initialize t_rand, style [e_rand_std, e_rand_file] */ 8 | 9 | - geneate(t_rand *v_this) 10 | /* This function generate a random number */ 11 | 12 | - change_seed(t_rand *v_this, size_t seed) 13 | /* This function change the seed */ 14 | 15 | - destroy(t_rand *v_this) 16 | /* This function destroy t_rand */ 17 | 18 | === 19 | ### How to use ? 20 | 21 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/rand). 22 | 23 | === 24 | ## License 25 | 26 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 27 | -------------------------------------------------------------------------------- /srcs/libc/f_math/README.md: -------------------------------------------------------------------------------- 1 | Math Function 2 | ========== 3 | 4 | ## Function 5 | 6 | - uf_abs(double value) 7 | /* Return the absolute value */ 8 | 9 | - uf_min(const double x, const double y) 10 | /* Return the minimal value between x and y */ 11 | 12 | - uf_max(const double x, const double y) 13 | /* Return the maximal value between x and y */ 14 | 15 | - uf_rad_to_deg(double rad) 16 | /* Convert radians to degree */ 17 | 18 | - uf_deg_to_rad(double deg) 19 | /* Convert degree to radians */ 20 | 21 | === 22 | ### How to use ? 23 | 24 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/f_math). 25 | 26 | === 27 | ## License 28 | 29 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 30 | -------------------------------------------------------------------------------- /srcs/libc/lock/README.md: -------------------------------------------------------------------------------- 1 | Lock 2 | ========== 3 | 4 | ## Function 5 | 6 | 7 | - init(t_lock *v_this, void *data, e_lock_type type) 8 | /* This function initialize t_lock with the data when you want to protect */ 9 | 10 | - lock(t_lock *v_this, void **data) 11 | /* This function lock the mutex variable and set data */ 12 | 13 | - release(t_lock *v_this, void **data) 14 | /* This function release the mutex variable and data == NULL */ 15 | 16 | - destroy(t_lock *v_this) 17 | /* This function destroy t_lock */ 18 | 19 | === 20 | ### How to use ? 21 | 22 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/lock). 23 | 24 | === 25 | ## License 26 | 27 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 28 | -------------------------------------------------------------------------------- /srcs/libc/arqueue/README.md: -------------------------------------------------------------------------------- 1 | Arqueue 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_arqueue *v_this, size_t elem_size, size_t nb_elem); 7 | /* This function initialize t_arqueue */ 8 | 9 | - push(t_arqueue *v_this, void *data) 10 | /* This function put element at the end */ 11 | 12 | - pop(t_arqueue *v_this) 13 | /* This function delete last element */ 14 | 15 | - empty(t_arqueue *v_this) 16 | /* This function return true if structure is empty */ 17 | 18 | - destroy(t_arqueue *v_this) 19 | /* This function free t_arqueue */ 20 | 21 | === 22 | ### How to use ? 23 | 24 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/arqueue). 25 | 26 | === 27 | ## License 28 | 29 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 30 | -------------------------------------------------------------------------------- /srcs/libc/getopt/README.md: -------------------------------------------------------------------------------- 1 | Getopt 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_getopt *v_this, int argc, const char **argv, const char *option) 7 | /* This function initialize t_getopt */ 8 | 9 | - option(t_getopt *v_this) 10 | /* This function return true if a new argument exists */ 11 | 12 | - check(t_getopt *v_this, const char *option) 13 | /* This function return true if option match */ 14 | 15 | - params(t_getopt *v_this); 16 | /* This function return next argument */ 17 | 18 | - destroy(t_getopt *v_this); 19 | /* This function free t_getopt */ 20 | 21 | === 22 | ### How to use ? 23 | 24 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/getopt). 25 | 26 | === 27 | ## License 28 | 29 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 30 | -------------------------------------------------------------------------------- /.HEADER: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** Copyright (C) name(s) 4 | ** 5 | ** This file is part of 42-toolkit. 6 | ** 7 | ** 42-toolkit is free software: you can redistribute it and/or modify 8 | ** it under the terms of the GNU General Public License as published by 9 | ** the Free Software Foundation, either version 3 of the License, or 10 | ** (at your option) any later version. 11 | ** 12 | ** This program is distributed in the hope that it will be useful, 13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ** GNU General Public License for more details. 16 | ** 17 | ** You should have received a copy of the GNU General Public License 18 | ** along with this program. If not, see . 19 | */ 20 | -------------------------------------------------------------------------------- /srcs/libc/timer/README.md: -------------------------------------------------------------------------------- 1 | Timer 2 | ========== 3 | 4 | ## Function 5 | 6 | - start(t_time *v_this) 7 | /* This function start timer */ 8 | 9 | - stop(t_time *v_this) 10 | /* This function stop timer */ 11 | 12 | - pause(t_time *v_this) 13 | /* This function pause timer */ 14 | 15 | - unpause(t_time *v_this) 16 | /* This function unpause timer */ 17 | 18 | - get_ticks(t_time *v_this) 19 | /* This function return time in milliseconds */ 20 | 21 | - is_started(t_time *v_this) 22 | /* This function return true if timer is started */ 23 | 24 | - is_paused(t_time *v_this) 25 | /* This function return true if timer is paused */ 26 | 27 | === 28 | ### How to use ? 29 | 30 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/timer). 31 | 32 | === 33 | ## License 34 | 35 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 36 | -------------------------------------------------------------------------------- /srcs/libc/f_crypto/README.md: -------------------------------------------------------------------------------- 1 | Crypto Function 2 | ========== 3 | 4 | ## Function 5 | 6 | - uf_crypto_xor(void *data, const char *key, ui data_size) 7 | /* This function use xor algorithm for encrypt / decrypt data */ 8 | 9 | - uf_crypto_rot5(char *str) 10 | /* ROT algorithm which encrypt / decrypt the numeric digits of a string */ 11 | 12 | - uf_crypto_rot13(char *str) 13 | /* ROT algorithm which encrypt / decrypt the alphabetics characters of a string */ 14 | 15 | - uf_crypto_rot18(char *str) 16 | /* A combinaison of ROT5 and ROT13 */ 17 | 18 | - uf_crypto_rot47(char *str) 19 | /* ROT47 is a variant of ROT13 which also treats numbers and commons symbols */ 20 | === 21 | 22 | ### How to use ? 23 | 24 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/f_crypto). 25 | 26 | === 27 | ## License 28 | 29 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 30 | -------------------------------------------------------------------------------- /srcs/libc/unit/README.md: -------------------------------------------------------------------------------- 1 | Unit 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_unit *v_this) 7 | /* This function initialize t_unit */ 8 | 9 | - add_context(t_unit *v_this, const char *name, bool (*init)(void *), bool (*destroy)(void *)) 10 | /* This function add a context */ 11 | 12 | - add_test(t_unit *v_this, const char *context, const char *name, void (*test)(struct s_unit_test *)) 13 | /* This function add test into context */ 14 | 15 | - assert(bool check) 16 | /* This macro add error if needed */ 17 | 18 | - console_run(t_unit *v_this) 19 | /* This function launch user-interface */ 20 | 21 | - destroy(t_unit *v_this) 22 | /* This function free t_unit */ 23 | 24 | === 25 | ### How to use ? 26 | 27 | You can see example [here](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/unit). 28 | 29 | === 30 | ## License 31 | 32 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 33 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | LIB42 RELEASES 2 | === 3 | 4 | ####Current release : 0.2.1 5 | 6 | -V0.2.1 11-02-2015 7 | add lockdata 8 | add lockallmemory 9 | add cmoka unit test 10 | add Dockerfile 11 | 12 | 13 | -V0.2 04-19-2015 14 | fix norme 15 | delete makedepend 16 | add fdnotify 17 | add options to lock 18 | 19 | -V0.1.8 11-14-2014 20 | add secure function 21 | fix matrix 22 | add the structure rand 23 | fix the behavior of Makefile 24 | 25 | -V0.1.7 09-03-2014 26 | add arqueue 27 | add threadpool 28 | add travis 29 | 30 | -V0.1.6 19-03-2014 31 | add lock 32 | fix examples compile 33 | 34 | -V0.1.5 02-03-2014 35 | fix list 36 | fix norme 37 | fix f_string 38 | 39 | -V0.1.4 08-01-2014 40 | fix norme 41 | 42 | -V0.1.3 12-02-2013 43 | some fix 44 | 45 | -V0.1.2 11-17-2013 46 | Add rbtree 47 | 48 | -V0.1.1 11-12-2013 49 | Add warning prepoc 50 | Fix bug #16 51 | Add matrix 52 | Add atoi 53 | 54 | -V0.1.0 11-05-2013 55 | First release 56 | -------------------------------------------------------------------------------- /srcs/libc/f_memory/README.md: -------------------------------------------------------------------------------- 1 | Memory Function 2 | ========== 3 | 4 | ## Function 5 | 6 | - uf_memset(void *src, unsigned char c, size_t size) 7 | /* This function writes len bytes of value c */ 8 | 9 | - uf_memcmp(const void *left, const void *right, size_t size) 10 | /* This function compare byte string form against byte string to */ 11 | 12 | - uf_memcpy(void *to, const void *from, size_t size) 13 | /* This function copies n bytes memory "from" to "to" */ 14 | 15 | - uf_print_memory(const void *to, ui size) 16 | /* This function print memory */ 17 | 18 | - uf_free_tab(void **tab) 19 | /* This function delete all element of tab and delete tab */ 20 | 21 | - uf_free_tab_fail(void **tab, ui current) 22 | /* This function delete element of tab and delete tab */ 23 | 24 | === 25 | ### How to use ? 26 | 27 | You can see example [here](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/f_memory). 28 | 29 | === 30 | ## License 31 | 32 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 33 | -------------------------------------------------------------------------------- /examples/makefile/print/f_print.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_print.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/26 18:57:58 by qperez #+# #+# */ 9 | /* Updated: 2013/08/26 18:58:55 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void f_print(const char *str) 16 | { 17 | printf("%s", str); 18 | } 19 | -------------------------------------------------------------------------------- /examples/makefile/includes/f_print.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_print.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/26 18:59:01 by qperez #+# #+# */ 9 | /* Updated: 2013/08/26 18:59:14 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef F_PRINT_H 14 | # define F_PRINT_H 15 | 16 | void f_print(const char *str); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /test/libc/timer/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/05 12:30:33 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char const** argv) 16 | { 17 | (void)argc; 18 | (void)argv; 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /test/libc/unit/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/05 12:30:33 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char const** argv) 16 | { 17 | (void)argc; 18 | (void)argv; 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /srcs/libc/matrix/README.md: -------------------------------------------------------------------------------- 1 | Matrix 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_matrix *v_this, ui c, ui r); 7 | /* This function initializes a t_matrix */ 8 | 9 | - destroy(t_matrix *v_this); 10 | /* This function free a t_matrix */ 11 | 12 | - sum(t_matrix *v_this, t_matrix *m1, t_matrix *m2); 13 | /* This function does the sum of two t_matrix */ 14 | 15 | - sub(t_matrix *v_this, t_matrix *m1, t_matrix *m2); 16 | /* This function does the sub of two t_matrix */ 17 | 18 | - mul(t_matrix *v_this, t_matrix *m1, t_matrix *m2); 19 | /* This function does the mul of two t_matrix */ 20 | 21 | - div(t_matrix *v_this, t_matrix *m1, t_matrix *m2); 22 | /* This function does the div of two t_matrix */ 23 | 24 | - print(const t_matrix *v_this, const char *name); 25 | /* This function print matrix */ 26 | 27 | === 28 | ### How to use ? 29 | 30 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/matrix). 31 | 32 | === 33 | ## License 34 | 35 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 36 | -------------------------------------------------------------------------------- /examples/makefile/srcs/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/26 18:56:27 by qperez #+# #+# */ 9 | /* Updated: 2013/08/26 18:57:10 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char const** argv) 16 | { 17 | f_print("Hello world!\n"); 18 | (void)argc; 19 | (void)argv; 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /srcs/libc/htable/README.md: -------------------------------------------------------------------------------- 1 | Htable 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_htable *v_this, ui number_prine, void (*f_delete)(void *data)) 7 | /* This function initialize t_htable */ 8 | /* WARNING Use a number prime */ 9 | 10 | - add(t_htable *v_this, const char *key, void *data) 11 | /* This function add new key */ 12 | 13 | - get(t_htable *v_this, const char *key) 14 | /* This function return element at key */ 15 | 16 | - delete(t_htable *v_this, const char *key) 17 | /* This function delete element at key */ 18 | 19 | - erase(t_htable *v_this, const char *key) 20 | /* This function remove element to htable and return data */ 21 | 22 | - print(t_htable *v_this, bool (*uf_print)(t_htable_cell *data)) 23 | /* This function print all element */ 24 | 25 | - destroy(t_htable *v_this) 26 | /* This function free t_htable */ 27 | 28 | === 29 | ### How to use ? 30 | 31 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/htable). 32 | 33 | === 34 | ## License 35 | 36 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 37 | -------------------------------------------------------------------------------- /srcs/libc/f_sort/README.md: -------------------------------------------------------------------------------- 1 | Sort Function 2 | ========== 3 | 4 | ## Function 5 | 6 | - uf_sort_bubble(int *ptr, ui size) 7 | /* Bubble sort Average case performance O(n^2) */ 8 | /* Bubble sort Worst case performance O(n^2) */ 9 | 10 | - uf_sort_shell(int *ptr, ui size) 11 | /* Shell sort Average case performance - */ 12 | /* Shell sort Worst case performance nlog^2n */ 13 | 14 | - uf_sort_counting(int *ptr, ui size) 15 | /* Counting sort Average case performance O(n + k) */ 16 | /* Counting sort Worst case performance O(n + k) */ 17 | 18 | - uf_sort_quick(int *ptr, ui size) 19 | /* Quick sort Average case performance O(nlogn) */ 20 | /* Quick sort Worst case performance O(n^2) */ 21 | 22 | - uf_sort_merge(int *ptr, ui size) 23 | /* Quick sort Average case performance O(nlogn) */ 24 | /* Quick sort Worst case performance O(nlogn) */ 25 | 26 | === 27 | ### How to use ? 28 | 29 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/f_sort). 30 | 31 | === 32 | ## License 33 | 34 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 35 | -------------------------------------------------------------------------------- /srcs/vim/header/README.md: -------------------------------------------------------------------------------- 1 | 42-toolkit header 2 | ========== 3 | 4 | ## Preview 5 | 6 |

7 | header 8 |

9 | 10 | ## Description 11 | 12 | This plugin generate header like 42. 13 | 14 | When you open `newfile.c` this plugin put header on the top. 15 | 16 | # Env 17 | 18 | Append the following lines into your config shell file `.bashrc, .zshrc, .profile | ...` 19 | 20 | ```bash 21 | export MAIL42=YourMail 22 | export USER42=YourUser 23 | ``` 24 | 25 | Open a new terminal 26 | 27 | ```console 28 | $> env 29 | ... 30 | MAIL42=YourMail 31 | USER42=YourUser 32 | ... 33 | ``` 34 | 35 | ## Installation with vundle 36 | 37 | ### For lazy people who want to copy/paste commands : 38 | 39 | Move `make_header.vim` in your `$HOME` 40 | ```console 41 | $> mkdir -p ~/.vim/bundle/42header/plugin 42 | $> mv ~/make_header.vim ~/.vim/bundle/42header/plugin/ 43 | ``` 44 | 45 | And append `Bundle '42header'` into your `~/.vimrc` 46 | 47 | ## License 48 | 49 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 50 | -------------------------------------------------------------------------------- /srcs/libc/stack/README.md: -------------------------------------------------------------------------------- 1 | Stack 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_stack *v_this, void (*funct_destroy)(void *data)) 7 | /* This function initialize t_stack */ 8 | 9 | - push(t_stack *v_this, void *data) 10 | /* This function put element at the end */ 11 | 12 | - pop(t_stack *v_this) 13 | /* This function delete last element */ 14 | 15 | - clear(t_stack *v_this) 16 | /* This function clear and delete all element */ 17 | 18 | - top(t_stack *v_this) 19 | /* This function return last element */ 20 | 21 | - empty(t_stack *v_this) 22 | /* This function return true if structure is empty */ 23 | 24 | - size(t_stack *v_this) 25 | /* This function return number element */ 26 | 27 | - foreach(t_stack *v_this, bool (*funct)(void *data)) 28 | /* This function apply funct for all element */ 29 | 30 | - destroy(t_stack *v_this) 31 | /* This function free t_stack */ 32 | 33 | === 34 | ### How to use ? 35 | 36 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/stack). 37 | 38 | === 39 | ## License 40 | 41 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 42 | -------------------------------------------------------------------------------- /test/libc/getopt/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/05 16:47:03 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char const** argv) 16 | { 17 | t_getopt getopt; 18 | 19 | D_GETOPT(init)(&getopt, argc, argv, 20 | "q:w:e:R:qwe:Qw:dqW:DqWD:qwd:qwd:s:d:a:d"); 21 | D_GETOPT(destroy)(&getopt); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /srcs/libc/queue/README.md: -------------------------------------------------------------------------------- 1 | Queue 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_queue *v_this, void (*funct_destroy)(void *data)) 7 | /* This function initialize t_queue */ 8 | 9 | - push(t_queue *v_this, void *data) 10 | /* This function put element at the end */ 11 | 12 | - pop(t_queue *v_this) 13 | /* This function delete first element */ 14 | 15 | - back(t_queue *v_this) 16 | /* This function return last element */ 17 | 18 | - front(t_queue *v_this) 19 | /* This function return first element */ 20 | 21 | - clear(t_queue *v_this) 22 | /* This function clear and delete all element */ 23 | 24 | - empty(t_queue *v_this) 25 | /* This function true if structure is empty */ 26 | 27 | - size(t_queue *v_this) 28 | /* This function return number element */ 29 | 30 | - foreach(t_queue *v_this, bool (*funct)(void *data)) 31 | /* This function apply funct for all element */ 32 | 33 | - destroy(t_queue *v_this) 34 | /* This function free t_queue */ 35 | 36 | === 37 | ### How to use ? 38 | 39 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/queue). 40 | 41 | === 42 | ## License 43 | 44 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 45 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_print_nstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_print_nstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/30 11:19:07 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:37:01 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | ssize_t uf_print_nstr_fd(const char *str, size_t size, int fd) 18 | { 19 | return (write(fd, str, size)); 20 | } 21 | 22 | void uf_print_nstr(const char *str, size_t size) 23 | { 24 | uf_print_nstr_fd(str, size, 1); 25 | } 26 | -------------------------------------------------------------------------------- /doc/misc/Makefile_part1.txt: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Copyright (C) <2013> Quentin Perez 4 | # 5 | # This file is part of 42-toolkit. 6 | # 7 | # 42-toolkit is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | SHELL = bash 22 | CFLAGS += -Wextra -Wall -Werror -Wshadow \ 23 | -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith \ 24 | -Wsign-compare -Wfloat-equal -Wwrite-strings -Waggregate-return \ 25 | -Wconversion -Wunreachable-code \ 26 | -Wundef \ 27 | -ftrapv \ 28 | -I./include -O2 29 | #LDFLAGS += -fmudflap -s 30 | DEBUG = -g3 -fno-inline 31 | 32 | OBJDIR = ./.objs 33 | LISTDIR = src 34 | 35 | DIRSRC = src 36 | 37 | NAME = lib42.a 38 | -------------------------------------------------------------------------------- /examples/libc/matrix/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/13 12:58:04 by qperez #+# #+# */ 9 | /* Updated: 2014/10/05 13:10:21 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char const** argv) 17 | { 18 | t_imatrix mat; 19 | 20 | /* 21 | * Initialize the structure 22 | */ 23 | if (D_IMATRIX(init)(&mat, 10, 10) == false) 24 | { 25 | return (-1); 26 | } 27 | D_IMATRIX(print)(&mat, "identity"); 28 | /* 29 | * Destroy the structure 30 | */ 31 | D_IMATRIX(destroy)(&mat); 32 | (void)argc; 33 | (void)argv; 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /srcs/vim/generator-h/generator_h.vim: -------------------------------------------------------------------------------- 1 | " 2 | " 3 | " Copyright (C) <2013> Quentin Perez 4 | " 5 | " This file is part of 42-toolkit. 6 | " 7 | " 42-toolkit is free software: you can redistribute it and/or modify 8 | " it under the terms of the GNU General Public License as published by 9 | " the Free Software Foundation, either version 3 of the License, or 10 | " (at your option) any later version. 11 | " 12 | " This program is distributed in the hope that it will be useful, 13 | " but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | " GNU General Public License for more details. 16 | " 17 | " You should have received a copy of the GNU General Public License 18 | " along with this program. If not, see . 19 | " 20 | 21 | autocmd BufNewFile *.h call Generate_h_42() 22 | 23 | function! Generate_h_42() 24 | let l:name = expand('%:f') 25 | let l:cmd = '/usr/bin/basename ' . l:name 26 | let l:newname = system(l:cmd) 27 | let l:newname = toupper(l:newname) 28 | let l:newname = substitute(l:newname, "\\.", "_", "g") 29 | let l:newname = substitute(l:newname, "\\n", "", "g") 30 | exe ":normal A" . "#ifndef " . l:newname . "\n# define " . l:newname . "\n\n\n\n#endif" 31 | if exists("*Insert_header_42") 32 | exe ":16" 33 | else 34 | exe ":4" 35 | endif 36 | endfunction 37 | -------------------------------------------------------------------------------- /examples/libc/ldata/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/13 12:58:04 by qperez #+# #+# */ 9 | /* Updated: 2015/04/19 16:46:57 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | int main(int argc, char const** argv) 19 | { 20 | t_ldata ldata; 21 | 22 | /* 23 | * Initialize the structure 24 | */ 25 | if (D_LDATA(init)(&ldata, 10) == false) 26 | { 27 | printf("Error\n"); 28 | return (-1); 29 | } 30 | strcpy((char *)D_LDATA(get_ptr)(&ldata), "Hello!"); 31 | dprintf(1, "%s\n", (char *)D_LDATA(get_ptr)(&ldata)); 32 | D_LDATA(destroy)(&ldata); 33 | (void)argc; 34 | (void)argv; 35 | return (0); 36 | } 37 | -------------------------------------------------------------------------------- /examples/libc/f_memory/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/26 13:26:45 by qperez #+# #+# */ 9 | /* Updated: 2014/10/29 10:22:24 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * This file is a little example of memory functions 18 | */ 19 | 20 | int main(int argc, char const** argv) 21 | { 22 | char data[256]; 23 | int i; 24 | 25 | i = 0; 26 | while (i < 256) 27 | { 28 | data[i] = i; 29 | i = i + 1; 30 | } 31 | uf_print_memory(data, sizeof(data)); 32 | uf_memset(data, 0, sizeof(data)); 33 | uf_memcpy(data, "AAAAAAAA", 8); 34 | uf_print_char('\n'); 35 | uf_memcpy(data + 50, "AAAAAAAA", 8); 36 | uf_print_memory(data, sizeof(data)); 37 | (void)argc; 38 | (void)argv; 39 | return (0); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/libc/rand/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/13 12:58:04 by qperez #+# #+# */ 9 | /* Updated: 2014/10/05 13:35:31 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char const** argv) 17 | { 18 | t_rand rand_fd; 19 | t_rand rand_std; 20 | 21 | /* 22 | * Initialize the structure 23 | */ 24 | if (D_RAND(init)(&rand_fd, e_rand_file) == false 25 | || D_RAND(init)(&rand_std, e_rand_std) == false) 26 | { 27 | printf("Error\n"); 28 | return (-1); 29 | } 30 | printf("/dev/urandom %zd\n", D_RAND(generate)(&rand_fd)); 31 | printf("libc %zd\n", D_RAND(generate)(&rand_std)); 32 | D_RAND(destroy)(&rand_fd); 33 | D_RAND(destroy)(&rand_std); 34 | (void)argc; 35 | (void)argv; 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /examples/libc/f_math/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:44:08 by qperez #+# #+# */ 9 | /* Updated: 2013/11/04 20:33:34 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /* 18 | * This file is a little example of math functions 19 | */ 20 | 21 | int main(int argc, char const** argv) 22 | { 23 | /* 24 | * Convert 240 deg to rad 25 | */ 26 | uf_print_variadic("Convert 240 deg to rad %d\n", (int)uf_deg_to_rad(240)); 27 | /* 28 | * Convert 240 deg to rad 29 | */ 30 | uf_print_variadic("Convert 4 rad to deg %d\n", (int)uf_rad_to_deg(4)); 31 | /* 32 | * And absolue value 33 | */ 34 | uf_print_variadic("Absolue value -42 = %d\n", (int)uf_abs(-42)); 35 | (void)argc; 36 | (void)argv; 37 | return (0); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /test/libc/vector/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/05 22:05:41 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void D_UNIT_FUNCT(memleaks) 18 | { 19 | int i; 20 | t_vector vector; 21 | 22 | i = 0; 23 | D_VECTOR(init)(&vector, 0, 0); 24 | while (i < 5000) 25 | { 26 | D_VECTOR(push_back)(&vector, (void*)(size_t)i); 27 | i = i + 1; 28 | } 29 | D_VECTOR(destroy)(&vector); 30 | (void)t; 31 | } 32 | 33 | int main(int argc, char const** argv) 34 | { 35 | t_unit unit; 36 | 37 | D_UNIT(init)(&unit); 38 | D_UNIT(add_context)(&unit, "Leaks", 0, 0); 39 | F_UNIT_ADD_TEST(&unit, "Leaks", memleaks); 40 | D_UNIT(console_run)(&unit); 41 | D_UNIT(destroy)(&unit); 42 | (void)argc; 43 | (void)argv; 44 | return (0); 45 | } 46 | -------------------------------------------------------------------------------- /test/libc/queue/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2014/09/03 16:51:52 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void D_UNIT_FUNCT(memleaks) 17 | { 18 | unsigned int i; 19 | t_queue queue; 20 | 21 | i = 0; 22 | D_QUEUE(init)(&queue, 0); 23 | while (i < 5000) 24 | { 25 | F_UNIT_ASSERT(D_QUEUE(push)(&queue, 0) == true); 26 | i = i + 1; 27 | } 28 | F_UNIT_ASSERT(D_QUEUE(size)(&queue) == 5000); 29 | D_QUEUE(destroy)(&queue); 30 | } 31 | 32 | int main(int argc, char const** argv) 33 | { 34 | t_unit unit; 35 | 36 | D_UNIT(init)(&unit); 37 | D_UNIT(add_context)(&unit, "Leaks", 0, 0); 38 | F_UNIT_ADD_TEST(&unit, "Leaks", memleaks); 39 | D_UNIT(console_run)(&unit); 40 | D_UNIT(destroy)(&unit); 41 | (void)argc; 42 | (void)argv; 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /test/libc/stack/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2014/09/03 16:52:09 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void D_UNIT_FUNCT(memleaks) 17 | { 18 | unsigned int i; 19 | t_stack stack; 20 | 21 | i = 0; 22 | D_STACK(init)(&stack, 0); 23 | while (i < 5000) 24 | { 25 | F_UNIT_ASSERT(D_STACK(push)(&stack, 0) == true); 26 | i = i + 1; 27 | } 28 | F_UNIT_ASSERT(D_STACK(size)(&stack) == 5000); 29 | D_STACK(destroy)(&stack); 30 | } 31 | 32 | int main(int argc, char const** argv) 33 | { 34 | t_unit unit; 35 | 36 | D_UNIT(init)(&unit); 37 | D_UNIT(add_context)(&unit, "Leaks", 0, 0); 38 | F_UNIT_ADD_TEST(&unit, "Leaks", memleaks); 39 | D_UNIT(console_run)(&unit); 40 | D_UNIT(destroy)(&unit); 41 | (void)argc; 42 | (void)argv; 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /srcs/libc/rbtree/README.md: -------------------------------------------------------------------------------- 1 | Rbtree 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_rbtree *v_this, int (*f_cmp)(void *d1, void *d2), void (*f_del)(void *data)); 7 | /* This function initializes a t_rbtree */ 8 | 9 | - find(t_rbtree *v_this, void *find); 10 | /* This function returns node with if the data match */ 11 | 12 | - root(t_rbtree *v_this); 13 | /* This function returns root node */ 14 | 15 | - empty(const t_rbtree *v_this); 16 | /* This function returns true if the structure is empty */ 17 | 18 | - foreach_inorder(t_rbtree *v_this, t_rbcell *node, void *data, bool (*funct)(void *node, void *data)); 19 | /* This function apply funct foreach node */ 20 | 21 | - foreach_preorder(t_rbtree *v_this, t_rbcell *node, void *data, bool (*funct)(void *node, void *data)); 22 | /* This function apply funct foreach node */ 23 | 24 | - foreach_postorder(t_rbtree *v_this, t_rbcell *node, void *data, bool (*funct)(void *node, void *data)); 25 | /* This function apply funct foreach node */ 26 | 27 | - insert(t_rbtree *v_this, void *v_data); 28 | /* This function insert data */ 29 | 30 | - erase(t_rbtree *tree, t_rbcell *node); 31 | /* This function erase node in rbtree and return data */ 32 | 33 | - delete(t_rbtree *tree, t_rbcell *node); 34 | /* This function erase node in rbtree and delete data */ 35 | 36 | - destroy(t_rbtree *v_this); 37 | /* This function free a t_rbtree */ 38 | 39 | === 40 | 41 | ### How to use ? 42 | 43 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/rbtree). 44 | 45 | === 46 | ## License 47 | 48 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 49 | -------------------------------------------------------------------------------- /srcs/vim/speed_open/speed_open.vim: -------------------------------------------------------------------------------- 1 | " 2 | " 3 | " Copyright (C) <2013> Quentin Perez 4 | " 5 | " This file is part of 42-toolkit. 6 | " 7 | " 42-toolkit is free software: you can redistribute it and/or modify 8 | " it under the terms of the GNU General Public License as published by 9 | " the Free Software Foundation, either version 3 of the License, or 10 | " (at your option) any later version. 11 | " 12 | " This program is distributed in the hope that it will be useful, 13 | " but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | " GNU General Public License for more details. 16 | " 17 | " You should have received a copy of the GNU General Public License 18 | " along with this program. If not, see . 19 | " 20 | 21 | function! Speed_open(split) 22 | let l:extension = "" 23 | if expand('%:e') ==? "c" 24 | let l:extension = ".h" 25 | endif 26 | if expand('%:e') ==? "h" 27 | let l:extension = ".c" 28 | endif 29 | let l:current_extension = "\\." . expand('%:e') 30 | let l:file_open = substitute(expand('%:f'), l:current_extension, l:extension, "g") 31 | let l:cmd = '/usr/bin/basename "' . l:file_open . '" 2> /dev/null | tr -d "\n"' 32 | let l:file_open = system(l:cmd) 33 | for dir in ["." , ".."] 34 | let l:cmd = "find " . dir . " -type f -name " . l:file_open . " 2> /dev/null | tr '\n' ' ' | awk '{print $1}' | tr -d '\n'" 35 | let l:file = system(l:cmd) 36 | if filereadable(l:file) 37 | exe ":" . a:split . " " . l:file 38 | return 39 | endif 40 | endfor 41 | echo "No such file " . l:file_open . "." 42 | endfunction 43 | -------------------------------------------------------------------------------- /srcs/libc/array/README.md: -------------------------------------------------------------------------------- 1 | Array 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_array *v_this, uint (*uf_realloc)(uint size), void (*uf_delete)(void *ptr)) 7 | /* This function initialize t_array */ 8 | 9 | - clear(t_array *v_this) 10 | /* This function remove all elements */ 11 | 12 | - empty(const t_array *v_this) 13 | /* This function return true if array is empty */ 14 | 15 | - size(const t_array *v_this) 16 | /* This function return size of array */ 17 | 18 | - capacity(const t_array *v_this) 19 | /* This function return capacity of array */ 20 | 21 | - push_back(t_array *v_this, void *data) 22 | /* This function push element at the end */ 23 | 24 | - foreach(t_array *v_this, bool (*funct)(void *ptr)) 25 | /* This function apply "funct" foreach elements */ 26 | 27 | - delete_if(t_array *v_this, bool (*ft_cmp)(void *d1, void *d2), void *data); 28 | /* This function delete element, if ft_cmp return true */ 29 | 30 | - resize(t_array *v_this, ui size) 31 | /* This function resize array */ 32 | 33 | - data(t_array *v_this, TYPEOF) 34 | /* This function data pointer */ 35 | /* WARNING here you pass typeof struct you can (must) see example */ 36 | 37 | - at(t_array *v_this, ui index, TYPEOF) 38 | /* This function pointer to index */ 39 | /* WARNING here you pass typeof struct you can (must) see example */ 40 | 41 | - destroy(t_array *v_this) 42 | /* This function free t_array */ 43 | 44 | === 45 | 46 | ### How to use ? 47 | 48 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/array). 49 | 50 | === 51 | ## License 52 | 53 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 54 | -------------------------------------------------------------------------------- /examples/libc/string/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/22 12:40:41 by qperez #+# #+# */ 9 | /* Updated: 2013/11/04 21:15:54 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * This file is a little example of the t_string structure 18 | */ 19 | 20 | int main(int argc, char const** argv) 21 | { 22 | t_string string; 23 | 24 | /* 25 | * Initialize with NULL because I want OK !!!! 26 | */ 27 | D_STRING(init)(&string, 0); 28 | /* 29 | * Like printf it's funny no ? 30 | */ 31 | D_STRING(variadic)(&string, "42 in hex %x, ptr %p\n", 42, (void*)0xdeadbff); 32 | /* 33 | * Print memory like hexeditor 34 | * For more skills bro 35 | */ 36 | D_STRING(print_memory)(&string, "Memory"); 37 | /* 38 | * Today I am nice boy 39 | * So I free the memory 40 | */ 41 | D_STRING(destroy)(&string); 42 | (void)argc; 43 | (void)argv; 44 | return (0); 45 | } 46 | -------------------------------------------------------------------------------- /examples/libc/stack/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/04 21:11:50 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | /* 19 | * This file is a little example of the t_stack structure 20 | */ 21 | 22 | bool uf_print(void *data) 23 | { 24 | uf_print_nbr((size_t)data); 25 | uf_print_char(' '); 26 | return (true); 27 | } 28 | 29 | int main(int argc, char const** argv) 30 | { 31 | size_t i; 32 | t_stack stack; 33 | 34 | /* 35 | * Like queue so cf:queue 36 | */ 37 | i = 0; 38 | D_STACK(init)(&stack, NULL); 39 | while (i < 5) 40 | { 41 | D_STACK(push)(&stack, (void*)i + (42 << (i * (i + 1)))); 42 | i = i + 1; 43 | } 44 | D_STACK(foreach)(&stack, &uf_print); 45 | uf_print_char('\n'); 46 | D_STACK(destroy)(&stack); 47 | (void)argc; 48 | (void)argv; 49 | return (0); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /test/libc/string/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2014/09/03 16:52:23 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void D_UNIT_FUNCT(memleaks) 17 | { 18 | unsigned int i; 19 | t_string string; 20 | 21 | i = 0; 22 | D_STRING(init)(&string, 0); 23 | while (i < 5) 24 | { 25 | D_STRING(add_str)(&string, "hello boys"); 26 | D_STRING(add_nbr)(&string, 42); 27 | D_STRING(add_ptr)(&string, &string); 28 | D_STRING(variadic)(&string, "%e%X", 35, 42); 29 | i = i + 1; 30 | } 31 | D_STRING(destroy)(&string); 32 | (void)t; 33 | } 34 | 35 | int main(int argc, char const** argv) 36 | { 37 | t_unit unit; 38 | 39 | D_UNIT(init)(&unit); 40 | D_UNIT(add_context)(&unit, "Leaks", 0, 0); 41 | F_UNIT_ADD_TEST(&unit, "Leaks", memleaks); 42 | D_UNIT(console_run)(&unit); 43 | D_UNIT(destroy)(&unit); 44 | (void)argc; 45 | (void)argv; 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /srcs/libc/vector/README.md: -------------------------------------------------------------------------------- 1 | Vector 2 | ========== 3 | 4 | ## Function 5 | 6 | - init(t_vector *v_this, uint (*uf_realloc)(uint size), void (*uf_delete)(void *ptr)) 7 | /* This function initialize t_vector */ 8 | 9 | - clear(t_vector *v_this) 10 | /* This function remove all elements */ 11 | 12 | - empty(const t_vector *v_this) 13 | /* This function return true if vector is empty */ 14 | 15 | - size(const t_vector *v_this) 16 | /* This function return size of vector */ 17 | 18 | - capacity(const t_vector *v_this) 19 | /* This function return capacity of vector */ 20 | 21 | - push_back(t_vector *v_this, void *data) 22 | /* This function push data at the end */ 23 | 24 | - foreach(t_vector *v_this, bool (*funct)(void *ptr)) 25 | /* This function apply for lot of elements */ 26 | 27 | - reserve(t_vector *v_this, uint new_size) 28 | /* This function change capacity */ 29 | 30 | - erase(t_vector *v_this, void *ptr) 31 | /* This function remove ptr to vector and return data */ 32 | 33 | - delete(t_vector *v_this, void *ptr) 34 | /* This function delete ptr */ 35 | 36 | - at(t_vector *v_this, uint index) 37 | /* This function return index element */ 38 | 39 | - data(t_vector *v_this) 40 | /* This function data pointer */ 41 | 42 | - front(t_vector *v_this) 43 | /* This function first element */ 44 | 45 | - back(t_vector *v_this,) 46 | /* This function last element */ 47 | 48 | - destroy(t_vector *v_this) 49 | /* This function free t_vector */ 50 | 51 | === 52 | ## How to use ? 53 | 54 | You can see [example](https://github.com/QuentinPerez/42-toolkit/tree/master/examples/libc/vector). 55 | 56 | === 57 | ## License 58 | 59 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 60 | -------------------------------------------------------------------------------- /examples/libc/f_string/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/28 18:08:55 by qperez #+# #+# */ 9 | /* Updated: 2015/04/19 14:09:36 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /* 20 | * This file is a little example of string function 21 | */ 22 | 23 | /* 24 | * If you see more ... the way is f_string/f_string.h 25 | */ 26 | 27 | int main(int argc, const char **argv) 28 | { 29 | char *ptr; 30 | size_t len; 31 | 32 | /* 33 | * Look f_string header for more functions 34 | */ 35 | uf_print_variadic("%s %d, hexa version %X ," 36 | "%egreen%E red bold%e%c", "Hello", 37 | 42, 42, 32, 31, 0, '\n'); 38 | if ((ptr = uf_mapfile("./f_string/src/main.c", &len, 39 | PROT_READ | PROT_WRITE, true)) != NULL) 40 | { 41 | write(1, ptr, len); 42 | if (uf_unmapfile(ptr, len) != true) 43 | return (1); 44 | } 45 | (void)argv; 46 | (void)argc; 47 | return (0); 48 | } 49 | -------------------------------------------------------------------------------- /examples/libc/list/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/05 15:08:40 by qperez #+# #+# */ 9 | /* Updated: 2014/12/02 13:11:57 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /* 18 | * This file is a little example of the t_list structure 19 | */ 20 | 21 | bool uf_print_data(void *data) 22 | { 23 | uf_print_variadic("Data = %d\n", (size_t)data); 24 | return (true); 25 | } 26 | 27 | int main(int argc, char const** argv) 28 | { 29 | t_list list; 30 | 31 | /* 32 | * Initialize with delete pointer NULL because my data it's not allocated 33 | */ 34 | D_LIST(init)(&list, NULL); 35 | /* 36 | * Push at the end, the data 101 37 | * Check return Value ? 38 | * No it's useless ! Ok Master 39 | */ 40 | D_LIST(push_back)(&list, (void *)101); 41 | D_LIST(push_back)(&list, (void *)11101); 42 | D_LIST(foreach)(&list, uf_print_data); 43 | /* 44 | * We free memory ? 45 | * Well ... let it and we'll see 46 | */ 47 | D_LIST(destroy)(&list); 48 | (void)argc; 49 | (void)argv; 50 | return (0); 51 | } 52 | -------------------------------------------------------------------------------- /examples/libc/error/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/13 12:58:04 by qperez #+# #+# */ 9 | /* Updated: 2015/04/19 16:24:52 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | bool uf_test_bool(t_error *v_this) 17 | { 18 | /* 19 | * Use variadic here Are you kidding ? 20 | * ... 21 | * Ok just for the skills 22 | */ 23 | return (F_ERROR_ADD(v_this, true, "The %s error", "first")); 24 | } 25 | 26 | /* 27 | * This file is a little example of the t_error structure 28 | */ 29 | 30 | int main(int argc, char const** argv) 31 | { 32 | t_error error; 33 | 34 | /* 35 | * Initialize the structure with the filename here file.txt 36 | */ 37 | if (D_ERROR(init)(&error, "file.txt") == false) 38 | { 39 | printf("Error\n"); 40 | return (-1); 41 | } 42 | /* 43 | * Add 2 errors to file.txt 44 | */ 45 | uf_test_bool(&error); 46 | /* 47 | * free memory used by array !! 48 | * ... 49 | * Pff it's useless the OS make it after 50 | * .... 51 | */ 52 | D_ERROR(destroy)(&error); 53 | (void)argc; 54 | (void)argv; 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /doc/misc/Makefile_part2.txt: -------------------------------------------------------------------------------- 1 | 2 | OBJ = $(addprefix $(OBJDIR)/, $(SRC:.c=.o)) 3 | DEP = $(OBJ:.o=.d) 4 | DEPFILE = $(OBJDIR)/$(DIRSRC)/.build 5 | 6 | .SILENT: 7 | 8 | all : $(OBJDIR) $(NAME) 9 | 10 | -include $(DEP) 11 | 12 | $(addprefix $(OBJDIR)/, %.d) : %.c 13 | $(CC) $(CFLAGS) $< -MM -MT $(@:.d=.o) 2> /dev/null > $@ 14 | 15 | $(addprefix $(OBJDIR)/, %.o) : %.c 16 | $(CC) $(CFLAGS) -o $@ -c $< 17 | echo -e '\033[0;32mBuilding C Object $@\033[0m' 18 | 19 | $(NAME) : $(OBJ) $(DEPFILE) 20 | ar rcs $(NAME) $(OBJ) 21 | echo -e '\033[1;31mC libraries \033[1;35m$(NAME) \033[1;33m$(CC)\033[0m' 22 | 23 | $(DEPFILE) : 24 | touch $@ 25 | echo -e '\033[1;35mBuilding dependencies \033[0m' 26 | make 2> /dev/null > /dev/null 27 | 28 | clean : 29 | /bin/rm -fr $(OBJDIR) 30 | echo -e '\033[1;34mClean libraries $(NAME)\033[0m' 31 | 32 | fclean : clean 33 | /bin/rm -fr $(NAME) 34 | echo -e '\033[1;34mFclean libraries $(NAME)\033[0m' 35 | 36 | re : fclean 37 | make 38 | 39 | debug : CFLAGS += $(DEBUG) 40 | debug : fclean all 41 | echo -e '\033[1;31mDebug version \033[1;35m$(DEBUG)\033[0m' 42 | 43 | analyze : 44 | clang --analyze -Xanalyzer -analyzer-output=html $(SRC) -I./include 45 | 46 | every : CFLAGS += -Weverything -Wno-gnu-zero-variadic-macro-arguments 47 | every : fclean all 48 | echo -e '\033[1;33mGood job !\033[0m' 49 | 50 | $(OBJDIR) : 51 | /bin/mkdir $(OBJDIR); \ 52 | for DIR in $(LISTDIR); \ 53 | do \ 54 | /bin/mkdir $(OBJDIR)/$$DIR; \ 55 | done \ 56 | 57 | help : 58 | echo -e '\033[1;34mclean\t\033[0m⇒ Cleaning all object' 59 | echo -e '\033[1;34mfclean\t\033[0m⇒ Cleaning all object and libraries' 60 | echo -e '\033[1;34mdebug\t\033[0m⇒ Add debug flags' 61 | echo -e '\033[1;34mre\t\033[0m⇒ Deleting all object and build' 62 | echo -e "" 63 | echo -e '\033[1;34mevery\t\033[0m⇒ God code' 64 | 65 | .PHONY: clean fclean re debug every 66 | -------------------------------------------------------------------------------- /examples/libc/queue/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/04 21:09:53 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /* 18 | * This file is a little example of the t_aueue structure 19 | */ 20 | 21 | bool uf_print(void *data) 22 | { 23 | uf_print_nbr((size_t)data); 24 | uf_print_char(' '); 25 | return (true); 26 | } 27 | 28 | int main(int argc, char const** argv) 29 | { 30 | size_t i; 31 | t_queue queue; 32 | 33 | i = 0; 34 | /* 35 | * Initialize with NULL like list 36 | */ 37 | D_QUEUE(init)(&queue, NULL); 38 | while (i < 5) 39 | { 40 | /* 41 | * Why i + 42 << i^2 42 | * For fun he is crazy 43 | */ 44 | D_QUEUE(push)(&queue, (void*)i + (42 << (i * i))); 45 | i = i + 1; 46 | } 47 | /* 48 | * Print all cellule 49 | */ 50 | D_QUEUE(foreach)(&queue, &uf_print); 51 | uf_print_char('\n'); 52 | /* 53 | * And yes I freeing memory 54 | */ 55 | D_QUEUE(destroy)(&queue); 56 | (void)argc; 57 | (void)argv; 58 | return (0); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /test/libc/rbtree/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2014/09/03 17:49:48 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int uf_rbcmp(void *d1, void *d2) 18 | { 19 | return ((size_t)d1 - (size_t)d2); 20 | } 21 | 22 | bool uf_print(void *d1, void *d2) 23 | { 24 | uf_print_nbr((size_t)d1); 25 | uf_print_char(' '); 26 | (void)d2; 27 | return (true); 28 | } 29 | 30 | void D_UNIT_FUNCT(memleaks) 31 | { 32 | size_t i; 33 | t_rbtree rbtree; 34 | 35 | D_RBTREE(init)(&rbtree, uf_rbcmp, 0); 36 | i = 0; 37 | while (i < 30) 38 | { 39 | D_RBTREE(insert)(&rbtree, (void*)i); 40 | i = i + 1; 41 | } 42 | D_RBTREE(destroy)(&rbtree); 43 | (void)t; 44 | } 45 | 46 | int main(int argc, char const** argv) 47 | { 48 | t_unit unit; 49 | 50 | D_UNIT(init)(&unit); 51 | D_UNIT(add_context)(&unit, "Leaks", 0, 0); 52 | F_UNIT_ADD_TEST(&unit, "Leaks", memleaks); 53 | D_UNIT(console_run)(&unit); 54 | D_UNIT(destroy)(&unit); 55 | (void)argc; 56 | (void)argv; 57 | return (0); 58 | } 59 | -------------------------------------------------------------------------------- /srcs/libc/f_math/include/f_convert.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_convert.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:42:18 by qperez #+# #+# */ 9 | /* Updated: 2013/10/21 23:46:54 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_CONVERT_H 30 | # define F_CONVERT_H 31 | 32 | double uf_deg_to_rad(double deg); 33 | double uf_rad_to_deg(double rad); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /srcs/libc/f_math/src/f_abs.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_abs.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:50:31 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:21:29 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < uf_abs > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | double uf_abs(double value) 33 | { 34 | if (value < 0) 35 | value = -value; 36 | return (value); 37 | } 38 | -------------------------------------------------------------------------------- /srcs/libc/f_memory/include/f_free.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_free.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/08 11:37:00 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:33:24 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_FREE_H 30 | # define F_FREE_H 31 | 32 | void uf_free_tab(void **tab); 33 | void uf_free_tab_fail(void **tab, size_t current); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /examples/libc/arqueue/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2014/06/30 02:04:22 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | typedef struct s_foo 20 | { 21 | int a; 22 | int b; 23 | int c; 24 | } t_foo; 25 | 26 | int main(int argc, char const** argv) 27 | { 28 | t_arqueue arqueue; 29 | t_foo foo; 30 | t_foo *bar; 31 | int i; 32 | 33 | i = 0; 34 | D_ARQUEUE(init)(&arqueue, sizeof(t_foo), 5); 35 | while (i < 5) 36 | { 37 | foo.a = i; 38 | foo.b = i + 20; 39 | foo.c = i + 30; 40 | if (D_ARQUEUE(push)(&arqueue, &foo) == true) 41 | dprintf(1, "push %d -> a.%d b.%d b.%d\n", i, foo.a, foo.b, foo.c); 42 | i = i + 1; 43 | } 44 | i = i - 1; 45 | dprintf(1, "\n"); 46 | while (i >= 0) 47 | { 48 | if ((bar = D_ARQUEUE(pop)(&arqueue)) != NULL) 49 | { 50 | dprintf(1, "pop %d -> a.%d b.%d b.%d\n", i, bar->a, bar->b, bar->c); 51 | } 52 | i = i - 1; 53 | } 54 | D_ARQUEUE(destroy)(&arqueue); 55 | (void)argc; 56 | (void)argv; 57 | return (0); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /examples/libc/timer/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/16 12:55:00 by qperez #+# #+# */ 9 | /* Updated: 2014/03/19 15:12:00 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * This file is a little example of the t_timer structure 18 | */ 19 | 20 | /* 21 | * This tools is useless ... 22 | * No not when you want know "Who has the biggest" 23 | */ 24 | 25 | int main(int argc, char const** argv) 26 | { 27 | size_t i; 28 | size_t j; 29 | t_timer timer; 30 | 31 | i = 0; 32 | /* 33 | * Initialize timer 34 | * Ok but initialize what ? 35 | * I don't know 36 | */ 37 | D_TIMER(start)(&timer); 38 | /* 39 | * BEWARE here you will see a bad code totally useless 40 | * 3 41 | * 2 42 | * 1 43 | * sorry for this 44 | */ 45 | while (i < 0xfffffff) 46 | { 47 | j = i * i * i; 48 | j = j * j * i; 49 | j = j * i; 50 | i = i + 1; 51 | } 52 | D_TIMER(pause)(&timer); 53 | /* 54 | * Get time 55 | * ... 56 | * Who has the biggest ? 57 | */ 58 | uf_print_variadic("Loop in %d milliseconds\n", D_TIMER(get_ticks)(&timer)); 59 | (void)argc; 60 | (void)argv; 61 | return (0); 62 | } 63 | 64 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_mapfile.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_mapfile.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/26 22:26:46 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 17:11:46 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | char *uf_mapfile(const char *name, size_t *len, 23 | int map_flags, bool private) 24 | { 25 | char *ret; 26 | int fd; 27 | struct stat st; 28 | 29 | if ((fd = open(name, O_RDWR)) == -1) 30 | return ((char *)M_ERROR(0, "An error has occured")); 31 | if (fstat(fd, &st) != 0) 32 | { 33 | close(fd); 34 | return ((char *)M_ERROR(0, "The file parameter are not" 35 | "available")); 36 | } 37 | if ((ret = mmap(NULL, (size_t)st.st_size, map_flags, 38 | private == true ? MAP_PRIVATE : MAP_SHARED, fd, 0)) == MAP_FAILED) 39 | { 40 | close(fd); 41 | return ((char *)M_ERROR(0, "Could'nt map the file")); 42 | } 43 | *len = (size_t)st.st_size; 44 | close(fd); 45 | return (ret); 46 | } 47 | 48 | bool uf_unmapfile(void *addr, size_t len) 49 | { 50 | return (munmap(addr, len) != 0); 51 | } 52 | -------------------------------------------------------------------------------- /examples/libc/vector/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/05 15:08:40 by qperez #+# #+# */ 9 | /* Updated: 2014/12/02 13:12:10 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | static bool uf_print(void *ptr) 18 | { 19 | uf_print_str("Value : "); 20 | uf_print_nbr((size_t)ptr); 21 | uf_print_char('\n'); 22 | return (true); 23 | } 24 | 25 | /* 26 | * This file is a little example of the t_vector structure 27 | */ 28 | 29 | /* 30 | * Nostalgie moment: 31 | * It's the first of Lib42 32 | */ 33 | 34 | int main(int argc, char const** argv) 35 | { 36 | size_t i; 37 | t_vector vector; 38 | 39 | /* 40 | * Initialize vector 41 | */ 42 | i = 1; 43 | D_VECTOR(init)(&vector, NULL, NULL); 44 | while (i < 3) 45 | { 46 | /* 47 | * Add data without check return value MUAHAHAHA 48 | */ 49 | D_VECTOR(push_back)(&vector, (void *)(size_t)i); 50 | i = i + 1; 51 | } 52 | /* 53 | * Print all value 54 | */ 55 | D_VECTOR(foreach)(&vector, &uf_print); 56 | /* 57 | * See you later memory 58 | */ 59 | D_VECTOR(destroy)(&vector); 60 | (void)argc; 61 | (void)argv; 62 | return (0); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /srcs/libc/f_string/include/f_space.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_space.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/07 23:42:21 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:35:14 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_SPACE_H 30 | # define F_SPACE_H 31 | 32 | # include 33 | 34 | bool uf_is_space(const unsigned char c); 35 | char *uf_skip_space(const char *str); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /srcs/libc/rbtree/src/s_rbtree_delete.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_rbtree_delete.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/15 13:21:58 by qperez #+# #+# */ 9 | /* Updated: 2013/11/15 13:23:40 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < delete > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | void f_rbtree_delete(t_rbtree *v_this, t_rbcell *node) 33 | { 34 | v_this->f_delete(D_RBTREE(erase)(v_this, node)); 35 | } 36 | -------------------------------------------------------------------------------- /srcs/libc/f_math/include/f_math.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_math.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:52:21 by qperez #+# #+# */ 9 | /* Updated: 2013/10/22 11:52:15 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_MATH_H 30 | # define F_MATH_H 31 | 32 | double uf_abs(double value); 33 | double uf_min(const double x, const double y); 34 | double uf_max(const double x, const double y); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /srcs/libc/f_string/include/f_str_tools.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_str_tools.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/28 15:12:43 by qperez #+# #+# */ 9 | /* Updated: 2014/01/08 12:26:37 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_STR_TOOLS_H 30 | # define F_STR_TOOLS_H 31 | 32 | # include 33 | 34 | size_t uf_str_len(const char *str); 35 | void uf_print_in_base(char nbr, int fd); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 42-toolkit 2 | ========== 3 | 4 | [![Build Status](https://travis-ci.org/QuentinPerez/42-toolkit.svg?branch=master)](https://travis-ci.org/QuentinPerez/42-toolkit) 5 | 6 |

7 | 42 8 |

9 | 10 | # School 11 | 12 | #### Demonstration: 13 | 42's priority is P2P so I started a open source project for me and my colleagues. 14 | This project contains basic tools that allow us to work faster and more efficiently. 15 | This code will prevent wasting time on rewriting the same function several times 16 | and allow us to share ideas at the same time. 17 | Less time on the generic code and more time on our school project. 18 | 19 | #### Why I wanted to do this 20 | 21 | Give me six hours to chop down a tree and 22 | I will spend the first four sharpening the axe. 23 | Abraham Lincoln. 24 | 25 | 26 | ## Contributing 27 | 28 | #### I've found a bug! 29 | 30 | We're glad you did, and certainly would like to know more! Please use the [issues tracker](https://github.com/QuentinPerez/42-toolkit/issues) to report it. 31 | 32 | You can share your thoughts, requests, feedback on that same [tracker](https://github.com/QuentinPerez/42-toolkit/issues)! 33 | 34 | #### I'm a dev, I can help! 35 | 36 | Welcome, First just take a look at [these guidelines](CONTRIBUTING.md) 37 | 38 | Feel free to contribute :smiley::beers: 39 | 40 | #### Docker 41 | 42 | ```console 43 | $> docker build -t="42-toolkit" . 44 | $> docker run -it --rm -v $(pwd):/usr/root/42-toolkit 42-toolkit 45 | ``` 46 | 47 | #### How to thank us ? 48 | 49 | Just click on :star: button :kissing_heart: 50 | 51 | 52 | ## Who's behind it? 53 | 54 | ### Owner 55 | * [Quentin Perez](https://github.com/QuentinPerez) 56 | 57 | 58 | ## Lib42 59 | 60 | The library has been tested on Darwin, Linux system and Windows with cygwin. 61 | 62 | 63 | ## License 64 | 65 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 66 | -------------------------------------------------------------------------------- /srcs/libc/stack/src/s_stack_access.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_stack_access.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 17:35:18 by qperez #+# #+# */ 9 | /* Updated: 2013/11/03 23:59:27 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < top > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | void *f_stack_top(t_stack *v_this) 34 | { 35 | if (v_this->v_last != NULL) 36 | return (v_this->v_last->v_data); 37 | return (NULL); 38 | } 39 | -------------------------------------------------------------------------------- /srcs/libc/README.md: -------------------------------------------------------------------------------- 1 | Libc 2 | ========== 3 | 4 | # Unable 5 | === 6 | 7 | ### Containers 8 | - list/ "Double linked-list" 9 | - vector/ "Pointer array that can change size" 10 | - array/ "Struct array that can change size" 11 | - stack/ "Last-in-First-out container" 12 | - queue/ "First-in-First-out container" 13 | - htable/ "Hash table" 14 | - rbtree/ "Red-Black Tree" 15 | ### Function 16 | - f_error/ "Treat return value with more skills" 17 | - f_string/ "Do you want play with char *?" 18 | - f_memory/ "Function to treat memory" 19 | - f_crypto/ "Function to encrypt-decrypt" 20 | - f_math/ "Math tools" 21 | - f_sort/ "Sort function" 22 | ### Tools 23 | - error/ "Write error to file" 24 | - timer/ "Timer in milliseconds" 25 | - getopt/ "Treat argv" 26 | - unit/ "42 unit testing" 27 | - matrix/ 28 | 29 | === 30 | 31 | ## How to make libraries ? 32 | - ./make_lib 33 | - cd lib42 34 | 35 | === 36 | 37 | ## How add to your git project (at school) ? 38 | 39 | - git submodule add https://github.com/QuentinPerez/42-toolkit.git 40 | - git submodule init 41 | 42 | #####Update: 43 | 44 | - git submodule update 45 | === 46 | 47 | ## How compile lib42 in your own Makefile ? 48 | 49 | #####Variables: 50 | 51 | - DIR42 = lib42 52 | - CFLAGS += -I./$(DIR42)/include 53 | - LDFLAGS += -L./$(DIR42) -l42 54 | - LIB42 = $(LIB42)/lib42.a 55 | 56 | #####Add dependencies: 57 | 58 | - $(EXEC) : $(LIB42) ... 59 | - ... 60 | 61 | #####Rules: 62 | 63 | - $(LIB42) : $(DIR42) 64 | make -C $(DIR42) 65 | 66 | - $(DIR42) : $(TOOLKIT) 67 | cd $(TOOLKIT)/srcs/libc && ./make_lib && mv $(DIR42) ../../../ 68 | 69 | - $(TOOLKIT) : 70 | git submodule init 71 | git submodule update 72 | === 73 | 74 | 75 | ### Example link 76 | 77 | [school's Makefile](https://github.com/QuentinPerez/42-toolkit/tree/master/doc/school/Makefile). 78 | 79 | === 80 | 81 | ### License 82 | 83 | 42-toolkit is available under the [GNU General Public License, version 3](LICENSE). 84 | -------------------------------------------------------------------------------- /srcs/libc/unit/include/s_unit_params.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_unit_params.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/31 12:06:36 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:53:50 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_UNIT_PARAMS_H 30 | # define S_UNIT_PARAMS_H 31 | 32 | # include 33 | # include 34 | 35 | typedef struct s_unit_params 36 | { 37 | size_t v_width; 38 | bool v_run; 39 | } t_unit_params; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /examples/libc/f_error/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/28 16:40:56 by qperez #+# #+# */ 9 | /* Updated: 2015/04/22 22:04:57 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /* 18 | * This file is a little example errors macros 19 | */ 20 | 21 | int main(int argc, const char **argv) 22 | { 23 | char *foo; 24 | void *bar; 25 | 26 | /* 27 | * Beware this is the best tools !! 28 | * He say with it's his code !! 29 | * ... 30 | * BANGGG !! 31 | */ 32 | /* 33 | * This function return the first parameter, show error and it's amazing 34 | * We begin with an easy 35 | */ 36 | M_ERROR(false, "It's nice but not amazing"); 37 | /* 38 | * Ok Level Up 39 | */ 40 | M_ERROR(42, "Nice it's an integer YOUHOU"); 41 | /* 42 | * Next Level 43 | */ 44 | bar = (void *)0xdeadb0ff; 45 | M_ERROR((size_t)bar, "What you want that i return an adress ? Easy it's %p", bar); 46 | /* 47 | * WHOOHA Ok it's amazing and you can pass arguments !! 48 | */ 49 | /* 50 | * Next Level 51 | * No it's not possible what again 52 | */ 53 | foo = (char *)M_ERROR((size_t)argv[0], "Easy bro %s", argv[0]); 54 | (void)foo; 55 | (void)argv; 56 | (void)argc; 57 | return (0); 58 | } 59 | -------------------------------------------------------------------------------- /examples/libc/lock/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/19 15:12:35 by qperez #+# #+# */ 9 | /* Updated: 2014/11/20 21:10:40 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * This file is a little example of the t_lock structure 18 | */ 19 | 20 | typedef struct s_share 21 | { 22 | int var1; 23 | int var2; 24 | } t_share; 25 | 26 | int main(int argc, char const** argv) 27 | { 28 | /* 29 | * Create all threads you want 30 | */ 31 | t_share private_share; 32 | t_lock lock; 33 | t_share *acces_share; 34 | 35 | dprintf(1, "Init lock\n"); 36 | if (D_LOCK(init)(&lock, &private_share, e_lock_default) == false) 37 | return (1); 38 | /* 39 | * safe access 40 | */ 41 | dprintf(1, "Lock variable\n"); 42 | if (D_LOCK(lock)(&lock, (void **)&acces_share) == true) 43 | { 44 | acces_share->var1 = 1; 45 | /* 46 | * treat variable 47 | */ 48 | D_LOCK(release)(&lock, (void **)&acces_share); 49 | /* 50 | * if here you access at the variable, you will crash because 51 | * acces_share == NULL 52 | */ 53 | dprintf(1, "Release variable\n"); 54 | } 55 | D_LOCK(destroy)(&lock); 56 | dprintf(1, "Destroy lock\n"); 57 | (void)argc; 58 | (void)argv; 59 | return (0); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /srcs/libc/list/src/s_list_capacity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_list_capacity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/30 17:43:18 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:47:11 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < empty, size > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | bool f_list_empty(const t_list *v_this) 33 | { 34 | return (v_this->v_size == 0); 35 | } 36 | 37 | size_t f_list_size(const t_list *v_this) 38 | { 39 | return (v_this->v_size); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/libc/queue/src/s_queue_capacity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_queue_capacity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/03 14:30:28 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:49:52 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < empty, size > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | bool f_queue_empty(const t_queue *v_this) 33 | { 34 | return (v_this->v_size == 0); 35 | } 36 | 37 | size_t f_queue_size(const t_queue *v_this) 38 | { 39 | return (v_this->v_size); 40 | } 41 | -------------------------------------------------------------------------------- /test/libc/f_math/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/27 15:48:40 by qperez #+# #+# */ 9 | /* Updated: 2013/11/05 14:02:45 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | static void 20 | t_abs(void **state) { 21 | assert_int_equal(uf_abs(-10), 10); 22 | assert_int_equal(uf_abs(10), 10); 23 | assert_int_equal(uf_abs(0), 0); 24 | (void)state; 25 | } 26 | 27 | static void 28 | t_min(void **state) { 29 | assert_int_equal(uf_min(-10, 10), -10); 30 | assert_int_equal(uf_min(10, 100), 10); 31 | assert_int_equal(uf_min(-10, -20), -20); 32 | assert_int_equal(uf_min(0, 0), 0); 33 | (void)state; 34 | } 35 | 36 | static void 37 | t_max(void **state) { 38 | assert_int_equal(uf_max(-10, 10), 10); 39 | assert_int_equal(uf_max(10, 100), 100); 40 | assert_int_equal(uf_max(-10, -20), -10); 41 | assert_int_equal(uf_max(0, 0), 0); 42 | (void)state; 43 | } 44 | 45 | int 46 | main(int argc, char const** argv) { 47 | const struct CMUnitTest test[] = { 48 | cmocka_unit_test(t_abs), 49 | cmocka_unit_test(t_min), 50 | cmocka_unit_test(t_max), 51 | }; 52 | 53 | (void)argc; 54 | (void)argv; 55 | return (cmocka_run_group_tests(test, 0, 0)); 56 | } 57 | -------------------------------------------------------------------------------- /examples/libc/htable/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/08 13:01:24 by qperez #+# #+# */ 9 | /* Updated: 2014/08/27 10:39:34 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | bool uf_print_value(t_htable_cell *cell) 19 | { 20 | uf_print_nbr((size_t)cell->v_data); 21 | uf_print_char(' '); 22 | return (true); 23 | } 24 | 25 | /* 26 | * This file is a little example of the t_htable structure 27 | */ 28 | 29 | int main(int argc, char const** argv) 30 | { 31 | t_htable htable; 32 | 33 | /* 34 | * 127 is prime number OK !! 35 | */ 36 | D_HTABLE(init)(&htable, 127, NULL, NULL); 37 | /* 38 | * Here I add "42" in htable 39 | * With data (void*)1; 40 | * Because it's demonstration not the truth ! 41 | */ 42 | D_HTABLE(add)(&htable, "42", (void*)7); 43 | D_HTABLE(add)(&htable, "paris", (void*)8); 44 | D_HTABLE(add)(&htable, "school", (void*)9); 45 | /* 46 | * Print all table 47 | */ 48 | D_HTABLE(print)(&htable, uf_print_value); 49 | uf_print_variadic("The data assigned at 42 is %d\n", D_HTABLE(get)(&htable, "42")); 50 | /* 51 | * Free memory again yes yes (wo)man ! 52 | */ 53 | D_HTABLE(destroy)(&htable); 54 | (void)argc; 55 | (void)argv; 56 | return (0); 57 | } 58 | -------------------------------------------------------------------------------- /srcs/libc/stack/src/s_stack_capacity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_stack_capacity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/03 14:31:57 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:50:19 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < empty, size > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | inline bool f_stack_empty(const t_stack *v_this) 33 | { 34 | return (v_this->v_size == 0); 35 | } 36 | 37 | inline size_t f_stack_size(const t_stack *v_this) 38 | { 39 | return (v_this->v_size); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/libc/f_math/src/f_convert_angle.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_convert_angle.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:36:28 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:25:43 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < uf_rad_to_deg, uf_deg_to_rad > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | double uf_deg_to_rad(double deg) 34 | { 35 | return (deg * D_PI / 180); 36 | } 37 | 38 | double uf_rad_to_deg(double rad) 39 | { 40 | return (rad * 180 / D_PI); 41 | } 42 | -------------------------------------------------------------------------------- /srcs/libc/timer/src/s_timer_access.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_timer_access.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/16 12:49:23 by qperez #+# #+# */ 9 | /* Updated: 2013/11/12 17:01:33 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < is_started, is_paused > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | bool f_timer_is_paused(const t_timer *v_this) 33 | { 34 | return (v_this->v_paused == true); 35 | } 36 | 37 | bool f_timer_is_started(const t_timer *v_this) 38 | { 39 | return (v_this->v_started == true); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/libc/f_math/src/f_minmax.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_minmax.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/22 11:46:25 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:34:29 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < uf_min, uf_max > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | double uf_min(const double x, const double y) 33 | { 34 | if (x > y) 35 | return (y); 36 | return (x); 37 | } 38 | 39 | double uf_max(const double x, const double y) 40 | { 41 | if (x > y) 42 | return (x); 43 | return (y); 44 | } 45 | -------------------------------------------------------------------------------- /examples/libc/rbtree/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/13 12:58:04 by qperez #+# #+# */ 9 | /* Updated: 2014/12/02 13:12:42 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int uf_rbcmp(void *d1, void *d2) 18 | { 19 | return ((size_t)d1 - (size_t)d2); 20 | } 21 | 22 | bool uf_print(void *d1, void *d2) 23 | { 24 | uf_print_nbr((size_t)d1); 25 | uf_print_char(' '); 26 | (void)d2; 27 | return (true); 28 | } 29 | 30 | int main(int argc, char const** argv) 31 | { 32 | size_t i; 33 | t_rbtree rbtree; 34 | 35 | /* 36 | * Initialize the structure rbtree 37 | */ 38 | D_RBTREE(init)(&rbtree, uf_rbcmp, 0); 39 | i = 0; 40 | while (i < 30) 41 | { 42 | /* 43 | * Insert number i 44 | */ 45 | D_RBTREE(insert)(&rbtree, (void*)i); 46 | i = i + 1; 47 | } 48 | /* 49 | * Print all value 50 | */ 51 | D_RBTREE(erase)(&rbtree, D_RBTREE(find)(&rbtree, (void *)4)); 52 | F_RBTREE_FOREACH_IN(&rbtree, uf_print, 0); 53 | uf_print_char('\n'); 54 | F_RBTREE_FOREACH_PRE(&rbtree, uf_print, 0); 55 | uf_print_char('\n'); 56 | F_RBTREE_FOREACH_POST(&rbtree, uf_print, 0); 57 | uf_print_char('\n'); 58 | /* 59 | * free memory 60 | */ 61 | D_RBTREE(destroy)(&rbtree); 62 | (void)argc; 63 | (void)argv; 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /srcs/libc/rbtree/src/s_rbtree_access.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_rbtree_access.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/13 18:33:52 by qperez #+# #+# */ 9 | /* Updated: 2014/01/08 18:31:45 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < root, empty > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | t_rbcell *f_rbtree_root(t_rbtree *v_this) 33 | { 34 | return (&v_this->v_root); 35 | } 36 | 37 | bool f_rbtree_empty(const t_rbtree *v_this) 38 | { 39 | return (v_this->v_root.v_left == &v_this->v_nil 40 | && v_this->v_root.v_right == &v_this->v_nil); 41 | } 42 | -------------------------------------------------------------------------------- /srcs/libc/f_crypto/include/f_crypto.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_crypto.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/18 17:27:57 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:59:54 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_CRYPTO_H 30 | # define F_CRYPTO_H 31 | 32 | # include 33 | 34 | void uf_crypto_xor(void *data, const unsigned char *key, size_t data_size); 35 | void uf_crypto_rot5(char *str); 36 | void uf_crypto_rot13(char *str); 37 | void uf_crypto_rot18(char *str); 38 | void uf_crypto_rot47(char *str); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /srcs/libc/f_sort/include/f_sort.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_sort.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/18 12:23:30 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:37:53 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_SORT_H 30 | # define F_SORT_H 31 | 32 | # include 33 | # include 34 | 35 | void uf_sort_bubble(int *ptr, size_t size); 36 | void uf_sort_shell(int *ptr, size_t size); 37 | void uf_sort_quick(int *ptr, size_t size); 38 | bool uf_sort_merge(int *ptr, size_t size); 39 | bool uf_sort_counting(int *ptr, size_t size); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /examples/libc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Copyright (C) <2013> Quentin Perez 4 | # 5 | # This file is part of 42-toolkit. 6 | # 7 | # 42-toolkit is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | DIR42 = lib42 22 | CFLAGS += -Wextra -Wall -Werror -I./$(DIR42)/include 23 | LDFLAGS += -L./$(DIR42) -l42 -lpthread 24 | DEBUG = -g3 -fno-inline 25 | 26 | LISTDIR = $(shell find ./* -maxdepth 0 -type d -not -path "./lib42") 27 | 28 | LIB42 = $(DIR42)/lib42.a 29 | 30 | EXELIST = $(addsuffix /a.out, $(LISTDIR)) 31 | 32 | .SILENT: 33 | 34 | all : $(DIR42) $(LIB42) $(EXELIST) 35 | 36 | %/a.out : 37 | $(CC) $(CFLAGS) -o $@ $(subst /a.out,/src/main.c,$@) $(LDFLAGS) 38 | printf '\033[1;31m%s \033[1;35m%s \033[1;33m%s\n\033[0m' "Linking C executable" "$@" "$(CC)" 39 | 40 | 41 | $(LIB42) : force 42 | make -C $(DIR42) 43 | 44 | clean : 45 | /bin/rm -fr $(DIR42) $(EXELIST) 46 | printf '\033[1;34m%s\n\033[0m' "Clean all project" 47 | 48 | debug : 49 | /bin/rm -fr $(EXELIST) 50 | make debug -C $(DIR42) 51 | make 52 | 53 | r : 54 | /bin/rm -fr $(EXELIST) 55 | make 56 | 57 | re : clean all 58 | 59 | relib : 60 | make re -C $(DIR42) 61 | 62 | $(DIR42) : 63 | ./configure 64 | 65 | force : 66 | true 67 | 68 | travis : 69 | for EXE in $(LISTDIR); \ 70 | do \ 71 | if [ $$EXE != "unit" ]; \ 72 | then \ 73 | echo "\033[32m----Testing $$EXE\033[m"; \ 74 | $$EXE/a.out; \ 75 | fi \ 76 | done 77 | 78 | .PHONY: clean re relib 79 | -------------------------------------------------------------------------------- /srcs/libc/array/src/s_array_capacity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_array_capacity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/03 13:26:16 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:42:31 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < empty, size, capacity > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | bool f_array_empty(const t_array *v_this) 33 | { 34 | return (v_this->v_size == 0); 35 | } 36 | 37 | size_t f_array_capacity(const t_array *v_this) 38 | { 39 | return (v_this->v_capacity); 40 | } 41 | 42 | size_t f_array_size(const t_array *v_this) 43 | { 44 | return (v_this->v_size); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/list/src/s_list_find.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_list_find.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/07 16:26:15 by qperez #+# #+# */ 9 | /* Updated: 2014/02/07 16:30:13 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < find > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | t_list_cell *f_list_find(t_list *v_this, bool (*cmp)(void *, void *), void *d) 34 | { 35 | t_list_cell *cell; 36 | 37 | cell = D_LIST(begin)(v_this); 38 | while (cell != NULL) 39 | { 40 | if (cmp(cell->v_data, d) == true) 41 | break ; 42 | cell = cell->v_next; 43 | } 44 | return (cell); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/queue/src/s_queue_operator.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_queue_operator.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/30 14:37:19 by qperez #+# #+# */ 9 | /* Updated: 2013/11/03 23:58:59 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < foreach > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | bool f_queue_foreach(t_queue *v_this, bool (*funct)(void *data)) 34 | { 35 | t_queue_cell *cur; 36 | 37 | cur = v_this->v_head; 38 | while (cur != NULL) 39 | { 40 | if (funct(cur->v_data) == false) 41 | return (false); 42 | cur = cur->v_next; 43 | } 44 | return (true); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/stack/src/s_stack_operator.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_stack_operator.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/30 14:46:15 by qperez #+# #+# */ 9 | /* Updated: 2013/09/30 14:50:08 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < foreach > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | bool f_stack_foreach(t_stack *v_this, bool (*funct)(void *data)) 34 | { 35 | t_stack_cell *cur; 36 | 37 | cur = v_this->v_last; 38 | while (cur != NULL) 39 | { 40 | if (funct(cur->v_data) == false) 41 | return (false); 42 | cur = cur->v_prev; 43 | } 44 | return (true); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/string/src/s_string_add_color.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_string_add_color.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/01 17:49:08 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:50:58 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < add_color > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | bool f_string_add_color(t_string *v_this, size_t color, size_t fx) 33 | { 34 | if (D_STRING(add_str)(v_this, "\033[") == false) 35 | return (false); 36 | if (fx > 0 && D_STRING(variadic)(v_this, "%d;", fx) == false) 37 | return (false); 38 | return (D_STRING(variadic)(v_this, "%dm", color)); 39 | } 40 | -------------------------------------------------------------------------------- /srcs/libc/fdnotify/include/s_fdnotify_event.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_fdnotify_event.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/12/04 09:42:41 by qperez #+# #+# */ 9 | /* Updated: 2014/12/04 10:17:23 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2014> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_FDNOTIFY_EVENT_H 30 | # define S_FDNOTIFY_EVENT_H 31 | 32 | typedef enum e_fdnotify_type 33 | { 34 | e_fdnotify_none = 0, 35 | e_fdnotify_read, 36 | e_fdnotify_write 37 | } t_fdnotify_type; 38 | 39 | typedef struct s_fdnotify_event 40 | { 41 | int v_fd; 42 | void *v_data; 43 | t_fdnotify_type v_type; 44 | } t_fdnotify_event; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /srcs/libc/queue/src/s_queue_access.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_queue_access.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/30 13:26:50 by qperez #+# #+# */ 9 | /* Updated: 2013/11/03 23:58:22 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < front, back > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | void *f_queue_front(t_queue *v_this) 34 | { 35 | if (v_this->v_head != NULL) 36 | return (v_this->v_head->v_data); 37 | return (NULL); 38 | } 39 | 40 | void *f_queue_back(t_queue *v_this) 41 | { 42 | if (v_this->v_tail != NULL) 43 | return (v_this->v_tail->v_data); 44 | return (NULL); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_print_color.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_print_color.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/01 15:29:06 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 17:12:57 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #include 30 | 31 | void uf_print_color_fx(size_t color, size_t params) 32 | { 33 | uf_print_str("\033["); 34 | if (params > 0) 35 | { 36 | uf_print_nbr((ssize_t)params); 37 | uf_print_char(';'); 38 | } 39 | uf_print_nbr((ssize_t)color); 40 | uf_print_char('m'); 41 | } 42 | 43 | void uf_print_color(size_t color) 44 | { 45 | uf_print_color_fx(color, 0); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/libc/vector/src/s_vector_capacity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_vector_capacity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/16 15:05:19 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:56:26 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < size, capacity, empty > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | inline bool f_vector_empty(const t_vector *v_this) 33 | { 34 | return (v_this->v_size == 0); 35 | } 36 | 37 | inline size_t f_vector_size(const t_vector *v_this) 38 | { 39 | return (v_this->v_size); 40 | } 41 | 42 | inline size_t f_vector_capacity(const t_vector *v_this) 43 | { 44 | return (v_this->v_capacity); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_space.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_space.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/07 23:41:00 by qperez #+# #+# */ 9 | /* Updated: 2015/07/04 10:04:38 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < uf_is_space, uf_skip_space > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | bool uf_is_space(const unsigned char c) 34 | { 35 | return (c == '\t' || c == ' ' || c == '\r' 36 | || c == '\f' || c == '\v' || c == '\n'); 37 | } 38 | 39 | char *uf_skip_space(const char *str) 40 | { 41 | while (uf_is_space((const unsigned char)*str) == true) 42 | str = str + 1; 43 | return ((char *)str); 44 | } 45 | -------------------------------------------------------------------------------- /srcs/libc/f_memory/include/f_memory.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_memory.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/09/26 12:48:37 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:33:39 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_MEMORY_H 30 | # define F_MEMORY_H 31 | 32 | # include 33 | # include 34 | 35 | void *uf_memset(void *src, unsigned char c, size_t size); 36 | void uf_memcpy(void *to, const void *from, size_t size); 37 | bool uf_memcmp(const void *left, const void *right, size_t size); 38 | void *uf_print_memory(const void *addr, size_t size); 39 | bool uf_lockallmemory(void); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_char_alnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_char_alnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:06:57 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:25:22 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < uf_isalpha, uf_isdigit, uf_isprint > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | bool uf_is_alpha(const unsigned char c) 34 | { 35 | return ((c > 96 && c < 123) || (c > 64 && c < 91)); 36 | } 37 | 38 | bool uf_is_digit(const unsigned char c) 39 | { 40 | return (c > 47 && c < 58); 41 | } 42 | 43 | bool uf_is_printable(const unsigned char c) 44 | { 45 | return (c > 31 && c < 127); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/libc/ldata/include/s_ldata.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_ldata.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/10/05 11:30:57 by qperez #+# #+# */ 9 | /* Updated: 2014/10/05 13:36:31 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2015> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_LDATA_H 30 | # define S_LDATA_H 31 | 32 | # include 33 | # include 34 | 35 | typedef struct s_ldata 36 | { 37 | void *v_ptr; 38 | size_t v_len; 39 | } t_ldata; 40 | 41 | # define D_LDATA(funct) f_ldata_##funct 42 | 43 | bool f_ldata_init(t_ldata *v_this, size_t len); 44 | void *f_ldata_get_ptr(t_ldata *v_this); 45 | void f_ldata_destroy(t_ldata *v_this); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_print_bool.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_print_bool.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/12 16:08:13 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:36:18 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | void uf_print_bool_fd(bool value, int fd) 35 | { 36 | ssize_t unused; 37 | 38 | if (value == true) 39 | unused = write(fd, "true", 4); 40 | else 41 | unused = write(fd, "false", 5); 42 | (void)unused; 43 | } 44 | 45 | void uf_print_bool(bool value) 46 | { 47 | uf_print_bool_fd(value, 1); 48 | } 49 | -------------------------------------------------------------------------------- /srcs/libc/f_string/include/f_char.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_char.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/07 21:03:48 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:31:51 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef F_CHAR_H 30 | # define F_CHAR_H 31 | 32 | # include 33 | 34 | bool uf_is_upper(const unsigned char c); 35 | bool uf_is_lower(const unsigned char c); 36 | unsigned char uf_to_lower(const unsigned char c); 37 | unsigned char uf_to_upper(const unsigned char c); 38 | bool uf_is_alpha(const unsigned char c); 39 | bool uf_is_printable(const unsigned char c); 40 | bool uf_is_digit(const unsigned char c); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /srcs/libc/array/src/s_array_access.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_array_access.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/03 13:59:04 by qperez #+# #+# */ 9 | /* Updated: 2016/01/24 15:59:00 by sfroment ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < data, at > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | void *mf_array_data(t_array *v_this) 35 | { 36 | return (v_this->v_data); 37 | } 38 | 39 | void *mf_array_at(t_array *v_this, size_t index) 40 | { 41 | if (index >= v_this->v_size) 42 | return ((void *)M_ERROR((size_t)0, "Out of range")); 43 | return ((void *)((uintptr_t)v_this->v_data + index * v_this->v_type_size)); 44 | } 45 | -------------------------------------------------------------------------------- /examples/libc/f_crypto/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/18 17:29:39 by qperez #+# #+# */ 9 | /* Updated: 2013/11/04 20:28:43 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | /* 19 | * This file is a little example crypto functions 20 | */ 21 | 22 | int main(int argc, char const** argv) 23 | { 24 | char dest[50]; 25 | 26 | /* 27 | * Cleaning before everything ... .. . 28 | */ 29 | uf_memset(dest, 0, sizeof(*dest) * 50); 30 | /* 31 | * Copying msg to dest 32 | */ 33 | uf_strcpy(dest, "The president is not dead, for the moment"); 34 | uf_print_variadic("Msg : %s\n", dest); 35 | /* 36 | * Use xor algorthym to encrypt msg ... 37 | */ 38 | uf_print_str("Xor Power\n"); 39 | uf_crypto_xor(dest, (const unsigned char *)"01/10/1110", sizeof(*dest) * 50); 40 | uf_print_variadic("Encrypt Msg : %s\n", dest); 41 | /* 42 | * Reuse xor algorthym to decrypt msg 43 | */ 44 | uf_crypto_xor(dest, (const unsigned char *)"01/10/1110", sizeof(*dest) * 50); 45 | uf_print_variadic("Decrypt Msg : %s\n", dest); 46 | /* 47 | * Now use a rot algorithym the 13 48 | */ 49 | uf_print_str("Rot Power\n"); 50 | uf_crypto_rot13(dest); 51 | uf_print_variadic("Encrypt Msg : %s\n", dest); 52 | uf_crypto_rot13(dest); 53 | uf_print_variadic("Decrypt Msg : %s\n", dest); 54 | (void)argc; 55 | (void)argv; 56 | return (0); 57 | } 58 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/08 20:33:45 by qperez #+# #+# */ 9 | /* Updated: 2014/12/02 11:43:15 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | char *uf_strdup(const char *str) 36 | { 37 | size_t size; 38 | char *ret; 39 | 40 | size = uf_str_len(str); 41 | if ((ret = uf_malloc_s((size + 1), sizeof(*ret))) == NULL) 42 | return ((char *)M_ERROR((size_t)NULL, "Bad alloc")); 43 | uf_strcpy(ret, str); 44 | return (ret); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/libc/array/src/s_array_operator.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_array_operator.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/02 15:46:25 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:43:03 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < foreach > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | bool f_array_foreach(t_array *v_this, bool (*funct)(void *data)) 33 | { 34 | size_t i; 35 | size_t size; 36 | char *ptr; 37 | 38 | i = 0; 39 | ptr = (char *)v_this->v_data; 40 | size = v_this->v_size * v_this->v_type_size; 41 | while (i < size) 42 | { 43 | if (funct((void *)(ptr + i)) == false) 44 | return (false); 45 | i = i + v_this->v_type_size; 46 | } 47 | return (true); 48 | } 49 | -------------------------------------------------------------------------------- /srcs/libc/f_memory/src/f_free.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_free.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/08 11:37:57 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:29:23 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | void uf_free_tab(void **tab) 33 | { 34 | size_t i; 35 | 36 | i = 0; 37 | while (tab[i] != NULL) 38 | { 39 | uf_free_s(&tab[i]); 40 | i = i + 1; 41 | } 42 | free(tab); 43 | } 44 | 45 | void uf_free_tab_fail(void **tab, size_t current) 46 | { 47 | size_t i; 48 | 49 | i = 0; 50 | while (i < current) 51 | { 52 | uf_free_s(&tab[i]); 53 | i = i + 1; 54 | } 55 | free(tab); 56 | } 57 | -------------------------------------------------------------------------------- /srcs/libc/unit/include/s_unit_context.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_unit_context.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/31 16:19:21 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:54:20 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_UNIT_CONTEXT_H 30 | # define S_UNIT_CONTEXT_H 31 | 32 | # include 33 | 34 | typedef struct s_unit_context 35 | { 36 | size_t v_id; 37 | t_list v_test; 38 | const char *v_name; 39 | bool (*f_init)(void *data); 40 | bool (*f_destroy)(void *data); 41 | } t_unit_context; 42 | 43 | bool uf_unit_print_context(void *data); 44 | void uf_unit_console_run(t_list *list); 45 | void uf_unit_console_failure(t_list *list); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /srcs/libc/f_sort/src/f_sort_bubble.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_sort_bubble.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/18 12:23:14 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:37:32 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < bubble > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | void uf_sort_bubble(int *begin, size_t size) 34 | { 35 | size_t x; 36 | size_t y; 37 | int tmp; 38 | 39 | x = 0; 40 | while (x < size) 41 | { 42 | y = 0; 43 | while (y < size - 1) 44 | { 45 | if (begin[y] > begin[y + 1]) 46 | { 47 | tmp = begin[y]; 48 | begin[y] = begin[y + 1]; 49 | begin[y + 1] = tmp; 50 | } 51 | y = y + 1; 52 | } 53 | x = x + 1; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /srcs/libc/list/src/s_list_interval.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_list_interval.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: irabeson +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/10 14:30:45 by irabeson #+# #+# */ 9 | /* Updated: 2014/01/08 17:55:50 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < init, begin, end > 16 | ** Copyright (C) <2013> Iohann Rabeson 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | 32 | void f_list_interval_init(t_list_interval *v_this, t_list_cell *begin, 33 | t_list_cell *end) 34 | { 35 | v_this->v_begin = begin; 36 | v_this->v_end = end; 37 | } 38 | 39 | t_list_cell *f_list_interval_begin(const t_list_interval *v_this) 40 | { 41 | return (v_this->v_begin); 42 | } 43 | 44 | t_list_cell *f_list_interval_end(const t_list_interval *v_this) 45 | { 46 | return (v_this->v_end); 47 | } 48 | -------------------------------------------------------------------------------- /srcs/libc/f_math/include/d_math.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* d_math.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/21 23:39:45 by qperez #+# #+# */ 9 | /* Updated: 2013/10/22 10:34:57 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef D_MATH_H 30 | # define D_MATH_H 31 | 32 | # define D_EPSILON 0.0000001192093 33 | # define D_E 2.71828182845904523536028747135266250 34 | # define D_LOG2E 1.44269504088896340735992468100189214 35 | # define D_LOG10E 0.434294481903251827651128918916605082 36 | # define D_LN2 0.693147180559945309417232121458176568 37 | # define D_LN10 2.30258509299404568401799145468436421 38 | # define D_PI 3.14159265358979323846264338327950288 39 | # define D_SQRT2 1.41421356237309504880168872420969808 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /srcs/libc/unit/include/s_unit_test.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_unit_test.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/31 18:18:43 by qperez #+# #+# */ 9 | /* Updated: 2014/02/12 19:54:30 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_UNIT_TEST_H 30 | # define S_UNIT_TEST_H 31 | 32 | # include 33 | # include 34 | # include 35 | 36 | typedef struct s_unit_assert 37 | { 38 | size_t v_line; 39 | const char *v_file; 40 | } t_unit_assert; 41 | 42 | typedef struct s_unit_test 43 | { 44 | bool v_active; 45 | bool v_tested; 46 | bool v_failed; 47 | const char *v_name; 48 | void (*f_func)(struct s_unit_test *unit); 49 | t_list v_assert; 50 | } t_unit_test; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /srcs/libc/fdnotify/include/s_fdnotify_cell.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_fdnotify_cell.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/12/03 09:41:04 by qperez #+# #+# */ 9 | /* Updated: 2014/12/04 10:02:54 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2014> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_FDNOTIFY_CELL_H 30 | # define S_FDNOTIFY_CELL_H 31 | 32 | # include 33 | 34 | typedef struct s_fdnotify_cell 35 | { 36 | int v_fd; 37 | bool v_add_to_write; 38 | } t_fdnotify_cell; 39 | 40 | # define D_FDNOTIFY_CELL(funct) f_fdnotify_cell_##funct 41 | 42 | bool f_fdnotify_cell_init(t_fdnotify_cell *v_this, int fd); 43 | void f_fdnotify_cell_add_to_write(t_fdnotify_cell *v_this); 44 | void f_fdnotify_cell_destroy(t_fdnotify_cell *v_this, bool close_fd); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /srcs/libc/fdnotify/src/s_fdnotify_cell.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_fdnotify_cell.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/12/03 11:21:46 by qperez #+# #+# */ 9 | /* Updated: 2014/12/04 10:21:55 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < init, destroy> 16 | ** Copyright (C) <2014> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | bool f_fdnotify_cell_init(t_fdnotify_cell *v_this, int fd) 34 | { 35 | v_this->v_fd = fd; 36 | v_this->v_add_to_write = false; 37 | return (true); 38 | } 39 | 40 | void f_fdnotify_cell_add_to_write(t_fdnotify_cell *v_this) 41 | { 42 | v_this->v_add_to_write = true; 43 | } 44 | 45 | void f_fdnotify_cell_destroy(t_fdnotify_cell *v_this, bool close_fd) 46 | { 47 | if (close_fd == true) 48 | close(v_this->v_fd); 49 | } 50 | -------------------------------------------------------------------------------- /examples/libc/getopt/src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/16 12:55:00 by qperez #+# #+# */ 9 | /* Updated: 2013/11/04 20:51:46 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int uf_usage(void) 17 | { 18 | uf_print_str("Lib42: Class getopt\nUsage: ./a.out \n" 19 | "Params: -h --help, -f --file \n"); 20 | return (-1); 21 | } 22 | 23 | void uf_open_file(const char *file) 24 | { 25 | if (file == NULL) 26 | uf_print_str("File: NULL\n"); 27 | else 28 | { 29 | uf_print_str("File: "); 30 | uf_print_str(file); 31 | uf_print_char('\n'); 32 | } 33 | } 34 | 35 | /* 36 | * This file is a little example of the t_getopt structure 37 | */ 38 | 39 | int main(int argc, char const** argv) 40 | { 41 | t_getopt getopt; 42 | 43 | if (argc < 2) 44 | return (uf_usage()); 45 | /* 46 | * You should pass argc and argv 47 | */ 48 | D_GETOPT(init)(&getopt, argc, argv, "file:f:h:help"); 49 | /* 50 | * If option return true, getopt has found an argument 51 | */ 52 | while (D_GETOPT(option)(&getopt) == true) 53 | { 54 | /* 55 | * Here you check argument 56 | */ 57 | if (D_GETOPT(check)(&getopt, "h") == true || 58 | D_GETOPT(check)(&getopt, "help") == true) 59 | uf_usage(); 60 | else if (D_GETOPT(check)(&getopt, "f") == true || 61 | D_GETOPT(check)(&getopt, "file") == true) 62 | uf_open_file(D_GETOPT(params)(&getopt)); 63 | } 64 | /* 65 | * And you free memory 66 | */ 67 | D_GETOPT(destroy)(&getopt); 68 | return (0); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /srcs/libc/f_sort/src/f_sort_shell.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_sort_shell.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/22 13:03:26 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:38:40 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < shell > 16 | ** Copyright (C) <2013> Quentin Perez 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | void uf_sort_shell(int *begin, size_t size) 34 | { 35 | size_t h; 36 | size_t i; 37 | size_t j; 38 | int tmp; 39 | 40 | h = size >> 1; 41 | while (h > 0) 42 | { 43 | i = h; 44 | while (i < size) 45 | { 46 | j = i; 47 | tmp = begin[i]; 48 | while (j >= h && tmp < begin[j - h]) 49 | { 50 | begin[j] = begin[j - h]; 51 | j = j - h; 52 | } 53 | begin[j] = tmp; 54 | i = i + 1; 55 | } 56 | h = h >> 1; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /srcs/libc/f_string/src/f_str_tools.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* f_str_tools.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/08/28 15:09:03 by qperez #+# #+# */ 9 | /* Updated: 2015/07/03 16:39:52 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2013> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | size_t uf_str_len(const char *str) 34 | { 35 | size_t len; 36 | 37 | len = 0; 38 | if (str == NULL) 39 | return (M_ERROR(0, "Pointer NULL")); 40 | while (str[len] != '\0') 41 | len = len + 1; 42 | return (len); 43 | } 44 | 45 | void uf_print_in_base(char nbr, int fd) 46 | { 47 | if (nbr < 10) 48 | nbr = (char)(nbr + '0'); 49 | else 50 | nbr = (char)(nbr + 'a' - 10); 51 | uf_print_char_fd(nbr, fd); 52 | } 53 | -------------------------------------------------------------------------------- /srcs/libc/list/src/s_list_cell_count.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_list_cell_count.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: irabeson +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/10/07 19:58:18 by irabeson #+# #+# */ 9 | /* Updated: 2014/02/12 19:47:28 by qperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** < count > 16 | ** Copyright (C) <2013> Iohann Rabeson 17 | ** This file is part of 42-toolkit. 18 | ** 42-toolkit is free software: you can redistribute it and/or modify 19 | ** it under the terms of the GNU General Public License as published by 20 | ** the Free Software Foundation, either version 3 of the License, or 21 | ** (at your option) any later version. 22 | ** This program is distributed in the hope that it will be useful, 23 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ** GNU General Public License for more details. 26 | ** You should have received a copy of the GNU General Public License 27 | ** along with this program. If not, see . 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | size_t f_list_cell_count(const t_list_cell *other_begin, 34 | const t_list_cell *other_end) 35 | { 36 | size_t count; 37 | 38 | count = 0; 39 | if (other_end != NULL) 40 | { 41 | while (other_begin != NULL) 42 | { 43 | if (other_begin == other_end) 44 | { 45 | count = count + 1; 46 | break ; 47 | } 48 | count = count + 1; 49 | other_begin = other_begin->v_next; 50 | } 51 | } 52 | return (count); 53 | } 54 | -------------------------------------------------------------------------------- /srcs/libc/threadpool/include/s_barrier.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* s_barrier.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: qperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2015/06/09 13:13:01 by qperez #+# #+# */ 9 | /* Updated: 2016/01/24 16:02:32 by sfroment ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** 15 | ** Copyright (C) <2015> Quentin Perez 16 | ** This file is part of 42-toolkit. 17 | ** 42-toolkit is free software: you can redistribute it and/or modify 18 | ** it under the terms of the GNU General Public License as published by 19 | ** the Free Software Foundation, either version 3 of the License, or 20 | ** (at your option) any later version. 21 | ** This program is distributed in the hope that it will be useful, 22 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ** GNU General Public License for more details. 25 | ** You should have received a copy of the GNU General Public License 26 | ** along with this program. If not, see . 27 | */ 28 | 29 | #ifndef S_BARRIER_H 30 | # define S_BARRIER_H 31 | 32 | # include 33 | # include 34 | # include 35 | 36 | typedef struct s_barrier 37 | { 38 | pthread_mutex_t mutex; 39 | pthread_cond_t cond; 40 | size_t nb_waiting; 41 | size_t max; 42 | } t_barrier; 43 | 44 | bool f_barrier_init(t_barrier *v_this, size_t count); 45 | bool f_barrier_destroy(t_barrier *v_this); 46 | int f_barrier_wait(t_barrier *v_this); 47 | 48 | # define D_BARRIER(func) f_barrier_##func 49 | 50 | #endif 51 | --------------------------------------------------------------------------------