add yaml library, example
This commit is contained in:
parent
edbe4eb8ae
commit
03da03d679
5 changed files with 96 additions and 2 deletions
|
|
@ -29,6 +29,7 @@ else()
|
|||
endif()
|
||||
|
||||
set(SOURCES
|
||||
kubo_file.c
|
||||
kubo_input.c
|
||||
kubo_command_bar.c
|
||||
kubo_bar.c
|
||||
|
|
@ -46,4 +47,7 @@ else()
|
|||
target_compile_options(kubo PRIVATE -Wall -Wextra -Werror)
|
||||
endif()
|
||||
|
||||
target_link_libraries(kubo raylib)
|
||||
target_include_directories(kubo PRIVATE ${CYAML_INCLUDE_DIR})
|
||||
target_link_libraries(kubo PRIVATE ${CYAML_LIBRARY})
|
||||
|
||||
target_link_libraries(kubo PRIVATE raylib)
|
||||
|
|
|
|||
8
data.yaml
Normal file
8
data.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
name: Fibonacci
|
||||
data:
|
||||
- 1
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- 5
|
||||
- 8
|
||||
26
kubo_file.c
Normal file
26
kubo_file.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "kubo_file.h"
|
||||
|
||||
void kubo_file_parse(char *file_name) {
|
||||
static const cyaml_config_t config = {
|
||||
.log_fn = cyaml_log,
|
||||
.mem_fn = cyaml_mem,
|
||||
.log_level = CYAML_LOG_WARNING,
|
||||
};
|
||||
|
||||
struct numbers *n;
|
||||
|
||||
cyaml_err_t err = cyaml_load_file(file_name, &config, &top_schema, (cyaml_data_t **)&n, NULL);
|
||||
if (err != CYAML_OK) {
|
||||
printf("cyaml err\n");
|
||||
}
|
||||
|
||||
printf("%s:\n", n->name);
|
||||
for (unsigned i = 0; i < n->data_count; i++) {
|
||||
printf(" - %i\n", n->data[i]);
|
||||
}
|
||||
|
||||
err = cyaml_free(&config, &top_schema, n, 0);
|
||||
if (err != CYAML_OK) {
|
||||
printf("cyaml free err\n");
|
||||
}
|
||||
}
|
||||
49
kubo_file.h
Normal file
49
kubo_file.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
/*
|
||||
* Copyright Luka Jankovic 2025
|
||||
*
|
||||
* This file is part of Kubo.
|
||||
*
|
||||
* Kubo is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* Kubo is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* Kubo. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KUBO_FILE_H
|
||||
#define KUBO_FILE_H
|
||||
|
||||
#include <cyaml/cyaml.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct numbers {
|
||||
char *name;
|
||||
int *data;
|
||||
unsigned data_count;
|
||||
};
|
||||
|
||||
static const cyaml_schema_value_t data_entry = {
|
||||
CYAML_VALUE_INT(CYAML_FLAG_DEFAULT, int),
|
||||
};
|
||||
|
||||
static const cyaml_schema_field_t top_mapping_schema[] = {
|
||||
CYAML_FIELD_STRING_PTR("name", CYAML_FLAG_POINTER, struct numbers, name, 0,
|
||||
CYAML_UNLIMITED),
|
||||
CYAML_FIELD_SEQUENCE("data", CYAML_FLAG_POINTER, struct numbers, data,
|
||||
&data_entry, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_END};
|
||||
|
||||
static const cyaml_schema_value_t top_schema = {
|
||||
CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct numbers, top_mapping_schema),
|
||||
};
|
||||
|
||||
void kubo_file_parse(char *file_name);
|
||||
|
||||
#endif
|
||||
9
main.c
9
main.c
|
|
@ -4,7 +4,14 @@
|
|||
#include "kubo_context.h"
|
||||
#include "kubo_window.h"
|
||||
|
||||
int main() {
|
||||
#include "kubo_file.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc == 2) {
|
||||
kubo_file_parse(argv[1]);
|
||||
}
|
||||
|
||||
struct kubo_context context;
|
||||
kubo_context_init(&context);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue