diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6b13f20 --- /dev/null +++ b/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Microsoft +IndentWidth: 4 +ColumnLimit: 80 +UseTab: Always +SortIncludes: CaseInsensitive +IndentPPDirectives: AfterHash +PPIndentWidth: 1 +AllowShortIfStatementsOnASingleLine: false +AlignConsecutiveDeclarations: true diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..1c222e6 --- /dev/null +++ b/.clangd @@ -0,0 +1,16 @@ +CompileFlags: # Tweak the parse settings + Add: + - "-I/usr/include/" + - "-I/home/maix/school/push_swap/mecstd/include/" + - "-I/home/maix/school/push_swap/mecstd/output/include/" + - "-I/home/maix/school/push_swap/mecstd/generic_sources/header/" + - "-I/home/maix/school/push_swap/include/" + - "-I/home/maix/school/push_swap/output/include/" + - "-I/home/maix/school/push_swap/generic_sources/header/" + - "-I/home/maiboyer/Documents/ring-1/push_swap/mecstd/include/" + - "-I/home/maiboyer/Documents/ring-1/push_swap/mecstd/output/include/" + - "-I/home/maiboyer/Documents/ring-1/push_swap/mecstd/generic_sources/header/" + - "-I/home/maiboyer/Documents/ring-1/push_swap/include/" + - "-I/home/maiboyer/Documents/ring-1/push_swap/output/include/" + - "-I/home/maiboyer/Documents/ring-1/push_swap/generic_sources/header/" + diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 41e62e3..6ccc634 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,61 @@ -build -/checker -/push_swap -*.list -*.o +# Prerequisites *.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +./generic +.direnv +test +# /output/ +push_swap +push_swap_visualizer +Push-Swap-Tester +checker diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..92ca1ba --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "mecstd"] + path = mecstd + url = git@github.com:Maix0/mecstd.git diff --git a/Makefile b/Makefile index d12c11a..bf3d702 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/02/15 17:58:38 by maiboyer ### ########.fr # +# Updated: 2024/02/09 15:27:44 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -16,8 +16,8 @@ BUILD_DIR = build SRC_DIR = src INCLUDE_DIR = include LIBS_DIR = . -GENERIC_DIR = -GENERIC_INCLUDE = +GENERIC_DIR = output/src +GENERIC_INCLUDE = output/include NAME = push_swap @@ -30,150 +30,13 @@ endif LIB_NAME ?= TARGET = $(NAME) CC ?= clang -CFLAGS += -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -Wno-unused-command-line-argument -MMD +CFLAGS += -Wall -Werror -Wextra -g2 -lme -L$(BUILD_DIR) -Wno-unused-command-line-argument -MMD BONUS_FILES = -LIBS_NAME = +LIBS_NAME = mecstd SUBJECT_URL = 'https://cdn.intra.42.fr/pdf/pdf/118610/en.subject.pdf' -GENERIC_FILES = -SRC_FILES = \ -app/actual_main \ -app/best_index_to_move \ -app/best_move \ -app/do_move \ -app/find_place \ -app/iter_find \ -app/main \ -app/main_bonus \ -app/moves \ -app/moves/push \ -app/moves/rev_rotate \ -app/moves/rotate \ -app/moves/swap \ -app/rotate \ -app/run_with_items \ -app/sort2 \ -app/sort3 \ -app/sort5 \ -app/state \ -app/target \ -bonus/move1 \ -buffered_str/mod \ -char/isalnum \ -char/isalpha \ -char/isascii \ -char/isdigit \ -char/islower \ -char/isprint \ -char/isspace \ -char/isupper \ -char/tolower \ -char/toupper \ -convert/atoi \ -convert/itoa \ -convert/str_to_i16 \ -convert/str_to_i16_utils \ -convert/str_to_i32 \ -convert/str_to_i32_utils \ -convert/str_to_i64 \ -convert/str_to_i64_utils \ -convert/str_to_i8 \ -convert/str_to_i8_utils \ -convert/str_to_u16 \ -convert/str_to_u16_utils \ -convert/str_to_u32 \ -convert/str_to_u32_utils \ -convert/str_to_u64 \ -convert/str_to_u64_utils \ -convert/str_to_u8 \ -convert/str_to_u8_utils \ -fs/close \ -fs/open \ -fs/putchar_fd \ -fs/putendl_fd \ -fs/putnbr_fd \ -fs/putstr_fd \ -fs/read \ -fs/read_to_vec \ -fs/write \ -gnl/get_next_line \ -hash/hasher \ -hash/hash_signed \ -hash/hash_unsigned \ -hash/sip/sip13 \ -hash/sip/sip_utils \ -hash/sip/sip_utils2 \ -img/qoi/qoi_decode \ -img/qoi/qoi_encode \ -img/qoi/qoi_fs \ -img/qoi/qoi_utils \ -list/list_add_back \ -list/list_add_front \ -list/list_alloc_node \ -list/list_free_all \ -list/list_free_one \ -list/list_get_last \ -list/list_iter \ -list/list_map \ -list/list_size \ -mem/mem_alloc \ -mem/mem_alloc_array \ -mem/mem_compare \ -mem/mem_copy \ -mem/mem_find \ -mem/mem_find_bytes \ -mem/mem_move \ -mem/mem_set \ -mem/mem_set_zero \ -num/u16/rotate \ -num/u32/rotate \ -num/u64/from_bytes \ -num/u64/rotate \ -num/u8/rotate \ -num/usize/rotate \ -printf/formatter/char \ -printf/formatter/decimal \ -printf/formatter/hex \ -printf/formatter/oct \ -printf/formatter/ptr \ -printf/formatter/unsigned_decimal \ -printf/formatter/utils \ -printf/formatter/utils2 \ -printf/formatter/utils3 \ -printf/formatter/utils_numbers \ -printf/matchers \ -printf/printf \ -printf/vprintf \ -string/str_clone \ -string/str_find_chr \ -string/str_find_rev_chr \ -string/str_find_str \ -string/str_iter \ -string/str_join \ -string/str_l_cat \ -string/str_l_copy \ -string/str_len \ -string/str_map \ -string/str_n_compare \ -string/str_n_find_str \ -string/str_split \ -string/str_substring \ -string/str_trim \ -vec/vec_buf_str \ -vec/vec_buf_str_functions2 \ -vec/vec_buf_str_functions3 \ -vec/vec_i64 \ -vec/vec_i64_bool \ -vec/vec_i64_bool_functions2 \ -vec/vec_i64_bool_functions3 \ -vec/vec_i64_bool_sort \ -vec/vec_i64_functions2 \ -vec/vec_i64_functions3 \ -vec/vec_i64_sort \ -vec/vec_u8 \ -vec/vec_u8_functions2 \ -vec/vec_u8_functions3 - +GENERIC_FILES = $(shell cat ./gen.list) +SRC_FILES = $(shell cat ./src.list) BONUS = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(BONUS_FILES))) SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) \ $(addsuffix .c,$(addprefix $(GENERIC_DIR)/,$(GENERIC_FILES))) diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..ded0e01 --- /dev/null +++ b/check.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +ARGS="133 193 -16 -234 239 85 -223 -100 178 212 -202 -102 -199 -233 227 86 -166 224 160 -21 -56 102 -62 62 -127 89 127 -246 1 140 38 157 179 220 154 -1 125 240 -238 78 -175 222 -145 -60 115 67 -220 80 -136 -134 -159 35 136 192 47 117 -51 -140 37 6 -26 -188 213 -204 -210 14 -70 112 201 -191 -22 219 15 -143 -131 -41 -152 -187 24 215 235 -147 170 -168 12 107 105 130 -91 230 -174 -176 -224 -35 5 -110 -180 60 -59 -24 94 -196 -39 21 131 -18 165 -2 -219 -198 -19 -11 244 -151 -80 43 -17 -244 -65 124 9 -153 118 -6 -235 81 225 121 217 -43 30 218 -111 163 -9 23 214 166 207 238 -217 -161 -165 116 -170 26 -44 -106 245 -155 48 -177 75 -66 -89 109 22 56 58 -53 203 -79 39 184 -94 -231 45 246 93 13 -128 -179 -236 -139 114 63 -32 196 -205 57 249 -243 233 247 -46 -90 -47 -201 -144 221 -172 66 -38 -101 -232 175 164 -215 -195 -126 209 -108 -64 126 134 -77 -69 113 146 -211 2 88 -28 -132 -250 77 -181 191 198 183 -239 -52 -118 187 -109 4 -208 73 -96 -81 87 188 122 -120 -29 83 18 92 -83 100 -68 -221 -186 189 41 68 -150 129 -49 -137 -99 -123 -42 150 -192 -82 -158 104 -61 145 16 96 -115 -27 -119 97 -203 -240 -173 -185 -227 -98 72 -237 -7 -105 -76 149 -218 -182 54 76 61 211 173 7 185 -10 19 -15 -84 -48 36 53 -67 -63 155 -169 -138 -141 -78 33 -85 234 138 -146 223 158 135 91 108 55 32 90 226 -230 -40 177 -34 -112 -190 144 -104 -241 71 237 -226 95 208 -31 180 59 52 151 153 -135 46 -50 -154 204 132 119 70 110 199 -225 169 194 -148 148 241 -37 27 -23 176 232 -156 206 200 -167 -14 3 -209 159 -75 -248 111 -73 34 -113 -184 25 -86 -122 106 11 162 -133 -88 -245 147 -178 -197 190 -117 84 210 -54 -247 98 -157 64 -95 -129 10 -207 -72 182 -71 181 51 79 -87 242 20 123 82 99 -130 49 101 216 -216 -93 -97 172 -125 -163 -200 -8 -206 197 -242 -194 -212 168 161 -45 103 -160 195 -249 -25 69 137 167 152 -20 -142 243 -55 -171 -36 156 -12 -149 29 28 -183 50 120 -222 17 174 -4 -74 143 236 -189 44 -228 -162 40 229 228 -124 248 231 -5 -193 65 -13 139 128 -92 31 -103 142 -3 -33 205 -164 186 -121 -57 0 -229 42 -114 -213 202 -58 141 -107 -30 -116 171 -214 74 8" + +echo -n "Mine: " +./push_swap $ARGS | valgrind --track-origins=yes ./checker $ARGS +echo -n "Their: " +./push_swap $ARGS | ./Push-Swap-Tester/checker_linux $ARGS diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d2e09c7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,351 @@ +{ + "nodes": { + "c_formatter_42": { + "inputs": { + "c_formatter_42_src": "c_formatter_42_src", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1700259489, + "narHash": "sha256-Ye2zwphDUY/eDjyFCPFt0r9RyqMr4ZQprCE4bydNdpw=", + "owner": "maix0", + "repo": "c_formatter_42-flake", + "rev": "3d4f6a40bd1edf9fdb4959051edc172473d9544d", + "type": "github" + }, + "original": { + "owner": "maix0", + "repo": "c_formatter_42-flake", + "type": "github" + } + }, + "c_formatter_42_src": { + "flake": false, + "locked": { + "lastModified": 1696506114, + "narHash": "sha256-jUScF2lAHhjTWOWZsIAocE6FN8+HG+kLdpbYsEA1SZs=", + "owner": "dawnbeen", + "repo": "c_formatter_42", + "rev": "ef91ff383966885374695c327fa6015f9cfbc364", + "type": "github" + }, + "original": { + "owner": "dawnbeen", + "repo": "c_formatter_42", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_5": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "generic_c": { + "inputs": { + "flake-utils": "flake-utils_3", + "naersk": "naersk", + "nixpkgs": "nixpkgs_3", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1706829609, + "narHash": "sha256-A0imQ9AIJafdL1/+j/1b3G7bm2j+N+VhzTsvKikKjz4=", + "owner": "maix0", + "repo": "generic_c", + "rev": "a470c2c5a8c8aadc852a7a50d72853f2a3873595", + "type": "github" + }, + "original": { + "owner": "maix0", + "repo": "generic_c", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1698420672, + "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", + "owner": "nix-community", + "repo": "naersk", + "rev": "aeb58d5e8faead8980a807c840232697982d47b9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixGL": { + "inputs": { + "flake-utils": "flake-utils_5", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1685908677, + "narHash": "sha256-E4zUPEUFyVWjVm45zICaHRpfGepfkE9Z2OECV9HXfA4=", + "owner": "guibou", + "repo": "nixGL", + "rev": "489d6b095ab9d289fe11af0219a9ff00fe87c7c5", + "type": "github" + }, + "original": { + "owner": "guibou", + "repo": "nixGL", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700108881, + "narHash": "sha256-+Lqybl8kj0+nD/IlAWPPG/RDTa47gff9nbei0u7BntE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7414e9ee0b3e9903c24d3379f577a417f0aae5f1", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1706683685, + "narHash": "sha256-FtPPshEpxH/ewBOsdKBNhlsL2MLEFv1hEnQ19f/bFsQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ad9903c16126a7d949101687af0aa589b1d7d3d", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1706683685, + "narHash": "sha256-FtPPshEpxH/ewBOsdKBNhlsL2MLEFv1hEnQ19f/bFsQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ad9903c16126a7d949101687af0aa589b1d7d3d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1706487304, + "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_5": { + "locked": { + "lastModified": 1706925685, + "narHash": "sha256-hVInjWMmgH4yZgA4ZtbgJM1qEAel72SYhP5nOWX4UIM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "79a13f1437e149dc7be2d1290c74d378dad60814", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "c_formatter_42": "c_formatter_42", + "flake-utils": "flake-utils_2", + "generic_c": "generic_c", + "nixGL": "nixGL", + "nixpkgs": "nixpkgs_5" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_4", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1706753617, + "narHash": "sha256-ZKqTFzhFwSWFEpQTJ0uXnfJBs5Y/po9/8TK4bzssdbs=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "58be43ae223034217ea1bd58c73210644031b687", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3a31d1f --- /dev/null +++ b/flake.nix @@ -0,0 +1,46 @@ +{ + description = "Flake utils demo"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + generic_c.url = "github:maix0/generic_c"; + c_formatter_42.url = "github:maix0/c_formatter_42-flake"; + nixGL.url = "github:guibou/nixGL"; + nixGL.inputs.nixpkgs.follows = "nixpkgs"; + }; + outputs = { + self, + nixpkgs, + flake-utils, + generic_c, + c_formatter_42, + nixGL, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [nixGL.overlay]; + }; + in { + devShell = pkgs.mkShell { + packages = [ + pkgs.xorg.libXext + pkgs.xorg.libX11 + pkgs.clang + pkgs.clang-tools + pkgs.norminette + pkgs.poppler_utils + pkgs.minilibx + pkgs.valgrind + pkgs.libbsd + pkgs.tree + pkgs.fastmod + generic_c.packages.${system}.default + c_formatter_42.packages.${system}.default + pkgs.nixgl.nixGLIntel + ]; + }; + } + ); +} diff --git a/gen.list b/gen.list new file mode 100644 index 0000000..a1c896e --- /dev/null +++ b/gen.list @@ -0,0 +1,24 @@ +convert/str_to_i16 +convert/str_to_i16_utils +convert/str_to_i32 +convert/str_to_i32_utils +convert/str_to_i64 +convert/str_to_i64_utils +convert/str_to_i8 +convert/str_to_i8_utils +convert/str_to_u16 +convert/str_to_u16_utils +convert/str_to_u32 +convert/str_to_u32_utils +convert/str_to_u64 +convert/str_to_u64_utils +convert/str_to_u8 +convert/str_to_u8_utils +vec/vec_i64 +vec/vec_i64_bool +vec/vec_i64_bool_functions2 +vec/vec_i64_bool_functions3 +vec/vec_i64_bool_sort +vec/vec_i64_functions2 +vec/vec_i64_functions3 +vec/vec_i64_sort diff --git a/include/me/buffered_str/buf_str.h b/include/me/buffered_str/buf_str.h deleted file mode 100644 index 6bf1092..0000000 --- a/include/me/buffered_str/buf_str.h +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* buf_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */ -/* Updated: 2023/12/31 15:34:29 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef BUF_STR_H -# define BUF_STR_H -# include "me/types.h" - -typedef struct s_buffer_str -{ - t_str buf; - t_usize capacity; - t_usize len; -} t_buffer_str; - -bool push_str_buffer(t_buffer_str *buf, t_const_str to_push); -bool push_str_char(t_buffer_str *buf, char to_push); -void str_clear(t_buffer_str *buf); -t_buffer_str alloc_new_buffer(t_usize capacity); - -static inline void str_free(t_buffer_str buf) -{ - void free(void *); - - free(buf.buf); -} - -static inline char str_pop(t_buffer_str *buf) -{ - char c; - - c = '\0'; - if (buf->buf && buf->len) - { - c = buf->buf[buf->len - 1]; - buf->buf[buf->len - 1] = '\0'; - } - return (c); -} - -#endif diff --git a/include/me/char/isalnum.h b/include/me/char/isalnum.h deleted file mode 100644 index f38c8e8..0000000 --- a/include/me/char/isalnum.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isalnum.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:39:39 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISALNUM_H -# define ISALNUM_H - -# include "me/types.h" - -bool me_isalnum(char chr); - -#endif diff --git a/include/me/char/isalpha.h b/include/me/char/isalpha.h deleted file mode 100644 index 680e197..0000000 --- a/include/me/char/isalpha.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isalpha.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:39:36 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISALPHA_H -# define ISALPHA_H - -# include "me/types.h" - -bool me_isalpha(char chr); - -#endif diff --git a/include/me/char/isascii.h b/include/me/char/isascii.h deleted file mode 100644 index dfa1961..0000000 --- a/include/me/char/isascii.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isascii.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 17:51:01 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:39:33 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISASCII_H -# define ISASCII_H - -# include "me/types.h" - -bool me_isascii(char chr); - -#endif diff --git a/include/me/char/isdigit.h b/include/me/char/isdigit.h deleted file mode 100644 index fbed927..0000000 --- a/include/me/char/isdigit.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isdigit.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:41:55 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISDIGIT_H -# define ISDIGIT_H - -# include "me/types.h" - -bool me_isdigit(char chr); - -#endif diff --git a/include/me/char/islower.h b/include/me/char/islower.h deleted file mode 100644 index de8eedf..0000000 --- a/include/me/char/islower.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* islower.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:48:25 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISLOWER_H -# define ISLOWER_H - -# include "me/types.h" - -bool me_islower(char chr); - -#endif diff --git a/include/me/char/isprint.h b/include/me/char/isprint.h deleted file mode 100644 index 30c6b6f..0000000 --- a/include/me/char/isprint.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isprint.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:44:49 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISPRINT_H -# define ISPRINT_H - -# include "me/types.h" - -bool me_isprint(char chr); - -#endif diff --git a/include/me/char/isspace.h b/include/me/char/isspace.h deleted file mode 100644 index b2aa5c5..0000000 --- a/include/me/char/isspace.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isspace.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 14:26:25 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:45:02 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISSPACE_H -# define ISSPACE_H - -# include "me/types.h" - -bool me_isspace(char chr); - -#endif diff --git a/include/me/char/isupper.h b/include/me/char/isupper.h deleted file mode 100644 index 4c485dd..0000000 --- a/include/me/char/isupper.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isupper.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:45:16 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ISUPPER_H -# define ISUPPER_H - -# include "me/types.h" - -bool me_isupper(char chr); - -#endif diff --git a/include/me/char/tolower.h b/include/me/char/tolower.h deleted file mode 100644 index 764f5a4..0000000 --- a/include/me/char/tolower.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* tolower.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:45:33 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef TOLOWER_H -# define TOLOWER_H - -# include "me/types.h" - -bool me_tolower(char chr); - -#endif diff --git a/include/me/char/toupper.h b/include/me/char/toupper.h deleted file mode 100644 index 0e5a3a0..0000000 --- a/include/me/char/toupper.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toupper.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:45:52 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef TOUPPER_H -# define TOUPPER_H - -# include "me/types.h" - -bool me_toupper(char chr); - -#endif diff --git a/include/me/convert/atoi.h b/include/me/convert/atoi.h deleted file mode 100644 index 1cce430..0000000 --- a/include/me/convert/atoi.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* atoi.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */ -/* Updated: 2024/01/11 15:36:12 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ATOI_H -# define ATOI_H - -# include "me/types.h" - -t_i32 me_atoi(t_const_str str); -t_i64 me_atoi_64(t_const_str str); - -#endif diff --git a/include/me/convert/itoa.h b/include/me/convert/itoa.h deleted file mode 100644 index a4afbf6..0000000 --- a/include/me/convert/itoa.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* itoa.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:48:37 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ITOA_H -# define ITOA_H - -# include "me/types.h" - -t_str me_itoa(t_i32 nb); - -#endif diff --git a/include/me/convert/str_to_numbers.h b/include/me/convert/str_to_numbers.h index a953680..9f90ddf 100644 --- a/include/me/convert/str_to_numbers.h +++ b/include/me/convert/str_to_numbers.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:08:13 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:02:28 by maiboyer ### ########.fr */ +/* Updated: 2024/02/02 00:22:50 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/me/fs/close.h b/include/me/fs/close.h deleted file mode 100644 index c764d79..0000000 --- a/include/me/fs/close.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* close.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 15:56:56 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:49:22 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef CLOSE_H -# define CLOSE_H - -# include "me/types.h" - -bool me_close(t_file file, t_i32 *error); - -#endif diff --git a/include/me/fs/open.h b/include/me/fs/open.h deleted file mode 100644 index 1f2f8f0..0000000 --- a/include/me/fs/open.h +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* open.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */ -/* Updated: 2024/01/05 16:43:37 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef OPEN_H -# define OPEN_H - -# include "me/types.h" - -t_error me_open(t_const_str path, bool read, bool write, t_file *file_out); -t_error me_open_truncate(t_const_str path, t_file *file_out); -t_error me_open_create(t_const_str path, t_file *file_out); - -#endif diff --git a/include/me/fs/putchar_fd.h b/include/me/fs/putchar_fd.h deleted file mode 100644 index 03039ac..0000000 --- a/include/me/fs/putchar_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putchar_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:49:06 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTCHAR_FD_H -# define PUTCHAR_FD_H - -# include "me/types.h" - -void me_putchar_fd(char chr, t_file file); - -#endif diff --git a/include/me/fs/putendl_fd.h b/include/me/fs/putendl_fd.h deleted file mode 100644 index 0325e1e..0000000 --- a/include/me/fs/putendl_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putendl_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:31:54 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTENDL_FD_H -# define PUTENDL_FD_H - -# include "me/types.h" - -void me_putendl_fd(t_str str, t_file file); - -#endif \ No newline at end of file diff --git a/include/me/fs/putnbr_fd.h b/include/me/fs/putnbr_fd.h deleted file mode 100644 index 933e945..0000000 --- a/include/me/fs/putnbr_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putnbr_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 12:45:06 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:32:41 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTNBR_FD_H -# define PUTNBR_FD_H - -# include "me/types.h" - -void me_putnbr_fd(t_i32 n, t_file file); - -#endif \ No newline at end of file diff --git a/include/me/fs/putstr_fd.h b/include/me/fs/putstr_fd.h deleted file mode 100644 index 5ada222..0000000 --- a/include/me/fs/putstr_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putstr_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:35:53 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTSTR_FD_H -# define PUTSTR_FD_H - -# include "me/types.h" - -void me_putstr_fd(t_str str, t_file file); - -#endif diff --git a/include/me/fs/read.h b/include/me/fs/read.h deleted file mode 100644 index 7fc2cd7..0000000 --- a/include/me/fs/read.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:21:19 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:37:03 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef READ_H -# define READ_H - -# include "me/types.h" - -t_usize me_read(t_file fd, t_u8 *buffer, t_i64 buffer_max, bool *eof_out); - -#endif \ No newline at end of file diff --git a/include/me/fs/read_to_vec.h b/include/me/fs/read_to_vec.h deleted file mode 100644 index 94375ae..0000000 --- a/include/me/fs/read_to_vec.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read_to_vec.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 18:50:37 by maiboyer #+# #+# */ -/* Updated: 2023/12/24 18:57:36 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef READ_TO_VEC_H -# define READ_TO_VEC_H - -# include "me/types.h" -# include "me/vec/vec_u8.h" - -# ifndef READ_BUFFER_SIZE -# define READ_BUFFER_SIZE 4096 -# endif - -bool read_to_vec(t_const_str path, t_vec_u8 *out); - -#endif diff --git a/include/me/fs/write.h b/include/me/fs/write.h deleted file mode 100644 index 66ea307..0000000 --- a/include/me/fs/write.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* write.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:27:33 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:36:48 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef WRITE_H -# define WRITE_H - -# include "me/types.h" - -bool me_write(t_file fd, t_u8 *buffer, t_i64 size); - -#endif diff --git a/include/me/gnl/gnl.h b/include/me/gnl/gnl.h deleted file mode 100644 index 2933c2d..0000000 --- a/include/me/gnl/gnl.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* gnl.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/23 14:40:15 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:21:56 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef GNL_H -# define GNL_H - -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 128 -# endif - -# ifndef BUFFER_LENGTH -# define BUFFER_LENGTH 512 -# endif - -# include "me/buffered_str/buf_str.h" -# include "me/types.h" - -typedef struct s_static_buffer -{ - t_file fd; - bool used; - char buf[BUFFER_SIZE + 1]; - bool init; -} t_static_buffer; - -typedef struct s_copy_flags -{ - bool error; - bool empty_read; -} t_copy_flags; - -t_buffer_str get_next_line(t_file fd, bool *error); - -#endif diff --git a/include/me/hash/hasher.h b/include/me/hash/hasher.h deleted file mode 100644 index d9a9c1c..0000000 --- a/include/me/hash/hasher.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hasher.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/10 19:50:39 by maix #+# #+# */ -/* Updated: 2023/12/27 16:44:09 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef HASHER_H -# define HASHER_H - -# include "me/types.h" - -typedef void (*t_hash_bytes)(void *hasher, t_u8 *bytes, - t_usize count); -typedef t_u64 (*t_hasher_finish)(void *hasher); -typedef t_u64 (*t_hasher_reset_and_finish)(void *hasher); - -typedef struct s_hasher -{ - void *hasher; - t_hash_bytes hash_bytes; - t_hasher_finish finish; - t_hasher_reset_and_finish reset_and_finish; - -} t_hasher; - -void hasher_write_bytes(t_hasher *hasher, - t_u8 *bytes, t_usize count); - -void hasher_write_u8(t_hasher *hasher, t_u8 n); -void hasher_write_u16(t_hasher *hasher, t_u16 n); -void hasher_write_u32(t_hasher *hasher, t_u32 n); -void hasher_write_u64(t_hasher *hasher, t_u64 n); -void hasher_write_usize(t_hasher *hasher, t_usize n); - -void hasher_write_i8(t_hasher *hasher, t_i8 n); -void hasher_write_i16(t_hasher *hasher, t_i16 n); -void hasher_write_i32(t_hasher *hasher, t_i32 n); -void hasher_write_i64(t_hasher *hasher, t_i64 n); -void hasher_write_isize(t_hasher *hasher, t_isize n); - -void hasher_write_str(t_hasher *hasher, t_str str); - -t_u64 hasher_finish(t_hasher *hasher); -t_u64 hasher_reset_and_finish(t_hasher *hasher); - -#endif diff --git a/include/me/hash/sip.h b/include/me/hash/sip.h deleted file mode 100644 index 3fed310..0000000 --- a/include/me/hash/sip.h +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* sip.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/10 19:33:46 by maix #+# #+# */ -/* Updated: 2023/12/11 15:10:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef SIP_H -# define SIP_H -# include "me/hash/hasher.h" -# include "me/types.h" - -typedef struct s_sip_state -{ - t_u64 v0; - t_u64 v2; - t_u64 v1; - t_u64 v3; -} t_sip_state; - -typedef struct s_sip13 -{ - t_u64 k0; - t_u64 k1; - t_usize length; - t_u64 tail; - t_usize ntail; - t_sip_state state; -} t_sip13; - -t_hasher hasher_sip13_new(void); - -#endif diff --git a/include/me/hash/sip/sip_utils.h b/include/me/hash/sip/sip_utils.h deleted file mode 100644 index 2843533..0000000 --- a/include/me/hash/sip/sip_utils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* sip_utils.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/10 19:34:10 by maix #+# #+# */ -/* Updated: 2023/12/27 16:48:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef SIP_UTILS_H -# define SIP_UTILS_H -# include "me/hash/sip.h" -# include "me/types.h" - -void compress(t_sip_state *state); -t_sip_state create_state_with_key(t_u64 k0, t_u64 k1); -t_u64 sip13_finish(t_sip13 *hasher); -t_u64 sip13_reset_and_finish(t_sip13 *hasher); -void sip13_write_bytes(t_sip13 *self, t_u8 *msg, t_usize count); - -#endif diff --git a/include/me/img/qoi.h b/include/me/img/qoi.h deleted file mode 100644 index d679be6..0000000 --- a/include/me/img/qoi.h +++ /dev/null @@ -1,305 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 17:39:36 by maiboyer #+# #+# */ -/* Updated: 2023/12/25 18:35:05 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -/* - -Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org -SPDX-License-Identifier: MIT - - -QOI - The "Quite OK Image" format for fast, lossless image compression - --- About - -QOI encodes and decodes images in a lossless format. Compared to stb_image and -stb_image_write QOI offers 20x-50x faster encoding, 3x-4x faster decoding and -20% better compression. - - --- Synopsis - -// Define `QOI_IMPLEMENTATION` in *one* C/C++ file before including this -// library to create the implementation. - -#define QOI_IMPLEMENTATION -#include "qoi.h" - -// Encode and store an RGBA buffer to the file system. The t_qoi_desc describes -// the input pixel data. -qoi_write("image_new.qoi", rgba_pixels, &(t_qoi_desc){ - .width = 1920, - .height = 1080, - .channels = 4, - .colorspace = QOI_SRGB -}); - -// Load and decode a QOI image from the file system t_i32o a 32bbp RGBA buffer. -// The t_qoi_desc struct will be filled with the width, height, - number of channels -// and colorspace read from the file header. -t_qoi_desc desc; -void *rgba_pixels = qoi_read("image.qoi", &desc, 4); - - - --- Documentation - -This library provides the following functions; -- qoi_read -- read and decode a QOI file -- qoi_decode -- decode the raw bytes of a QOI image from memory -- qoi_write -- encode and write a QOI file -- qoi_encode -- encode an rgba buffer t_i32o a QOI image in memory - -See the function declaration below for the signature and more information. - -If you don't want/need the qoi_read and qoi_write functions, you can define -QOI_NO_STDIO before including this library. - -This library uses malloc() and free(). To supply your own malloc implementation -you can define QOI_MALLOC and QOI_FREE before including this library. - -This library uses memset() to zero-initialize the index. To supply your own -implementation you can define QOI_ZEROARR before including this library. - - --- Data Format - -A QOI file has a 14 byte header, followed by any number of data "chunks" and an -8-byte end marker. - -struct qoi_header_t { - char magic[4]; // magic bytes "qoif" - ut_i3232_t width; // image width in pixels (BE) - ut_i3232_t height; // sprite.height in pixels (BE) - ut_i328_t channels; // 3 = RGB, 4 = RGBA - ut_i328_t colorspace; // 0 = sRGB with linear alpha, 1 = all channels -linear -}; - -Images are encoded row by row, left to right, top to bottom. The decoder and -encoder start with {r: 0, g: 0, b: 0, a: 255} as the previous pixel value. An -image is complete when all pixels specified by width * height have been covered. - -Pixels are encoded as - - a run of the previous pixel - - an index t_i32o an array of previously seen pixels - - a difference to the previous pixel value in r,g,b - - full r,g,b or r,g,b,a values - -The color channels are assumed to not be premultiplied with the alpha channel -("un-premultiplied alpha"). - -A running array[64] (zero-initialized) of previously seen pixel values is -mat_i32ained by the encoder and decoder. Each pixel that is seen by the encoder -and decoder is put t_i32o this array at the position formed by a hash function -of the color value. In the encoder, if the pixel value at the index matches the -current pixel, this index position is written to the stream as QOI_OP_INDEX. -The hash function for the index is: - - index_position = (r * 3 + g * 5 + b * 7 + a * 11) % 64 - -Each chunk starts with a 2- or 8-bit tag, followed by a number of data bits. The -bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All -values encoded in these data bits have the most significant bit on the left. - -The 8-bit tags have precedence over the 2-bit tags. A decoder must check for the -presence of an 8-bit tag first. - -The byte stream's end is marked with 7 0x00 bytes followed a single 0x01 byte. - - -The possible chunks are: - - -.- QOI_OP_INDEX ----------. -| Byte[0] | -| 7 6 5 4 3 2 1 0 | -|-------+-----------------| -| 0 0 | index | -`-------------------------` -2-bit tag b00 -6-bit index t_i32o the color index array: 0..63 - -A valid encoder must not issue 2 or more consecutive QOI_OP_INDEX chunks to the -same index. QOI_OP_RUN should be used instead. - - -.- QOI_OP_DIFF -----------. -| Byte[0] | -| 7 6 5 4 3 2 1 0 | -|-------+-----+-----+-----| -| 0 1 | dr | dg | db | -`-------------------------` -2-bit tag b01 -2-bit red channel difference from the previous pixel between -2..1 -2-bit green channel difference from the previous pixel between -2..1 -2-bit blue channel difference from the previous pixel between -2..1 - -The difference to the current channel values are using a wraparound operation, -so "1 - 2" will result in 255, while "255 + 1" will result in 0. - -Values are stored as unsigned t_i32egers with a bias of 2. E.g. -2 is stored as -0 (b00). 1 is stored as 3 (b11). - -The alpha value remains unchanged from the previous pixel. - - -.- QOI_OP_LUMA -------------------------------------. -| Byte[0] | Byte[1] | -| 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 | -|-------+-----------------+-------------+-----------| -| 1 0 | green diff | dr - dg | db - dg | -`---------------------------------------------------` -2-bit tag b10 -6-bit green channel difference from the previous pixel -32..31 -4-bit red channel difference minus green channel difference -8..7 -4-bit blue channel difference minus green channel difference -8..7 - -The green channel is used to indicate the general direction of change and is -encoded in 6 bits. The red and blue channels (dr and db) base their diffs off -of the green channel difference and are encoded in 4 bits. I.e.: - dr_dg = (cur_px.r - prev_px.r) - (cur_px.g - prev_px.g) - db_dg = (cur_px.b - prev_px.b) - (cur_px.g - prev_px.g) - -The difference to the current channel values are using a wraparound operation, -so "10 - 13" will result in 253, while "250 + 7" will result in 1. - -Values are stored as unsigned t_i32egers with a bias of 32 for the green channel -and a bias of 8 for the red and blue channel. - -The alpha value remains unchanged from the previous pixel. - - -.- QOI_OP_RUN ------------. -| Byte[0] | -| 7 6 5 4 3 2 1 0 | -|-------+-----------------| -| 1 1 | run | -`-------------------------` -2-bit tag b11 -6-bit run-length repeating the previous pixel: 1..62 - -The run-length is stored with a bias of -1. Note that the run-lengths 63 and 64 -(b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB and -QOI_OP_RGBA tags. - - -.- QOI_OP_RGB ------------------------------------------. -| Byte[0] | Byte[1] | Byte[2] | Byte[3] | -| 7 6 5 4 3 2 1 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 | -|-------------------------+---------+---------+---------| -| 1 1 1 1 1 1 1 0 | red | green | blue | -`-------------------------------------------------------` -8-bit tag b11111110 -8-bit red channel value -8-bit green channel value -8-bit blue channel value - -The alpha value remains unchanged from the previous pixel. - - -.- QOI_OP_RGBA ---------------------------------------------------. -| Byte[0] | Byte[1] | Byte[2] | Byte[3] | Byte[4] | -| 7 6 5 4 3 2 1 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 | -|-------------------------+---------+---------+---------+---------| -| 1 1 1 1 1 1 1 1 | red | green | blue | alpha | -`-----------------------------------------------------------------` -8-bit tag b11111111 -8-bit red channel value -8-bit green channel value -8-bit blue channel value -8-bit alpha channel value - -*/ - -/* ----------------------------------------------------------------------------- -Header - Public functions */ - -#ifndef QOI_H -# define QOI_H - -# include "me/mem/mem_alloc.h" -# include "me/mem/mem_set_zero.h" -# include "me/types.h" -/* A pot_i32er to a t_qoi_desc struct has to be supplied to all of qoi's -functions. It describes either the input format (for qoi_write and qoi_encode), -or is filled with the description read from the file header (for qoi_read and -qoi_decode). - -The colorspace in this t_qoi_desc is an enum where - 0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel - 1 = all channels are linear -You may use the constants QOI_SRGB or QOI_LINEAR. The colorspace is purely -informative. It will be saved to the file header, but does not affect -how chunks are en-/decoded. */ - -# define QOI_SRGB 0 -# define QOI_LINEAR 1 - -typedef struct s_t_qoi_desc -{ - t_u32 width; - t_u32 height; - t_u8 channels; - t_u8 colorspace; -} t_qoi_desc; - -# ifndef QOI_NO_STDIO - -/* Encode raw RGB or RGBA pixels t_i32o a QOI image and write it to the file -system. The t_qoi_desc struct must be filled with the image width, height, -number of channels (3 = RGB, 4 = RGBA) and the colorspace. - -The function returns 0 on failure (invalid parameters, or fopen or malloc -failed) or the number of bytes written on success. */ - -t_i32 qoi_write(t_const_str filename, const void *data, - const t_qoi_desc *desc); - -/* Read and decode a QOI image from the file system. If channels is 0, the -number of channels from the file header is used. If channels is 3 or 4 the -output format will be forced t_i32o this number of channels. - -The function either returns NULL on failure (invalid data, or malloc or fopen -failed) or a pot_i32er to the decoded pixels. On success, the t_qoi_desc struct -will be filled with the description from the file header. - -The returned pixel data should be free()d after use. */ - -void *qoi_read(t_const_str filename, t_qoi_desc *desc, - t_i32 channels); - -# endif /* QOI_NO_STDIO */ - -/* Encode raw RGB or RGBA pixels t_i32o a QOI image in memory. - -The function either returns NULL on failure (invalid parameters or malloc -failed) or a pot_i32er to the encoded data on success. On success the out_len -is set to the size in bytes of the encoded data. - -The returned qoi data should be free()d after use. */ - -void *qoi_encode(const void *data, const t_qoi_desc *desc, - t_i32 *out_len); - -/* Decode a QOI image from memory. - -The function either returns NULL on failure (invalid parameters or malloc -failed) or a pot_i32er to the decoded pixels. On success, the t_qoi_desc struct -is filled with the description from the file header. - -The returned pixel data should be free()d after use. */ - -void *qoi_decode(const void *data, t_i32 size, t_qoi_desc *desc, - t_i32 channels); - -#endif /* QOI_H */ diff --git a/include/me/img/qoi/qoi_decode.h b/include/me/img/qoi/qoi_decode.h deleted file mode 100644 index d11ebe9..0000000 --- a/include/me/img/qoi/qoi_decode.h +++ /dev/null @@ -1,86 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_decode.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/25 22:33:19 by maiboyer #+# #+# */ -/* Updated: 2023/12/25 22:58:27 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef QOI_DECODE_H -# define QOI_DECODE_H - -# include "me/img/qoi.h" -# include "me/img/qoi/qoi_utils.h" - -typedef struct s_decode_vals -{ - t_i32 px_len; - t_i32 chunks_len; - t_i32 px_pos; - t_i32 p; - t_i32 run; - t_i32 b1; - t_i32 b2; - t_i32 vg; - t_u32 header_magic; - t_qoi_rgba index[64]; - t_qoi_rgba px; - -} t_decode_vals; - -static inline void qoi_op_luma_decode(t_decode_vals *vals, const t_u8 *bytes) -{ - vals->b2 = bytes[vals->p++]; - vals->vg = (vals->b1 & 0x3f) - 32; - vals->px.rgba.r += vals->vg - 8 + ((vals->b2 >> 4) & 0x0f); - vals->px.rgba.g += vals->vg; - vals->px.rgba.b += vals->vg - 8 + (vals->b2 & 0x0f); -} - -static inline void qoi_op_diff_decode(t_decode_vals *vals, const t_u8 *bytes) -{ - (void)(bytes); - vals->px.rgba.r += ((vals->b1 >> 4) & 0x03) - 2; - vals->px.rgba.g += ((vals->b1 >> 2) & 0x03) - 2; - vals->px.rgba.b += (vals->b1 & 0x03) - 2; -} - -static inline void qoi_op_rgba_decode(t_decode_vals *vals, const t_u8 *bytes) -{ - vals->px.rgba.r = bytes[vals->p++]; - vals->px.rgba.g = bytes[vals->p++]; - vals->px.rgba.b = bytes[vals->p++]; - vals->px.rgba.a = bytes[vals->p++]; -} - -static inline void qoi_op_rgb_decode(t_decode_vals *vals, const t_u8 *bytes) -{ - vals->px.rgba.r = bytes[vals->p++]; - vals->px.rgba.g = bytes[vals->p++]; - vals->px.rgba.b = bytes[vals->p++]; -} - -static inline void qoi_decode_inner_inner(t_decode_vals *vals, \ - const t_u8 *bytes) -{ - vals->b1 = bytes[vals->p++]; - if (vals->b1 == QOI_OP_RGB) - qoi_op_rgb_decode(vals, bytes); - else if (vals->b1 == QOI_OP_RGBA) - qoi_op_rgba_decode(vals, bytes); - else if ((vals->b1 & QOI_MASK_2) == QOI_OP_INDEX) - vals->px = vals->index[vals->b1]; - else if ((vals->b1 & QOI_MASK_2) == QOI_OP_DIFF) - qoi_op_diff_decode(vals, bytes); - else if ((vals->b1 & QOI_MASK_2) == QOI_OP_LUMA) - qoi_op_luma_decode(vals, bytes); - else if ((vals->b1 & QOI_MASK_2) == QOI_OP_RUN) - vals->run = (vals->b1 & 0x3f); - vals->index[qoi_color_hash(vals->px) % 64] = vals->px; -} - -#endif /* QOI_DECODE_H */ diff --git a/include/me/img/qoi/qoi_encode.h b/include/me/img/qoi/qoi_encode.h deleted file mode 100644 index bea2a22..0000000 --- a/include/me/img/qoi/qoi_encode.h +++ /dev/null @@ -1,155 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_encode.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/25 22:36:06 by maiboyer #+# #+# */ -/* Updated: 2023/12/25 22:56:36 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef QOI_ENCODE_H -# define QOI_ENCODE_H - -# include "me/img/qoi.h" -# include "me/img/qoi/qoi_utils.h" - -typedef struct s_encode_vals -{ - t_i32 i; - t_i32 max_size; - t_i32 p; - t_i32 run; - t_i32 px_len; - t_i32 px_end; - t_i32 px_pos; - t_i32 channels; - t_i32 index_pos; - t_qoi_rgba index[64]; - t_qoi_rgba px; - t_qoi_rgba px_prev; -} t_encode_vals; - -typedef struct s_v -{ - t_i8 r; - t_i8 g; - t_i8 b; - t_i8 g_r; - t_i8 g_b; -} t_v; - -static inline void qoi_encode_if_thingy1(t_encode_vals *vals, - t_v *v, t_u8 *bytes) -{ - v->r = vals->px.rgba.r - vals->px_prev.rgba.r; - v->g = vals->px.rgba.g - vals->px_prev.rgba.g; - v->b = vals->px.rgba.b - vals->px_prev.rgba.b; - v->g_r = v->r - v->g; - v->g_b = v->b - v->g; - if (v->r > -3 && v->r < 2 && v->g > -3 && v->g < 2 && v->b > -3 - && v->b < 2) - bytes[vals->p++] = QOI_OP_DIFF | (v->r + 2) << 4 | (v->g - + 2) << 2 | (v->b + 2); - else if (v->g_r > -9 && v->g_r < 8 && v->g > -33 && v->g < 32 - && v->g_b > -9 && v->g_b < 8) - { - bytes[vals->p++] = QOI_OP_LUMA | (v->g + 32); - bytes[vals->p++] = (v->g_r + 8) << 4 | (v->g_b + 8); - } - else - { - bytes[vals->p++] = QOI_OP_RGB; - bytes[vals->p++] = vals->px.rgba.r; - bytes[vals->p++] = vals->px.rgba.g; - bytes[vals->p++] = vals->px.rgba.b; - } -} - -static inline void qoi_encode_inner_inner_inner(t_encode_vals *vals, - t_v *v, t_u8 *bytes) -{ - if (vals->run > 0) - { - bytes[vals->p++] = QOI_OP_RUN | (vals->run - 1); - vals->run = 0; - } - vals->index_pos = qoi_color_hash(vals->px) % 64; - if (vals->index[vals->index_pos].v == vals->px.v) - bytes[vals->p++] = QOI_OP_INDEX | vals->index_pos; - else - { - vals->index[vals->index_pos] = vals->px; - if (vals->px.rgba.a == vals->px_prev.rgba.a) - qoi_encode_if_thingy1(vals, v, bytes); - else - { - bytes[vals->p++] = QOI_OP_RGBA; - bytes[vals->p++] = vals->px.rgba.r; - bytes[vals->p++] = vals->px.rgba.g; - bytes[vals->p++] = vals->px.rgba.b; - bytes[vals->p++] = vals->px.rgba.a; - } - } -} - -static inline void qoi_encode_inner_inner(t_encode_vals *vals, - const t_u8 *pixels, t_u8 *bytes) -{ - t_v v; - - v = (t_v){0}; - while (vals->px_pos < vals->px_len) - { - vals->px.rgba.r = pixels[vals->px_pos + 0]; - vals->px.rgba.g = pixels[vals->px_pos + 1]; - vals->px.rgba.b = pixels[vals->px_pos + 2]; - if (vals->channels == 4) - vals->px.rgba.a = pixels[vals->px_pos + 3]; - if (vals->px.v == vals->px_prev.v) - { - vals->run++; - if (vals->run == 62 || vals->px_pos == vals->px_end) - { - bytes[vals->p++] = QOI_OP_RUN | (vals->run - 1); - vals->run = 0; - } - } - else - qoi_encode_inner_inner_inner(vals, &v, bytes); - vals->px_prev = vals->px; - vals->px_pos += vals->channels; - } -} - -static inline void *qoi_encode_inner(t_encode_vals *vals, - const t_qoi_desc *desc, - const t_u8 *pixels, t_i32 *out_len) -{ - t_u8 *bytes; - - bytes = (t_u8 *)mem_alloc(vals->max_size); - if (!bytes) - return (NULL); - qoi_write_32(bytes, &vals->p, QOI_MAGIC); - qoi_write_32(bytes, &vals->p, desc->width); - qoi_write_32(bytes, &vals->p, desc->height); - bytes[vals->p++] = desc->channels; - bytes[vals->p++] = desc->colorspace; - mem_set_zero(vals->index, sizeof(vals->index)); - vals->px_prev.rgba.a = 255; - vals->px = vals->px_prev; - vals->px_len = desc->width * desc->height * desc->channels; - vals->px_end = vals->px_len - desc->channels; - vals->channels = desc->channels; - qoi_encode_inner_inner(vals, pixels, bytes); - vals->i = 0; - while (vals->i < (t_i32) sizeof(t_u8[8])) - bytes[vals->p++] = ((t_u8[8]){0, 0, 0, 0, 0, 0, 0, 1})[vals->i++]; - *out_len = vals->p; - return (bytes); -} - -#endif /* QOI_ENCODE_H */ diff --git a/include/me/img/qoi/qoi_utils.h b/include/me/img/qoi/qoi_utils.h deleted file mode 100644 index 543296b..0000000 --- a/include/me/img/qoi/qoi_utils.h +++ /dev/null @@ -1,56 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_utils.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 18:59:56 by maiboyer #+# #+# */ -/* Updated: 2023/12/25 22:33:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef QOI_UTILS_H -# define QOI_UTILS_H - -# include "me/img/qoi.h" -# include "me/types.h" - -# define QOI_OP_INDEX 0x00 /* 00xxxxxx */ -# define QOI_OP_DIFF 0x40 /* 01xxxxxx */ -# define QOI_OP_LUMA 0x80 /* 10xxxxxx */ -# define QOI_OP_RUN 0xc0 /* 11xxxxxx */ -# define QOI_OP_RGB 0xfe /* 11111110 */ -# define QOI_OP_RGBA 0xff /* 11111111 */ -# define QOI_MASK_2 0xc0 /* 11000000 */ -# define QOI_MAGIC 0x716f6966u -//(((t_u32)'q') << 24 | ((t_u32)'o') << 16 | ((t_u32)'i') << 8 | ((t_u32)'f')) -# define QOI_HEADER_SIZE 14 -/* 2GB is the max file size that this implementation can safely handle. We guard -against anything larger than that, assuming the worst case with 5 bytes per -pixel, rounded down to a nice clean value. 400 million pixels ought to be -enough for anybody. */ -# define QOI_PIXELS_MAX 400000000u - -typedef union u_qoi_rgba -{ - struct s_qoi_rgba - { - t_u8 r; - t_u8 g; - t_u8 b; - t_u8 a; - } rgba; - t_u32 v; -} t_qoi_rgba; - -void qoi_write_32(t_u8 *bytes, t_i32 *p, t_u32 v); - -t_u32 qoi_read_32(const t_u8 *bytes, t_i32 *p); - -static inline t_u32 qoi_color_hash(t_qoi_rgba c) -{ - return (c.rgba.r * 3 + c.rgba.g * 5 + c.rgba.b * 7 + c.rgba.a * 11); -} - -#endif /* QOI_UTILS_H */ diff --git a/include/me/list/list_add_back.h b/include/me/list/list_add_back.h deleted file mode 100644 index 97dd2ef..0000000 --- a/include/me/list/list_add_back.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_add_back.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:38:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:27:56 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_ADD_BACK_H -# define LIST_ADD_BACK_H - -# include "me/types.h" - -void list_add_back(t_list **list, t_list *new); - -#endif diff --git a/include/me/list/list_add_front.h b/include/me/list/list_add_front.h deleted file mode 100644 index 8cc7fbc..0000000 --- a/include/me/list/list_add_front.h +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_add_front.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:15:23 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:28:15 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_ADD_FRONT_H -# define LIST_ADD_FRONT_H - -# include "me/types.h" - -void list_add_front(t_list **lst, t_list *new); -#endif \ No newline at end of file diff --git a/include/me/list/list_alloc_node.h b/include/me/list/list_alloc_node.h deleted file mode 100644 index a84fb05..0000000 --- a/include/me/list/list_alloc_node.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_alloc_node.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 19:57:28 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:28:30 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_ALLOC_NODE_H -# define LIST_ALLOC_NODE_H - -# include "me/types.h" - -t_list *list_alloc_node(void *content); - -#endif diff --git a/include/me/list/list_free_all.h b/include/me/list/list_free_all.h deleted file mode 100644 index 151eb5f..0000000 --- a/include/me/list/list_free_all.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_free_all.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:35:20 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:28:47 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_FREE_ALL_H -# define LIST_FREE_ALL_H - -# include "me/types.h" - -void list_free_all(t_list **lst, void (*del)(void *)); - -#endif diff --git a/include/me/list/list_free_one.h b/include/me/list/list_free_one.h deleted file mode 100644 index cac9897..0000000 --- a/include/me/list/list_free_one.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_free_one.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:30:20 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:29:15 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_FREE_ONE_H -# define LIST_FREE_ONE_H - -# include "me/types.h" - -void list_free_one(t_list *lst, void (*del)(void *)); - -#endif diff --git a/include/me/list/list_get_last.h b/include/me/list/list_get_last.h deleted file mode 100644 index b0172ee..0000000 --- a/include/me/list/list_get_last.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_get_last.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:37:08 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:29:37 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_GET_LAST_H -# define LIST_GET_LAST_H - -# include "me/types.h" - -t_list *list_get_last(t_list *list); - -#endif \ No newline at end of file diff --git a/include/me/list/list_iter.h b/include/me/list/list_iter.h deleted file mode 100644 index 1dc5c0b..0000000 --- a/include/me/list/list_iter.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_iter.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:39:05 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:29:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_ITER_H -# define LIST_ITER_H - -# include "me/types.h" - -void list_iter(t_list *list, void (*f)(void *)); - -#endif diff --git a/include/me/list/list_map.h b/include/me/list/list_map.h deleted file mode 100644 index 996f672..0000000 --- a/include/me/list/list_map.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_map.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:40:24 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:30:08 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_MAP_H -# define LIST_MAP_H - -# include "me/types.h" - -t_list *list_map(t_list *lst, void *(*f)(void *), void (*del)(void *)); - -#endif \ No newline at end of file diff --git a/include/me/list/list_size.h b/include/me/list/list_size.h deleted file mode 100644 index 758131e..0000000 --- a/include/me/list/list_size.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_size.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:23:19 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:30:23 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIST_SIZE_H -# define LIST_SIZE_H - -# include "me/types.h" - -t_usize list_size(t_list *lst); - -#endif diff --git a/include/me/mem/mem_alloc.h b/include/me/mem/mem_alloc.h deleted file mode 100644 index 1afc6fb..0000000 --- a/include/me/mem/mem_alloc.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_alloc.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:41:31 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_ALLOC_H -# define MEM_ALLOC_H - -# include "me/types.h" - -void *mem_alloc(t_usize size); - -#endif diff --git a/include/me/mem/mem_alloc_array.h b/include/me/mem/mem_alloc_array.h deleted file mode 100644 index 2979ef3..0000000 --- a/include/me/mem/mem_alloc_array.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_alloc_array.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:19:45 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_ALLOC_ARRAY_H -# define MEM_ALLOC_ARRAY_H - -# include "me/types.h" - -void *mem_alloc_array(t_usize item_count, t_usize item_size); - -#endif diff --git a/include/me/mem/mem_compare.h b/include/me/mem/mem_compare.h deleted file mode 100644 index 1ae3c3e..0000000 --- a/include/me/mem/mem_compare.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_compare.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:21:14 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_COMPARE_H -# define MEM_COMPARE_H - -# include "me/types.h" - -t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count); - -#endif \ No newline at end of file diff --git a/include/me/mem/mem_copy.h b/include/me/mem/mem_copy.h deleted file mode 100644 index 59d7124..0000000 --- a/include/me/mem/mem_copy.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_copy.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:21:31 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_COPY_H -# define MEM_COPY_H - -# include "me/types.h" - -void *mem_copy(void *destination, const void *source, t_usize count); - -#endif \ No newline at end of file diff --git a/include/me/mem/mem_find.h b/include/me/mem/mem_find.h deleted file mode 100644 index 048d844..0000000 --- a/include/me/mem/mem_find.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_find.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:24:03 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_FIND_H -# define MEM_FIND_H - -# include "me/types.h" - -void *mem_find(void *buf, t_u8 find, t_usize count); - -#endif \ No newline at end of file diff --git a/include/me/mem/mem_find_bytes.h b/include/me/mem/mem_find_bytes.h deleted file mode 100644 index 5f220b6..0000000 --- a/include/me/mem/mem_find_bytes.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_find_bytes.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2024/01/06 18:24:04 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_FIND_BYTES_H -# define MEM_FIND_BYTES_H - -# include "me/types.h" - -void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count, - t_usize count); - -#endif diff --git a/include/me/mem/mem_move.h b/include/me/mem/mem_move.h deleted file mode 100644 index b2bce61..0000000 --- a/include/me/mem/mem_move.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_move.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:24:26 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_MOVE_H -# define MEM_MOVE_H - -# include "me/types.h" - -void *mem_move(void *destination, const void *source, t_usize count); - -#endif \ No newline at end of file diff --git a/include/me/mem/mem_set.h b/include/me/mem/mem_set.h deleted file mode 100644 index c6702a1..0000000 --- a/include/me/mem/mem_set.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_set.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:25:19 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_SET_H -# define MEM_SET_H - -# include "me/types.h" - -void mem_set(void *buf, t_u8 byte, t_usize count); - -#endif \ No newline at end of file diff --git a/include/me/mem/mem_set_zero.h b/include/me/mem/mem_set_zero.h deleted file mode 100644 index dc38393..0000000 --- a/include/me/mem/mem_set_zero.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_set_zero.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:58:11 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:24:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MEM_SET_ZERO_H -# define MEM_SET_ZERO_H - -# include "me/types.h" - -void mem_set_zero(void *buf, t_usize count); - -#endif \ No newline at end of file diff --git a/include/me/num/u16.h b/include/me/num/u16.h deleted file mode 100644 index e2791fd..0000000 --- a/include/me/num/u16.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* u16.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:16:58 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef U16_H -# define U16_H - -# include "me/types.h" - -t_u16 u16_rotate_left(t_u16 n, t_usize by); -t_u16 u16_rotate_right(t_u16 n, t_usize by); - -#endif diff --git a/include/me/num/u32.h b/include/me/num/u32.h deleted file mode 100644 index 4eab4f8..0000000 --- a/include/me/num/u32.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* u32.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:17:08 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef U32_H -# define U32_H - -# include "me/types.h" - -t_u32 u32_rotate_left(t_u32 n, t_usize by); -t_u32 u32_rotate_right(t_u32 n, t_usize by); - -#endif diff --git a/include/me/num/u64.h b/include/me/num/u64.h deleted file mode 100644 index 5ff2137..0000000 --- a/include/me/num/u64.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* u64.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 17:59:34 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef U64_H -# define U64_H - -# include "me/types.h" - -t_u64 u64_rotate_left(t_u64 n, t_usize by); -t_u64 u64_rotate_right(t_u64 n, t_usize by); - -t_u64 u64_from_7bytes(t_u8 *bytes, t_usize start, t_usize len); -t_u64 u64_from_bytes(t_u8 *bytes, t_usize len); - -#endif diff --git a/include/me/num/u8.h b/include/me/num/u8.h deleted file mode 100644 index fb254ae..0000000 --- a/include/me/num/u8.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* u8.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:17:24 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef U8_H -# define U8_H - -# include "me/types.h" - -t_u8 u8_rotate_left(t_u8 n, t_usize by); -t_u8 u8_rotate_right(t_u8 n, t_usize by); - -#endif diff --git a/include/me/num/usize.h b/include/me/num/usize.h deleted file mode 100644 index 2c9cc6b..0000000 --- a/include/me/num/usize.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* usize.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:17:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef USIZE_H -# define USIZE_H - -# include "me/types.h" - -t_usize usize_rotate_left(t_usize n, t_usize by); -t_usize usize_rotate_right(t_usize n, t_usize by); - -#endif diff --git a/include/me/printf/formatter/formatter.h b/include/me/printf/formatter/formatter.h deleted file mode 100644 index 67346c5..0000000 --- a/include/me/printf/formatter/formatter.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* formatter.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:18:19 by maiboyer #+# #+# */ -/* Updated: 2023/11/18 19:11:23 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FORMATTER_H -# define FORMATTER_H -# include "me/printf/printf.h" -# include "me/types.h" - -void printf_x_low(t_printf_arg data, t_printf_func f); -void printf_x_up(t_printf_arg data, t_printf_func f); -void printf_o(t_printf_arg data, t_printf_func f); -void printf_d(t_printf_arg data, t_printf_func f); -void printf_u(t_printf_arg data, t_printf_func f); -void printf_c(t_printf_arg data, t_printf_func f); -void printf_s(t_printf_arg data, t_printf_func f); -void printf_p(t_printf_arg data, t_printf_func f); - -#endif diff --git a/include/me/printf/formatter/utils.h b/include/me/printf/formatter/utils.h deleted file mode 100644 index 150d5aa..0000000 --- a/include/me/printf/formatter/utils.h +++ /dev/null @@ -1,76 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 17:58:41 by maiboyer #+# #+# */ -/* Updated: 2023/12/01 21:24:21 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef UTILS_H -# define UTILS_H - -# include "me/printf/matchers/matchers.h" -# include "me/printf/printf.h" -# include "me/types.h" -# include - -typedef struct s_prec_strs -{ - t_str *out; - t_str *pretty; - bool free_out; -} t_prec_strs; - -typedef struct s_pad_and_stuff_args -{ - t_usize fill_zero; - t_usize fill; - t_usize len; - t_usize pretty_len; - t_usize sign_len; - t_str pretty; - t_str str; - t_str sign; - bool allow_zero_fill; - -} t_pad_and_stuff_args; -typedef struct s_pad_inner_args -{ - void *p_args; - t_usize fmt_len; - t_printf_func f; - va_list *arguments; - t_matcher_list *matchers; -} t_pad_inner_args; - -void set_var_for_pad_and_stuff(t_pad_and_stuff_args *a, - t_printf_arg *d); -void print_with_func(t_pad_and_stuff_args *a, t_printf_arg *d, - t_printf_func f, t_const_str t); -void pad_and_stuff(t_pad_and_stuff_args a, t_printf_arg d, - t_printf_func f); -void handle_prec_and_align(t_const_str fmt, t_usize *c_idx, - t_printf_arg *c_arg); -bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx, - t_usize *nxt, t_printf_arg *c_arg); -void set_params2(t_const_str fmt, t_usize *c_idx, t_usize *nxt, - t_printf_arg *c_arg); -bool set_params(t_const_str fmt, t_usize *c_idx, t_usize *nxt, - t_printf_arg *c_arg); -void ret_reset(t_usize *c_idx, t_usize *nxt, t_const_str fmt); -t_printf_arg print_substr(t_usize *c_idx, t_usize *nxt, t_const_str fmt, - t_pad_inner_args extra); -void pad_inner(t_const_str fmt, t_usize *c_idx, t_usize *nxt, - t_pad_inner_args extra); -void advance_atoi(t_const_str fmt, t_usize *idx); -void me_printf_str_inner(t_const_str fmt, t_printf_func f, - va_list *arguments, void *p_args); -void print_sign_if_needed(t_pad_and_stuff_args a, t_printf_arg d, - t_printf_func f); -void handle_weird_precision_stuff(t_printf_arg *data, - t_prec_strs strs, t_usize value); -#endif diff --git a/include/me/printf/matchers/matchers.h b/include/me/printf/matchers/matchers.h deleted file mode 100644 index 7dc4239..0000000 --- a/include/me/printf/matchers/matchers.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* matchers.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:09:07 by maiboyer #+# #+# */ -/* Updated: 2023/11/18 18:10:33 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MATCHERS_H -# define MATCHERS_H - -# include "me/printf/printf.h" -# include "me/types.h" -# include -# define PRINTF_BUFFER_CHUNK 20 - -typedef struct s_matcher_tmp -{ - char chr_val; - t_i64 i64_val; - t_u64 u64_val; -} t_matcher_tmp_val; - -typedef void (*t_matcher_func)(t_printf_arg data, - t_printf_func f); -typedef struct s_matcher -{ - t_const_str matcher; - t_usize matcher_len; - t_printf_type arg_type; - t_matcher_func f; -} t_matcher; - -typedef struct s_matcher_list -{ - t_matcher data[PRINTF_BUFFER_CHUNK]; - struct s_matcher_list *next; -} t_matcher_list; - -t_matcher_list *get_matchers(void); -bool insert_matcher(t_matcher matcher); -t_matcher *find_matcher(t_const_str fmt, - t_matcher_list *matchers, t_usize *c_idx); -void call_matcher(t_matcher *matcher, - t_printf_arg matcher_arguments, va_list args, - t_printf_func f); - -#endif diff --git a/include/me/printf/printf.h b/include/me/printf/printf.h deleted file mode 100644 index f12bbd6..0000000 --- a/include/me/printf/printf.h +++ /dev/null @@ -1,69 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* printf.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:10:27 by maiboyer #+# #+# */ -/* Updated: 2024/02/09 15:06:53 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PRINTF_H - -# define PRINTF_H -# include "me/types.h" -# include - -typedef struct s_fprintf_arg -{ - t_usize total_print; - t_file fd; -} t_fprintf_arg; - -typedef enum e_printf_flags -{ - PRECISION = 1 << 1, - ALIGN = 1 << 2, - ZERO_ALIGN = 1 << 3, - SIGN = 1 << 4, -} t_printf_flags; - -typedef enum e_printf_type -{ - CHAR = 1 << 0, - STR = 1 << 1, - U64 = 1 << 2, - I64 = 1 << 3, - VOID_PTR = 1 << 4, - I32 = 1 << 5, - U32 = 1 << 6, -} t_printf_type; - -typedef struct s_printf_extra_args -{ - t_u64 precision; - t_u64 align; - bool left_align; - bool space_align; - bool pretty; -} t_printf_extra_args; - -typedef struct s_printf_args -{ - void *argument; - void *p_args; - t_printf_extra_args extra; - t_printf_flags flags; -} t_printf_arg; - -typedef void (*t_printf_func)(t_const_str to_write, - t_usize to_write_len, void *p_args); - -t_usize me_printf(t_const_str fmt, ...); -t_usize me_eprintf(t_const_str fmt, ...); -t_usize me_vprintf(t_const_str fmt, va_list *args); -t_usize me_veprintf(t_const_str fmt, va_list *args); - -#endif diff --git a/include/me/string/str_clone.h b/include/me/string/str_clone.h deleted file mode 100644 index a152316..0000000 --- a/include/me/string/str_clone.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_clone.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 17:30:19 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_CLONE_H -# define STR_CLONE_H - -# include "me/types.h" - -t_str str_clone(t_const_str source); - -#endif diff --git a/include/me/string/str_find_chr.h b/include/me/string/str_find_chr.h deleted file mode 100644 index 0c583d6..0000000 --- a/include/me/string/str_find_chr.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_chr.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:07:01 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_FIND_CHR_H -# define STR_FIND_CHR_H - -# include "me/types.h" - -char *str_find_chr(t_const_str str, char chr); - -#endif \ No newline at end of file diff --git a/include/me/string/str_find_rev_chr.h b/include/me/string/str_find_rev_chr.h deleted file mode 100644 index 5dcd107..0000000 --- a/include/me/string/str_find_rev_chr.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_rev_chr.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:07:15 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_FIND_REV_CHR_H -# define STR_FIND_REV_CHR_H - -# include "me/types.h" - -char *str_find_rev_chr(t_const_str str, char chr); - -#endif \ No newline at end of file diff --git a/include/me/string/str_find_str.h b/include/me/string/str_find_str.h deleted file mode 100644 index 30bd878..0000000 --- a/include/me/string/str_find_str.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:53:44 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_FIND_STR_H -# define STR_FIND_STR_H - -# include "me/types.h" - -const char *str_find_str(t_const_str str, t_const_str to_find); - -#endif diff --git a/include/me/string/str_iter.h b/include/me/string/str_iter.h deleted file mode 100644 index e9bf1f5..0000000 --- a/include/me/string/str_iter.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_iter.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:08:09 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_ITER_H -# define STR_ITER_H - -# include "me/types.h" - -void str_iter(t_str s, void (*f)(t_usize, char *)); - -#endif \ No newline at end of file diff --git a/include/me/string/str_join.h b/include/me/string/str_join.h deleted file mode 100644 index 408eb2c..0000000 --- a/include/me/string/str_join.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_join.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 23:02:58 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:08:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_JOIN_H -# define STR_JOIN_H - -# include "me/types.h" - -t_str str_join(t_const_str s1, t_const_str s2); - -#endif \ No newline at end of file diff --git a/include/me/string/str_l_cat.h b/include/me/string/str_l_cat.h deleted file mode 100644 index fa752cb..0000000 --- a/include/me/string/str_l_cat.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_l_cat.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:09:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_L_CAT_H -# define STR_L_CAT_H - -# include "me/types.h" - -t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size); - -#endif diff --git a/include/me/string/str_l_copy.h b/include/me/string/str_l_copy.h deleted file mode 100644 index a75fbb4..0000000 --- a/include/me/string/str_l_copy.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_l_copy.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:09:38 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_L_COPY_H -# define STR_L_COPY_H - -# include "me/types.h" - -t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size); - -#endif \ No newline at end of file diff --git a/include/me/string/str_len.h b/include/me/string/str_len.h deleted file mode 100644 index a1dddf3..0000000 --- a/include/me/string/str_len.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_len.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 17:07:41 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 16:08:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_LEN_H -# define STR_LEN_H - -# include "me/types.h" - -t_usize str_len(t_const_str str); - -#endif diff --git a/include/me/string/str_map.h b/include/me/string/str_map.h deleted file mode 100644 index a64e3d2..0000000 --- a/include/me/string/str_map.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_map.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:11:40 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_MAP_H -# define STR_MAP_H - -# include "me/types.h" - -t_str str_map(t_const_str s, char (*f)(t_usize, char)); - -#endif \ No newline at end of file diff --git a/include/me/string/str_n_compare.h b/include/me/string/str_n_compare.h deleted file mode 100644 index c07c04f..0000000 --- a/include/me/string/str_n_compare.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_n_compare.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:17:14 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_N_COMPARE_H -# define STR_N_COMPARE_H - -# include "me/types.h" - -t_i32 str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n); - -#endif \ No newline at end of file diff --git a/include/me/string/str_n_find_str.h b/include/me/string/str_n_find_str.h deleted file mode 100644 index eea578b..0000000 --- a/include/me/string/str_n_find_str.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_n_find_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:53:35 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_N_FIND_STR_H -# define STR_N_FIND_STR_H - -# include "me/types.h" - -const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len); - -#endif diff --git a/include/me/string/str_split.h b/include/me/string/str_split.h deleted file mode 100644 index 578f1dd..0000000 --- a/include/me/string/str_split.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_split.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/17 15:56:59 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:18:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_SPLIT_H -# define STR_SPLIT_H - -# include "me/types.h" - -t_str *str_split(t_const_str str, char chr); - -#endif \ No newline at end of file diff --git a/include/me/string/str_substring.h b/include/me/string/str_substring.h deleted file mode 100644 index da9cb41..0000000 --- a/include/me/string/str_substring.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_substring.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 22:42:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:18:41 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_SUBSTRING_H -# define STR_SUBSTRING_H - -# include "me/types.h" - -t_str str_substring(t_const_str str, t_usize start, t_usize len); - -#endif \ No newline at end of file diff --git a/include/me/string/str_trim.h b/include/me/string/str_trim.h deleted file mode 100644 index e7682d3..0000000 --- a/include/me/string/str_trim.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_trim.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 23:43:42 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:19:11 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef STR_TRIM_H -# define STR_TRIM_H - -# include "me/types.h" - -t_str str_trim(t_const_str str, t_const_str charset); - -#endif \ No newline at end of file diff --git a/include/me/types.h b/include/me/types.h deleted file mode 100644 index 55a0360..0000000 --- a/include/me/types.h +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* types.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 14:31:12 by maiboyer #+# #+# */ -/* Updated: 2024/01/05 00:08:41 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef TYPES_H -# define TYPES_H - -# include -# include -# include - -typedef char *t_str; -typedef const char *t_const_str; - -typedef unsigned char t_u8; -typedef char t_i8; -typedef unsigned short t_u16; -typedef short t_i16; -typedef int t_i32; -typedef unsigned int t_u32; -typedef unsigned long long t_u64; -typedef long long t_i64; -typedef ssize_t t_isize; -typedef size_t t_usize; - -typedef float t_f32; -typedef double t_f64; - -typedef int t_file; -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -typedef bool t_error; - -# define ERROR 1 -# define NO_ERROR 0 - -#endif diff --git a/include/me/vec/vec_buf_str.h b/include/me/vec/vec_buf_str.h deleted file mode 100644 index afd4058..0000000 --- a/include/me/vec/vec_buf_str.h +++ /dev/null @@ -1,60 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_buf_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:02:08 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef VEC_BUF_STR_H -# define VEC_BUF_STR_H - -# include "me/buffered_str/buf_str.h" -# include "me/types.h" - -typedef bool (*t_vec_buf_str_sort_fn)(t_buffer_str *, - t_buffer_str *); -typedef void (*t_free_buf_str_item)(t_buffer_str); - -typedef struct s_vec_buf_str -{ - t_free_buf_str_item free_func; - t_usize len; - t_usize capacity; - t_buffer_str *buffer; -} t_vec_buf_str; - -t_vec_buf_str vec_buf_str_new(t_usize capacity, - t_free_buf_str_item free_function); -t_error vec_buf_str_push(t_vec_buf_str *vec, - t_buffer_str element); -t_error vec_buf_str_push_front(t_vec_buf_str *vec, - t_buffer_str element); -t_error vec_buf_str_pop(t_vec_buf_str *vec, - t_buffer_str *value); -t_error vec_buf_str_pop_front(t_vec_buf_str *vec, - t_buffer_str *value); -void vec_buf_str_free(t_vec_buf_str vec); -t_error vec_buf_str_reserve(t_vec_buf_str *vec, - t_usize wanted_capacity); -t_error vec_buf_str_find(t_vec_buf_str *vec, - bool (*fn)(const t_buffer_str *), t_usize *index); -t_error vec_buf_str_find_starting(t_vec_buf_str *vec, - bool (*fn)(const t_buffer_str *), - t_usize starting_index, t_usize *index); -t_error vec_buf_str_all(t_vec_buf_str *vec, - bool (*fn)(const t_buffer_str *), bool *result); -t_error vec_buf_str_any(t_vec_buf_str *vec, - bool (*fn)(const t_buffer_str *), bool *result); -void vec_buf_str_iter(t_vec_buf_str *vec, - void (*fn)(t_usize index, t_buffer_str *value, - void *state), void *state); -void vec_buf_str_reverse(t_vec_buf_str *vec); -void vec_buf_str_sort(t_vec_buf_str *vec, - t_vec_buf_str_sort_fn is_sorted); - -#endif diff --git a/include/me/vec/vec_u8.h b/include/me/vec/vec_u8.h deleted file mode 100644 index e0a8c23..0000000 --- a/include/me/vec/vec_u8.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_u8.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:02:19 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef VEC_U8_H -# define VEC_U8_H - -# include "me/types.h" - -typedef bool (*t_vec_u8_sort_fn)(t_u8 *, t_u8 *); -typedef void (*t_free_u8_item)(t_u8); - -typedef struct s_vec_u8 -{ - t_free_u8_item free_func; - t_usize len; - t_usize capacity; - t_u8 *buffer; -} t_vec_u8; - -t_vec_u8 vec_u8_new(t_usize capacity, t_free_u8_item free_function); -t_error vec_u8_push(t_vec_u8 *vec, t_u8 element); -t_error vec_u8_push_front(t_vec_u8 *vec, t_u8 element); -t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value); -t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value); -void vec_u8_free(t_vec_u8 vec); -t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity); -t_error vec_u8_find(t_vec_u8 *vec, bool (*fn)(const t_u8 *), - t_usize *index); -t_error vec_u8_find_starting(t_vec_u8 *vec, - bool (*fn)(const t_u8 *), t_usize starting_index, - t_usize *index); -t_error vec_u8_all(t_vec_u8 *vec, bool (*fn)(const t_u8 *), - bool *result); -t_error vec_u8_any(t_vec_u8 *vec, bool (*fn)(const t_u8 *), - bool *result); -void vec_u8_iter(t_vec_u8 *vec, void (*fn)(t_usize index, - t_u8 *value, void *state), void *state); -void vec_u8_reverse(t_vec_u8 *vec); -void vec_u8_sort(t_vec_u8 *vec, t_vec_u8_sort_fn is_sorted); - -#endif diff --git a/include/me/vec2/vec2.h b/include/me/vec2/vec2.h deleted file mode 100644 index 81a0e52..0000000 --- a/include/me/vec2/vec2.h +++ /dev/null @@ -1,60 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec2.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/31 14:54:39 by maiboyer #+# #+# */ -/* Updated: 2023/12/31 15:07:54 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef VEC2_H -# define VEC2_H - -# include "me/types.h" - -typedef struct s_vi2d -{ - t_i32 x; - t_i32 y; -} t_vi2d; - -typedef struct s_vu2d -{ - t_u32 x; - t_u32 y; -} t_vu2d; - -typedef struct s_vf2d -{ - t_f32 x; - t_f32 y; -} t_vf2d; - -static inline t_vf2d vf2d(t_f32 x, t_f32 y) -{ - return ((t_vf2d){.x = x, .y = y}); -} - -static inline t_vi2d vi2d(t_i32 x, t_i32 y) -{ - return ((t_vi2d){.x = x, .y = y}); -} - -static inline t_vu2d vu2d(t_u32 x, t_u32 y) -{ - return ((t_vu2d){.x = x, .y = y}); -} - -static inline t_vi2d vi2d_add(t_vi2d lhs, t_vi2d rhs) -{ - return ((t_vi2d){.x = lhs.x + rhs.x, .y = lhs.y + rhs.y}); -} - -static inline t_vi2d vi2d_sub(t_vi2d lhs, t_vi2d rhs) -{ - return ((t_vi2d){.x = lhs.x - rhs.x, .y = lhs.y - rhs.y}); -} -#endif /* VEC2_H */ diff --git a/input.toml b/input.toml new file mode 100644 index 0000000..8125265 --- /dev/null +++ b/input.toml @@ -0,0 +1,144 @@ +[definition.vec] +headers = ["mecstd/generic_sources/header/vec_C__PREFIX__.h__TEMPLATE__"] +sources = [ + "mecstd/generic_sources/src/vec_C__PREFIX__.c__TEMPLATE__", + "mecstd/generic_sources/src/vec_C__PREFIX___functions2.c__TEMPLATE__", + "mecstd/generic_sources/src/vec_C__PREFIX___functions3.c__TEMPLATE__", + "mecstd/generic_sources/src/vec_C__PREFIX___sort.c__TEMPLATE__", +] +replace.C__TYPENAME__ = "type" +replace.C__TYPEHEADER__ = "header_include" +replace.C__PREFIX__ = "prefix" +replace.C__PREFIXUP__ = "prefix" + + +[definition.hashmap] +headers = ["mecstd/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__"] +sources = [ + "mecstd/generic_sources/src/hashmap_C__PREFIX__.c__TEMPLATE__", + "mecstd/generic_sources/src/hashmap_C__PREFIX___utils.c__TEMPLATE__", +] +replace.C__VALTYPE__ = "type" +replace.C__KEYTYPE__ = "type" +replace.C__TYPEHEADER__ = "header_include" +replace.C__PREFIX__ = "prefix" +replace.C__PREFIXUP__ = "prefix" + +[definition.str_to_num] +headers = [] +sources = [ + "mecstd/generic_sources/src/str_to_C__PREFIX__.c__TEMPLATE__", + "mecstd/generic_sources/src/str_to_C__PREFIX___utils.c__TEMPLATE__", +] +replace.C__TYPE__ = "type" +replace.C__UNSIGNED_TYPE__ = "type" +replace.C__PREFIX__ = "prefix" +replace.C__MAX__ = "value" +replace.C__MIN__ = "value" +replace.C__ZERO__ = "value" +replace.C__SIGNED_TYPE__ = "bool" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_i64" +replace.C__UNSIGNED_TYPE__ = "t_u64" +replace.C__PREFIX__ = "i64" +replace.C__MAX__ = "9223372036854775807ll" +replace.C__MIN__ = "-(~9223372036854775807ll + 1)" +replace.C__ZERO__ = "0ll" +replace.C__SIGNED_TYPE__ = "true" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_i32" +replace.C__UNSIGNED_TYPE__ = "t_u32" +replace.C__PREFIX__ = "i32" +replace.C__MAX__ = "2147483647" +replace.C__MIN__ = "-2147483648" +replace.C__ZERO__ = "0" +replace.C__SIGNED_TYPE__ = "true" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_i16" +replace.C__UNSIGNED_TYPE__ = "t_u16" +replace.C__PREFIX__ = "i16" +replace.C__MAX__ = "32767" +replace.C__MIN__ = "-32768" +replace.C__ZERO__ = "0" +replace.C__SIGNED_TYPE__ = "true" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_i8" +replace.C__UNSIGNED_TYPE__ = "t_u8" +replace.C__PREFIX__ = "i8" +replace.C__MAX__ = "127" +replace.C__MIN__ = "-128" +replace.C__ZERO__ = "0" +replace.C__SIGNED_TYPE__ = "true" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_u64" +replace.C__UNSIGNED_TYPE__ = "t_u64" +replace.C__PREFIX__ = "u64" +replace.C__MAX__ = "18446744073709551615llu" +replace.C__MIN__ = "0llu" +replace.C__ZERO__ = "0llu" +replace.C__SIGNED_TYPE__ = "false" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_u32" +replace.C__UNSIGNED_TYPE__ = "t_u32" +replace.C__PREFIX__ = "u32" +replace.C__MAX__ = "4294967295u" +replace.C__MIN__ = "0u" +replace.C__ZERO__ = "0u" +replace.C__SIGNED_TYPE__ = "false" + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_u16" +replace.C__UNSIGNED_TYPE__ = "t_u16" +replace.C__PREFIX__ = "u16" +replace.C__MAX__ = "65535u" +replace.C__MIN__ = "0u" +replace.C__ZERO__ = "0u" +replace.C__SIGNED_TYPE__ = "false" + + +[[create.str_to_num]] +sources_output = "src/convert/" +headers_output = "" +replace.C__TYPE__ = "t_u8" +replace.C__UNSIGNED_TYPE__ = "t_u8" +replace.C__PREFIX__ = "u8" +replace.C__MAX__ = "128u" +replace.C__MIN__ = "0u" +replace.C__ZERO__ = "0u" +replace.C__SIGNED_TYPE__ = "false" + +[[create.vec]] +sources_output = "src/vec/" +headers_output = "include/me/vec/" +replace.C__TYPENAME__ = "t_i64" +replace.C__TYPEHEADER__ = '' +replace.C__PREFIX__ = "i64" +replace.C__PREFIXUP__ = "I64" + +[[create.vec]] +sources_output = "src/vec/" +headers_output = "include/me/vec/" +replace.C__TYPENAME__ = "t_i64_bool" +replace.C__TYPEHEADER__ = '#include "app/types/type_i64_bool.h"' +replace.C__PREFIX__ = "i64_bool" +replace.C__PREFIXUP__ = "I64_BOOL" diff --git a/mecstd b/mecstd new file mode 160000 index 0000000..07ea967 --- /dev/null +++ b/mecstd @@ -0,0 +1 @@ +Subproject commit 07ea9679e2413366502a73ea9391d89847d6b3c2 diff --git a/include/me/vec/vec_i64.h b/output/include/me/vec/vec_i64.h similarity index 93% rename from include/me/vec/vec_i64.h rename to output/include/me/vec/vec_i64.h index 6b4c417..8a8f200 100644 --- a/include/me/vec/vec_i64.h +++ b/output/include/me/vec/vec_i64.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64.h :+: :+: :+: */ +/* vec_i64.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:02:14 by maiboyer ### ########.fr */ +/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/me/vec/vec_i64_bool.h b/output/include/me/vec/vec_i64_bool.h similarity index 94% rename from include/me/vec/vec_i64_bool.h rename to output/include/me/vec/vec_i64_bool.h index e64bf16..42f456a 100644 --- a/include/me/vec/vec_i64_bool.h +++ b/output/include/me/vec/vec_i64_bool.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_bool.h :+: :+: :+: */ +/* vec_i64_bool.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:02:10 by maiboyer ### ########.fr */ +/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i16.c b/output/src/convert/str_to_i16.c similarity index 96% rename from src/convert/str_to_i16.c rename to output/src/convert/str_to_i16.c index c120781..b1d2bc8 100644 --- a/src/convert/str_to_i16.c +++ b/output/src/convert/str_to_i16.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_i16.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:39 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i16_utils.c b/output/src/convert/str_to_i16_utils.c similarity index 96% rename from src/convert/str_to_i16_utils.c rename to output/src/convert/str_to_i16_utils.c index 915d55a..4ecbbe2 100644 --- a/src/convert/str_to_i16_utils.c +++ b/output/src/convert/str_to_i16_utils.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:36 by maiboyer ### ########.fr */ +/* Updated: 2024/02/08 18:55:47 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i32.c b/output/src/convert/str_to_i32.c similarity index 96% rename from src/convert/str_to_i32.c rename to output/src/convert/str_to_i32.c index 34cf1d9..4956029 100644 --- a/src/convert/str_to_i32.c +++ b/output/src/convert/str_to_i32.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_i32.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:43 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i32_utils.c b/output/src/convert/str_to_i32_utils.c similarity index 96% rename from src/convert/str_to_i32_utils.c rename to output/src/convert/str_to_i32_utils.c index 75221dc..5b6f5fd 100644 --- a/src/convert/str_to_i32_utils.c +++ b/output/src/convert/str_to_i32_utils.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:44 by maiboyer ### ########.fr */ +/* Updated: 2024/02/08 18:56:06 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i64.c b/output/src/convert/str_to_i64.c similarity index 98% rename from src/convert/str_to_i64.c rename to output/src/convert/str_to_i64.c index 6a2a51e..56a48cc 100644 --- a/src/convert/str_to_i64.c +++ b/output/src/convert/str_to_i64.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:46 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i64_utils.c b/output/src/convert/str_to_i64_utils.c similarity index 96% rename from src/convert/str_to_i64_utils.c rename to output/src/convert/str_to_i64_utils.c index 4c0f81d..1dd268d 100644 --- a/src/convert/str_to_i64_utils.c +++ b/output/src/convert/str_to_i64_utils.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:45 by maiboyer ### ########.fr */ +/* Updated: 2024/02/08 18:55:37 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i8.c b/output/src/convert/str_to_i8.c similarity index 96% rename from src/convert/str_to_i8.c rename to output/src/convert/str_to_i8.c index d0bee76..80f91a0 100644 --- a/src/convert/str_to_i8.c +++ b/output/src/convert/str_to_i8.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_i8.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:35 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_i8_utils.c b/output/src/convert/str_to_i8_utils.c similarity index 91% rename from src/convert/str_to_i8_utils.c rename to output/src/convert/str_to_i8_utils.c index 210a975..2073dd6 100644 --- a/src/convert/str_to_i8_utils.c +++ b/output/src/convert/str_to_i8_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_i8_utils.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:34 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u16.c b/output/src/convert/str_to_u16.c similarity index 96% rename from src/convert/str_to_u16.c rename to output/src/convert/str_to_u16.c index af63a8e..7c5bbaa 100644 --- a/src/convert/str_to_u16.c +++ b/output/src/convert/str_to_u16.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u16.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:49 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u16_utils.c b/output/src/convert/str_to_u16_utils.c similarity index 92% rename from src/convert/str_to_u16_utils.c rename to output/src/convert/str_to_u16_utils.c index 4803db1..85fd7b2 100644 --- a/src/convert/str_to_u16_utils.c +++ b/output/src/convert/str_to_u16_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u16_utils.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:48 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u32.c b/output/src/convert/str_to_u32.c similarity index 96% rename from src/convert/str_to_u32.c rename to output/src/convert/str_to_u32.c index f68794d..1b625d1 100644 --- a/src/convert/str_to_u32.c +++ b/output/src/convert/str_to_u32.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u32.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:50 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u32_utils.c b/output/src/convert/str_to_u32_utils.c similarity index 92% rename from src/convert/str_to_u32_utils.c rename to output/src/convert/str_to_u32_utils.c index 33001bf..3a929d5 100644 --- a/src/convert/str_to_u32_utils.c +++ b/output/src/convert/str_to_u32_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u32_utils.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:49 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u64.c b/output/src/convert/str_to_u64.c similarity index 96% rename from src/convert/str_to_u64.c rename to output/src/convert/str_to_u64.c index fcd95c4..b744be8 100644 --- a/src/convert/str_to_u64.c +++ b/output/src/convert/str_to_u64.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u64.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:52 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u64_utils.c b/output/src/convert/str_to_u64_utils.c similarity index 92% rename from src/convert/str_to_u64_utils.c rename to output/src/convert/str_to_u64_utils.c index f04b99a..f2bb77f 100644 --- a/src/convert/str_to_u64_utils.c +++ b/output/src/convert/str_to_u64_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u64_utils.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:51 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u8.c b/output/src/convert/str_to_u8.c similarity index 96% rename from src/convert/str_to_u8.c rename to output/src/convert/str_to_u8.c index 57413fc..8fac9fa 100644 --- a/src/convert/str_to_u8.c +++ b/output/src/convert/str_to_u8.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u8.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:47 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/convert/str_to_u8_utils.c b/output/src/convert/str_to_u8_utils.c similarity index 91% rename from src/convert/str_to_u8_utils.c rename to output/src/convert/str_to_u8_utils.c index f66e0cd..14a4a04 100644 --- a/src/convert/str_to_u8_utils.c +++ b/output/src/convert/str_to_u8_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* str_to_u8_utils.c :+: :+: :+: */ +/* str_to_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:47 by maiboyer ### ########.fr */ +/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64.c b/output/src/vec/vec_i64.c similarity index 95% rename from src/vec/vec_i64.c rename to output/src/vec/vec_i64.c index ee0272d..1a24dec 100644 --- a/src/vec/vec_i64.c +++ b/output/src/vec/vec_i64.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64.c :+: :+: :+: */ +/* vec_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:08 by maiboyer ### ########.fr */ +/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_bool.c b/output/src/vec/vec_i64_bool.c similarity index 95% rename from src/vec/vec_i64_bool.c rename to output/src/vec/vec_i64_bool.c index 4f405f2..af10724 100644 --- a/src/vec/vec_i64_bool.c +++ b/output/src/vec/vec_i64_bool.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_bool.c :+: :+: :+: */ +/* vec_i64_bool.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:52 by maiboyer ### ########.fr */ +/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_bool_functions2.c b/output/src/vec/vec_i64_bool_functions2.c similarity index 94% rename from src/vec/vec_i64_bool_functions2.c rename to output/src/vec/vec_i64_bool_functions2.c index b5d59f6..01927c2 100644 --- a/src/vec/vec_i64_bool_functions2.c +++ b/output/src/vec/vec_i64_bool_functions2.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_bool_functions2.c :+: :+: :+: */ +/* vec_i64_bool.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:38 by maiboyer ### ########.fr */ +/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_bool_functions3.c b/output/src/vec/vec_i64_bool_functions3.c similarity index 93% rename from src/vec/vec_i64_bool_functions3.c rename to output/src/vec/vec_i64_bool_functions3.c index 32f2007..ee82947 100644 --- a/src/vec/vec_i64_bool_functions3.c +++ b/output/src/vec/vec_i64_bool_functions3.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_bool_functions3.c :+: :+: :+: */ +/* vec_i64_bool.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:41 by maiboyer ### ########.fr */ +/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_bool_sort.c b/output/src/vec/vec_i64_bool_sort.c similarity index 90% rename from src/vec/vec_i64_bool_sort.c rename to output/src/vec/vec_i64_bool_sort.c index e20a733..edbdfc1 100644 --- a/src/vec/vec_i64_bool_sort.c +++ b/output/src/vec/vec_i64_bool_sort.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_bool_sort.c :+: :+: :+: */ +/* best_move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:47 by maiboyer ### ########.fr */ +/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_functions2.c b/output/src/vec/vec_i64_functions2.c similarity index 94% rename from src/vec/vec_i64_functions2.c rename to output/src/vec/vec_i64_functions2.c index db278db..d7180bc 100644 --- a/src/vec/vec_i64_functions2.c +++ b/output/src/vec/vec_i64_functions2.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_functions2.c :+: :+: :+: */ +/* vec_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:57 by maiboyer ### ########.fr */ +/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_functions3.c b/output/src/vec/vec_i64_functions3.c similarity index 92% rename from src/vec/vec_i64_functions3.c rename to output/src/vec/vec_i64_functions3.c index 3bcb369..653eee8 100644 --- a/src/vec/vec_i64_functions3.c +++ b/output/src/vec/vec_i64_functions3.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_functions3.c :+: :+: :+: */ +/* vec_i64.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:02 by maiboyer ### ########.fr */ +/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/vec/vec_i64_sort.c b/output/src/vec/vec_i64_sort.c similarity index 90% rename from src/vec/vec_i64_sort.c rename to output/src/vec/vec_i64_sort.c index 43c86df..d32b66b 100644 --- a/src/vec/vec_i64_sort.c +++ b/output/src/vec/vec_i64_sort.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vec_i64_sort.c :+: :+: :+: */ +/* best_move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:04 by maiboyer ### ########.fr */ +/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src.list b/src.list new file mode 100644 index 0000000..e78502d --- /dev/null +++ b/src.list @@ -0,0 +1,21 @@ +app/actual_main +app/best_index_to_move +app/best_move +app/do_move +app/find_place +app/iter_find +app/main +app/main_bonus +app/moves +app/moves/push +app/moves/rev_rotate +app/moves/rotate +app/moves/swap +app/rotate +app/run_with_items +app/sort2 +app/sort3 +app/sort5 +app/state +app/target +bonus/move1 diff --git a/src/app/main_bonus.c b/src/app/main_bonus.c index 5d112a9..4de3a02 100644 --- a/src/app/main_bonus.c +++ b/src/app/main_bonus.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/08 18:59:33 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 19:09:47 by maiboyer ### ########.fr */ +/* Updated: 2024/02/15 17:47:33 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,10 +81,9 @@ int main_checker(t_i32 argc, t_str argv[]) bool err; (void)(argc--, argv++); + s.buf = ""; err = false; state = parses_arguments(argc, argv); - if (state.stack_a.len == 0) - return (free_state(state), 0); while (!err) { s = get_next_line(0, &err); @@ -95,7 +94,7 @@ int main_checker(t_i32 argc, t_str argv[]) if (s.buf[0] == '\0') continue ; if (handle_operation(s, &state)) - return (me_printf("Error\n"), str_free(s), free_state(state), 1); + return (me_printf("KO\n"), str_free(s), free_state(state), 1); if (s.buf != NULL) str_free(s); } diff --git a/src/buffered_str/mod.c b/src/buffered_str/mod.c deleted file mode 100644 index f408679..0000000 --- a/src/buffered_str/mod.c +++ /dev/null @@ -1,82 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mod.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */ -/* Updated: 2023/12/26 19:54:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/buffered_str/buf_str.h" -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_set_zero.h" -#include "me/string/str_l_cat.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include "me/types.h" -#include - -bool push_str_buffer(t_buffer_str *buf, t_const_str to_push) -{ - t_usize to_push_len; - t_str temp_buffer; - t_usize new_capacity; - - if (buf == NULL || to_push == NULL) - return (true); - to_push_len = str_len(to_push); - while (buf->len + to_push_len + 2 > buf->capacity) - { - new_capacity = (buf->capacity * 3) / 2 + 1; - temp_buffer = mem_alloc(new_capacity); - if (temp_buffer == NULL) - return (true); - str_l_copy(temp_buffer, buf->buf, new_capacity); - free(buf->buf); - buf->buf = temp_buffer; - buf->capacity = new_capacity; - } - buf->len += to_push_len; - str_l_cat(buf->buf, to_push, buf->capacity); - return (false); -} - -bool push_str_char(t_buffer_str *buf, char to_push) -{ - char push_str[2]; - - push_str[0] = to_push; - push_str[1] = 0; - return (push_str_buffer(buf, push_str)); -} - -void str_clear(t_buffer_str *buf) -{ - mem_set_zero(buf->buf, buf->capacity); - buf->len = 0; - return ; -} - -t_buffer_str alloc_new_buffer(t_usize capacity) -{ - t_buffer_str out; - t_str buf; - - if (capacity == 0) - capacity = 16; - buf = mem_alloc(sizeof(char) * capacity); - if (buf == NULL) - { - out.buf = NULL; - out.capacity = 0; - out.len = 0; - return (out); - } - out.buf = buf; - out.capacity = capacity; - out.len = 0; - return (out); -} diff --git a/src/char/isalnum.c b/src/char/isalnum.c deleted file mode 100644 index c4ebcfc..0000000 --- a/src/char/isalnum.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isalnum.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/11/09 19:38:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isalnum.h" -#include "me/char/isalpha.h" -#include "me/char/isdigit.h" - -bool me_isalnum(char chr) -{ - return (me_isalpha(chr) || me_isdigit(chr)); -} diff --git a/src/char/isalpha.c b/src/char/isalpha.c deleted file mode 100644 index bffddf0..0000000 --- a/src/char/isalpha.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/11/08 04:01:25 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isalpha.h" - -bool me_isalpha(char chr) -{ - return (('z' >= chr && chr >= 'a') || ('Z' >= chr && chr >= 'A')); -} diff --git a/src/char/isascii.c b/src/char/isascii.c deleted file mode 100644 index 208a84f..0000000 --- a/src/char/isascii.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 17:51:01 by maiboyer #+# #+# */ -/* Updated: 2023/11/09 18:25:14 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isascii.h" - -bool me_isascii(char chr) -{ - return (0 <= chr && chr <= 127); -} diff --git a/src/char/isdigit.c b/src/char/isdigit.c deleted file mode 100644 index f75d219..0000000 --- a/src/char/isdigit.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/11/04 16:59:06 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isdigit.h" - -bool me_isdigit(char chr) -{ - return (chr >= '0' && chr <= '9'); -} diff --git a/src/char/islower.c b/src/char/islower.c deleted file mode 100644 index 384e88c..0000000 --- a/src/char/islower.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* islower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/11/04 16:58:56 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/islower.h" - -bool me_islower(char chr) -{ - return (chr >= 'a' && chr <= 'z'); -} diff --git a/src/char/isprint.c b/src/char/isprint.c deleted file mode 100644 index f45c9ee..0000000 --- a/src/char/isprint.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/11/04 16:42:38 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isprint.h" - -bool me_isprint(char chr) -{ - return (chr >= ' ' && chr <= '~'); -} diff --git a/src/char/isspace.c b/src/char/isspace.c deleted file mode 100644 index 1757f34..0000000 --- a/src/char/isspace.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isspace.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 14:26:25 by maiboyer #+# #+# */ -/* Updated: 2023/11/08 02:39:24 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isspace.h" - -bool me_isspace(char chr) -{ - return (chr == ' ' || chr == '\f' || chr == '\n' || chr == '\r' - || chr == '\t' || chr == '\v'); -} diff --git a/src/char/isupper.c b/src/char/isupper.c deleted file mode 100644 index 405cb09..0000000 --- a/src/char/isupper.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */ -/* Updated: 2023/11/08 04:01:59 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isupper.h" - -bool me_isupper(char chr) -{ - return ('Z' >= chr && chr >= 'A'); -} diff --git a/src/char/tolower.c b/src/char/tolower.c deleted file mode 100644 index 4ee817c..0000000 --- a/src/char/tolower.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */ -/* Updated: 2023/11/04 16:56:03 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isupper.h" -#include "me/char/tolower.h" - -bool me_tolower(char chr) -{ - if (me_isupper(chr)) - return (chr + ('a' - 'A')); - else - return (chr); -} diff --git a/src/char/toupper.c b/src/char/toupper.c deleted file mode 100644 index 9888b7e..0000000 --- a/src/char/toupper.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */ -/* Updated: 2023/11/04 16:51:28 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/islower.h" -#include "me/char/toupper.h" - -bool me_toupper(char chr) -{ - if (me_islower(chr)) - return (chr - ('a' - 'A')); - else - return (chr); -} diff --git a/src/convert/atoi.c b/src/convert/atoi.c deleted file mode 100644 index 076e6ef..0000000 --- a/src/convert/atoi.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */ -/* Updated: 2024/01/11 15:37:28 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/isdigit.h" -#include "me/char/isspace.h" -#include "me/convert/atoi.h" - -t_i32 me_atoi(t_const_str str) -{ - t_u64 out; - t_u64 sign; - t_usize i; - - out = 0; - i = 0; - sign = 1; - while (me_isspace(str[i])) - i++; - if (str[i] == '+' || str[i] == '-') - if (str[i++] == '-') - sign = -1; - while (me_isdigit(str[i])) - { - out *= 10; - out += str[i] - '0'; - i++; - } - return ((t_i32)(out * sign)); -} - -t_i64 me_atoi_64(t_const_str str) -{ - t_u64 out; - t_u64 sign; - t_usize i; - - out = 0; - i = 0; - sign = 1; - while (me_isspace(str[i])) - i++; - if (str[i] == '+' || str[i] == '-') - if (str[i++] == '-') - sign = -1; - while (me_isdigit(str[i])) - { - out *= 10; - out += str[i] - '0'; - i++; - } - return ((t_i64)(out * sign)); -} diff --git a/src/convert/itoa.c b/src/convert/itoa.c deleted file mode 100644 index 426d84c..0000000 --- a/src/convert/itoa.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */ -/* Updated: 2023/11/10 14:56:42 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/convert/itoa.h" -#include "me/mem/mem_set.h" -#include "me/string/str_clone.h" -#include - -static void me_itoa_inner(t_u64 nb, t_str out) -{ - t_i32 modulus; - bool need_print; - char c; - t_usize idx; - - need_print = false; - modulus = 1000000000; - idx = 0; - while (modulus) - { - c = (char)(nb / modulus) + '0'; - if (c != '0' || need_print) - { - out[idx++] = c; - need_print = true; - } - nb = nb % modulus; - modulus /= 10; - } -} - -t_str me_itoa(t_i32 nb) -{ - char out[12]; - t_u64 n; - - n = (t_u64)nb; - mem_set(out, 0, 12); - if (nb < 0) - { - out[0] = '-'; - me_itoa_inner(-n, out + 1); - } - else if (nb == 0) - out[0] = '0'; - else - me_itoa_inner(n, out); - return (str_clone(out)); -} -/*R -int main(void) -{ - me_putnbr(-2147483648); - write(1, "\n", 1); - me_putnbr(0); - write(1, "\n", 1); - me_putnbr(12345); - return (0); -} -R*/ diff --git a/src/fs/close.c b/src/fs/close.c deleted file mode 100644 index 1b4ef62..0000000 --- a/src/fs/close.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* close.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 15:56:56 by maiboyer #+# #+# */ -/* Updated: 2023/12/10 19:05:48 by maix ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/close.h" -#include "me/types.h" -#include - -bool me_close(t_file file, t_i32 *error) -{ - t_i32 res; - bool out; - - res = close(file); - out = res != 0; - if (res && error != NULL) - *error = res; - return (out); -} diff --git a/src/fs/open.c b/src/fs/open.c deleted file mode 100644 index 96d6200..0000000 --- a/src/fs/open.c +++ /dev/null @@ -1,60 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* open.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */ -/* Updated: 2024/01/06 18:19:11 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/open.h" -#include - -t_error me_open(t_const_str path, bool read, bool write, t_file *file_out) -{ - t_file out; - int flags; - - flags = 0; - if (read && write) - flags = O_RDWR; - else if (read) - flags = O_RDONLY; - else if (write) - flags = O_WRONLY; - out = open(path, flags, 0666); - if (out < 0) - return (ERROR); - *file_out = out; - return (NO_ERROR); -} - -t_error me_open_truncate(t_const_str path, t_file *file_out) -{ - t_file out; - int flags; - - unlink(path); - flags = O_WRONLY | O_CREAT | O_TRUNC; - out = open(path, flags, 0666); - if (out < 0) - return (ERROR); - *file_out = out; - return (NO_ERROR); -} - -t_error me_open_create(t_const_str path, t_file *file_out) -{ - t_file out; - int flags; - - flags = O_WRONLY | O_CREAT | O_APPEND; - out = open(path, flags, 0666); - if (out < 0) - return (ERROR); - *file_out = out; - return (NO_ERROR); -} diff --git a/src/fs/putchar_fd.c b/src/fs/putchar_fd.c deleted file mode 100644 index 2a10051..0000000 --- a/src/fs/putchar_fd.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/11/08 13:22:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/putchar_fd.h" -#include "me/fs/write.h" -#include "me/string/str_len.h" - -void me_putchar_fd(char chr, t_file file) -{ - me_write(file, (t_u8 *)&chr, 1); -} diff --git a/src/fs/putendl_fd.c b/src/fs/putendl_fd.c deleted file mode 100644 index ba94ff5..0000000 --- a/src/fs/putendl_fd.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/11/10 16:23:27 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/putstr_fd.h" -#include "me/fs/write.h" -#include "me/string/str_len.h" - -void me_putendl_fd(t_str str, t_file file) -{ - if (str == NULL) - return ; - me_write(file, (t_u8 *)str, str_len(str)); - me_write(file, (t_u8 *)"\n", 1); -} diff --git a/src/fs/putnbr_fd.c b/src/fs/putnbr_fd.c deleted file mode 100644 index 62143ad..0000000 --- a/src/fs/putnbr_fd.c +++ /dev/null @@ -1,55 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 12:45:06 by maiboyer #+# #+# */ -/* Updated: 2023/11/08 13:11:40 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/putnbr_fd.h" -#include "me/fs/write.h" -#include "me/mem/mem_set.h" - -static void me_inner(t_u64 nb, t_str out, t_usize *idx) -{ - bool need_print; - t_u64 modulus; - char c; - - modulus = 1000000000; - need_print = false; - while (modulus) - { - c = (char)(nb / modulus); - if (c != 0 || need_print) - { - out[(*idx)++] = c + '0'; - need_print = true; - } - nb = nb % modulus; - modulus /= 10; - } -} - -void me_putnbr_fd(t_i32 n, t_file file) -{ - t_usize idx; - t_u64 nb; - char out[15]; - - nb = (t_u64)n; - idx = 0; - if (nb < 0) - { - out[idx++] = '-'; - nb = -nb; - } - if (nb == 0) - out[idx++] = '0'; - me_inner(nb, out, &idx); - me_write(file, (t_u8 *)out, idx); -} diff --git a/src/fs/putstr_fd.c b/src/fs/putstr_fd.c deleted file mode 100644 index 065b490..0000000 --- a/src/fs/putstr_fd.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/11/10 16:23:44 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/putstr_fd.h" -#include "me/fs/write.h" -#include "me/string/str_len.h" - -void me_putstr_fd(t_str str, t_file file) -{ - if (str == NULL) - return ; - me_write(file, (t_u8 *)str, str_len(str)); -} diff --git a/src/fs/read.c b/src/fs/read.c deleted file mode 100644 index 6635d6b..0000000 --- a/src/fs/read.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:21:19 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:08:10 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/read.h" -#include - -t_usize me_read(t_file fd, t_u8 *buffer, t_i64 buffer_max, bool *eof_out) -{ - ssize_t out; - - out = read(fd, buffer, buffer_max); - if (out == 0 && buffer_max != 0 && eof_out != NULL) - *eof_out = true; - return (out); -} diff --git a/src/fs/read_to_vec.c b/src/fs/read_to_vec.c deleted file mode 100644 index b04f316..0000000 --- a/src/fs/read_to_vec.c +++ /dev/null @@ -1,43 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read_to_vec.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 18:38:47 by maiboyer #+# #+# */ -/* Updated: 2023/12/30 18:15:58 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/open.h" -#include "me/fs/read.h" -#include "me/mem/mem_copy.h" -#include "me/vec/vec_u8.h" - -#define READ_BUFFER_SIZE 4096 - -bool read_to_vec(t_const_str path, t_vec_u8 *out) -{ - t_u8 temp_buffer[READ_BUFFER_SIZE]; - t_isize read_amount; - t_file f; - bool eof; - t_usize current_size; - - eof = false; - current_size = 0; - if (out == NULL || me_open(path, true, false, &f)) - return (true); - *out = vec_u8_new(READ_BUFFER_SIZE, NULL); - while (!eof) - { - read_amount = me_read(f, temp_buffer, READ_BUFFER_SIZE, &eof); - if (read_amount < 0) - return (true); - vec_u8_reserve(out, current_size + (t_usize)read_amount); - mem_copy(&out->buffer[out->len], temp_buffer, (t_usize)read_amount); - out->len += (t_usize)read_amount; - } - return (false); -} diff --git a/src/fs/write.c b/src/fs/write.c deleted file mode 100644 index a51e5fe..0000000 --- a/src/fs/write.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* write.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:27:33 by maiboyer #+# #+# */ -/* Updated: 2023/11/03 15:44:38 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/write.h" -#include - -bool me_write(t_file fd, t_u8 *buffer, t_i64 size) -{ - return (write(fd, buffer, size) < 0); -} diff --git a/src/gnl/get_next_line.c b/src/gnl/get_next_line.c deleted file mode 100644 index 74ec66f..0000000 --- a/src/gnl/get_next_line.c +++ /dev/null @@ -1,128 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/23 17:38:21 by maix #+# #+# */ -/* Updated: 2023/12/11 19:10:26 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/buffered_str/buf_str.h" -#include "me/gnl/gnl.h" -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_move.h" -#include "me/string/str_len.h" -#include "me/types.h" -#include -#include -#include - -static t_static_buffer *get_next_line_buffer(t_file fd) -{ - t_usize index; - static t_static_buffer bufs[BUFFER_LENGTH] = {0}; - - index = 0; - while (index < BUFFER_LENGTH && (bufs[index].fd != fd && bufs[index].used)) - index++; - if (index == BUFFER_LENGTH) - return (NULL); - bufs[index].fd = fd; - bufs[index].used = true; - return (&bufs[index]); -} - -static bool copy_next_line_into_buffer(t_file fd, t_buffer_str *out, - char *temp_buffer, t_usize amount) -{ - char *buf; - char *newline; - bool got_newline; - t_usize other_part_len; - - buf = get_next_line_buffer(fd)->buf; - newline = buf; - while (*newline != '\n' && *newline && newline < buf + amount) - newline++; - got_newline = *newline == '\n'; - other_part_len = amount - (t_usize)(newline - buf + !got_newline); - if (amount < (t_usize)(newline - buf + !got_newline)) - other_part_len = 0; - mem_move(temp_buffer, buf, (t_usize)(newline - buf + got_newline)); - buf[(t_usize)(newline - buf)] = 0; - temp_buffer[(t_usize)(newline - buf + got_newline)] = 0; - mem_move(buf, newline + 1, other_part_len); - push_str_buffer(out, temp_buffer); - buf[amount - (t_usize)(newline - buf + got_newline)] = 0; - return (got_newline); -} - -static bool read_and_copy(t_file fd, t_buffer_str *out, char *tmp, - t_copy_flags *flags) -{ - t_isize amount; - t_static_buffer *buf; - - buf = get_next_line_buffer(fd); - amount = read(fd, &buf->buf, BUFFER_SIZE); - flags->error = amount < 0; - if (flags->error) - return (true); - buf->init = true; - if ((t_isize)amount < (t_isize)BUFFER_SIZE) - { - copy_next_line_into_buffer(fd, out, tmp, (t_usize)amount); - flags->empty_read = (amount == 0 && out->len == 0); - return (true); - } - buf->buf[(t_usize)amount] = 0; - return (copy_next_line_into_buffer(fd, out, tmp, (t_usize)amount)); -} - -static bool handle_leftovers(t_file fd, char *temp_buffer, t_buffer_str *buf) -{ - t_static_buffer *static_buffer; - - static_buffer = get_next_line_buffer(fd); - if (static_buffer->init) - { - if (copy_next_line_into_buffer(fd, buf, temp_buffer, - str_len(static_buffer->buf))) - { - free(temp_buffer); - return (true); - } - } - return (false); -} - -t_buffer_str get_next_line(t_file fd, bool *error) -{ - t_buffer_str buf; - char *temp_buffer; - t_copy_flags flags; - - *error = false; - if (fd < 0 || BUFFER_SIZE <= 0) - return (*error = true, (t_buffer_str){0}); - flags = (t_copy_flags){ - .error = false, - .empty_read = false, - }; - temp_buffer = mem_alloc(sizeof(char) * (BUFFER_SIZE + 2)); - buf = alloc_new_buffer(32); - if (handle_leftovers(fd, temp_buffer, &buf)) - return (buf); - while (!read_and_copy(fd, &buf, temp_buffer, &flags) && !flags.empty_read) - ; - free(temp_buffer); - if (flags.error || flags.empty_read) - { - free(buf.buf); - return (*error = true, (t_buffer_str){0}); - } - return (buf); -} diff --git a/src/hash/hash_signed.c b/src/hash/hash_signed.c deleted file mode 100644 index 28fd330..0000000 --- a/src/hash/hash_signed.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hash_signed.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 17:26:06 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 17:27:12 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/hash/hasher.h" -#include "me/types.h" - -void hasher_write_i8(t_hasher *hasher, t_i8 n) -{ - hasher_write_bytes(hasher, (t_u8 *)&n, 1); -} - -void hasher_write_i16(t_hasher *hasher, t_i16 n) -{ - hasher_write_bytes(hasher, (t_u8 *)&n, 2); -} - -void hasher_write_i32(t_hasher *hasher, t_i32 n) -{ - hasher_write_bytes(hasher, (t_u8 *)&n, 1); -} - -void hasher_write_i64(t_hasher *hasher, t_i64 n) -{ - hasher_write_bytes(hasher, (t_u8 *)&n, 1); -} - -void hasher_write_isize(t_hasher *hasher, t_isize n) -{ - hasher_write_bytes(hasher, (t_u8 *)&n, sizeof(t_isize)); -} diff --git a/src/hash/hash_unsigned.c b/src/hash/hash_unsigned.c deleted file mode 100644 index 2e4ed86..0000000 --- a/src/hash/hash_unsigned.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hash_unsigned.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 17:25:23 by maiboyer #+# #+# */ -/* Updated: 2023/12/27 16:37:58 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/hash/hasher.h" -#include "me/types.h" - -void hasher_write_u8(t_hasher *hasher, t_u8 byte) -{ - hasher->hash_bytes(hasher->hasher, &byte, 1); -} - -void hasher_write_u16(t_hasher *hasher, t_u16 byte) -{ - hasher->hash_bytes(hasher->hasher, (t_u8 *)&byte, 2); -} - -void hasher_write_u32(t_hasher *hasher, t_u32 byte) -{ - hasher->hash_bytes(hasher->hasher, (t_u8 *)&byte, 4); -} - -void hasher_write_u64(t_hasher *hasher, t_u64 byte) -{ - hasher->hash_bytes(hasher->hasher, (t_u8 *)&byte, 8); -} diff --git a/src/hash/hasher.c b/src/hash/hasher.c deleted file mode 100644 index 8e544e1..0000000 --- a/src/hash/hasher.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hasher.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 15:58:12 by maiboyer #+# #+# */ -/* Updated: 2023/12/27 16:44:25 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/hash/hasher.h" -#include "me/types.h" - -t_u64 hasher_finish(t_hasher *hasher) -{ - return (hasher->finish(hasher->hasher)); -} - -t_u64 hasher_reset_and_finish(t_hasher *hasher) -{ - return (hasher->reset_and_finish(hasher->hasher)); -} - -void hasher_write_bytes(t_hasher *hasher, t_u8 *bytes, t_usize count) -{ - hasher->hash_bytes(hasher->hasher, bytes, count); -} diff --git a/src/hash/sip/sip13.c b/src/hash/sip/sip13.c deleted file mode 100644 index d9ab515..0000000 --- a/src/hash/sip/sip13.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* sip13.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/10 19:32:28 by maiboyer #+# #+# */ -/* Updated: 2023/12/27 16:48:13 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/hash/sip.h" -#include "me/hash/sip/sip_utils.h" -#include "me/mem/mem_alloc.h" - -t_hasher hasher_sip13_new(void) -{ - t_hasher out; - t_sip13 *inner; - - inner = mem_alloc(sizeof(t_sip13)); - inner->state = create_state_with_key(0, 0); - inner->k0 = 0; - inner->k1 = 0; - out.hasher = inner; - out.hash_bytes = (t_hash_bytes)sip13_write_bytes; - out.finish = (t_hasher_finish)sip13_finish; - out.reset_and_finish = (t_hasher_reset_and_finish)sip13_reset_and_finish; - return (out); -} diff --git a/src/hash/sip/sip_utils.c b/src/hash/sip/sip_utils.c deleted file mode 100644 index aed4a33..0000000 --- a/src/hash/sip/sip_utils.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* sip_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/10 20:02:12 by maix #+# #+# */ -/* Updated: 2023/12/11 19:09:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/hash/sip.h" -#include "me/hash/sip/sip_utils.h" -#include "me/num/u64.h" -#include "me/num/usize.h" -#include -#include - -static t_usize me_min(t_usize lhs, t_usize rhs) -{ - if (lhs < rhs) - return (lhs); - return (rhs); -} - -static t_usize handle_remaining(t_sip13 *self, t_u8 *msg, t_usize count, - bool *exit_early) -{ - t_usize needed; - - needed = 0; - *exit_early = false; - if (self->ntail != 0) - { - needed = 8 - self->ntail; - self->tail |= u64_from_bytes(msg, me_min(count, needed)) << (8 \ - * self->ntail); - if (count < needed) - { - self->ntail += count; - *exit_early = true; - return (needed); - } - else - { - self->state.v3 ^= self->tail; - compress(&self->state); - self->state.v0 ^= self->tail; - self->ntail = 0; - } - } - return (needed); -} - -t_usize read_u8_to_u64(t_u8 p[]) -{ - return (((t_u64)((p)[0])) | ((t_u64)((p)[1]) << 8) | \ - ((t_u64)((p)[2]) << 16) | ((t_u64)((p)[3]) << 24) | \ - ((t_u64)((p)[4]) << 32) | ((t_u64)((p)[5]) << 40) | \ - ((t_u64)((p)[6]) << 48) | ((t_u64)((p)[7]) << 56)); -} - -void sip13_write_bytes(t_sip13 *self, t_u8 *msg, t_usize count) -{ - bool exit_early; - t_usize needed; - t_usize left; - t_usize i; - t_u64 mi; - - self->length += count; - needed = handle_remaining(self, msg, count, &exit_early); - if (exit_early) - return ; - count = count - needed; - left = count & 0x7; - i = needed; - while (i < count - left) - { - mi = read_u8_to_u64(msg + i); - self->state.v3 ^= mi; - compress(&self->state); - self->state.v0 ^= mi; - i += 8; - } - self->tail = u64_from_7bytes(msg, i, left); - self->ntail = left; -} - -t_u64 sip13_finish(t_sip13 *self) -{ - t_sip_state state; - t_u64 b; - - state = self->state; - b = (((t_u64)self->length & 0xff) << 56) | self->tail; - state.v3 ^= b; - compress(&state); - state.v0 ^= b; - state.v2 ^= 0xff; - compress(&state); - compress(&state); - free(self); - return (state.v0 ^ state.v1 ^ state.v2 ^ state.v3); -} diff --git a/src/hash/sip/sip_utils2.c b/src/hash/sip/sip_utils2.c deleted file mode 100644 index 4575821..0000000 --- a/src/hash/sip/sip_utils2.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* sip_utils2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:29:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/27 16:52:17 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/hash/sip/sip_utils.h" -#include "me/num/usize.h" - -void compress(t_sip_state *state) -{ - state->v0 = state->v0 + state->v1; - state->v1 = usize_rotate_left(state->v1, 13); - state->v1 ^= state->v0; - state->v0 = usize_rotate_left(state->v0, 32); - state->v2 = state->v2 + state->v3; - state->v3 = usize_rotate_left(state->v3, 16); - state->v3 ^= state->v2; - state->v0 = state->v0 + state->v3; - state->v3 = usize_rotate_left(state->v3, 21); - state->v3 ^= state->v0; - state->v2 = state->v2 + state->v1; - state->v1 = usize_rotate_left(state->v1, 17); - state->v1 ^= state->v2; - state->v2 = usize_rotate_left(state->v2, 32); -} - -t_sip_state create_state_with_key(t_u64 k0, t_u64 k1) -{ - t_sip_state state; - - state = (t_sip_state){.v0 = 0, .v1 = 0, .v2 = 0, .v3 = 0}; - state.v0 = k0 ^ 0x736f6d6570736575; - state.v1 = k1 ^ 0x646f72616e646f6d; - state.v2 = k0 ^ 0x6c7967656e657261; - state.v3 = k1 ^ 0x7465646279746573; - return (state); -} - -t_u64 sip13_reset_and_finish(t_sip13 *self) -{ - t_sip_state state; - t_u64 b; - t_u64 ret; - - state = self->state; - b = (((t_u64)self->length & 0xff) << 56) | self->tail; - state.v3 ^= b; - compress(&state); - state.v0 ^= b; - state.v2 ^= 0xff; - compress(&state); - compress(&state); - ret = (state.v0 ^ state.v1 ^ state.v2 ^ state.v3); - self->length = 0; - self->state.v0 = self->k0 ^ 0x736f6d6570736575; - self->state.v1 = self->k1 ^ 0x646f72616e646f6d; - self->state.v2 = self->k0 ^ 0x6c7967656e657261; - self->state.v3 = self->k1 ^ 0x7465646279746573; - self->ntail = 0; - return (ret); -} diff --git a/src/img/qoi/qoi_decode.c b/src/img/qoi/qoi_decode.c deleted file mode 100644 index 971f8bc..0000000 --- a/src/img/qoi/qoi_decode.c +++ /dev/null @@ -1,73 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_decode.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/25 22:31:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/25 22:35:44 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/img/qoi.h" -#include "me/img/qoi/qoi_utils.h" -#include "me/img/qoi/qoi_decode.h" - -static inline void *qoi_decode_inner(t_decode_vals *vals, const t_u8 *bytes, - t_i32 channels, t_i32 size) -{ - t_u8 *pixels; - - pixels = (t_u8 *)mem_alloc(vals->px_len); - if (!pixels) - return (NULL); - mem_set_zero(vals->index, sizeof(vals->index)); - vals->px.v = 0; - vals->px.rgba.a = 255; - vals->chunks_len = size - (t_i32) sizeof(t_u8[8]); - vals->px_pos = 0; - while (vals->px_pos < vals->px_len) - { - if (vals->run > 0) - vals->run--; - else if (vals->p < vals->chunks_len) - qoi_decode_inner_inner(vals, bytes); - pixels[vals->px_pos + 0] = vals->px.rgba.r; - pixels[vals->px_pos + 1] = vals->px.rgba.g; - pixels[vals->px_pos + 2] = vals->px.rgba.b; - if (channels == 4) - pixels[vals->px_pos + 3] = vals->px.rgba.a; - vals->px_pos += channels; - } - return (pixels); -} - -void *qoi_decode(const void *data, t_i32 size, t_qoi_desc *desc, - t_i32 channels) -{ - const t_u8 *bytes; - t_decode_vals vals; - - vals.p = 0; - vals.run = 0; - if (data == NULL || desc == NULL || (channels != 0 && channels != 3 - && channels != 4) || size < QOI_HEADER_SIZE - + (t_i32) sizeof(t_u8[8])) - return (NULL); - bytes = (const t_u8 *)data; - vals.header_magic = qoi_read_32(bytes, &vals.p); - desc->width = qoi_read_32(bytes, &vals.p); - desc->height = qoi_read_32(bytes, &vals.p); - desc->channels = bytes[vals.p++]; - desc->colorspace = bytes[vals.p++]; - if (desc->width == 0 || desc->height == 0 || desc->channels < 3 - || desc->channels > 4 || desc->colorspace > 1 - || vals.header_magic != QOI_MAGIC || desc->height >= QOI_PIXELS_MAX - / desc->width) - return (NULL); - if (channels == 0) - channels = desc->channels; - vals.px_len = desc->width * desc->height * channels; - return (qoi_decode_inner(&vals, bytes, channels, size)); -} diff --git a/src/img/qoi/qoi_encode.c b/src/img/qoi/qoi_encode.c deleted file mode 100644 index 137bc96..0000000 --- a/src/img/qoi/qoi_encode.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_encode.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/25 22:38:42 by maiboyer #+# #+# */ -/* Updated: 2023/12/25 22:56:06 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/img/qoi.h" -#include "me/img/qoi/qoi_encode.h" -#include "me/img/qoi/qoi_utils.h" - -void *qoi_encode(const void *data, const t_qoi_desc *desc, t_i32 *out_len) -{ - t_encode_vals vals; - - if (data == NULL || out_len == NULL || desc == NULL || desc->width == 0 - || desc->height == 0 || desc->channels < 3 || desc->channels > 4 - || desc->colorspace > 1 || desc->height >= QOI_PIXELS_MAX / desc->width) - return (NULL); - vals = (t_encode_vals){0}; - vals.max_size = desc->width * desc->height * (desc->channels + 1) - + QOI_HEADER_SIZE + sizeof(t_u8[8]); - return (qoi_encode_inner(&vals, desc, (const t_u8 *)data, out_len)); -} diff --git a/src/img/qoi/qoi_fs.c b/src/img/qoi/qoi_fs.c deleted file mode 100644 index 9be0545..0000000 --- a/src/img/qoi/qoi_fs.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_fs.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 19:06:05 by maiboyer #+# #+# */ -/* Updated: 2023/12/24 19:18:01 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/fs/close.h" -#include "me/fs/open.h" -#include "me/fs/read_to_vec.h" -#include "me/fs/write.h" -#include "me/img/qoi.h" -#include - -t_i32 qoi_write(t_const_str filename, const void *data, - const t_qoi_desc *desc) -{ - t_file f; - void *encoded; - t_i32 size; - - if (me_open(filename, false, true, &f)) - return (0); - encoded = qoi_encode(data, desc, &size); - if (!encoded) - return (me_close(f, NULL), 0); - if (me_write(f, encoded, size)) - return (me_close(f, NULL), 0); - me_close(f, NULL); - free(encoded); - return (size); -} - -void *qoi_read(t_const_str filename, t_qoi_desc *desc, t_i32 channels) -{ - t_vec_u8 out; - void *pixels; - - if (read_to_vec(filename, &out)) - return (NULL); - pixels = qoi_decode(out.buffer, out.len, desc, channels); - vec_u8_free(out); - return (pixels); -} diff --git a/src/img/qoi/qoi_utils.c b/src/img/qoi/qoi_utils.c deleted file mode 100644 index 7eb494b..0000000 --- a/src/img/qoi/qoi_utils.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* qoi_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 19:02:03 by maiboyer #+# #+# */ -/* Updated: 2023/12/24 19:02:42 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/img/qoi/qoi_utils.h" -#include "me/types.h" - -void qoi_write_32(t_u8 *bytes, t_i32 *p, t_u32 v) -{ - bytes[(*p)++] = (0xff000000 & v) >> 24; - bytes[(*p)++] = (0x00ff0000 & v) >> 16; - bytes[(*p)++] = (0x0000ff00 & v) >> 8; - bytes[(*p)++] = (0x000000ff & v); -} - -t_u32 qoi_read_32(const t_u8 *bytes, t_i32 *p) -{ - t_u32 a; - t_u32 b; - t_u32 c; - t_u32 d; - - a = bytes[(*p)++]; - b = bytes[(*p)++]; - c = bytes[(*p)++]; - d = bytes[(*p)++]; - return (a << 24 | b << 16 | c << 8 | d); -} diff --git a/src/list/list_add_back.c b/src/list/list_add_back.c deleted file mode 100644 index 0c8bea4..0000000 --- a/src/list/list_add_back.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_add_back.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:38:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:02:42 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_add_back.h" -#include "me/list/list_get_last.h" - -void list_add_back(t_list **list, t_list *new) -{ - if (*list) - list_get_last(*list)->next = new; - else - *list = new; -} diff --git a/src/list/list_add_front.c b/src/list/list_add_front.c deleted file mode 100644 index 5b1244f..0000000 --- a/src/list/list_add_front.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_add_front.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:15:23 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:02:50 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_add_front.h" -#include "me/list/list_alloc_node.h" - -void list_add_front(t_list **lst, t_list *new) -{ - new->next = *lst; - *lst = new; -} diff --git a/src/list/list_alloc_node.c b/src/list/list_alloc_node.c deleted file mode 100644 index 7e93cdc..0000000 --- a/src/list/list_alloc_node.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_alloc_node.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 19:57:28 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:13:05 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_alloc_node.h" -#include "me/mem/mem_alloc.h" - -t_list *list_alloc_node(void *content) -{ - t_list *out; - - out = mem_alloc(sizeof(t_list) * 1); - if (out == NULL) - return (NULL); - out->content = content; - out->next = NULL; - return (out); -} diff --git a/src/list/list_free_all.c b/src/list/list_free_all.c deleted file mode 100644 index af358b9..0000000 --- a/src/list/list_free_all.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_free_all.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:35:20 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:03:34 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_free_all.h" -#include - -void list_free_all(t_list **lst, void (*del)(void *)) -{ - t_list *tmp; - - if (lst == NULL || del == NULL) - return ; - while (*lst) - { - del((*lst)->content); - tmp = *lst; - *lst = (*lst)->next; - free(tmp); - } - *lst = NULL; -} diff --git a/src/list/list_free_one.c b/src/list/list_free_one.c deleted file mode 100644 index df44299..0000000 --- a/src/list/list_free_one.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_free_one.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:30:20 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:03:42 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_free_one.h" -#include - -void list_free_one(t_list *lst, void (*del)(void *)) -{ - if (lst == NULL || del == NULL) - return ; - del(lst->content); - free(lst); -} diff --git a/src/list/list_get_last.c b/src/list/list_get_last.c deleted file mode 100644 index 789796c..0000000 --- a/src/list/list_get_last.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_get_last.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:37:08 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:03:49 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_get_last.h" - -t_list *list_get_last(t_list *list) -{ - t_list *head; - - head = list; - if (head == NULL) - return (NULL); - while (head->next) - head = head->next; - return (head); -} diff --git a/src/list/list_iter.c b/src/list/list_iter.c deleted file mode 100644 index e1d6c6e..0000000 --- a/src/list/list_iter.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_iter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:39:05 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:03:55 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_iter.h" - -void list_iter(t_list *list, void (*f)(void *)) -{ - while (list) - { - f(list->content); - list = list->next; - } -} diff --git a/src/list/list_map.c b/src/list/list_map.c deleted file mode 100644 index 0be2735..0000000 --- a/src/list/list_map.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_map.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 21:40:24 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:05:20 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_alloc_node.h" -#include "me/list/list_free_all.h" -#include "me/list/list_map.h" -#include - -t_list *list_map(t_list *lst, void *(*f)(void *), void (*del)(void *)) -{ - void *data; - t_list new; - t_list *cursor; - - new = (t_list){.next = NULL, .content = NULL}; - cursor = &new; - while (lst) - { - data = f(lst->content); - cursor->next = list_alloc_node(data); - if (cursor->next == NULL) - { - del(data); - list_free_all(&new.next, del); - return (NULL); - } - cursor = cursor->next; - lst = lst->next; - } - return (new.next); -} diff --git a/src/list/list_size.c b/src/list/list_size.c deleted file mode 100644 index 58efc4a..0000000 --- a/src/list/list_size.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_size.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 20:23:19 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:05:00 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/list/list_size.h" - -t_usize list_size(t_list *lst) -{ - t_list *head; - t_usize idx; - - head = lst; - idx = 0; - while (head) - { - head = head->next; - idx++; - } - return (idx); -} diff --git a/src/mem/mem_alloc.c b/src/mem/mem_alloc.c deleted file mode 100644 index a52c40a..0000000 --- a/src/mem/mem_alloc.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_alloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:14:11 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include - -void *mem_alloc(t_usize size) -{ - void *out; - size_t i; - - i = 0; - out = malloc(size); - while (out && i < size) - ((t_u8 *)out)[i++] = 0; - return (out); -} diff --git a/src/mem/mem_alloc_array.c b/src/mem/mem_alloc_array.c deleted file mode 100644 index b17ce7f..0000000 --- a/src/mem/mem_alloc_array.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_alloc_array.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:14:47 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_alloc_array.h" -#include - -void *mem_alloc_array(t_usize item_count, t_usize item_size) -{ - t_usize multiplied; - - multiplied = item_count * item_size; - if (multiplied == 0 || multiplied / item_count != item_size) - return (NULL); - return (mem_alloc(multiplied)); -} diff --git a/src/mem/mem_compare.c b/src/mem/mem_compare.c deleted file mode 100644 index 76d9d5b..0000000 --- a/src/mem/mem_compare.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_compare.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:00:58 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_compare.h" - -t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count) -{ - t_usize i; - t_u8 *lhs_; - t_u8 *rhs_; - - i = 0; - lhs_ = (t_u8 *)lhs; - rhs_ = (t_u8 *)rhs; - while (i < count) - { - if (lhs_[i] - rhs_[i]) - return ((t_i32)(lhs_[i] - rhs_[i])); - i++; - } - return (0); -} diff --git a/src/mem/mem_copy.c b/src/mem/mem_copy.c deleted file mode 100644 index bbd7298..0000000 --- a/src/mem/mem_copy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_copy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:01:08 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_copy.h" - -void *mem_copy(void *destination, const void *source, t_usize count) -{ - t_usize i; - t_u8 *dst; - t_u8 *src; - - i = 0; - dst = (t_u8 *)destination; - src = (t_u8 *)source; - if (dst == src) - return (destination); - while (i < count) - { - dst[i] = src[i]; - i++; - } - return (destination); -} diff --git a/src/mem/mem_find.c b/src/mem/mem_find.c deleted file mode 100644 index e38303e..0000000 --- a/src/mem/mem_find.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_find.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:01:36 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_find.h" - -void *mem_find(void *buf, t_u8 find, t_usize count) -{ - t_usize i; - t_u8 *buf_bytes; - - i = 0; - buf_bytes = (t_u8 *)buf; - while (i < count) - { - if (buf_bytes[i] == find) - return ((void *)&buf_bytes[i]); - i++; - } - return (NULL); -} diff --git a/src/mem/mem_find_bytes.c b/src/mem/mem_find_bytes.c deleted file mode 100644 index 59eb784..0000000 --- a/src/mem/mem_find_bytes.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_find_bytes.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2024/01/06 17:14:23 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_find_bytes.h" -#include "stdio.h" - -void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_len, t_usize count) -{ - t_usize i; - t_usize j; - t_u8 *buf_bytes; - - i = 0; - printf("inside\n"); - buf_bytes = (t_u8 *)buf; - while (i < count) - { - j = 0; - while (j < find_len && i + j < count) - { - if (buf_bytes[i + j] != find[j]) - break ; - j++; - } - if (j == find_len) - return ((void *)&buf_bytes[i]); - i++; - } - return (NULL); -} diff --git a/src/mem/mem_move.c b/src/mem/mem_move.c deleted file mode 100644 index 03ebde3..0000000 --- a/src/mem/mem_move.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_move.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:01:43 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_move.h" - -void *mem_move(void *destination, const void *source, t_usize count) -{ - t_usize i; - t_u8 *dst; - t_u8 *src; - - i = 0; - dst = (t_u8 *)destination; - src = (t_u8 *)source; - if (dst < src) - { - while (i < count) - { - dst[i] = src[i]; - i++; - } - } - else if (dst > src) - { - i = count; - while (i > 0) - { - i--; - dst[i] = src[i]; - } - } - return (destination); -} diff --git a/src/mem/mem_set.c b/src/mem/mem_set.c deleted file mode 100644 index 106c736..0000000 --- a/src/mem/mem_set.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_set.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:15:22 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_set.h" - -void mem_set(void *buf, t_u8 fill_by, t_usize count) -{ - t_usize i; - t_u8 *buf_bytes; - - i = 0; - buf_bytes = (t_u8 *)buf; - while (i < count) - { - buf_bytes[i] = fill_by; - i++; - } -} diff --git a/src/mem/mem_set_zero.c b/src/mem/mem_set_zero.c deleted file mode 100644 index b12e07d..0000000 --- a/src/mem/mem_set_zero.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_set_zero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 11:58:11 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 15:01:57 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_set_zero.h" - -void mem_set_zero(void *buf, t_usize count) -{ - t_u8 *buffer; - t_usize index; - - index = 0; - buffer = (t_u8 *)buf; - while (index < count) - { - buffer[index] = 0; - index++; - } -} diff --git a/src/num/u16/rotate.c b/src/num/u16/rotate.c deleted file mode 100644 index 6d1a3f8..0000000 --- a/src/num/u16/rotate.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rotate.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:08:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:13:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/num/u16.h" - -t_u16 u16_rotate_left(t_u16 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value << by) | (value >> (sizeof(value) * 8 - by))); -} - -t_u16 u16_rotate_right(t_u16 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value >> by) | (value << (sizeof(value) * 8 - by))); -} diff --git a/src/num/u32/rotate.c b/src/num/u32/rotate.c deleted file mode 100644 index 2a7e5c2..0000000 --- a/src/num/u32/rotate.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rotate.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:08:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:13:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/num/u32.h" - -t_u32 u32_rotate_left(t_u32 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value << by) | (value >> (sizeof(value) * 8 - by))); -} - -t_u32 u32_rotate_right(t_u32 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value >> by) | (value << (sizeof(value) * 8 - by))); -} diff --git a/src/num/u64/from_bytes.c b/src/num/u64/from_bytes.c deleted file mode 100644 index 70b162f..0000000 --- a/src/num/u64/from_bytes.c +++ /dev/null @@ -1,57 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* from_bytes.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:30:56 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:09:52 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/num/u64.h" - -t_u64 u64_from_7bytes(t_u8 *msg, t_usize start, t_usize len) -{ - t_usize i; - t_usize out; - t_u64 temp_val; - - i = 0; - out = 0; - if (i + 3 < len) - { - temp_val = (t_u64)(msg[start + i]); - temp_val |= (t_u64)(msg[start + i + 1]) << (8 * 1); - temp_val |= (t_u64)(msg[start + i + 2]) << (8 * 2); - temp_val |= (t_u64)(msg[start + i + 3]) << (8 * 3); - out = temp_val; - i += 4; - } - if (i + 1 < len) - { - temp_val = ((t_u64)(msg[start + i + 1]) << (8 * 1)) | (t_u64)(msg[start \ - + i]); - out |= temp_val << (i * 8); - i += 2; - } - if (i++ < len) - out |= (t_u64)(msg[start + i - 1]) << ((i - 1) * 8); - return (out); -} - -t_u64 u64_from_bytes(t_u8 *bytes, t_usize len) -{ - t_u64 out; - t_usize i; - - i = 0; - out = 0; - while (i < len && i < 8) - { - out |= ((t_u64)(bytes[i])) << (8 * i); - i++; - } - return (out); -} diff --git a/src/num/u64/rotate.c b/src/num/u64/rotate.c deleted file mode 100644 index 561d553..0000000 --- a/src/num/u64/rotate.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rotate.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:08:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:24:16 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/num/u64.h" - -t_u64 u64_rotate_left(t_u64 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value << by) | (value >> (sizeof(value) * 8 - by))); -} - -t_u64 u64_rotate_right(t_u64 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value >> by) | (value << (sizeof(value) * 8 - by))); -} diff --git a/src/num/u8/rotate.c b/src/num/u8/rotate.c deleted file mode 100644 index 45f0fd8..0000000 --- a/src/num/u8/rotate.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rotate.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:08:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:13:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/num/u8.h" - -t_u8 u8_rotate_left(t_u8 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value << by) | (value >> (sizeof(value) * 8 - by))); -} - -t_u8 u8_rotate_right(t_u8 value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value >> by) | (value << (sizeof(value) * 8 - by))); -} diff --git a/src/num/usize/rotate.c b/src/num/usize/rotate.c deleted file mode 100644 index 7ad365d..0000000 --- a/src/num/usize/rotate.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rotate.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 14:08:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 14:13:32 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/num/usize.h" - -t_usize usize_rotate_left(t_usize value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value << by) | (value >> (sizeof(value) * 8 - by))); -} - -t_usize usize_rotate_right(t_usize value, t_usize by) -{ - by &= sizeof(value) * 8 - 1; - if (by == 0) - return (value); - return ((value >> by) | (value << (sizeof(value) * 8 - by))); -} diff --git a/src/printf/formatter/char.c b/src/printf/formatter/char.c deleted file mode 100644 index dcbe742..0000000 --- a/src/printf/formatter/char.c +++ /dev/null @@ -1,70 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* char.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/18 18:12:11 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:18:48 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_set.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/string/str_len.h" -#include "me/string/str_substring.h" -#include - -void printf_c(t_printf_arg data, t_printf_func f) -{ - char value[2]; - t_str start_num; - - value[0] = *(char *)data.argument; - value[1] = 0; - start_num = &value[0]; - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .len = 1, .pretty = "", .pretty_len = 0, \ -.str = start_num, .allow_zero_fill = false, .sign = NULL, \ -.sign_len = 0, }, data, f); -} - -t_usize printf_s_inner(t_str *value, t_printf_arg *data, t_printf_func *f) -{ - t_usize len; - - if (*value == NULL) - { - if (data->flags & (PRECISION) && data->extra.precision < 6) - *value = ""; - else - *value = "(null)"; - } - len = str_len(*value); - if (data->flags & (PRECISION) && len > data->extra.precision) - len = data->extra.precision; - if (data->flags & (PRECISION) && len < data->extra.precision) - data->extra.precision = len; - (void)(f); - return (len); -} - -void printf_s(t_printf_arg data, t_printf_func f) -{ - t_str value; - t_str start_num; - t_usize len; - - value = (t_str)data.argument; - len = printf_s_inner(&value, &data, &f); - start_num = str_substring(value, 0, len); - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .len = len, .pretty = "", .pretty_len = 0, \ -.str = start_num, .allow_zero_fill = false, .sign = NULL, \ -.sign_len = 0, }, data, f); - free(start_num); -} diff --git a/src/printf/formatter/decimal.c b/src/printf/formatter/decimal.c deleted file mode 100644 index b99b5e3..0000000 --- a/src/printf/formatter/decimal.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* decimal.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/18 01:44:35 by maix #+# #+# */ -/* Updated: 2023/12/11 19:19:27 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_set.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/string/str_clone.h" -#include "me/string/str_len.h" -#include -#include -#define INT_INLINE_BUF 21 - -static void itoa_inner(t_u64 nb, t_str out) -{ - t_u64 modulus; - bool need_print; - char c; - t_usize idx; - - need_print = false; - modulus = 1000000000000000000; - idx = 0; - while (modulus) - { - c = (char)(nb / modulus) + '0'; - if (c != '0' || need_print) - { - out[idx++] = c; - need_print = true; - } - nb = nb % modulus; - modulus /= 10; - } -} - -static t_str itoa_64(t_i64 nb) -{ - char out[INT_INLINE_BUF]; - t_u64 n; - - n = (t_u64)nb; - mem_set(out, 0, INT_INLINE_BUF); - if (nb < 0) - itoa_inner(-n, out); - else if (nb == 0) - out[0] = '0'; - else - itoa_inner(n, out); - return (str_clone(out)); -} - -void printf_d(t_printf_arg data, t_printf_func f) -{ - t_u64 value; - t_str start_num; - t_str sign; - t_str void_write; - - value = *(t_i64 *)data.argument; - if ((t_u64)value & ((t_u64)1 << 31)) - sign = "-"; - else - sign = "+"; - if (!(data.flags & SIGN) && !((t_u64)value & ((t_u64)1 << 31))) - sign = ""; - if (!(data.flags & SIGN) && data.extra.space_align - && !((t_u64)value & ((t_u64)1 << 31))) - sign = " "; - data.flags |= SIGN; - start_num = itoa_64(value); - handle_weird_precision_stuff(&data, (t_prec_strs){.out = &start_num, - .free_out = true, .pretty = &void_write}, value); - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .sign = sign, .pretty = NULL, .len = \ -str_len(start_num), .pretty_len = 0, .str = start_num, .allow_zero_fill \ - = true, .sign_len = str_len(sign), }, data, f); - free(start_num); -} diff --git a/src/printf/formatter/hex.c b/src/printf/formatter/hex.c deleted file mode 100644 index 9e91150..0000000 --- a/src/printf/formatter/hex.c +++ /dev/null @@ -1,67 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hex.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:16:16 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:19:03 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_set.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/string/str_len.h" -#define HEX_INLINE_BUF 17 - -static void fill_hex(t_str out_buf, t_u64 num, t_const_str base) -{ - t_usize i; - - mem_set(out_buf, 0, HEX_INLINE_BUF); - out_buf[HEX_INLINE_BUF - 1] = 0; - i = 0; - while (i < HEX_INLINE_BUF - 1) - { - out_buf[HEX_INLINE_BUF - i - 2] = base[(num >> (4 * i) & 15)]; - i++; - } -} - -static void printf_x_common(t_printf_arg data, t_printf_func f, - t_const_str pretty, t_const_str base) -{ - t_u64 value; - char inline_buffer[HEX_INLINE_BUF]; - t_str start_num; - - value = *(t_u64 *)data.argument; - inline_buffer[0] = '0'; - inline_buffer[1] = '\0'; - if (value) - fill_hex(inline_buffer, value, base); - start_num = &inline_buffer[0]; - while (start_num[1] != '\0' && start_num[0] == '0') - start_num++; - if (value == 0) - data.extra.pretty = false; - handle_weird_precision_stuff(&data, (t_prec_strs){.out = &start_num, - .free_out = false, .pretty = (t_str *)&pretty}, value); - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .len = str_len(start_num), .pretty = (t_str)pretty, \ -.pretty_len = 2, .str = start_num, .allow_zero_fill = true, .sign = NULL, \ -.sign_len = 0, }, data, f); -} - -void printf_x_up(t_printf_arg data, t_printf_func f) -{ - printf_x_common(data, f, "0X", "0123456789ABCDEF"); -} - -void printf_x_low(t_printf_arg data, t_printf_func f) -{ - printf_x_common(data, f, "0x", "0123456789abcdef"); -} diff --git a/src/printf/formatter/oct.c b/src/printf/formatter/oct.c deleted file mode 100644 index a6befc2..0000000 --- a/src/printf/formatter/oct.c +++ /dev/null @@ -1,60 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* oct.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/18 01:19:18 by maix #+# #+# */ -/* Updated: 2023/12/11 19:17:23 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_set.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/string/str_len.h" -#include -#define OCT_INLINE_BUF 23 - -static void fill_oct(t_str out_buf, t_u64 num, t_str base) -{ - t_usize i; - - mem_set(out_buf, 0, OCT_INLINE_BUF); - out_buf[OCT_INLINE_BUF - 1] = 0; - i = 0; - while (i < OCT_INLINE_BUF - 1) - { - out_buf[OCT_INLINE_BUF - i - 2] = base[(num >> (3 * i) & 7)]; - i++; - } -} - -void printf_o(t_printf_arg data, t_printf_func f) -{ - t_u64 value; - char inline_buffer[OCT_INLINE_BUF]; - t_str start_num; - t_str pretty; - - value = *(t_u64 *)data.argument; - inline_buffer[0] = '0'; - inline_buffer[1] = '\0'; - pretty = "0o"; - if (value) - fill_oct(inline_buffer, value, "01234567"); - start_num = &inline_buffer[0]; - while (start_num[1] != '\0' && start_num[0] == '0') - start_num++; - if (!value && data.extra.precision == 0 && (data.flags & PRECISION)) - { - start_num = ""; - pretty = ""; - } - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .len = str_len(start_num), .pretty = pretty, \ -.pretty_len = str_len(pretty), .str = start_num, .allow_zero_fill = true, \ -.sign = NULL, .sign_len = 0, }, data, f); -} diff --git a/src/printf/formatter/ptr.c b/src/printf/formatter/ptr.c deleted file mode 100644 index 9f169eb..0000000 --- a/src/printf/formatter/ptr.c +++ /dev/null @@ -1,74 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ptr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:16:16 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:20:42 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_set.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/string/str_len.h" -#define PTR_INLINE_BUF 17 - -static void fill_hex(t_str out_buf, t_u64 num, t_str base) -{ - t_usize i; - - mem_set(out_buf, 0, PTR_INLINE_BUF); - out_buf[PTR_INLINE_BUF - 1] = 0; - i = 0; - while (i < PTR_INLINE_BUF - 1) - { - out_buf[PTR_INLINE_BUF - i - 2] = base[(num >> (4 * i) & 15)]; - i++; - } -} - -static void set_values_for_nil(t_usize value, t_str *out, t_printf_arg *data, - t_printf_func f) -{ - (void)(f); - if (value) - { - data->flags &= ~PRECISION; - data->extra.precision = 0; - data->extra.pretty = true; - } - else - { - *out = "(nil)"; - data->extra.precision = 0; - data->extra.pretty = false; - data->flags &= ~(ZERO_ALIGN | PRECISION); - data->flags |= ALIGN; - } -} - -void printf_p(t_printf_arg data, t_printf_func f) -{ - t_u64 value; - char inline_buffer[PTR_INLINE_BUF + 1]; - t_str start_num; - - value = (t_u64)data.argument; - inline_buffer[0] = '0'; - inline_buffer[1] = '\0'; - if (value) - fill_hex(inline_buffer, value, "0123456789abcdef"); - start_num = &inline_buffer[0]; - inline_buffer[PTR_INLINE_BUF] = 0; - while (start_num[1] != '\0' && start_num[0] == '0') - start_num++; - set_values_for_nil(value, &start_num, &data, f); - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .len = str_len(start_num), .pretty = "0x", \ -.pretty_len = 2, .str = start_num, .allow_zero_fill = value != 0, \ -.sign = NULL, .sign_len = 0, }, data, f); -} diff --git a/src/printf/formatter/unsigned_decimal.c b/src/printf/formatter/unsigned_decimal.c deleted file mode 100644 index 5d44f4e..0000000 --- a/src/printf/formatter/unsigned_decimal.c +++ /dev/null @@ -1,76 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* unsigned_decimal.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maix +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/18 01:44:35 by maix #+# #+# */ -/* Updated: 2023/12/11 19:19:59 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_set.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/string/str_clone.h" -#include "me/string/str_len.h" -#include -#include -#define UINT_INLINE_BUF 21 - -static void itoa_inner(t_u64 nb, t_str out) -{ - t_u64 modulus; - bool need_print; - char c; - t_usize idx; - - need_print = false; - modulus = 10000000000000000000u; - idx = 0; - while (modulus) - { - c = (char)(nb / modulus) + '0'; - if (c != '0' || need_print) - { - out[idx++] = c; - need_print = true; - } - nb = nb % modulus; - modulus /= 10; - } -} - -static t_str itoa_u64(t_u64 nb) -{ - char out[UINT_INLINE_BUF]; - t_u64 n; - - n = (t_u64)nb; - mem_set(out, 0, UINT_INLINE_BUF); - if (nb == 0) - out[0] = '0'; - else - itoa_inner(n, out); - return (str_clone(out)); -} - -void printf_u(t_printf_arg data, t_printf_func f) -{ - t_u64 value; - t_str start_num; - t_str void_write; - - value = *(t_u64 *)data.argument; - start_num = itoa_u64(value); - handle_weird_precision_stuff(&data, (t_prec_strs){.out = &start_num, - .free_out = true, .pretty = &void_write}, value); - pad_and_stuff( - (t_pad_and_stuff_args){\ -.fill_zero = 0, .fill = 0, .len = str_len(start_num), \ -.pretty = NULL, .pretty_len = 0, .str = start_num, \ -.allow_zero_fill = true, .sign = NULL, .sign_len = 0, }, data, f); - free(start_num); -} diff --git a/src/printf/formatter/utils.c b/src/printf/formatter/utils.c deleted file mode 100644 index f8dd664..0000000 --- a/src/printf/formatter/utils.c +++ /dev/null @@ -1,136 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */ -/* Updated: 2023/12/01 21:20:07 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/buffered_str/buf_str.h" -#include "me/convert/atoi.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/matchers/matchers.h" -#include "me/printf/printf.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_substring.h" -#include "me/types.h" -#include -#include - -bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx, t_usize *nxt, - t_printf_arg *c_arg) -{ - t_i32 atoi_res; - - atoi_res = me_atoi(&fmt[*c_idx]); - if (atoi_res < 0) - { - *c_idx = *nxt; - *nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt); - return (false); - } - advance_atoi(fmt, c_idx); - c_arg->extra.align = (t_u64)atoi_res; - handle_prec_and_align(fmt, c_idx, c_arg); - atoi_res = atoi(&fmt[*c_idx]); - if (atoi_res < 0) - { - *c_idx = *nxt; - *nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt); - return (false); - } - advance_atoi(fmt, c_idx); - c_arg->extra.precision = (t_u64)atoi_res; - return (true); -} - -static void set_flags_if_needed(t_const_str fmt, t_usize *c_idx, - t_printf_arg *c_arg) -{ - if (fmt[*c_idx] == ' ') - { - (*c_idx)++; - c_arg->extra.space_align = true; - } - if (fmt[*c_idx] == '#') - { - (*c_idx)++; - c_arg->extra.pretty = true; - } - if (fmt[*c_idx] == '+') - { - (*c_idx)++; - c_arg->flags |= SIGN; - } - if (fmt[*c_idx] == '-') - { - (*c_idx)++; - c_arg->extra.left_align = true; - } - if (fmt[*c_idx] == '0') - { - (*c_idx)++; - c_arg->flags |= ZERO_ALIGN; - } -} - -bool set_params(t_const_str fmt, t_usize *c_idx, t_usize *nxt, - t_printf_arg *c_arg) -{ - t_usize b_idx; - - b_idx = ~0; - while (b_idx != *c_idx) - { - b_idx = *c_idx; - set_flags_if_needed(fmt, c_idx, c_arg); - } - return (handle_atoi_stuff(fmt, c_idx, nxt, c_arg)); -} - -t_printf_arg print_substr(t_usize *c_idx, t_usize *nxt, t_const_str fmt, - t_pad_inner_args extra) -{ - t_str truc; - - truc = str_substring(fmt, *c_idx, *nxt - *c_idx); - extra.f(truc, *nxt - *c_idx, extra.p_args); - free(truc); - *c_idx = *nxt + 1; - return ((t_printf_arg){ - .p_args = extra.p_args, - .argument = extra.arguments, - }); -} - -void pad_inner(t_const_str fmt, t_usize *c_idx, t_usize *nxt, - t_pad_inner_args extra) -{ - t_printf_arg c_arg; - t_matcher *matcher; - - c_arg = print_substr(c_idx, nxt, fmt, extra); - if (fmt[*c_idx] == '%') - { - (*c_idx)++; - extra.f("%", 1, extra.p_args); - } - else - { - if (!set_params(fmt, c_idx, nxt, &c_arg)) - return (ret_reset(c_idx, nxt, fmt)); - matcher = find_matcher(fmt, extra.matchers, c_idx); - if (matcher == NULL) - return (ret_reset(c_idx, nxt, fmt)); - call_matcher(matcher, c_arg, *extra.arguments, extra.f); - } - *nxt = (t_usize)(str_find_chr(fmt + *c_idx, '%')); - if (*nxt == 0) - return (*nxt = extra.fmt_len, (void)extra.f(fmt + *c_idx, extra.fmt_len - - *c_idx, extra.p_args)); - *nxt = *nxt - (t_usize)fmt; -} diff --git a/src/printf/formatter/utils2.c b/src/printf/formatter/utils2.c deleted file mode 100644 index 1537211..0000000 --- a/src/printf/formatter/utils2.c +++ /dev/null @@ -1,96 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:00:07 by maiboyer #+# #+# */ -/* Updated: 2023/12/01 21:48:22 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/buffered_str/buf_str.h" -#include "me/char/isdigit.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include "me/types.h" - -void set_var_for_pad_and_stuff(t_pad_and_stuff_args *a, t_printf_arg *d) -{ - t_isize fill_zero; - t_isize fill; - - fill_zero = 0; - fill = 0; - if (d->flags & ZERO_ALIGN && a->len < d->extra.align) - fill_zero = d->extra.align - a->len - a->fill_zero - 2 * d->extra.pretty - - a->sign_len; - if (d->flags & PRECISION && a->len < d->extra.precision) - fill_zero = d->extra.precision - a->len; - if (d->flags & (ALIGN) && a->len < d->extra.align) - fill = d->extra.align - a->len - a->fill_zero - 2 * d->extra.pretty - - a->sign_len - fill_zero; - if (fill_zero < 0) - fill_zero = 0; - if (fill < 0) - fill = 0; - if (fill_zero < 0) - fill_zero = 0; - if (fill < 0) - fill = 0; - a->fill_zero = fill_zero; - a->fill = fill; -} - -void print_with_func(t_pad_and_stuff_args *a, t_printf_arg *d, - t_printf_func f, t_const_str t) -{ - f(t, 1, d->p_args); - if (t[0] == ' ' && t[1] == 0 && a->fill) - a->fill--; - if (t[0] == '0' && t[1] == 0 && a->fill_zero) - a->fill_zero--; -} - -void pad_and_stuff(t_pad_and_stuff_args a, t_printf_arg d, t_printf_func f) -{ - set_var_for_pad_and_stuff(&a, &d); - if (!(d.extra.left_align || d.extra.precision) && d.flags & (ZERO_ALIGN)) - { - print_sign_if_needed(a, d, f); - while (a.allow_zero_fill && a.fill_zero > 0) - print_with_func(&a, &d, f, "0"); - } - else - { - while (!(d.extra.left_align) && d.flags & (ALIGN) && a.fill > 0) - print_with_func(&a, &d, f, " "); - print_sign_if_needed(a, d, f); - if (d.extra.pretty) - f(a.pretty, a.pretty_len, d.p_args); - } - while (a.allow_zero_fill && a.fill_zero > 0) - print_with_func(&a, &d, f, "0"); - f(a.str, a.len, d.p_args); - while (d.extra.left_align && a.fill > 0) - print_with_func(&a, &d, f, " "); -} - -void handle_prec_and_align(t_const_str fmt, t_usize *c_idx, - t_printf_arg *c_arg) -{ - if (c_arg->extra.align && !(c_arg->flags & ZERO_ALIGN)) - c_arg->flags |= ALIGN; - if (fmt[*c_idx] == '.') - { - (*c_idx)++; - c_arg->flags |= PRECISION; - } -} - -void advance_atoi(t_const_str fmt, t_usize *idx) -{ - while (me_isdigit(fmt[*idx])) - (*idx)++; -} diff --git a/src/printf/formatter/utils3.c b/src/printf/formatter/utils3.c deleted file mode 100644 index 1b03f1e..0000000 --- a/src/printf/formatter/utils3.c +++ /dev/null @@ -1,53 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils3.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:06:15 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:21:38 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/printf/formatter/utils.h" -#include "me/printf/matchers/matchers.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_len.h" -#include "me/types.h" -#include - -void ret_reset(t_usize *c_idx, t_usize *nxt, t_const_str fmt) -{ - *c_idx = *nxt; - *nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt); -} - -void me_printf_str_inner(t_const_str fmt, t_printf_func f, - va_list *arguments, void *p_args) -{ - t_usize c_idx; - t_usize nxt; - t_usize fmt_len; - - c_idx = 0; - fmt_len = str_len(fmt); - nxt = (t_usize)(str_find_chr(fmt, '%')); - if (nxt == 0) - return (f(fmt, fmt_len, p_args)); - nxt = nxt - (t_usize)fmt; - while (nxt < fmt_len) - { - pad_inner(fmt, &c_idx, &nxt, \ - ((t_pad_inner_args){\ - .p_args = p_args, .fmt_len = fmt_len, .f = f, \ - .arguments = arguments, .matchers = get_matchers(), })); - } -} - -void print_sign_if_needed(t_pad_and_stuff_args a, t_printf_arg d, - t_printf_func f) -{ - if (d.flags & (SIGN) && a.sign != NULL) - f(a.sign, a.sign_len, d.p_args); -} diff --git a/src/printf/formatter/utils_numbers.c b/src/printf/formatter/utils_numbers.c deleted file mode 100644 index 58e5095..0000000 --- a/src/printf/formatter/utils_numbers.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils_numbers.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/01 21:05:47 by maiboyer #+# #+# */ -/* Updated: 2023/12/01 21:49:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/printf.h" -#include - -void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs, - t_usize value) -{ - if (!value && data->extra.precision == 0 && (data->flags & PRECISION)) - { - data->flags &= (~ZERO_ALIGN); - data->flags |= ALIGN; - if (strs.free_out) - *strs.out = (free(*strs.out), (t_str)mem_alloc_array(1, 1)); - else - *strs.out = ""; - *strs.pretty = ""; - } - else if ((data->flags & PRECISION) && !data->extra.left_align) - { - data->flags &= (~ZERO_ALIGN); - data->flags |= ALIGN; - } -} diff --git a/src/printf/matchers.c b/src/printf/matchers.c deleted file mode 100644 index d122dac..0000000 --- a/src/printf/matchers.c +++ /dev/null @@ -1,120 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* matchers.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/16 18:07:40 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 19:11:51 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_compare.h" -#include "me/printf/formatter/formatter.h" -#include "me/printf/matchers/matchers.h" -#include "me/printf/printf.h" -#include -#include -#include - -t_matcher_list *get_matchers(void) -{ - static t_matcher_list printf_matchers = (t_matcher_list){ - .data = { - {.matcher = "o", .matcher_len = 1, .arg_type = U64, .f = &printf_o}, - {.matcher = "c", .matcher_len = 1, .arg_type = CHAR, .f = &printf_c}, - {.matcher = "s", .matcher_len = 1, .arg_type = STR, .f = &printf_s}, - {.matcher = "p", .matcher_len = 1, .arg_type = VOID_PTR, .f = &printf_p}, - {.matcher = "d", .matcher_len = 1, .arg_type = I32, .f = &printf_d}, - {.matcher = "i", .matcher_len = 1, .arg_type = I32, .f = &printf_d}, - {.matcher = "u", .matcher_len = 1, .arg_type = U32, .f = &printf_u}, - {.matcher = "x", .matcher_len = 1, .arg_type = U32, .f = &printf_x_low}, - {.matcher = "X", .matcher_len = 1, .arg_type = U32, .f = &printf_x_up}, - }, - .next = NULL, - }; - - return (&printf_matchers); -} - -bool insert_matcher(t_matcher matcher) -{ - t_matcher_list *matchers; - t_usize i; - - matchers = get_matchers(); - while (matchers) - { - i = 0; - while (i < PRINTF_BUFFER_CHUNK) - { - if (matchers->data[i].f == NULL) - { - (*matchers).data[i] = matcher; - return (true); - } - } - matchers->next = malloc(sizeof(t_matcher_list) * 1); - } - return (false); -} - -t_matcher *find_matcher(t_const_str fmt, t_matcher_list *matchers, - t_usize *c_idx) -{ - t_usize matcher_index; - t_matcher *matcher; - - while (matchers) - { - matcher_index = 0; - while (matcher_index < PRINTF_BUFFER_CHUNK) - { - matcher = &matchers->data[matcher_index]; - if (matcher->f) - { - if (!mem_compare(&fmt[*c_idx], matcher->matcher, - matcher->matcher_len)) - { - *c_idx += matcher->matcher_len; - return (matcher); - } - } - matcher_index++; - } - matchers = matchers->next; - } - return (NULL); -} - -// FIGURE OUT HOW TO MAKE I64 WORK -void call_matcher(t_matcher *matcher, t_printf_arg matcher_arguments, - va_list args, t_printf_func f) -{ - t_matcher_tmp_val vals; - - matcher_arguments.argument = NULL; - if (matcher->arg_type == CHAR) - { - vals.chr_val = (char)va_arg(args, int); - matcher_arguments.argument = (void *)&vals.chr_val; - } - if (matcher->arg_type == U32) - vals.u64_val = va_arg(args, t_u32); - if (matcher->arg_type == U64) - vals.u64_val = va_arg(args, t_u64); - if (matcher->arg_type == I64) - vals.i64_val = va_arg(args, t_i64); - if (matcher->arg_type == I32) - vals.i64_val = va_arg(args, t_i32); - if (matcher->arg_type == I32 || matcher->arg_type == I64) - matcher_arguments.argument = (void *)&vals.i64_val; - if (matcher->arg_type == U32 || matcher->arg_type == U64) - matcher_arguments.argument = (void *)&vals.u64_val; - if (matcher->arg_type == VOID_PTR) - matcher_arguments.argument = (void *)va_arg(args, void *); - if (matcher->arg_type == STR) - matcher_arguments.argument = (void *)va_arg(args, t_str); - matcher->f(matcher_arguments, f); -} diff --git a/src/printf/printf.c b/src/printf/printf.c deleted file mode 100644 index 935b3cd..0000000 --- a/src/printf/printf.c +++ /dev/null @@ -1,120 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* printf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/11 17:50:56 by maiboyer #+# #+# */ -/* Updated: 2024/02/09 14:58:10 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/buffered_str/buf_str.h" -#include "me/fs/write.h" -#include "me/printf/formatter/formatter.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/matchers/matchers.h" -#include "me/printf/printf.h" -#include "me/string/str_len.h" -#include "me/types.h" -#include -#include -#include -#include - -// p_args is an t_buffer_str; -static void me_printf_add_to_string(t_const_str to_write, t_usize to_write_len, - void *p_args) -{ - t_buffer_str *out_buf; - - out_buf = (t_buffer_str *)p_args; - (void)(to_write_len); - push_str_buffer(out_buf, to_write); -} - -t_str me_printf_str(t_const_str fmt, va_list *arguments) -{ - t_buffer_str out; - - out = alloc_new_buffer(str_len(fmt)); - if (out.buf == NULL) - { - return (NULL); - } - me_printf_str_inner(fmt, &me_printf_add_to_string, arguments, (void *)&out); - return (out.buf); -} - -void me_printf_write(t_const_str to_write, t_usize to_write_len, - void *p_args) -{ - t_fprintf_arg *arg; - - arg = (t_fprintf_arg *)p_args; - me_write(arg->fd, (t_u8 *)to_write, to_write_len); - arg->total_print += to_write_len; -} - -t_usize me_printf(t_const_str fmt, ...) -{ - va_list args; - t_fprintf_arg passthru; - - passthru = (t_fprintf_arg){ - .fd = 1, - .total_print = 0, - }; - va_start(args, fmt); - me_printf_str_inner(fmt, &me_printf_write, &args, (void *)&passthru); - va_end(args); - return (passthru.total_print); -} - -t_usize me_eprintf(t_const_str fmt, ...) -{ - va_list args; - t_fprintf_arg passthru; - - passthru = (t_fprintf_arg){ - .fd = 2, - .total_print = 0, - }; - va_start(args, fmt); - me_printf_str_inner(fmt, &me_printf_write, &args, (void *)&passthru); - va_end(args); - return (passthru.total_print); -} - -/* -t_usize me_printf(t_const_str fmt, ...) -{ - va_list args; - t_str str; - t_usize len; - - va_start(args, fmt); - str = me_printf_str(fmt, &args); - va_end(args); - len = str_len(str); - write(1, str, len); - free(str); - return (len); -} - -t_usize me_eprintf(t_const_str fmt, ...) -{ - va_list args; - t_str str; - t_usize len; - - va_start(args, fmt); - str = me_printf_str(fmt, &args); - va_end(args); - len = str_len(str); - write(2, str, len); - free(str); - return (len); -} -*/ diff --git a/src/printf/vprintf.c b/src/printf/vprintf.c deleted file mode 100644 index 6cf3bc0..0000000 --- a/src/printf/vprintf.c +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/02/09 14:57:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/09 15:00:39 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/buffered_str/buf_str.h" -#include "me/fs/write.h" -#include "me/printf/formatter/formatter.h" -#include "me/printf/formatter/utils.h" -#include "me/printf/matchers/matchers.h" -#include "me/printf/printf.h" -#include "me/string/str_len.h" -#include "me/types.h" -#include -#include -#include -#include - -void me_printf_write(t_const_str to_write, t_usize to_write_len, - void *p_args); - -t_usize me_vprintf(t_const_str fmt, va_list *args) -{ - t_fprintf_arg passthru; - - passthru = (t_fprintf_arg){ - .fd = 1, - .total_print = 0, - }; - me_printf_str_inner(fmt, &me_printf_write, args, (void *)&passthru); - return (passthru.total_print); -} - -t_usize me_veprintf(t_const_str fmt, va_list *args) -{ - t_fprintf_arg passthru; - - passthru = (t_fprintf_arg){ - .fd = 2, - .total_print = 0, - }; - me_printf_str_inner(fmt, &me_printf_write, args, (void *)&passthru); - return (passthru.total_print); -} diff --git a/src/string/str_clone.c b/src/string/str_clone.c deleted file mode 100644 index 70fd942..0000000 --- a/src/string/str_clone.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_clone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:15:57 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include "me/string/str_clone.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include - -t_str str_clone(t_const_str source) -{ - t_str res; - t_usize len; - - len = str_len(source) + 1; - res = mem_alloc(sizeof(unsigned char) * len); - if (res == NULL) - return (NULL); - str_l_copy(res, source, len); - return (res); -} diff --git a/src/string/str_find_chr.c b/src/string/str_find_chr.c deleted file mode 100644 index 565ead1..0000000 --- a/src/string/str_find_chr.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_chr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:47:43 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_find_chr.h" - -char *str_find_chr(t_const_str str, char chr) -{ - t_usize index; - - index = 0; - while (str[index]) - { - if (str[index] == chr) - return ((char *)&str[index]); - index++; - } - if (str[index] == chr) - return ((char *)&str[index]); - return (NULL); -} diff --git a/src/string/str_find_rev_chr.c b/src/string/str_find_rev_chr.c deleted file mode 100644 index 1930873..0000000 --- a/src/string/str_find_rev_chr.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_rev_chr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:47:47 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_find_rev_chr.h" -#include "me/string/str_len.h" - -char *str_find_rev_chr(t_const_str str, char chr) -{ - t_usize index; - - index = str_len((t_str)str); - while (index >= 0) - { - if (str[index] == chr) - return ((char *)&str[index]); - index--; - } - return (NULL); -} diff --git a/src/string/str_find_str.c b/src/string/str_find_str.c deleted file mode 100644 index 4afa489..0000000 --- a/src/string/str_find_str.c +++ /dev/null @@ -1,56 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:53:53 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_n_find_str.h" - -const char *str_find_str(t_const_str str, t_const_str to_find) -{ - t_str needle; - t_str haystack; - - if (*to_find == '\0') - return (str); - while (*str) - { - haystack = (t_str)str; - needle = (t_str)to_find; - while (*haystack && *haystack == *needle) - { - haystack++; - needle++; - } - if (*needle == '\0') - return (str); - str++; - } - return (NULL); -} - -/*R - -#include -#include - -int main(int argc, char *argv[]) { - if (argc != 3) - return (2); - printf("HAYSTACK = '%s'\n", argv[1]); - printf(" NEEDLE = '%s'\n", argv[2]); - - printf("libc: %p : '%s'\n", str_find_str(argv[1], argv[2]), - str_find_str(argv[1], - argv[2])); - printf(" ft : %p : '%s'\n", - str_find_str(argv[1], argv[2]), - str_find_str(argv[1], argv[2])); -} -R*/ diff --git a/src/string/str_iter.c b/src/string/str_iter.c deleted file mode 100644 index dc9abb0..0000000 --- a/src/string/str_iter.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_iter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:49:47 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_iter.h" - -void str_iter(t_str s, void (*f)(t_usize, char *)) -{ - t_usize idx; - - if (s == NULL) - return ; - idx = 0; - while (s[idx]) - { - f(idx, &s[idx]); - idx++; - } -} diff --git a/src/string/str_join.c b/src/string/str_join.c deleted file mode 100644 index 5aacfd9..0000000 --- a/src/string/str_join.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_join.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 23:02:58 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:16:19 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include "me/string/str_join.h" -#include "me/string/str_l_cat.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include - -t_str str_join(t_const_str s1, t_const_str s2) -{ - t_str out; - t_usize buf_size; - - if (s1 == NULL || s2 == NULL) - return (NULL); - buf_size = str_len(s1) + str_len(s2) + 1; - out = mem_alloc(sizeof(char) * buf_size); - if (out == NULL) - return (NULL); - str_l_copy(out, s1, buf_size); - str_l_cat(out, s2, buf_size); - return (out); -} diff --git a/src/string/str_l_cat.c b/src/string/str_l_cat.c deleted file mode 100644 index a606722..0000000 --- a/src/string/str_l_cat.c +++ /dev/null @@ -1,108 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_l_cat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:51:34 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -/*R - -//CFLAGS="-lbsd" - -#include -#include -#include - -R*/ - -#include "me/string/str_l_cat.h" -#include "me/string/str_len.h" - -t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size) -{ - t_usize dest_len; - t_usize src_len; - t_usize i; - - if (buffer_size == 0 && (dest == NULL || src == NULL)) - return (0); - dest_len = str_len(dest); - src_len = str_len(src); - if (dest_len >= buffer_size) - return (buffer_size + src_len); - i = 0; - while (src[i] && dest_len + i < buffer_size - 1) - { - dest[dest_len + i] = src[i]; - i++; - } - dest[dest_len + i] = '\0'; - return (dest_len + src_len); -} - -/*R - -#include -#include -#include - -#define SIZE 64 - -int main(void) { - char* dest_ft; - char* dest_libc; - char* to_cat = "banane"; - unsigned int res_libc = 0; - unsigned int res_ft = 0; - int i; - - for (int v = 0; v <= SIZE; v++) - for (int j = 0; j < SIZE; j++) - { - dest_ft = malloc(SIZE); - dest_libc = malloc(SIZE); - i = 0; - while (i < SIZE) - { - dest_ft[i] = 'X'; - dest_libc[i] = 'X'; - i++; - } - dest_ft[SIZE - j - 1] = 0; - dest_libc[SIZE - j - 1] = 0; - res_libc = str_l_cat(dest_libc, to_cat, SIZE - v); - res_ft = str_l_cat(dest_ft, to_cat, SIZE - v); - int k; - k = 0; - while (k < SIZE && dest_libc[k] == dest_ft[k]) - k++; - - if (strcmp(dest_ft, dest_libc) != 0 || res_ft != res_libc - || k != SIZE) - { - printf("----------v[%d]-j[%d]---------\n", v, j); - printf("libc: [%d]\t'%s'\n", res_libc ,dest_libc); - printf(" ft : [%d]\t'%s'\n", res_ft, dest_ft); - printf("[ERROR] byte %d is different: LIBC[%X] != FT[%X]\n\n", - i, - dest_libc[j], dest_ft[j]); - printf(" ft :"); - for (int x = 0; x < SIZE; x++) - printf("%02X", dest_ft[x]); - printf("\n"); - printf("libc:"); - for (int x = 0; x < SIZE; x++) - printf("%02X", dest_libc[x]); - printf("\n"); - printf("\n"); - } - free(dest_libc); - free(dest_ft); - } -} -R*/ diff --git a/src/string/str_l_copy.c b/src/string/str_l_copy.c deleted file mode 100644 index e4bb6bc..0000000 --- a/src/string/str_l_copy.c +++ /dev/null @@ -1,104 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_l_copy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:51:55 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -/*R - -//CFLAGS="-lbsd" - -#include -#include -#include - -R*/ - -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" - -t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size) -{ - t_usize src_len; - t_usize i; - - src_len = str_len(src); - i = 0; - if (buffer_size == 0) - return (src_len); - while (src[i] && i < buffer_size - 1) - { - dest[i] = src[i]; - i++; - } - dest[i] = '\0'; - return (src_len); -} - -/*R - -#include -#include -#include - -#define SIZE 64 - -int main(void) { - char* dest_ft; - char* dest_libc; - char* to_cat = "banane"; - unsigned int res_libc = 0; - unsigned int res_ft = 0; - int i; - - for (int v = 0; v <= SIZE; v++) - for (int j = 0; j < SIZE; j++) - { - dest_ft = malloc(SIZE); - dest_libc = malloc(SIZE); - i = 0; - while (i < SIZE) - { - dest_ft[i] = 'X'; - dest_libc[i] = 'X'; - i++; - } - dest_ft[SIZE - j - 1] = 0; - dest_libc[SIZE - j - 1] = 0; - res_libc = str_l_cat(dest_libc, to_cat, SIZE - v); - res_ft = str_l_cat(dest_ft, to_cat, SIZE - v); - int k; - k = 0; - while (k < SIZE && dest_libc[k] == dest_ft[k]) - k++; - - if (strcmp(dest_ft, dest_libc) != 0 || res_ft != res_libc - || k != SIZE) - { - printf("----------v[%d]-j[%d]---------\n", v, j); - printf("libc: [%d]\t'%s'\n", res_libc ,dest_libc); - printf(" ft : [%d]\t'%s'\n", res_ft, dest_ft); - printf("[ERROR] byte %d is different: LIBC[%X] != FT[%X]\n\n", - i, - dest_libc[j], dest_ft[j]); - printf(" ft :"); - for (int x = 0; x < SIZE; x++) - printf("%02X", dest_ft[x]); - printf("\n"); - printf("libc:"); - for (int x = 0; x < SIZE; x++) - printf("%02X", dest_libc[x]); - printf("\n"); - printf("\n"); - } - free(dest_libc); - free(dest_ft); - } -} -R*/ diff --git a/src/string/str_len.c b/src/string/str_len.c deleted file mode 100644 index 1feb088..0000000 --- a/src/string/str_len.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_len.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 17:07:41 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:52:13 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_len.h" - -t_usize str_len(t_const_str str) -{ - t_usize out; - - out = 0; - while (str[out]) - out++; - return (out); -} diff --git a/src/string/str_map.c b/src/string/str_map.c deleted file mode 100644 index 2e65a86..0000000 --- a/src/string/str_map.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_map.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:52:34 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_clone.h" -#include "me/string/str_map.h" - -t_str str_map(t_const_str s, char (*f)(t_usize, char)) -{ - t_str out; - t_usize idx; - - if (f == NULL || s == NULL) - return (NULL); - out = str_clone((t_str)s); - if (out == NULL) - return (NULL); - idx = 0; - while (s[idx]) - { - out[idx] = f(idx, s[idx]); - idx++; - } - return (out); -} diff --git a/src/string/str_n_compare.c b/src/string/str_n_compare.c deleted file mode 100644 index 5c39ac5..0000000 --- a/src/string/str_n_compare.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_n_compare.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 14:52:48 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_n_compare.h" - -// PLEASE FIX THIS FUNCTION IF NEEDED ! -t_i32 str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n) -{ - t_usize index; - - index = 0; - if (n == 0) - return (0); - while (lhs[index] && rhs[index] && lhs[index] == rhs[index] && index < n - - 1) - index++; - return ((t_i32)(t_u8)lhs[index] - (t_i32)(t_u8)rhs[index]); -} diff --git a/src/string/str_n_find_str.c b/src/string/str_n_find_str.c deleted file mode 100644 index 321af97..0000000 --- a/src/string/str_n_find_str.c +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_n_find_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:53:21 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/string/str_len.h" -#include "me/string/str_n_find_str.h" - -static t_str local_get_end_of_search(t_usize len, t_str str) -{ - t_usize out_len; - - out_len = str_len(str); - if (len > out_len) - len = out_len; - return (str + len); -} - -const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len) -{ - t_str needle; - t_str haystack; - t_str end_of_search; - - if ((str == NULL || to_find == NULL) && len == 0) - return (NULL); - if (*to_find == '\0') - return ((t_str)str); - end_of_search = local_get_end_of_search(len, (t_str)str); - while (*str) - { - haystack = (t_str)str; - needle = (t_str)to_find; - while (haystack < end_of_search && *haystack && *haystack == *needle) - { - haystack++; - needle++; - } - if (*needle == '\0') - return (str); - str++; - } - return (NULL); -} diff --git a/src/string/str_split.c b/src/string/str_split.c deleted file mode 100644 index d533e60..0000000 --- a/src/string/str_split.c +++ /dev/null @@ -1,93 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/17 15:56:59 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:52:08 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_alloc_array.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_split.h" -#include - -static t_usize local_count_words(t_const_str str, char chr); -static t_str *local_split_inner(t_const_str str, char chr, t_str *out); -static t_str *local_split_freeall(t_str **to_free); - -static t_usize local_count_words(t_const_str str, char chr) -{ - t_usize i; - t_usize out; - - out = 0; - i = 0; - while (str[i]) - { - while (str[i] && str[i] == chr) - i++; - if (str[i] == 0) - return (out); - out++; - while (str[i] && str[i] != chr) - i++; - } - return (out); -} - -static t_str *local_split_freeall(t_str **to_free) -{ - while (*to_free) - free(*(to_free++)); - return (NULL); -} - -static t_str *local_split_inner(t_const_str str, char chr, t_str *out) -{ - t_usize str_i; - t_usize sub_i; - t_usize ptr_i; - - str_i = 0; - ptr_i = 0; - while (str[str_i]) - { - while (str[str_i] && str[str_i] == chr) - str_i++; - if (str[str_i] == 0) - break ; - sub_i = 0; - while (str[str_i + sub_i] && str[str_i + sub_i] != chr) - sub_i++; - out[ptr_i] = mem_alloc(sizeof(char) * (sub_i + 1)); - if (out[ptr_i] == NULL) - return (local_split_freeall(&out)); - str_l_copy(out[ptr_i++], (t_str)(str + str_i), sub_i + 1); - str_i += sub_i; - } - out[ptr_i] = NULL; - return (out); -} - -t_str *str_split(t_const_str str, char chr) -{ - t_usize ptr_len; - t_str *out; - - if (str == NULL || *str == 0) - { - out = mem_alloc(sizeof(t_str) * 1); - *out = NULL; - return (out); - } - ptr_len = local_count_words(str, chr); - out = mem_alloc_array(sizeof(t_str), (ptr_len + 1)); - if (out == NULL) - return (NULL); - return (local_split_inner(str, chr, out)); -} diff --git a/src/string/str_substring.c b/src/string/str_substring.c deleted file mode 100644 index 790bd31..0000000 --- a/src/string/str_substring.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_substring.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 22:42:55 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:52:34 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include "me/string/str_substring.h" -#include - -t_str str_substring(t_const_str str, t_usize start, t_usize len) -{ - t_usize len_str; - t_usize len_str_substring; - t_str out; - - if (str == NULL) - return (NULL); - len_str = str_len(str); - if (start >= len_str) - return (mem_alloc(1)); - len_str_substring = len_str - start + 1; - if (len_str_substring > len) - len_str_substring = len + 1; - out = mem_alloc(sizeof(char) * len_str_substring); - if (out == NULL) - return (NULL); - str_l_copy(out, &str[start], len_str_substring); - return (out); -} diff --git a/src/string/str_trim.c b/src/string/str_trim.c deleted file mode 100644 index 9320f10..0000000 --- a/src/string/str_trim.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_trim.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 23:43:42 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:16:31 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include "me/string/str_trim.h" -#include - -t_str str_trim(t_const_str str, t_const_str charset) -{ - t_usize start_idx; - t_usize end_idx; - t_usize buf_size; - t_str out; - - if (str == NULL || charset == NULL) - return (0); - start_idx = 0; - while (str[start_idx] && str_find_chr((t_str)charset, - str[start_idx]) != NULL) - start_idx++; - end_idx = str_len((t_str)str); - while (end_idx > 0 && str_find_chr((t_str)charset, str[end_idx]) != NULL) - end_idx--; - buf_size = end_idx - start_idx + 2; - if (end_idx == 0) - buf_size = 1; - out = mem_alloc(sizeof(char) * buf_size); - if (out == NULL) - return (NULL); - str_l_copy(out, &((t_str)str)[start_idx], buf_size); - return (out); -} diff --git a/src/vec/vec_buf_str.c b/src/vec/vec_buf_str.c deleted file mode 100644 index 0c423f0..0000000 --- a/src/vec/vec_buf_str.c +++ /dev/null @@ -1,115 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_buf_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:33 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/types.h" -#include "me/vec/vec_buf_str.h" -#include - -t_vec_buf_str vec_buf_str_new(t_usize capacity, - t_free_buf_str_item free_function) -{ - t_vec_buf_str out; - - out = (t_vec_buf_str){0}; - out.free_func = free_function; - out.buffer = mem_alloc_array(capacity, sizeof(t_buffer_str)); - if (out.buffer) - out.capacity = capacity; - return (out); -} - -/// Return true in case of an error -t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element) -{ - t_buffer_str *temp_buffer; - size_t new_capacity; - - if (vec == NULL) - return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > new_capacity) - new_capacity = (new_capacity * 3) / 2 + 1; - temp_buffer = mem_alloc_array(new_capacity, sizeof(t_buffer_str)); - if (temp_buffer == NULL) - return (ERROR); - mem_copy(temp_buffer, vec->buffer, vec->len * sizeof(t_buffer_str)); - free(vec->buffer); - vec->buffer = temp_buffer; - vec->capacity = new_capacity; - } - vec->buffer[vec->len] = element; - vec->len += 1; - return (NO_ERROR); -} - -/// Return true in case of an error -t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity) -{ - t_buffer_str *temp_buffer; - size_t new_capacity; - - if (vec == NULL) - return (ERROR); - if (wanted_capacity > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (wanted_capacity > new_capacity) - new_capacity = (new_capacity * 3) / 2 + 1; - temp_buffer = mem_alloc_array(new_capacity, sizeof(t_buffer_str)); - if (temp_buffer == NULL) - return (ERROR); - mem_copy(temp_buffer, vec->buffer, vec->len * sizeof(t_buffer_str)); - free(vec->buffer); - vec->buffer = temp_buffer; - vec->capacity = new_capacity; - } - return (NO_ERROR); -} - -/// Return true if the vector is empty -/// This function is safe to call with value being NULL -t_error vec_buf_str_pop(t_vec_buf_str *vec, t_buffer_str *value) -{ - t_buffer_str temp_value; - t_buffer_str *ptr; - - if (vec == NULL) - return (ERROR); - ptr = value; - if (vec->len == 0) - return (ERROR); - if (value == NULL) - ptr = &temp_value; - vec->len--; - *ptr = vec->buffer[vec->len]; - mem_set_zero(&vec->buffer[vec->len], sizeof(t_buffer_str)); - return (NO_ERROR); -} - -/// This function is safe to call with `free_elem` being NULL -void vec_buf_str_free(t_vec_buf_str vec) -{ - if (vec.free_func) - { - while (vec.len) - { - vec.free_func(vec.buffer[vec.len - 1]); - vec.len--; - } - } - free(vec.buffer); -} diff --git a/src/vec/vec_buf_str_functions2.c b/src/vec/vec_buf_str_functions2.c deleted file mode 100644 index b43d83b..0000000 --- a/src/vec/vec_buf_str_functions2.c +++ /dev/null @@ -1,110 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_buf_str_functions2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:22 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/types.h" -#include "me/vec/vec_buf_str.h" -#include - -t_error vec_buf_str_find(t_vec_buf_str *vec, bool (*fn)(const t_buffer_str *), - t_usize *index) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || index == NULL) - return (ERROR); - idx = 0; - while (idx < vec->len) - { - if (fn(&vec->buffer[idx])) - { - *index = idx; - return (NO_ERROR); - } - idx++; - } - return (ERROR); -} - -t_error vec_buf_str_find_starting(t_vec_buf_str *vec, - bool (*fn)(const t_buffer_str *), t_usize starting_index, - t_usize *index) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || index == NULL) - return (ERROR); - idx = starting_index; - while (idx < vec->len) - { - if (fn(&vec->buffer[idx])) - { - *index = idx; - return (NO_ERROR); - } - idx++; - } - return (ERROR); -} - -t_error vec_buf_str_all(t_vec_buf_str *vec, bool (*fn)(const t_buffer_str *), - bool *result) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || result == NULL) - return (ERROR); - idx = 0; - *result = true; - while (*result && idx < vec->len) - { - if (!fn(&vec->buffer[idx])) - *result = false; - idx++; - } - return (ERROR); -} - -t_error vec_buf_str_any(t_vec_buf_str *vec, bool (*fn)(const t_buffer_str *), - bool *result) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || result == NULL) - return (ERROR); - idx = 0; - *result = false; - while (*result && idx < vec->len) - { - if (fn(&vec->buffer[idx])) - *result = true; - idx++; - } - return (ERROR); -} - -void vec_buf_str_iter(t_vec_buf_str *vec, void (*fn)(t_usize index, - t_buffer_str *value, void *state), void *state) -{ - t_usize idx; - - if (vec == NULL || fn == NULL) - return ; - idx = 0; - while (idx < vec->len) - { - fn(idx, &vec->buffer[idx], state); - idx++; - } -} diff --git a/src/vec/vec_buf_str_functions3.c b/src/vec/vec_buf_str_functions3.c deleted file mode 100644 index c4b7d87..0000000 --- a/src/vec/vec_buf_str_functions3.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_buf_str_functions3.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:00:26 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/types.h" -#include "me/vec/vec_buf_str.h" -#include - -t_error vec_buf_str_push_front(t_vec_buf_str *vec, t_buffer_str element) -{ - t_usize i; - - if (vec->len == 0) - return (vec_buf_str_push(vec, element)); - i = vec->len - 1; - if (vec->capacity < vec->len + 1 && vec_buf_str_reserve(vec, 3 * vec->len - / 2 + 1)) - return (ERROR); - while (i > 0) - { - vec->buffer[i + 1] = vec->buffer[i]; - i--; - } - vec->buffer[1] = vec->buffer[0]; - vec->buffer[0] = element; - vec->len++; - return (NO_ERROR); -} - -t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_buffer_str *value) -{ - t_usize i; - - if (vec->len <= 1) - return (vec_buf_str_pop(vec, value)); - i = 0; - *value = vec->buffer[0]; - vec->len--; - while (i < vec->len) - { - vec->buffer[i] = vec->buffer[i + 1]; - i++; - } - mem_set_zero(&vec->buffer[i], sizeof(*vec->buffer)); - return (NO_ERROR); -} - -void vec_buf_str_reverse(t_vec_buf_str *vec) -{ - t_buffer_str temporary; - t_usize i; - - i = 0; - while (i < vec->len / 2) - { - temporary = vec->buffer[vec->len - 1 - i]; - vec->buffer[vec->len - 1 - i] = vec->buffer[i]; - vec->buffer[i] = temporary; - i++; - } -} diff --git a/src/vec/vec_u8.c b/src/vec/vec_u8.c deleted file mode 100644 index 0ca886d..0000000 --- a/src/vec/vec_u8.c +++ /dev/null @@ -1,114 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_u8.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:21 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/types.h" -#include "me/vec/vec_u8.h" -#include - -t_vec_u8 vec_u8_new(t_usize capacity, t_free_u8_item free_function) -{ - t_vec_u8 out; - - out = (t_vec_u8){0}; - out.free_func = free_function; - out.buffer = mem_alloc_array(capacity, sizeof(t_u8)); - if (out.buffer) - out.capacity = capacity; - return (out); -} - -/// Return true in case of an error -t_error vec_u8_push(t_vec_u8 *vec, t_u8 element) -{ - t_u8 *temp_buffer; - size_t new_capacity; - - if (vec == NULL) - return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > new_capacity) - new_capacity = (new_capacity * 3) / 2 + 1; - temp_buffer = mem_alloc_array(new_capacity, sizeof(t_u8)); - if (temp_buffer == NULL) - return (ERROR); - mem_copy(temp_buffer, vec->buffer, vec->len * sizeof(t_u8)); - free(vec->buffer); - vec->buffer = temp_buffer; - vec->capacity = new_capacity; - } - vec->buffer[vec->len] = element; - vec->len += 1; - return (NO_ERROR); -} - -/// Return true in case of an error -t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity) -{ - t_u8 *temp_buffer; - size_t new_capacity; - - if (vec == NULL) - return (ERROR); - if (wanted_capacity > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (wanted_capacity > new_capacity) - new_capacity = (new_capacity * 3) / 2 + 1; - temp_buffer = mem_alloc_array(new_capacity, sizeof(t_u8)); - if (temp_buffer == NULL) - return (ERROR); - mem_copy(temp_buffer, vec->buffer, vec->len * sizeof(t_u8)); - free(vec->buffer); - vec->buffer = temp_buffer; - vec->capacity = new_capacity; - } - return (NO_ERROR); -} - -/// Return true if the vector is empty -/// This function is safe to call with value being NULL -t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value) -{ - t_u8 temp_value; - t_u8 *ptr; - - if (vec == NULL) - return (ERROR); - ptr = value; - if (vec->len == 0) - return (ERROR); - if (value == NULL) - ptr = &temp_value; - vec->len--; - *ptr = vec->buffer[vec->len]; - mem_set_zero(&vec->buffer[vec->len], sizeof(t_u8)); - return (NO_ERROR); -} - -/// This function is safe to call with `free_elem` being NULL -void vec_u8_free(t_vec_u8 vec) -{ - if (vec.free_func) - { - while (vec.len) - { - vec.free_func(vec.buffer[vec.len - 1]); - vec.len--; - } - } - free(vec.buffer); -} diff --git a/src/vec/vec_u8_functions2.c b/src/vec/vec_u8_functions2.c deleted file mode 100644 index bc4b22b..0000000 --- a/src/vec/vec_u8_functions2.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_u8_functions2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:12 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/types.h" -#include "me/vec/vec_u8.h" -#include - -t_error vec_u8_find(t_vec_u8 *vec, bool (*fn)(const t_u8 *), t_usize *index) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || index == NULL) - return (ERROR); - idx = 0; - while (idx < vec->len) - { - if (fn(&vec->buffer[idx])) - { - *index = idx; - return (NO_ERROR); - } - idx++; - } - return (ERROR); -} - -t_error vec_u8_find_starting(t_vec_u8 *vec, bool (*fn)(const t_u8 *), - t_usize starting_index, t_usize *index) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || index == NULL) - return (ERROR); - idx = starting_index; - while (idx < vec->len) - { - if (fn(&vec->buffer[idx])) - { - *index = idx; - return (NO_ERROR); - } - idx++; - } - return (ERROR); -} - -t_error vec_u8_all(t_vec_u8 *vec, bool (*fn)(const t_u8 *), bool *result) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || result == NULL) - return (ERROR); - idx = 0; - *result = true; - while (*result && idx < vec->len) - { - if (!fn(&vec->buffer[idx])) - *result = false; - idx++; - } - return (ERROR); -} - -t_error vec_u8_any(t_vec_u8 *vec, bool (*fn)(const t_u8 *), bool *result) -{ - t_usize idx; - - if (vec == NULL || fn == NULL || result == NULL) - return (ERROR); - idx = 0; - *result = false; - while (*result && idx < vec->len) - { - if (fn(&vec->buffer[idx])) - *result = true; - idx++; - } - return (ERROR); -} - -void vec_u8_iter(t_vec_u8 *vec, void (*fn)(t_usize index, t_u8 *value, - void *state), void *state) -{ - t_usize idx; - - if (vec == NULL || fn == NULL) - return ; - idx = 0; - while (idx < vec->len) - { - fn(idx, &vec->buffer[idx], state); - idx++; - } -} diff --git a/src/vec/vec_u8_functions3.c b/src/vec/vec_u8_functions3.c deleted file mode 100644 index b71f31b..0000000 --- a/src/vec/vec_u8_functions3.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* vec_u8_functions3.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */ -/* Updated: 2024/02/15 18:01:17 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/mem/mem_alloc_array.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/types.h" -#include "me/vec/vec_u8.h" -#include - -t_error vec_u8_push_front(t_vec_u8 *vec, t_u8 element) -{ - t_usize i; - - if (vec->len == 0) - return (vec_u8_push(vec, element)); - i = vec->len - 1; - if (vec->capacity < vec->len + 1 && vec_u8_reserve(vec, 3 * vec->len / 2 - + 1)) - return (ERROR); - while (i > 0) - { - vec->buffer[i + 1] = vec->buffer[i]; - i--; - } - vec->buffer[1] = vec->buffer[0]; - vec->buffer[0] = element; - vec->len++; - return (NO_ERROR); -} - -t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value) -{ - t_usize i; - - if (vec->len <= 1) - return (vec_u8_pop(vec, value)); - i = 0; - *value = vec->buffer[0]; - vec->len--; - while (i < vec->len) - { - vec->buffer[i] = vec->buffer[i + 1]; - i++; - } - mem_set_zero(&vec->buffer[i], sizeof(*vec->buffer)); - return (NO_ERROR); -} - -void vec_u8_reverse(t_vec_u8 *vec) -{ - t_u8 temporary; - t_usize i; - - i = 0; - while (i < vec->len / 2) - { - temporary = vec->buffer[vec->len - 1 - i]; - vec->buffer[vec->len - 1 - i] = vec->buffer[i]; - vec->buffer[i] = temporary; - i++; - } -} diff --git a/subject.txt b/subject.txt new file mode 100644 index 0000000..83b2e90 --- /dev/null +++ b/subject.txt @@ -0,0 +1,556 @@ + Push_swap + Because Swap_push isn’t as natural + + + + + Summary: +This project will make you sort data on a stack, with a limited set of instructions, using + the lowest possible number of actions. To succeed you’ll have to manipulate various + types of algorithms and choose the most appropriate solution (out of many) for an + optimized data sorting. + + Version: 7 +Contents +I Foreword 2 + +II Introduction 4 + +III Objectives 5 + +IV Common Instructions 6 + +V Mandatory part 8 + V.1 The rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 + V.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 + V.3 The "push_swap" program . . . . . . . . . . . . . . . . . . . . . . . . 10 + +VI Bonus part 12 + VI.1 The "checker" program . . . . . . . . . . . . . . . . . . . . . . . . . . 12 + +VII Submission and peer-evaluation 14 + + + + + 1 +Chapter I + +Foreword + + • C + #include + + int main(void) + { + printf("hello, world\n"); + return 0; + } + + + + • ASM + cseg segment + assume cs:cseg, ds:cseg + org 100h + main proc + jmp debut + mess db 'Hello world!$' + debut: + mov dx, offset mess + mov ah, 9 + int 21h + ret + main endp + cseg ends + end main + + + + • LOLCODE + HAI + CAN HAS STDIO? + VISIBLE "HELLO WORLD!" + KTHXBYE + + + + • PHP + + + + + • BrainFuck + ++++++++++[>+++++++>++++++++++>+++>+<<<<-] + >++.>+.+++++++..+++.>++. + <<+++++++++++++++.>.+++.------.--------.>+.>. + + + + + 2 +Push_swap Because Swap_push isn’t as natural + + + • C# + using System; + + public class HelloWorld { + public static void Main () { + Console.WriteLine("Hello world!"); + } + } + + + + • HTML5 + + + + + Hello world ! + + +

Hello World !

+ + + + + + • YASL + "Hello world!" + print + + + + • OCaml + let main () = + print_endline "Hello world !" + + let _ = main () + + + + + 3 +Chapter II + +Introduction + +The Push swap project is a very simple and a highly straightforward algorithm project: +data must be sorted. + + You have at your disposal a set of integer values, 2 stacks, and a set of instructions +to manipulate both stacks. + + Your goal? Write a program in C called push_swap which calculates and displays +on the standard output the smallest program, made of Push swap language instructions, +that sorts the integers received as arguments. + + Easy? + + We’ll see... + + + + + 4 +Chapter III + +Objectives + +Writing a sorting algorithm is always a very important step in a developer’s journey. It +is often the first encounter with the concept of complexity. + + Sorting algorithms and their complexity are part of the classic questions discussed +during job interviews. It’s probably a good time to look at these concepts since you’ll +have to face them at some point. + + The learning objectives of this project are rigor, use of C, and use of basic algorithms. +Especially focusing on their complexity. + + Sorting values is simple. To sort them the fastest way possible is less simple. Especially +because from one integers configuration to another, the most efficient sorting solution can +differ. + + + + + 5 +Chapter IV + +Common Instructions + + • Your project must be written in C. + + • Your project must be written in accordance with the Norm. If you have bonus + files/functions, they are included in the norm check and you will receive a 0 if there + is a norm error inside. + + • Your functions should not quit unexpectedly (segmentation fault, bus error, double + free, etc) apart from undefined behaviors. If this happens, your project will be + considered non functional and will receive a 0 during the evaluation. + + • All heap allocated memory space must be properly freed when necessary. No leaks + will be tolerated. + + • If the subject requires it, you must submit a Makefile which will compile your + source files to the required output with the flags -Wall, -Wextra and -Werror, use + cc, and your Makefile must not relink. + + • Your Makefile must at least contain the rules $(NAME), all, clean, fclean and + re. + + • To turn in bonuses to your project, you must include a rule bonus to your Makefile, + which will add all the various headers, librairies or functions that are forbidden on + the main part of the project. Bonuses must be in a different file _bonus.{c/h} if + the subject does not specify anything else. Mandatory and bonus part evaluation + is done separately. + + • If your project allows you to use your libft, you must copy its sources and its + associated Makefile in a libft folder with its associated Makefile. Your project’s + Makefile must compile the library by using its Makefile, then compile the project. + + • We encourage you to create test programs for your project even though this work + won’t have to be submitted and won’t be graded. It will give you a chance + to easily test your work and your peers’ work. You will find those tests especially + useful during your defence. Indeed, during defence, you are free to use your tests + and/or the tests of the peer you are evaluating. + + • Submit your work to your assigned git repository. Only the work in the git reposi- + tory will be graded. If Deepthought is assigned to grade your work, it will be done + + + 6 +Push_swap Because Swap_push isn’t as natural + + + after your peer-evaluations. If an error happens in any section of your work during + Deepthought’s grading, the evaluation will stop. + + + + + 7 +Chapter V + +Mandatory part + +V.1 The rules + • You have 2 stacks named a and b. + • At the beginning: + + ◦ The stack a contains a random amount of negative and/or positive numbers + which cannot be duplicated. + ◦ The stack b is empty. + + • The goal is to sort in ascending order numbers into stack a. To do so you have the + following operations at your disposal: + + sa (swap a): Swap the first 2 elements at the top of stack a. + Do nothing if there is only one or no elements. + sb (swap b): Swap the first 2 elements at the top of stack b. + Do nothing if there is only one or no elements. + ss : sa and sb at the same time. + pa (push a): Take the first element at the top of b and put it at the top of a. + Do nothing if b is empty. + pb (push b): Take the first element at the top of a and put it at the top of b. + Do nothing if a is empty. + ra (rotate a): Shift up all elements of stack a by 1. + The first element becomes the last one. + rb (rotate b): Shift up all elements of stack b by 1. + The first element becomes the last one. + rr : ra and rb at the same time. + rra (reverse rotate a): Shift down all elements of stack a by 1. + The last element becomes the first one. + rrb (reverse rotate b): Shift down all elements of stack b by 1. + The last element becomes the first one. + rrr : rra and rrb at the same time. + + + 8 +Push_swap Because Swap_push isn’t as natural + + +V.2 Example +To illustrate the effect of some of these instructions, let’s sort a random list of integers. +In this example, we’ll consider that both stacks grow from the right. + +---------------------------------------------------------------------------------------------------------- +Init a and b: +2 +1 +3 +6 +5 +8 +_ _ +a b +---------------------------------------------------------------------------------------------------------- +Exec sa: +1 +2 +3 +6 +5 +8 +_ _ +a b +---------------------------------------------------------------------------------------------------------- +Exec pb pb pb: +6 3 +5 2 +8 1 +_ _ +a b +---------------------------------------------------------------------------------------------------------- +Exec ra rb (equiv. to rr): +5 2 +8 1 +6 3 +_ _ +a b +---------------------------------------------------------------------------------------------------------- +Exec rra rrb (equiv. to rrr): +6 3 +5 2 +8 1 +_ _ +a b +---------------------------------------------------------------------------------------------------------- +Exec sa: +5 3 +6 2 +8 1 +_ _ +a b +---------------------------------------------------------------------------------------------------------- +Exec pa pa pa: +1 +2 +3 +5 +6 +8 +_ _ +a b +---------------------------------------------------------------------------------------------------------- + + Integers from a get sorted in 12 instructions. Can you do better? + + + + + 9 +Push_swap Because Swap_push isn’t as natural + + +V.3 The "push_swap" program + + Program name push_swap + Turn in files Makefile, *.h, *.c + Makefile NAME, all, clean, fclean, re + Arguments stack a: A list of integers + External functs. + + • read, write, malloc, free, + exit + • ft_printf and any equivalent + YOU coded + + Libft authorized Yes + Description Sort stacks + + + + Your project must comply with the following rules: + + • You have to turn in a Makefile which will compile your source files. It must not + relink. + + • Global variables are forbidden. + + • You have to write a program named push_swap that takes as an argument the stack + a formatted as a list of integers. The first argument should be at the top of the + stack (be careful about the order). + + • The program must display the smallest list of instructions possible to sort the stack + a, the smallest number being at the top. + + • Instructions must be separated by a ’\n’ and nothing else. + + • The goal is to sort the stack with the lowest possible number of operations. During + the evaluation process, the number of instructions found by your program will be + compared against a limit: the maximum number of operations tolerated. If your + program either displays a longer list or if the numbers aren’t sorted properly, your + grade will be 0. + + • If no parameters are specified, the program must not display anything and give the + prompt back. + + • In case of error, it must display "Error" followed by a ’\n’ on the standard error. + Errors include for example: some arguments aren’t integers, some arguments are + bigger than an integer and/or there are duplicates. + + + + + 10 +Push_swap Because Swap_push isn’t as natural + + +$>./push_swap 2 1 3 6 5 8 +sa +pb +pb +pb +sa +pa +pa +pa +$>./push_swap 0 one 2 3 +Error +$> + + + + During the evaluation process, a binary will be provided in order to properly check +your program. + + It will work as follows: + +$>ARG="4 67 3 87 23"; ./push_swap $ARG | wc -l + 6 +$>ARG="4 67 3 87 23"; ./push_swap $ARG | ./checker_OS $ARG +OK +$> + + + + If the program checker_OS displays "KO", it means that your push_swap came up +with a list of instructions that doesn’t sort the numbers. + + + The checker_OS program is available in the resources of the project + in the intranet. + You can find a description of how it works in the Bonus Part of this + document. + + + + + 11 +Chapter VI + +Bonus part + +This project leaves little room for adding extra features due to its simplicity. However, +how about creating your own checker? + + + Thanks to the checker program, you will be able to check whether + the list of instructions generated by the push_swap program actually + sorts the stack properly. + + + + +VI.1 The "checker" program + + Program name checker + Turn in files *.h, *.c + Makefile bonus + Arguments stack a: A list of integers + External functs. + + • read, write, malloc, free, + exit + • ft_printf and any equivalent + YOU coded + + Libft authorized Yes + Description Execute the sorting instructions + + • Write a program named checker that takes as an argument the stack a formatted + as a list of integers. The first argument should be at the top of the stack (be careful + about the order). If no argument is given, it stops and displays nothing. + • It will then wait and read instructions on the standard input, each instruction will + be followed by ’\n’. Once all the instructions have been read, the program has to + execute them on the stack received as an argument. + + 12 +Push_swap Because Swap_push isn’t as natural + + + • If after executing those instructions, the stack a is actually sorted and the stack b + is empty, then the program must display "OK" followed by a ’\n’ on the standard + output. + + • In every other case, it must display "KO" followed by a ’\n’ on the standard output. + + • In case of error, you must display "Error" followed by a ’\n’ on the standard er- + ror. Errors include for example: some arguments are not integers, some arguments + are bigger than an integer, there are duplicates, an instruction doesn’t exist and/or + is incorrectly formatted. + + +$>./checker 3 2 1 0 +rra +pb +sa +rra +pa +OK +$>./checker 3 2 1 0 +sa +rra +pb +KO +$>./checker 3 2 one 0 +Error +$>./checker "" 1 +Error +$> + + + + + You DO NOT have to reproduce the exact same behavior as the provided + binary. It is mandatory to manage errors but it is up to you to + decide how you want to parse the arguments. + + + + + The bonus part will only be assessed if the mandatory part is + PERFECT. Perfect means the mandatory part has been integrally done + and works without malfunctioning. If you have not passed ALL the + mandatory requirements, your bonus part will not be evaluated at all. + + + + + 13 +Chapter VII + +Submission and peer-evaluation + +Turn in your assignment in your Git repository as usual. Only the work inside your repos- +itory will be evaluated during the defense. Don’t hesitate to double check the names of +your files to ensure they are correct. + + As these assignments are not verified by a program, feel free to organize your files as +you wish, as long as you turn in the mandatory files and comply with the requirements. + + + + + file.bfe:VABB7yO9xm7xWXROeASsmsgnY0o0sDMJev7zFHhwQS8mvM8V5xQQp + Lc6cDCFXDWTiFzZ2H9skYkiJ/DpQtnM/uZ0 + + + + + 14