ossp-pkg/cfg/cfg_test.c
1.2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cfg.h"
#include "cfg_util.h"
#include "cfg_node.h"
#include "cfg_syn.h"
#include "cfg_buf.h"
int main(int argc, char *argv[])
{
cfg_rc_t rc;
char *buf_ptr;
size_t buf_size;
cfg_node_t *node;
char err_buf[1024];
if (argc != 2) {
fprintf(stderr, "USAGE: %s <file>\n", argv[0]);
exit(1);
}
if ((rc = cfg_util_readfile(argv[1], &buf_ptr, &buf_size)) != CFG_OK) {
fprintf(stderr, "ERROR: reading file \"%s\"\n", argv[1]);
exit(1);
}
rc = cfg_syn_import(NULL, &node, buf_ptr, err_buf, sizeof(err_buf));
free(buf_ptr);
if (rc != CFG_OK)
fprintf(stderr, "ERROR: %s\n", err_buf);
else {
cfg_syn_export(NULL, node, &buf_ptr);
fprintf(stdout, "%s\n", buf_ptr);
}
return 0;
}