40 lines
750 B
C
40 lines
750 B
C
|
|
#include <sys/errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <toml.h>
|
|
|
|
#define ERRBUFSZ 200
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc < 2) {
|
|
error("missing required argument: game.toml", "");
|
|
}
|
|
|
|
FILE *fp;
|
|
char errbuf[ERRBUFSZ];
|
|
fp = fopen(argv[1], "r");
|
|
if (!fp) {
|
|
snprintf(errbuf, 200, "can't open %s: ", argv[1]);
|
|
error(errbuf, strerror(errno));
|
|
}
|
|
|
|
toml_table_t *conf = toml_parse_file(fp, errbuf, ERRBUFSZ);
|
|
fclose(fp);
|
|
|
|
if (!conf) {
|
|
char str[ERRBUFSZ];
|
|
snprintf(str, ERRBUFSZ, "can't parse %s: ", argv[1]);
|
|
error(str, errbuf);
|
|
}
|
|
|
|
toml_datum_t name = toml_string_in(conf, "name");
|
|
if (!name.ok) {
|
|
error("missing key: name", "");
|
|
}
|
|
|
|
printf("Preparing to process %s...\n", name.u.s);
|
|
}
|