kmx.io/kv/buffer.h

Branch

Thomas de Grivel 543019593 2022-01-03T11:06:25
wip quoting
/*
 * kv - key value text file format
 *
 * Copyright 2022 Thomas de Grivel
*/

#ifndef BUFFER_H
#define BUFFER_H

#include "kv_path.h"

#ifdef DEBUG
# define BUFFER_SIZE 64
#else
# define BUFFER_SIZE (1024 * 1024)
#endif

typedef struct buffer
{
  char       *chars;
  size_t      col;
  const char *file_path;
  FILE       *fp;
  s_kv_path  *k;
  size_t      line;
  size_t      pos;
  size_t      size;
  void       *state;
  size_t      wpos;
} s_buffer;

int        buffer_init (s_buffer *b, void *state);
s_buffer * buffer_new (void *state);
int        buffer_open (s_buffer *b, const char *file_path);
int        buffer_close (s_buffer *b);
int        buffer_fp (s_buffer *b, FILE *fp, const char *file_path);
int        buffer_resize (s_buffer *b, size_t new_size);
int        buffer_fill (s_buffer *b);
int        buffer_peek (s_buffer *b);
int        buffer_peek_n (s_buffer *b, size_t n);
int        buffer_read (s_buffer *b);
int        buffer_read_n (s_buffer *b, size_t n);
int        buffer_flush (s_buffer *b);
int        buffer_destroy (s_buffer *b);
int        buffer_delete (s_buffer *b);
void       buffer_err (s_buffer *b, const char *fmt, ...);
int        buffer_eat (s_buffer *b, const char *str);

#endif
Download