Started from buttom go to the sky

This commit is contained in:
Raphaël 2024-04-28 19:59:01 +02:00
parent 96215449bd
commit f811e55dea
4781 changed files with 10121 additions and 1743 deletions

9
stdme/.clang-format Normal file
View file

@ -0,0 +1,9 @@
BasedOnStyle: Microsoft
IndentWidth: 4
ColumnLimit: 80
UseTab: Always
SortIncludes: CaseInsensitive
IndentPPDirectives: AfterHash
PPIndentWidth: 1
AllowShortIfStatementsOnASingleLine: false
AlignConsecutiveDeclarations: true

9
stdme/.clangd Normal file
View file

@ -0,0 +1,9 @@
CompileFlags: # Tweak the parse settings
Add:
- "-I/home/maiboyer/Documents/mecstd/include/"
- "-I/home/maiboyer/Documents/mecstd/output/include/"
- "-I/home/maiboyer/Documents/mecstd/generic_sources/header/"
- "-I/home/maix/school/mecstd/include/"
- "-I/home/maix/school/mecstd/output/include/"
- "-I/home/maix/school/mecstd/generic_sources/header/"

1
stdme/.envrc Normal file
View file

@ -0,0 +1 @@
use flake

56
stdme/.gitignore vendored Normal file
View file

@ -0,0 +1,56 @@
# 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

21
stdme/LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Maix0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

106
stdme/Makefile Normal file
View file

@ -0,0 +1,106 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
# Updated: 2024/04/28 19:33:09 by maiboyer ### ########.fr #
# #
# **************************************************************************** #
BUILD_DIR ?= build
SRC_DIR = src
INCLUDE_DIR = include output/include
LIBS_DIR = .
GENERIC_DIR = output/src
GENERIC_INCLUDE = output/include
NAME = libme.a
LIB_NAME ?=
TARGET = $(BUILD_DIR)/$(NAME)
CC = clang
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD
BONUS_FILES =
LIBS_NAME =
SUBJECT_URL =
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)))
BONUS_OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(BONUS_FILES)))
OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES) )) \
$(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES)))
DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) \
$(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES)))
LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME))
INCLUDES = $(addprefix -I,$(foreach P,$(INCLUDE_DIR) $(GENERIC_INCLUDE) $(LIBS) $(addsuffix /include,$(LIBS)) vendor $(addsuffix /vendor,$(LIBS)),$(realpath $(P))))
COL_GRAY = \\e[90m
COL_WHITE = \\e[37m
COL_GREEN = \\e[32m
COL_BOLD = \\e[1m
COL_RESET = \\e[0m
.PHONY = all bonus clean re subject
all: $(NAME)
$(NAME): $(TARGET)
$(TARGET): $(OBJ)
@printf \\n$(COL_GRAY)Building\ Output\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \
$(NAME)
@#$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME)
@ar rcs $(BUILD_DIR)/$(NAME) $(OBJ)
@printf $(COL_GREEN)done$(COL_RESET)\\n
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
@printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$<
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
$(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c
@mkdir -p $(dir $@)
@printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$<
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
clean:
@- $(foreach LIB,$(LIBS), \
make clean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\
)
@- $(if $(LIB_NAME),,\
printf $(COL_WHITE)Clearing\ Artefacts\ ; \
printf $(COL_GRAY)\%-25s$(COL_RESET)\ \($(BUILD_DIR)\); \
rm -rf $(BUILD_DIR); \
printf $(COL_GREEN)done$(COL_RESET)\\n; \
)
@echo >/dev/null
fclean: clean
@- $(foreach LIB,$(LIBS), \
make fclean LIB_NAME=$(LIB)/ BUILD_DIR=$(shell realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\
)
@printf $(COL_WHITE)Clearing\ Output\ $(COL_GRAY)%-28s$(COL_RESET)\ \
\($(LIB_NAME)$(NAME)\)
@rm -f $(BUILD_DIR)$(NAME)
@printf $(COL_GREEN)done$(COL_RESET)\\n
re: fclean all
subject: subject.txt
bat --plain ./subject.txt
subject.txt:
@curl $(SUBJECT_URL) | pdftotext -layout -nopgbrk -q - subject.txt
generate_filelist::
@/usr/bin/env zsh -c "tree -iFf --noreport output | rg '^output/src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./gen.list
@/usr/bin/env zsh -c "tree -iFf --noreport src | rg '^src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./src.list
-include $(DEPS)

2
stdme/README.md Normal file
View file

@ -0,0 +1,2 @@
# meclib
My C "standard library" used for my school projects

314
stdme/flake.lock generated Normal file
View file

@ -0,0 +1,314 @@
{
"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"
}
},
"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"
}
},
"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": 1708976803,
"narHash": "sha256-yvRygcySjjSvj5JTaCdo7lPqJ/2mBV2XQ94Oaq/14qw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "548a86b335d7ecd8b57ec617781f5e652ab0c38e",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"c_formatter_42": "c_formatter_42",
"flake-utils": "flake-utils_2",
"generic_c": "generic_c",
"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
}

35
stdme/flake.nix Normal file
View file

@ -0,0 +1,35 @@
{
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";
};
outputs = {
self,
nixpkgs,
flake-utils,
generic_c,
c_formatter_42,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
packages = [
generic_c.packages.${system}.default
c_formatter_42.packages.${system}.default
pkgs.clang
pkgs.clang-tools
pkgs.fastmod
pkgs.libbsd
pkgs.norminette
pkgs.valgrind
pkgs.tree
];
};
}
);
}

