diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-02-11 18:17:33 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-02-11 18:17:33 +0100 |
commit | df00df5a7a5bcd9076d4423128ea014ab3535626 (patch) | |
tree | 337e62f8ca39b19b250b155a3fbeb495384e356b /source/kit/input_buffer.h | |
parent | 80da54bb97c279aa60fb77a9bbad9baa0f2e4477 (diff) | |
download | saw-df00df5a7a5bcd9076d4423128ea014ab3535626.zip |
Update kit
Diffstat (limited to 'source/kit/input_buffer.h')
-rw-r--r-- | source/kit/input_buffer.h | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/source/kit/input_buffer.h b/source/kit/input_buffer.h index a40ec99..0114e3c 100644 --- a/source/kit/input_buffer.h +++ b/source/kit/input_buffer.h @@ -3,49 +3,52 @@ #include "string_builder.h" #include "input_stream.h" -#include "status.h" #ifdef __cplusplus extern "C" { #endif typedef struct { - kit_status_t status; - i64 offset; - void *internal; + kit_is_handle_t upstream; kit_str_builder_t data; -} kit_ib_t; +} kit_input_buffer_t; -typedef i8 (*kit_ib_read_condition_fn)(kit_str_t data, void *context); +typedef struct { + s32 status; + i64 offset; + i64 size; + kit_input_buffer_t *buffer; +} kit_ib_token_t; + +typedef b8 (*kit_ib_read_condition_fn)(kit_str_t data, void *context); -kit_ib_t kit_ib_wrap(kit_is_handle_t upstream, - kit_allocator_t *alloc); +kit_input_buffer_t kit_ib_wrap(kit_is_handle_t upstream, + kit_allocator_t *alloc); -kit_ib_t kit_ib_copy(kit_ib_t buf); +void kit_ib_destroy(kit_input_buffer_t *buf); -kit_ib_t kit_ib_read(kit_ib_t buf, i64 size); +kit_ib_token_t kit_ib_token(kit_input_buffer_t *buf); -kit_ib_t kit_ib_any(kit_ib_t buf, kit_str_t data); +kit_str_t kit_ib_str(kit_ib_token_t tok); -kit_ib_t kit_ib_none(kit_ib_t buf, kit_str_t data); +kit_ib_token_t kit_ib_read(kit_ib_token_t tok, i64 size); -kit_ib_t kit_ib_exact(kit_ib_t buf, kit_str_t data); +kit_ib_token_t kit_ib_any(kit_ib_token_t tok, kit_str_t data); -kit_ib_t kit_ib_until(kit_ib_t buf, kit_str_t data); +kit_ib_token_t kit_ib_none(kit_ib_token_t tok, kit_str_t data); -kit_ib_t kit_ib_while(kit_ib_t buf, - kit_ib_read_condition_fn condition, - void *context); +kit_ib_token_t kit_ib_exact(kit_ib_token_t tok, kit_str_t data); -void kit_ib_destroy(kit_ib_t buf); +kit_ib_token_t kit_ib_until(kit_ib_token_t tok, kit_str_t data); -#define KIT_IB_WRAP(upstream) kit_ib_wrap(upstream, NULL) +kit_ib_token_t kit_ib_while(kit_ib_token_t buf, + kit_ib_read_condition_fn condition, + void *context); -#define KIT_IB_SKIP(buf_, proc_, ...) \ - do { \ - kit_ib_t temp_buf_ = (buf_); \ - (buf_) = proc_((buf_), __VA_ARGS__); \ - kit_ib_destroy((temp_buf_)); \ +#define KIT_IB_SKIP(buf_, proc_, ...) \ + do { \ + kit_ib_token_t temp_buf_ = (buf_); \ + (buf_) = proc_((buf_), __VA_ARGS__); \ } while (0) #ifdef __cplusplus @@ -53,19 +56,19 @@ void kit_ib_destroy(kit_ib_t buf); #endif #ifndef KIT_DISABLE_SHORT_NAMES -# define ib_t kit_ib_t +# define input_buffer_t kit_input_buffer_t +# define ib_token_t kit_ib_token_t # define ib_read_condition_fn kit_ib_read_condition_fn # define ib_wrap kit_ib_wrap -# define ib_copy kit_ib_copy +# define ib_destroy kit_ib_destroy +# define ib_token kit_ib_token +# define ib_str kit_ib_str # define ib_read kit_ib_read # define ib_any kit_ib_any # define ib_none kit_ib_none # define ib_exact kit_ib_exact # define ib_until kit_ib_until # define ib_while kit_ib_while -# define ib_destroy kit_ib_destroy - -# define IB_WRAP KIT_IB_WRAP # define IB_SKIP KIT_IB_SKIP #endif |