codex
Loading...
Searching...
No Matches
yaml.h
Go to the documentation of this file.
1#include <assert.h>
2#include <stdbool.h>
3#include <stddef.h>
4#include <stdio.h>
5
6#include </usr/include/yaml.h>
7
8#define MAX_DEPTH 128
9
10#define ARRAY_RESIZE(p, pn0, n1) array_resize(p, pn0, n1, sizeof(*p))
11
19
20struct parser {
21 yaml_parser_t yaml;
22};
23
25 const char *p;
26 size_t n;
27};
28
29struct scalar {
31 union {
32 long long i;
33 unsigned long long u;
34 long double f;
36 };
37};
38
39const char *event_type_str(yaml_event_type_t t);
40const char *scalar_type_str(enum scalar_type t);
41void scalar_print(const struct scalar *s, FILE *out);
42bool scalar_from_event(const yaml_event_t *event, struct scalar *s);
43
44int process_text(struct parser *parser, FILE *out);
45int process_json(struct parser *parser, FILE *out);
46int process_yaml(struct parser *parser, FILE *out);
47
48static inline void *array_resize(void *p, size_t *pn0, size_t n1, size_t s);
49
50inline void *array_resize(void *p, size_t *pn0, size_t n1, size_t s) {
51 size_t n0 = *pn0;
52 if(n1 <= n0)
53 return p;
54 for(n0 = n0 ? n0 : n1; n0 <= n1;)
55 n0 *= 2;
56 *pn0 = n0;
57 p = realloc(p, s * n0);
58 assert(p);
59 return p;
60}
Definition event.cpp:6
Definition bit.cpp:17
Definition bit.cpp:27
#define p()
Definition std2.c:11
#define t(a)
Definition std2.c:10
Definition parser.hpp:140
yaml_parser_t yaml
Definition yaml.h:21
Definition yaml.h:24
size_t n
Definition yaml.h:26
const char * p
Definition yaml.h:25
Definition yaml.h:29
unsigned long long u
Definition yaml.h:33
enum scalar_type type
Definition yaml.h:30
struct scalar_string s
Definition yaml.h:35
long long i
Definition yaml.h:32
long double f
Definition yaml.h:34
constexpr fixed_string s
Definition test.cpp:6
const char * scalar_type_str(enum scalar_type t)
Definition yaml.c:26
int process_text(struct parser *parser, FILE *out)
Definition text.c:35
int process_json(struct parser *parser, FILE *out)
Definition json.c:197
scalar_type
Definition yaml.h:12
@ SCALAR_EMPTY
Definition yaml.h:13
@ SCALAR_FLOAT
Definition yaml.h:16
@ SCALAR_INT
Definition yaml.h:14
@ SCALAR_UINT
Definition yaml.h:15
@ SCALAR_STRING
Definition yaml.h:17
const char * event_type_str(yaml_event_type_t t)
Definition yaml.c:7
bool scalar_from_event(const yaml_event_t *event, struct scalar *s)
Definition yaml.c:49
static void * array_resize(void *p, size_t *pn0, size_t n1, size_t s)
Definition yaml.h:50
int process_yaml(struct parser *parser, FILE *out)
Definition yaml.c:90
void scalar_print(const struct scalar *s, FILE *out)
Definition yaml.c:39
scalar_type
Definition yaml.h:12