simplify example in README.md
This commit is contained in:
parent
a1a8911503
commit
9ed009b950
28
README.md
28
README.md
|
@ -28,47 +28,33 @@ convert it to a string or integer depending on context.
|
||||||
|
|
||||||
/* open file and parse */
|
/* open file and parse */
|
||||||
if (0 == (fp = fopen(FNAME, "r"))) {
|
if (0 == (fp = fopen(FNAME, "r"))) {
|
||||||
perror("fopen");
|
return handle_error();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
|
conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (0 == conf) {
|
if (0 == conf) {
|
||||||
fprintf(stderr, "ERROR: %s\n", errbuf);
|
return handle_error();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* locate the [server] table */
|
/* locate the [server] table */
|
||||||
if (0 == (server = toml_table_in(conf, "server"))) {
|
if (0 == (server = toml_table_in(conf, "server"))) {
|
||||||
fprintf(stderr, "ERROR: missing [server]\n");
|
return handle_error();
|
||||||
toml_free(conf);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* extract host config value */
|
/* extract host config value */
|
||||||
if (0 == (raw = toml_raw_in(server, "host"))) {
|
if (0 == (raw = toml_raw_in(server, "host"))) {
|
||||||
fprintf(stderr, "ERROR: missing 'host' in [server]\n");
|
return handle_error();
|
||||||
toml_free(conf);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (toml_rtos(raw, &host)) {
|
if (toml_rtos(raw, &host)) {
|
||||||
fprintf(stderr, "ERROR: bad value in 'host'\n");
|
return handle_error();
|
||||||
toml_free(conf);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* extract port config value */
|
/* extract port config value */
|
||||||
if (0 == (raw = toml_raw_in(server, "port"))) {
|
if (0 == (raw = toml_raw_in(server, "port"))) {
|
||||||
fprintf(stderr, "ERROR: missing 'port' in [server]\n");
|
return handle_error();
|
||||||
free(host);
|
|
||||||
toml_free(conf);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (toml_rtoi(raw, &port)) {
|
if (toml_rtoi(raw, &port)) {
|
||||||
fprintf(stderr, "ERROR: bad value in 'port'\n");
|
return handle_error();
|
||||||
free(host);
|
|
||||||
toml_free(conf);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* done with conf */
|
/* done with conf */
|
||||||
|
|
Loading…
Reference in New Issue