diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2023-12-29 06:21:33 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2023-12-29 06:21:33 +0100 |
commit | 2d6c8fec45b23a8a28668ecf3ef281139ab778a7 (patch) | |
tree | 75d2a8538992129a83c0c2b83688289443d697e5 /source/kit/input_buffer.h | |
parent | 820b171245f2f14766f3accdb0246a4e2c0d596a (diff) | |
download | saw-2d6c8fec45b23a8a28668ecf3ef281139ab778a7.zip |
refactor dependencies; include dependencies source code
Diffstat (limited to 'source/kit/input_buffer.h')
-rw-r--r-- | source/kit/input_buffer.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/source/kit/input_buffer.h b/source/kit/input_buffer.h new file mode 100644 index 0000000..a40ec99 --- /dev/null +++ b/source/kit/input_buffer.h @@ -0,0 +1,72 @@ +#ifndef KIT_INPUT_BUFFER_H +#define KIT_INPUT_BUFFER_H + +#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_str_builder_t data; +} kit_ib_t; + +typedef i8 (*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_ib_t kit_ib_copy(kit_ib_t buf); + +kit_ib_t kit_ib_read(kit_ib_t buf, i64 size); + +kit_ib_t kit_ib_any(kit_ib_t buf, kit_str_t data); + +kit_ib_t kit_ib_none(kit_ib_t buf, kit_str_t data); + +kit_ib_t kit_ib_exact(kit_ib_t buf, kit_str_t data); + +kit_ib_t kit_ib_until(kit_ib_t buf, kit_str_t data); + +kit_ib_t kit_ib_while(kit_ib_t buf, + kit_ib_read_condition_fn condition, + void *context); + +void kit_ib_destroy(kit_ib_t buf); + +#define KIT_IB_WRAP(upstream) kit_ib_wrap(upstream, NULL) + +#define KIT_IB_SKIP(buf_, proc_, ...) \ + do { \ + kit_ib_t temp_buf_ = (buf_); \ + (buf_) = proc_((buf_), __VA_ARGS__); \ + kit_ib_destroy((temp_buf_)); \ + } while (0) + +#ifdef __cplusplus +} +#endif + +#ifndef KIT_DISABLE_SHORT_NAMES +# define ib_t kit_ib_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_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 + +#endif |