22
stdme/gen.list Normal file
View file

@ -0,0 +1,22 @@
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_buf_str
vec/vec_buf_str_functions2
vec/vec_buf_str_functions3
vec/vec_u8
vec/vec_u8_functions2
vec/vec_u8_functions3

View file

@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashmap_C__PREFIX__.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 11:00:22 by maiboyer #+# #+# */
/* Updated: 2023/12/11 15:24:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HASHMAP_C__PREFIXUP___H
#define HASHMAP_C__PREFIXUP___H
#define DEFAULT_BUCKETS 750
C__TYPEHEADER__
#include "me/hash/hasher.h"
#include "me/types.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct s_kv_C__PREFIX__
{
C__KEYTYPE__ key;
C__VALTYPE__ val;
} t_kv_C__PREFIX__;
typedef void (*t_hash_C__PREFIX___fn)(t_hasher *hasher, C__KEYTYPE__ *key);
typedef void (*t_drop_C__PREFIX___fn)(t_kv_C__PREFIX__ val);
typedef bool (*t_eq_C__PREFIX___fn)(C__KEYTYPE__ *lhs, C__KEYTYPE__ *rhs);
typedef struct s_entry_C__PREFIX__
{
t_usize hash_id;
t_kv_C__PREFIX__ kv;
struct s_entry_C__PREFIX__ *next;
} t_entry_C__PREFIX__;
typedef struct s_hashmap_C__PREFIX__
{
t_entry_C__PREFIX__ **buckets;
t_usize num_buckets;
t_hasher hasher;
t_hash_C__PREFIX___fn hfunc;
t_eq_C__PREFIX___fn cfunc;
t_drop_C__PREFIX___fn drop;
} t_hashmap_C__PREFIX__;
t_hashmap_C__PREFIX__ *new_hashmap_C__PREFIX__(t_hash_C__PREFIX___fn hash,
t_eq_C__PREFIX___fn cmp,
t_drop_C__PREFIX___fn drop);
t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp,
t_drop_C__PREFIX___fn drop, size_t cap);
void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap);
void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
C__VALTYPE__ value);
C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
C__KEYTYPE__ *key);
void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
t_usize hash,
C__KEYTYPE__ *key,
t_entry_C__PREFIX__ **prev);
#endif

View file

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_C__PREFIX__.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VEC_C__PREFIXUP___H
#define VEC_C__PREFIXUP___H
C__TYPEHEADER__
#include "me/types.h"
typedef bool (*t_vec_C__PREFIX___sort_fn)(C__TYPENAME__ *, C__TYPENAME__ *);
typedef void (*t_free_C__PREFIX___item)(C__TYPENAME__);
typedef struct s_vec_C__PREFIX__
{
t_free_C__PREFIX___item free_func;
t_usize len;
t_usize capacity;
C__TYPENAME__ *buffer;
} t_vec_C__PREFIX__;
t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity,
t_free_C__PREFIX___item free_function);
t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element);
t_error vec_C__PREFIX___push_front(t_vec_C__PREFIX__ *vec,
C__TYPENAME__ element);
t_error vec_C__PREFIX___pop(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value);
t_error vec_C__PREFIX___pop_front(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value);
void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec);
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec,
t_usize wanted_capacity);
t_error vec_C__PREFIX___find(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *), t_usize *index);
t_error vec_C__PREFIX___find_starting(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *),
t_usize starting_index, t_usize *index);
t_error vec_C__PREFIX___all(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *), bool *result);
t_error vec_C__PREFIX___any(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *), bool *result);
void vec_C__PREFIX___iter(t_vec_C__PREFIX__ *vec,
void (*fn)(t_usize index, C__TYPENAME__ *value,
void *state),
void *state);
void vec_C__PREFIX___reverse(t_vec_C__PREFIX__ *vec);
void vec_C__PREFIX___sort(t_vec_C__PREFIX__ *vec,
t_vec_C__PREFIX___sort_fn is_sorted);
#endif

View file

@ -0,0 +1,116 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashmap_C__PREFIX__.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */
/* Updated: 2023/12/11 15:32:51 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/hash/hasher.h"
#include "me/hash/sip.h"
#include "me/hashmap/hashmap_C__PREFIX__.h"
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include "me/mem/mem_copy.h"
#include "me/types.h"
#include <stdlib.h>
t_hashmap_C__PREFIX__ *new_hashmap_C__PREFIX__(t_hash_C__PREFIX___fn hfunc,
t_eq_C__PREFIX___fn cfunc,
t_drop_C__PREFIX___fn drop)
{
return (new_hashmap_with_buckets_C__PREFIX__(hfunc, cfunc, drop,
DEFAULT_BUCKETS));
}
t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
t_hash_C__PREFIX___fn hfunc, t_eq_C__PREFIX___fn cfunc,
t_drop_C__PREFIX___fn drop, t_usize buckets)
{
t_hashmap_C__PREFIX__ *hmap;
hmap = mem_alloc(sizeof(*hmap));
if (hmap == NULL)
return (NULL);
hmap->buckets = mem_alloc_array(buckets, sizeof(t_entry_C__PREFIX__ *));
hmap->num_buckets = buckets;
hmap->hasher = hasher_sip13_new();
hmap->hfunc = hfunc;
hmap->cfunc = cfunc;
hmap->drop = drop;
if (hmap->buckets == NULL)
return ((void)free(hmap), NULL);
return (hmap);
}
void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
{
t_usize index;
index = 0;
while (index < hmap->num_buckets)
{
if (hmap->buckets[index])
{
hmap->drop(hmap->buckets[index]->kv);
free(hmap->buckets[index]);
}
index++;
}
hasher_finish(&hmap->hasher);
free(hmap->buckets);
free(hmap);
}
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
t_usize hashed_key,
C__KEYTYPE__ *key,
t_entry_C__PREFIX__ **prev)
{
t_entry_C__PREFIX__ *entry;
entry = hmap->buckets[hashed_key % hmap->num_buckets];
while (entry != NULL)
{
if (!hmap->cfunc(&entry->kv.key, key))
{
*prev = entry;
entry = entry->next;
}
else
{
return (entry);
}
}
return (NULL);
}
void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
C__VALTYPE__ value)
{
t_usize hashed_key;
t_entry_C__PREFIX__ *prev;
t_entry_C__PREFIX__ *entry;
hmap->hfunc(&hmap->hasher, &key);
hashed_key = hasher_reset_and_finish(&hmap->hasher);
prev = NULL;
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, &key, &prev);
if (entry == NULL)
{
entry = mem_alloc(sizeof(t_entry_tile));
entry->hash_id = hashed_key;
entry->kv = (t_kv_tile){.key = key, .val = value};
entry->next = NULL;
if (prev == NULL)
hmap->buckets[hashed_key % hmap->num_buckets] = entry;
else
prev->next = entry;
}
else
entry->kv.val = value;
}

View file

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashmap_C__PREFIX___utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */
/* Updated: 2023/12/11 15:35:37 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/hash/sip.h"
#include "me/hashmap/hashmap_C__PREFIX__.h"
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include "me/mem/mem_copy.h"
#include "me/types.h"
#include <stdlib.h>
C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
C__KEYTYPE__ *key)
{
t_usize hashed_key;
t_entry_C__PREFIX__ *entry;
t_entry_C__PREFIX__ *prev;
hmap->hfunc(&hmap->hasher, key);
hashed_key = hasher_reset_and_finish(&hmap->hasher);
entry = hashmap_get_entry_tile(hmap, hashed_key, key, &prev);
if (entry == NULL)
return (NULL);
return (&entry->kv.val);
}
void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
{
t_usize hashed_key;
t_entry_C__PREFIX__ *prev;
t_entry_C__PREFIX__ *entry;
hmap->hfunc(&hmap->hasher, key);
hashed_key = hasher_reset_and_finish(&hmap->hasher);
hmap->hasher = hasher_sip13_new();
prev = NULL;
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
if (entry == NULL)
return;
if (prev == NULL)
hmap->buckets[hashed_key % hmap->num_buckets] = entry->next;
else
prev->next = entry->next;
hmap->drop(entry->kv);
free(entry);
hmap->buckets[hashed_key % hmap->num_buckets] = NULL;
}

View file

@ -0,0 +1,130 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_i64.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */
/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/char/isalpha.h"
#include "me/convert/str_to_numbers.h"
#include "me/string/str_len.h"
#include "me/types.h"
#define OP_ADD 0b0001
#define OP_SUB 0b0010
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_C__PREFIX__(C__TYPE__ lhs, C__TYPE__ rhs, C__TYPE__ *out);
t_error checked_sub_C__PREFIX__(C__TYPE__ lhs, C__TYPE__ rhs, C__TYPE__ *out);
t_error checked_mul_C__PREFIX__(C__TYPE__ lhs, C__TYPE__ rhs, C__TYPE__ *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(C__TYPE__) * 2 - (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
digit = ascii - '0';
if (radix > 10 && digit >= 10)
{
if (!me_isalpha(ascii))
return (ERROR);
digit = ((ascii | 0b100000) - 'a') + 10;
}
if (digit >= radix)
return (ERROR);
*out = digit;
return (NO_ERROR);
}
static inline t_error do_operation(C__TYPE__ digit, t_u8 op, C__TYPE__ *result)
{
C__TYPE__ rhs;
C__TYPE__ res;
rhs = *result;
res = *result;
if (op & OP_CHK)
{
if (op & OP_MUL && checked_mul_C__PREFIX__(rhs, digit, &res))
return (ERROR);
else if (op & OP_ADD && checked_add_C__PREFIX__(rhs, digit, &res))
return (ERROR);
else if (op & OP_SUB && checked_sub_C__PREFIX__(rhs, digit, &res))
return (ERROR);
}
else
{
if (op & OP_MUL)
res = rhs * digit;
else if (op & OP_ADD)
res = rhs + digit;
else if (op & OP_SUB)
res = rhs - digit;
}
*result = res;
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
C__TYPE__ *out)
{
t_u32 digit;
C__TYPE__ result;
result = C__ZERO__;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
return (ERROR);
if (to_digit(*s, radix, &digit))
return (ERROR);
if (do_operation(digit, op, &result))
return (ERROR);
s++;
}
if (out)
*out = result;
return (NO_ERROR);
}
t_error str_to_C__PREFIX__(t_const_str s, t_u32 radix, C__TYPE__ *out)
{
t_usize digits_len;
bool is_positive;
t_u8 op;
if (radix < 2 || radix > 36)
return (ERROR);
digits_len = str_len(s);
is_positive = true;
if (digits_len == 0)
return (ERROR);
if ((s[0] == '-' || s[0] == '+') && s[1] == '\0')
return (ERROR);
else if (s[0] == '+')
is_positive = (s++, digits_len--, true);
else if (s[0] == '-' && C__SIGNED_TYPE__)
is_positive = (s++, digits_len--, false);
if (is_positive)
op = OP_ADD;
else
op = OP_SUB;
if (!can_not_overflow(radix, C__SIGNED_TYPE__, digits_len))
op |= OP_CHK;
return (loop_inner(s, radix, op, out));
}

View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_i64.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */
/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/char/isalpha.h"
#include "me/convert/str_to_numbers.h"
#include "me/string/str_len.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_C__PREFIX__(C__TYPE__ lhs, C__TYPE__ rhs, C__TYPE__ *out)
{
if (rhs > 0 && (lhs > C__MAX__ - rhs))
return (ERROR);
*out = (C__TYPE__)(lhs + rhs);
return (NO_ERROR);
}
t_error checked_sub_C__PREFIX__(C__TYPE__ lhs, C__TYPE__ rhs, C__TYPE__ *out)
{
if ((((rhs & (1 << (sizeof(C__TYPE__) - 1)) || rhs == 0) || !C__SIGNED_TYPE__) && (lhs < C__MIN__ + rhs)))
return (ERROR);
*out = (C__TYPE__)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_C__PREFIX__(C__TYPE__ lhs, C__TYPE__ rhs, C__TYPE__ *out)
{
C__TYPE__ mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)
return (ERROR);
*out = mul;
return (NO_ERROR);
}

View file

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_C__PREFIX__.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:54:11 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_C__PREFIX__.h"
#include <stdlib.h>
t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity,
t_free_C__PREFIX___item free_function)
{
t_vec_C__PREFIX__ out;
out = (t_vec_C__PREFIX__){0};
out.free_func = free_function;
out.buffer = mem_alloc_array(capacity, sizeof(C__TYPENAME__));
if (out.buffer)
out.capacity = capacity;
return (out);
}
/// Return true in case of an error
t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element)
{
C__TYPENAME__ *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(C__TYPENAME__));
if (temp_buffer == NULL)
return (ERROR);
mem_copy(temp_buffer, vec->buffer, vec->len * sizeof(C__TYPENAME__));
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_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity)
{
C__TYPENAME__ *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(C__TYPENAME__));
if (temp_buffer == NULL)
return (ERROR);
mem_copy(temp_buffer, vec->buffer, vec->len * sizeof(C__TYPENAME__));
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_C__PREFIX___pop(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value)
{
C__TYPENAME__ temp_value;
C__TYPENAME__ *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(C__TYPENAME__));
return (NO_ERROR);
}
/// This function is safe to call with `free_elem` being NULL
void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec)
{
if (vec.free_func)
{
while (vec.len)
{
vec.free_func(vec.buffer[vec.len - 1]);
vec.len--;
}
}
free(vec.buffer);
}

View file

@ -0,0 +1,112 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_C__PREFIX__.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 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_C__PREFIX__.h"
#include <stdlib.h>
t_error vec_C__PREFIX___find(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *), 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_C__PREFIX___find_starting(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *),
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_C__PREFIX___all(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *), 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_C__PREFIX___any(t_vec_C__PREFIX__ *vec,
bool (*fn)(const C__TYPENAME__ *), 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_C__PREFIX___iter(t_vec_C__PREFIX__ *vec,
void (*fn)(t_usize index, C__TYPENAME__ *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++;
}
}

View file

@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_C__PREFIX__.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 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_C__PREFIX__.h"
#include <stdlib.h>
t_error vec_C__PREFIX___push_front(t_vec_C__PREFIX__ *vec,
C__TYPENAME__ element)
{
t_usize i;
if (vec->len == 0)
return (vec_C__PREFIX___push(vec, element));
i = vec->len - 1;
if (vec->capacity < vec->len + 1 &&
vec_C__PREFIX___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_C__PREFIX___pop_front(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value)
{
t_usize i;
if (vec->len <= 1)
return (vec_C__PREFIX___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_C__PREFIX___reverse(t_vec_C__PREFIX__ *vec)
{
C__TYPENAME__ 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++;
}
}

View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* best_move.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/types.h"
#include "me/vec/vec_C__PREFIX__.h"
void vec_C__PREFIX___sort(t_vec_C__PREFIX__ *v,
t_vec_C__PREFIX___sort_fn is_sorted_fn)
{
t_usize sorted_part;
t_usize i;
C__TYPENAME__ tmp;
if (v == NULL)
return;
sorted_part = v->len;
while (sorted_part > 0)
{
i = 0;
while (i < sorted_part - 1)
{
if (!is_sorted_fn(&v->buffer[i], &v->buffer[i + 1]))
{
tmp = v->buffer[i];
v->buffer[i] = v->buffer[i + 1];
v->buffer[i + 1] = tmp;
}
i++;
}
sorted_part--;
}
}

View file

@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* blx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:05:45 by maiboyer #+# #+# */
/* Updated: 2023/12/31 18:48:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BLX_H
# define BLX_H
# include "me/blx/blx_key.h"
# include "me/blx/colors.h"
# include "me/vec2/vec2.h"
# include "me/blx/sprite.h"
# include "me/blx/inputs.h"
# include "me/blx/points.h"
# include "me/types.h"
typedef struct s_blx t_blx;
typedef struct s_blx_app
{
t_str title;
t_u32 size_x;
t_u32 size_y;
t_u32 pixel_size;
void *data;
} t_blx_app;
typedef bool (*t_run_function)(t_blx *ctx);
typedef void (*t_free_function)(t_blx_app app);
typedef enum e_draw_mode
{
REPLACE,
MASK,
ALPHA,
} t_draw_mode;
typedef struct s_blx_data
{
t_sprite screen;
bool exit;
t_draw_mode draw_mode;
t_sprite font;
} t_blx_data;
typedef struct s_blx
{
void *mlx;
void *win;
t_blx_input inputs;
t_run_function func;
t_free_function free;
t_blx_app app;
t_blx_data _data;
} t_blx;
int blx_loop_func(t_blx *ctx);
t_blx blx_initialize(t_run_function func,
t_free_function free_fn, t_blx_app data);
void draw_sprite(t_blx *app, t_vi2d pos,
t_sprite *spr);
bool is_key_pressed(t_blx *ctx, t_keysym input);
bool is_key_held(t_blx *ctx, t_keysym input);
bool is_key_released(t_blx *ctx, t_keysym input);
void blx_run(t_blx app);
void blx_free(t_blx app);
void blx_draw(t_blx *app, t_vi2d pos, t_color col);
void blx_clear(t_blx *app, t_color col);
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
t_sprite *source);
void blx_draw_string(t_blx *app, t_vi2d pos,
t_const_str s, t_color col);
static inline t_draw_mode get_draw_mode(t_blx *app)
{
return (app->_data.draw_mode);
}
static inline void set_draw_mode(t_blx *app, t_draw_mode mode)
{
app->_data.draw_mode = mode;
}
#endif

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* blx_handlers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 17:37:50 by maiboyer #+# #+# */
/* Updated: 2023/12/21 18:32:01 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BLX_HANDLERS_H
# define BLX_HANDLERS_H
# include "me/blx/blx_key.h"
# include "me/types.h"
int blx_key_pressed_handler(t_keysym keysym, t_blx *ctx);
int blx_key_released_handler(t_keysym keysym, t_blx *ctx);
int blx_key_exit_handler(t_blx *ctx);
#endif

View file

@ -0,0 +1,175 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* blx_key.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 18:15:50 by maiboyer #+# #+# */
/* Updated: 2023/12/21 17:37:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BLX_KEY_H
# define BLX_KEY_H
# include "me/types.h"
# include "me/vec/vec_u8.h"
typedef enum e_keysym
{
KB_space = 0x0020,
KB_exclam = 0x0021,
KB_quotedbl = 0x0022,
KB_numbersign = 0x0023,
KB_dollar = 0x0024,
KB_percent = 0x0025,
KB_ampersand = 0x0026,
KB_apostrophe = 0x0027,
KB_quoteright = 0x0027,
KB_parenleft = 0x0028,
KB_parenright = 0x0029,
KB_asterisk = 0x002a,
KB_plus = 0x002b,
KB_comma = 0x002c,
KB_minus = 0x002d,
KB_period = 0x002e,
KB_slash = 0x002f,
KB_0 = 0x0030,
KB_1 = 0x0031,
KB_2 = 0x0032,
KB_3 = 0x0033,
KB_4 = 0x0034,
KB_5 = 0x0035,
KB_6 = 0x0036,
KB_7 = 0x0037,
KB_8 = 0x0038,
KB_9 = 0x0039,
KB_colon = 0x003a,
KB_semicolon = 0x003b,
KB_less = 0x003c,
KB_equal = 0x003d,
KB_greater = 0x003e,
KB_question = 0x003f,
KB_at = 0x0040,
KB_A = 0x0041,
KB_B = 0x0042,
KB_C = 0x0043,
KB_D = 0x0044,
KB_E = 0x0045,
KB_F = 0x0046,
KB_G = 0x0047,
KB_H = 0x0048,
KB_I = 0x0049,
KB_J = 0x004a,
KB_K = 0x004b,
KB_L = 0x004c,
KB_M = 0x004d,
KB_N = 0x004e,
KB_O = 0x004f,
KB_P = 0x0050,
KB_Q = 0x0051,
KB_R = 0x0052,
KB_S = 0x0053,
KB_T = 0x0054,
KB_U = 0x0055,
KB_V = 0x0056,
KB_W = 0x0057,
KB_X = 0x0058,
KB_Y = 0x0059,
KB_Z = 0x005a,
KB_bracketleft = 0x005b,
KB_backslash = 0x005c,
KB_bracketright = 0x005d,
KB_asciicircum = 0x005e,
KB_underscore = 0x005f,
KB_grave = 0x0060,
KB_quoteleft = 0x0060,
KB_a = 0x0061,
KB_b = 0x0062,
KB_c = 0x0063,
KB_d = 0x0064,
KB_e = 0x0065,
KB_f = 0x0066,
KB_g = 0x0067,
KB_h = 0x0068,
KB_i = 0x0069,
KB_j = 0x006a,
KB_k = 0x006b,
KB_l = 0x006c,
KB_m = 0x006d,
KB_n = 0x006e,
KB_o = 0x006f,
KB_p = 0x0070,
KB_q = 0x0071,
KB_r = 0x0072,
KB_s = 0x0073,
KB_t = 0x0074,
KB_u = 0x0075,
KB_v = 0x0076,
KB_w = 0x0077,
KB_x = 0x0078,
KB_y = 0x0079,
KB_z = 0x007a,
KB_braceleft = 0x007b,
KB_bar = 0x007c,
KB_braceright = 0x007d,
KB_asciitilde = 0x007e,
KB_BackSpace = 0xff08,
KB_Tab = 0xff09,
KB_Linefeed = 0xff0a,
KB_Clear = 0xff0b,
KB_Return = 0xff0d,
KB_Pause = 0xff13,
KB_Scroll_Lock = 0xff14,
KB_Sys_Req = 0xff15,
KB_Escape = 0xff1b,
KB_Delete = 0xffff,
KB_Home = 0xff50,
KB_Left = 0xff51,
KB_Up = 0xff52,
KB_Right = 0xff53,
KB_Down = 0xff54,
KB_Prior = 0xff55,
KB_Page_Up = 0xff55,
KB_Next = 0xff56,
KB_Page_Down = 0xff56,
KB_End = 0xff57,
KB_Begin = 0xff58,
KB_F1 = 0xffbe,
KB_F2 = 0xffbf,
KB_F3 = 0xffc0,
KB_F4 = 0xffc1,
KB_F5 = 0xffc2,
KB_F6 = 0xffc3,
KB_F7 = 0xffc4,
KB_F8 = 0xffc5,
KB_F9 = 0xffc6,
KB_F10 = 0xffc7,
KB_F11 = 0xffc8,
KB_F12 = 0xffc9,
KB_Shift_L = 0xffe1,
KB_Shift_R = 0xffe2,
KB_Control_L = 0xffe3,
KB_Control_R = 0xffe4,
KB_Caps_Lock = 0xffe5,
KB_Shift_Lock = 0xffe6,
KB_Meta_L = 0xffe7,
KB_Meta_R = 0xffe8,
KB_Alt_L = 0xffe9,
KB_Alt_R = 0xffea,
KB_Super_L = 0xffeb,
KB_Super_R = 0xffec,
KB_Hyper_L = 0xffed,
KB_Hyper_R = 0xffee,
} t_keysym;
typedef struct s_blx t_blx;
t_usize keysym_to_bit_index(t_keysym key);
bool get_key(t_vec_u8 *key_storage, t_keysym keysym);
bool is_key_pressed(t_blx *ctx, t_keysym key);
bool is_key_held(t_blx *ctx, t_keysym key);
bool is_key_released(t_blx *ctx, t_keysym key);
#endif

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* colors.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:49:02 by maiboyer #+# #+# */
/* Updated: 2023/12/24 17:36:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COLORS_H
# define COLORS_H
# include "me/types.h"
typedef __attribute__((aligned(4))) struct s_color
{
t_u8 r;
t_u8 b;
t_u8 g;
t_u8 a;
} t_color;
t_color new_color_with_alpha(t_u8 r, t_u8 g, t_u8 b, t_u8 alpha);
t_color new_color(t_u8 r, t_u8 g, t_u8 b);
#endif

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inputs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:38:22 by maiboyer #+# #+# */
/* Updated: 2023/12/21 20:15:54 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef INPUTS_H
# define INPUTS_H
# include "me/types.h"
# include "me/vec/vec_u8.h"
# ifndef BLX_H
typedef struct s_blx t_blx;
# endif
typedef struct s_blx_input
{
t_vec_u8 keysyms_pressed;
t_vec_u8 keysyms_held;
t_vec_u8 keysyms_released;
t_u8 mouse;
} t_blx_input;
t_blx_input create_inputs_manager(t_blx *ctx);
#endif

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* points.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:47:17 by maiboyer #+# #+# */
/* Updated: 2023/12/13 18:14:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef POINTS_H
# define POINTS_H
# include "me/types.h"
typedef struct s_point
{
t_i32 x;
t_i32 y;
} t_point;
#endif

View file

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sprite.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 21:59:18 by maiboyer #+# #+# */
/* Updated: 2024/01/05 00:09:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SPRITE_H
# define SPRITE_H
# include "me/blx/colors.h"
# include "me/types.h"
# include "me/vec2/vec2.h"
# ifndef BLX_H
typedef struct s_blx t_blx;
# endif
typedef struct s_sprite
{
t_blx *ctx;
void *img;
t_i32 width;
t_i32 height;
t_u8 *data;
t_i32 bpp;
t_usize line_size;
bool big_endian;
} t_sprite;
bool blx_sprite_from_xpm(t_blx *ctx, t_str path,
t_sprite *out);
bool blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height,
t_sprite *out);
void blx_sprite_free(t_sprite img);
void blx_draw_sprite_raw(t_blx *ctx, t_vi2d pos,
t_sprite *img);
void sprite_draw(t_sprite *img, t_vi2d pos, t_color col);
void sprite_clear(t_sprite *img, t_color col);
bool sprite_get_pixel(t_sprite *spr, t_vi2d pos,
t_color *out);
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
t_sprite *source);
void sprite_draw_string(t_sprite *spr, t_vi2d pos,
t_const_str sText, t_color col);
#endif

View file

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* xdata.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 17:20:57 by maiboyer #+# #+# */
/* Updated: 2023/12/21 20:15:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef XDATA_H
# define XDATA_H
# define KEYPRESS 2
# define KEYRELEASE 3
# define BUTTONPRESS 4
# define BUTTONRELEASE 5
# define MOTIONNOTIFY 6
# define ENTERNOTIFY 7
# define LEAVENOTIFY 8
# define FOCUSIN 9
# define FOCUSOUT 10
# define KEYMAPNOTIFY 11
# define EXPOSE 12
# define GRAPHICSEXPOSE 13
# define NOEXPOSE 14
# define VISIBILITYNOTIFY 15
# define CREATENOTIFY 16
# define DESTROYNOTIFY 17
# define UNMAPNOTIFY 18
# define MAPNOTIFY 19
# define MAPREQUEST 20
# define REPARENTNOTIFY 21
# define CONFIGURENOTIFY 22
# define CONFIGUREREQUEST 23
# define GRAVITYNOTIFY 24
# define RESIZEREQUEST 25
# define CIRCULATENOTIFY 26
# define CIRCULATEREQUEST 27
# define PROPERTYNOTIFY 28
# define SELECTIONCLEAR 29
# define SELECTIONREQUEST 30
# define SELECTIONNOTIFY 31
# define COLORMAPNOTIFY 32
# define CLIENTMESSAGE 33
# define MAPPINGNOTIFY 34
# define GENERICEVENT 35
# define NOEVENTMASK 0b0L
# define KEYPRESSMASK 0b1L
# define KEYRELEASEMASK 0b10L
# define BUTTONPRESSMASK 0b100L
# define BUTTONRELEASEMASK 0b1000L
# define ENTERWINDOWMASK 0b10000L
# define LEAVEWINDOWMASK 0b100000L
# define POINTERMOTIONMASK 0b1000000L
# define POINTERMOTIONHINTMASK 0b10000000L
# define BUTTON1MOTIONMASK 0b100000000L
# define BUTTON2MOTIONMASK 0b1000000000L
# define BUTTON3MOTIONMASK 0b10000000000L
# define BUTTON4MOTIONMASK 0b100000000000L
# define BUTTON5MOTIONMASK 0b1000000000000L
# define BUTTONMOTIONMASK 0b10000000000000L
# define KEYMAPSTATEMASK 0b100000000000000L
# define EXPOSUREMASK 0b1000000000000000L
# define VISIBILITYCHANGEMASK 0b10000000000000000L
# define STRUCTURENOTIFYMASK 0b100000000000000000L
# define RESIZEREDIRECTMASK 0b1000000000000000000L
# define SUBSTRUCTURENOTIFYMASK 0b10000000000000000000L
# define SUBSTRUCTUREREDIRECTMASK 0b100000000000000000000L
# define FOCUSCHANGEMASK 0b1000000000000000000000L
# define PROPERTYCHANGEMASK 0b10000000000000000000000L
# define COLORMAPCHANGEMASK 0b100000000000000000000000L
# define OWNERGRABBUTTONMASK 0b1000000000000000000000000L
#endif

View file

@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buf_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isalnum.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isalpha.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isascii.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isdigit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* islower.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isprint.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isspace.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isupper.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tolower.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* toupper.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* atoi.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* itoa.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_numbers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:08:13 by maiboyer #+# #+# */
/* Updated: 2024/02/02 00:22:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_TO_NUMBERS_H
# define STR_TO_NUMBERS_H
# include "me/types.h"
t_error str_to_isize(t_const_str str, t_u32 radix, t_isize *out);
t_error str_to_i64(t_const_str str, t_u32 radix, t_i64 *out);
t_error str_to_i32(t_const_str str, t_u32 radix, t_i32 *out);
t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *out);
t_error str_to_i8(t_const_str str, t_u32 radix, t_i8 *out);
t_error str_to_usize(t_const_str str, t_u32 radix, t_usize *out);
t_error str_to_u64(t_const_str str, t_u32 radix, t_u64 *out);
t_error str_to_u32(t_const_str str, t_u32 radix, t_u32 *out);
t_error str_to_u16(t_const_str str, t_u32 radix, t_u16 *out);
t_error str_to_u8(t_const_str str, t_u32 radix, t_u8 *out);
#endif /* STR_TO_NUMBERS_H */

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* close.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* open.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putchar_fd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putendl_fd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putnbr_fd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putstr_fd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_to_vec.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* write.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* gnl.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer42@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hasher.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sip.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sip_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

305
stdme/include/me/img/qoi.h Normal file
View file

@ -0,0 +1,305 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qoi.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */

View file

@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qoi_decode.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */

View file

@ -0,0 +1,155 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qoi_encode.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */

View file

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qoi_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_add_back.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_add_front.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_alloc_node.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_free_all.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_free_one.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_get_last.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_iter.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_size.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_alloc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_alloc_array.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_compare.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_copy.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_find.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_find_bytes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_move.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_set.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_set_zero.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* u16.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* u32.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* u64.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

21
stdme/include/me/num/u8.h Normal file
View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* u8.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* usize.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* formatter.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdarg.h>
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

View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* matchers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdarg.h>
# 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

View file

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdarg.h>
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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_clone.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_find_chr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_find_rev_chr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_find_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_iter.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_join.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_l_cat.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_l_copy.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_len.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_n_compare.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_n_find_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_split.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_substring.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

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