Started from buttom go to the sky
This commit is contained in:
parent
96215449bd
commit
f811e55dea
4781 changed files with 10121 additions and 1743 deletions
91
stdme/include/me/blx/blx.h
Normal file
91
stdme/include/me/blx/blx.h
Normal 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
|
||||
22
stdme/include/me/blx/blx_handlers.h
Normal file
22
stdme/include/me/blx/blx_handlers.h
Normal 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
|
||||
175
stdme/include/me/blx/blx_key.h
Normal file
175
stdme/include/me/blx/blx_key.h
Normal 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
|
||||
29
stdme/include/me/blx/colors.h
Normal file
29
stdme/include/me/blx/colors.h
Normal 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
|
||||
36
stdme/include/me/blx/inputs.h
Normal file
36
stdme/include/me/blx/inputs.h
Normal 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
|
||||
24
stdme/include/me/blx/points.h
Normal file
24
stdme/include/me/blx/points.h
Normal 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
|
||||
54
stdme/include/me/blx/sprite.h
Normal file
54
stdme/include/me/blx/sprite.h
Normal 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
|
||||
78
stdme/include/me/blx/xdata.h
Normal file
78
stdme/include/me/blx/xdata.h
Normal 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
|
||||
49
stdme/include/me/buffered_str/buf_str.h
Normal file
49
stdme/include/me/buffered_str/buf_str.h
Normal 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
|
||||
20
stdme/include/me/char/isalnum.h
Normal file
20
stdme/include/me/char/isalnum.h
Normal 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
|
||||
20
stdme/include/me/char/isalpha.h
Normal file
20
stdme/include/me/char/isalpha.h
Normal 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
|
||||
20
stdme/include/me/char/isascii.h
Normal file
20
stdme/include/me/char/isascii.h
Normal 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
|
||||
20
stdme/include/me/char/isdigit.h
Normal file
20
stdme/include/me/char/isdigit.h
Normal 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
|
||||
20
stdme/include/me/char/islower.h
Normal file
20
stdme/include/me/char/islower.h
Normal 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
|
||||
20
stdme/include/me/char/isprint.h
Normal file
20
stdme/include/me/char/isprint.h
Normal 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
|
||||
20
stdme/include/me/char/isspace.h
Normal file
20
stdme/include/me/char/isspace.h
Normal 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
|
||||
20
stdme/include/me/char/isupper.h
Normal file
20
stdme/include/me/char/isupper.h
Normal 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
|
||||
20
stdme/include/me/char/tolower.h
Normal file
20
stdme/include/me/char/tolower.h
Normal 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
|
||||
20
stdme/include/me/char/toupper.h
Normal file
20
stdme/include/me/char/toupper.h
Normal 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
|
||||
21
stdme/include/me/convert/atoi.h
Normal file
21
stdme/include/me/convert/atoi.h
Normal 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
|
||||
20
stdme/include/me/convert/itoa.h
Normal file
20
stdme/include/me/convert/itoa.h
Normal 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
|
||||
30
stdme/include/me/convert/str_to_numbers.h
Normal file
30
stdme/include/me/convert/str_to_numbers.h
Normal 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 */
|
||||
20
stdme/include/me/fs/close.h
Normal file
20
stdme/include/me/fs/close.h
Normal 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
|
||||
22
stdme/include/me/fs/open.h
Normal file
22
stdme/include/me/fs/open.h
Normal 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
|
||||
20
stdme/include/me/fs/putchar_fd.h
Normal file
20
stdme/include/me/fs/putchar_fd.h
Normal 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
|
||||
20
stdme/include/me/fs/putendl_fd.h
Normal file
20
stdme/include/me/fs/putendl_fd.h
Normal 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
|
||||
20
stdme/include/me/fs/putnbr_fd.h
Normal file
20
stdme/include/me/fs/putnbr_fd.h
Normal 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
|
||||
20
stdme/include/me/fs/putstr_fd.h
Normal file
20
stdme/include/me/fs/putstr_fd.h
Normal 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
|
||||
20
stdme/include/me/fs/read.h
Normal file
20
stdme/include/me/fs/read.h
Normal 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
|
||||
25
stdme/include/me/fs/read_to_vec.h
Normal file
25
stdme/include/me/fs/read_to_vec.h
Normal 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
|
||||
20
stdme/include/me/fs/write.h
Normal file
20
stdme/include/me/fs/write.h
Normal 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
|
||||
43
stdme/include/me/gnl/gnl.h
Normal file
43
stdme/include/me/gnl/gnl.h
Normal 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
|
||||
52
stdme/include/me/hash/hasher.h
Normal file
52
stdme/include/me/hash/hasher.h
Normal 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
|
||||
38
stdme/include/me/hash/sip.h
Normal file
38
stdme/include/me/hash/sip.h
Normal 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
|
||||
24
stdme/include/me/hash/sip/sip_utils.h
Normal file
24
stdme/include/me/hash/sip/sip_utils.h
Normal 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
305
stdme/include/me/img/qoi.h
Normal 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 */
|
||||
86
stdme/include/me/img/qoi/qoi_decode.h
Normal file
86
stdme/include/me/img/qoi/qoi_decode.h
Normal 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 */
|
||||
155
stdme/include/me/img/qoi/qoi_encode.h
Normal file
155
stdme/include/me/img/qoi/qoi_encode.h
Normal 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 */
|
||||
56
stdme/include/me/img/qoi/qoi_utils.h
Normal file
56
stdme/include/me/img/qoi/qoi_utils.h
Normal 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 */
|
||||
20
stdme/include/me/list/list_add_back.h
Normal file
20
stdme/include/me/list/list_add_back.h
Normal 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
|
||||
19
stdme/include/me/list/list_add_front.h
Normal file
19
stdme/include/me/list/list_add_front.h
Normal 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
|
||||
20
stdme/include/me/list/list_alloc_node.h
Normal file
20
stdme/include/me/list/list_alloc_node.h
Normal 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
|
||||
20
stdme/include/me/list/list_free_all.h
Normal file
20
stdme/include/me/list/list_free_all.h
Normal 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
|
||||
20
stdme/include/me/list/list_free_one.h
Normal file
20
stdme/include/me/list/list_free_one.h
Normal 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
|
||||
20
stdme/include/me/list/list_get_last.h
Normal file
20
stdme/include/me/list/list_get_last.h
Normal 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
|
||||
20
stdme/include/me/list/list_iter.h
Normal file
20
stdme/include/me/list/list_iter.h
Normal 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
|
||||
20
stdme/include/me/list/list_map.h
Normal file
20
stdme/include/me/list/list_map.h
Normal 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
|
||||
20
stdme/include/me/list/list_size.h
Normal file
20
stdme/include/me/list/list_size.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_alloc.h
Normal file
20
stdme/include/me/mem/mem_alloc.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_alloc_array.h
Normal file
20
stdme/include/me/mem/mem_alloc_array.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_compare.h
Normal file
20
stdme/include/me/mem/mem_compare.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_copy.h
Normal file
20
stdme/include/me/mem/mem_copy.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_find.h
Normal file
20
stdme/include/me/mem/mem_find.h
Normal 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
|
||||
21
stdme/include/me/mem/mem_find_bytes.h
Normal file
21
stdme/include/me/mem/mem_find_bytes.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_move.h
Normal file
20
stdme/include/me/mem/mem_move.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_set.h
Normal file
20
stdme/include/me/mem/mem_set.h
Normal 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
|
||||
20
stdme/include/me/mem/mem_set_zero.h
Normal file
20
stdme/include/me/mem/mem_set_zero.h
Normal 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
|
||||
21
stdme/include/me/num/u16.h
Normal file
21
stdme/include/me/num/u16.h
Normal 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
|
||||
21
stdme/include/me/num/u32.h
Normal file
21
stdme/include/me/num/u32.h
Normal 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
|
||||
24
stdme/include/me/num/u64.h
Normal file
24
stdme/include/me/num/u64.h
Normal 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
21
stdme/include/me/num/u8.h
Normal 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
|
||||
21
stdme/include/me/num/usize.h
Normal file
21
stdme/include/me/num/usize.h
Normal 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
|
||||
27
stdme/include/me/printf/formatter/formatter.h
Normal file
27
stdme/include/me/printf/formatter/formatter.h
Normal 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
|
||||
76
stdme/include/me/printf/formatter/utils.h
Normal file
76
stdme/include/me/printf/formatter/utils.h
Normal 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
|
||||
52
stdme/include/me/printf/matchers/matchers.h
Normal file
52
stdme/include/me/printf/matchers/matchers.h
Normal 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
|
||||
69
stdme/include/me/printf/printf.h
Normal file
69
stdme/include/me/printf/printf.h
Normal 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
|
||||
20
stdme/include/me/string/str_clone.h
Normal file
20
stdme/include/me/string/str_clone.h
Normal 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
|
||||
20
stdme/include/me/string/str_find_chr.h
Normal file
20
stdme/include/me/string/str_find_chr.h
Normal 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
|
||||
20
stdme/include/me/string/str_find_rev_chr.h
Normal file
20
stdme/include/me/string/str_find_rev_chr.h
Normal 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
|
||||
20
stdme/include/me/string/str_find_str.h
Normal file
20
stdme/include/me/string/str_find_str.h
Normal 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
|
||||
20
stdme/include/me/string/str_iter.h
Normal file
20
stdme/include/me/string/str_iter.h
Normal 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
|
||||
20
stdme/include/me/string/str_join.h
Normal file
20
stdme/include/me/string/str_join.h
Normal 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
|
||||
20
stdme/include/me/string/str_l_cat.h
Normal file
20
stdme/include/me/string/str_l_cat.h
Normal 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
|
||||
20
stdme/include/me/string/str_l_copy.h
Normal file
20
stdme/include/me/string/str_l_copy.h
Normal 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
|
||||
20
stdme/include/me/string/str_len.h
Normal file
20
stdme/include/me/string/str_len.h
Normal 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
|
||||
20
stdme/include/me/string/str_map.h
Normal file
20
stdme/include/me/string/str_map.h
Normal 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
|
||||
20
stdme/include/me/string/str_n_compare.h
Normal file
20
stdme/include/me/string/str_n_compare.h
Normal 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
|
||||
20
stdme/include/me/string/str_n_find_str.h
Normal file
20
stdme/include/me/string/str_n_find_str.h
Normal 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
|
||||
20
stdme/include/me/string/str_split.h
Normal file
20
stdme/include/me/string/str_split.h
Normal 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
|
||||
20
stdme/include/me/string/str_substring.h
Normal file
20
stdme/include/me/string/str_substring.h
Normal 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
|
||||
20
stdme/include/me/string/str_trim.h
Normal file
20
stdme/include/me/string/str_trim.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_trim.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 23:43:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:19:11 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_TRIM_H
|
||||
# define STR_TRIM_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_trim(t_const_str str, t_const_str charset);
|
||||
|
||||
#endif
|
||||
49
stdme/include/me/types.h
Normal file
49
stdme/include/me/types.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* types.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 14:31:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/05 00:08:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPES_H
|
||||
# define TYPES_H
|
||||
|
||||
# include <stdbool.h>
|
||||
# include <stddef.h>
|
||||
# include <unistd.h>
|
||||
|
||||
typedef char *t_str;
|
||||
typedef const char *t_const_str;
|
||||
|
||||
typedef unsigned char t_u8;
|
||||
typedef char t_i8;
|
||||
typedef unsigned short t_u16;
|
||||
typedef short t_i16;
|
||||
typedef int t_i32;
|
||||
typedef unsigned int t_u32;
|
||||
typedef unsigned long long t_u64;
|
||||
typedef long long t_i64;
|
||||
typedef ssize_t t_isize;
|
||||
typedef size_t t_usize;
|
||||
|
||||
typedef float t_f32;
|
||||
typedef double t_f64;
|
||||
|
||||
typedef int t_file;
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
typedef bool t_error;
|
||||
|
||||
# define ERROR 1
|
||||
# define NO_ERROR 0
|
||||
|
||||
#endif
|
||||
60
stdme/include/me/vec2/vec2.h
Normal file
60
stdme/include/me/vec2/vec2.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec2.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 14:54:39 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/31 15:07:54 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC2_H
|
||||
# define VEC2_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_vi2d
|
||||
{
|
||||
t_i32 x;
|
||||
t_i32 y;
|
||||
} t_vi2d;
|
||||
|
||||
typedef struct s_vu2d
|
||||
{
|
||||
t_u32 x;
|
||||
t_u32 y;
|
||||
} t_vu2d;
|
||||
|
||||
typedef struct s_vf2d
|
||||
{
|
||||
t_f32 x;
|
||||
t_f32 y;
|
||||
} t_vf2d;
|
||||
|
||||
static inline t_vf2d vf2d(t_f32 x, t_f32 y)
|
||||
{
|
||||
return ((t_vf2d){.x = x, .y = y});
|
||||
}
|
||||
|
||||
static inline t_vi2d vi2d(t_i32 x, t_i32 y)
|
||||
{
|
||||
return ((t_vi2d){.x = x, .y = y});
|
||||
}
|
||||
|
||||
static inline t_vu2d vu2d(t_u32 x, t_u32 y)
|
||||
{
|
||||
return ((t_vu2d){.x = x, .y = y});
|
||||
}
|
||||
|
||||
static inline t_vi2d vi2d_add(t_vi2d lhs, t_vi2d rhs)
|
||||
{
|
||||
return ((t_vi2d){.x = lhs.x + rhs.x, .y = lhs.y + rhs.y});
|
||||
}
|
||||
|
||||
static inline t_vi2d vi2d_sub(t_vi2d lhs, t_vi2d rhs)
|
||||
{
|
||||
return ((t_vi2d){.x = lhs.x - rhs.x, .y = lhs.y - rhs.y});
|
||||
}
|
||||
#endif /* VEC2_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue