ossp-pkg/cfg/cfg_test.c
1.6
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cfg.h"
#include "cfg_util.h"
int main(int argc, char *argv[])
{
cfg_rc_t rc;
char *im_ptr;
size_t im_size;
char *ex_ptr;
char *error;
cfg_t *cfg;
if (argc != 2) {
fprintf(stderr, "USAGE: %s <file>\n", argv[0]);
exit(1);
}
if ((rc = cfg_util_readfile(argv[1], &im_ptr, &im_size)) != CFG_OK) {
fprintf(stderr, "ERROR: reading file \"%s\"\n", argv[1]);
exit(1);
}
if ((rc = cfg_create(&cfg)) != CFG_OK) {
cfg_error(cfg, rc, &error);
fprintf(stderr, "ERROR: cfg_create: %s\n", error);
free(im_ptr);
exit(1);
}
if ((rc = cfg_import(cfg, NULL, CFG_FMT_CFG, im_ptr, im_size)) != CFG_OK) {
cfg_error(cfg, rc, &error);
fprintf(stderr, "ERROR: cfg_import: %s\n", error);
free(im_ptr);
cfg_destroy(cfg);
exit(1);
}
if ((rc = cfg_export(cfg, NULL, CFG_FMT_CFG, &ex_ptr, 0)) != CFG_OK) {
cfg_error(cfg, rc, &error);
fprintf(stderr, "ERROR: cfg_export: %s\n", error);
free(im_ptr);
cfg_destroy(cfg);
exit(1);
}
fprintf(stdout, "%s", ex_ptr);
#if 0
cfg_syn_destroy(cfg, node);
cfg_destroy(cfg);
#endif
return 0;
}