32 lines
955 B
C
32 lines
955 B
C
#define CYAML_IMPLEMENTATION
|
|
#include "../include/cyaml.h"
|
|
#include <stdio.h>
|
|
|
|
int main(void) {
|
|
// Load a YAML document from a string.
|
|
cyaml_document_t *doc = cyaml_load_string("example: Hello, cyaml!");
|
|
if (!doc) {
|
|
fprintf(stderr, "Failed to load YAML.\n");
|
|
return 1;
|
|
}
|
|
|
|
// Get and print the root node's scalar value.
|
|
const cyaml_node_t *root = cyaml_document_get_root(doc);
|
|
if (root && cyaml_node_get_type(root) == CYAML_NODE_SCALAR) {
|
|
printf("YAML Content: %s\n", cyaml_node_as_string(root));
|
|
}
|
|
|
|
// Create an emitter and output the document.
|
|
cyaml_emitter_t *emitter = cyaml_emitter_create();
|
|
if (cyaml_emitter_emit(emitter, doc) == 0) {
|
|
char *output = cyaml_emitter_to_string(emitter);
|
|
printf("Emitted YAML:\n%s\n", output);
|
|
free(output);
|
|
}
|
|
|
|
// Cleanup.
|
|
cyaml_emitter_destroy(emitter);
|
|
cyaml_document_destroy(doc);
|
|
return 0;
|
|
}
|