mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
allow configuration via stdin
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@264 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
78322b1515
commit
caec04dab2
2 changed files with 12 additions and 3 deletions
|
@ -130,7 +130,8 @@ int system2(const char* cmd, ...);
|
|||
/** Print configuration error and exit. */
|
||||
#define cerror(c, msg, ...) do { \
|
||||
print(ERROR, msg " in %s:%u", ##__VA_ARGS__, \
|
||||
config_setting_source_file(c), \
|
||||
(config_setting_source_file(c)) ? \
|
||||
config_setting_source_file(c) : "(stdio)", \
|
||||
config_setting_source_line(c)); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
|
@ -25,12 +26,19 @@ int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
|||
{
|
||||
config_set_auto_convert(cfg, 1);
|
||||
|
||||
if (!config_read_file(cfg, filename))
|
||||
FILE *file = (strcmp("-", filename)) ? fopen(filename, "r") : stdin;
|
||||
if (!file)
|
||||
error("Failed to open configuration file: %s", filename);
|
||||
|
||||
if (!config_read(cfg, file))
|
||||
error("Failed to parse configuration: %s in %s:%d",
|
||||
config_error_text(cfg), filename,
|
||||
config_error_line(cfg)
|
||||
);
|
||||
|
||||
if (file != stdin)
|
||||
fclose(file);
|
||||
|
||||
config_setting_t *cfg_root = config_root_setting(cfg);
|
||||
|
||||
/* Parse global settings */
|
||||
|
@ -177,7 +185,7 @@ int config_parse_node(config_setting_t *cfg, struct node **nodes)
|
|||
|
||||
n->vt = node_lookup_vtable(type);
|
||||
if (!n->vt)
|
||||
cerror(cfg, "Invalid node type");
|
||||
cerror(cfg, "Invalid type for node '%s'", n->name);
|
||||
|
||||
ret = n->vt->parse(cfg, n);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue