permanent-satori-hole/include/config.h

57 lines
1.6 KiB
C
Raw Normal View History

2023-12-27 00:35:22 +00:00
#ifndef H_SATORI_CONFIG
#define H_SATORI_CONFIG
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <threads.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <stdint.h>
#define SAT_CONFIG_TYPE_STREAM (1)
#define SAT_CONFIG_TYPE_SCOPED (2)
typedef struct _sat_config {
int type;
void *info;
struct _sat_config *(*scopeTo)(struct _sat_config *ctx, char *prefix);
char *(*readValue)(struct _sat_config *ctx, char *name, char *fallback);
} sat_config, *sat_config_ptr;
typedef struct _sat_config_stream {
FILE *stream;
bool ownsStream;
long offset;
mtx_t *lock;
} sat_config_stream, *sat_config_stream_ptr;
typedef struct _sat_config_scoped {
sat_config_ptr parent;
char *prefix;
} sat_config_scoped, *sat_config_scoped_ptr;
sat_config_ptr sat_config_alloc(int type);
sat_config_ptr sat_config_alloc_stream(void);
sat_config_ptr sat_config_alloc_scoped(void);
void sat_config_free(sat_config_ptr ctx);
void sat_config_free_stream(sat_config_ptr ctx);
void sat_config_free_scoped(sat_config_ptr ctx);
sat_config_ptr sat_config_scope_to(sat_config_ptr ctx, char *prefix);
char* sat_config_read_value(sat_config_ptr ctx, char *name, char *fallback);
bool sat_config_read_bool(sat_config_ptr ctx, char *name, bool fallback);
uint64_t sat_config_read_u64(sat_config_ptr ctx, char *name, uint64_t fallback);
int sat_config_stream_open(sat_config_ptr ctx, FILE *stream, bool ownsStream);
int sat_config_stream_open_file(sat_config_ptr ctx, char *path);
int sat_config_write_example(FILE *stream);
int sat_config_write_example_file(char *path);
#endif // H_SATORI_CONFIG