--- cfg_test.c 2004/07/17 07:37:55 1.14
+++ cfg_test.c 2004/11/20 11:48:39 1.15
@@ -28,14 +28,17 @@
** cfg_test.c: test suite
*/
+/* standard system headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+/* OSSP cfg headers */
#include "cfg.h"
#include "cfg_global.h"
#include "cfg_util.h"
+/* main test program procedure */
int main(int argc, char *argv[])
{
cfg_rc_t rc;
@@ -47,16 +50,19 @@
cfg_node_t **vec;
int i;
+ /* command line processing */
if (argc < 2 || argc > 3) {
fprintf(stderr, "USAGE: %s <file> [<select>]\n", argv[0]);
exit(1);
}
+ /* read configuration file into memory */
if ((rc = cfg_util_readfile(argv[1], &im_ptr, &im_size)) != CFG_OK) {
fprintf(stderr, "ERROR: reading file \"%s\"\n", argv[1]);
exit(1);
}
+ /* create configuration object */
if ((rc = cfg_create(&cfg)) != CFG_OK) {
cfg_error(cfg, rc, &error);
fprintf(stderr, "ERROR: cfg_create: %s\n", error);
@@ -64,6 +70,7 @@
exit(1);
}
+ /* parse configuration */
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);
@@ -71,8 +78,11 @@
cfg_destroy(cfg);
exit(1);
}
+
+ /* free configuration file in memory */
free(im_ptr);
+ /* export configuration again into memory */
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);
@@ -80,10 +90,14 @@
exit(1);
}
+ /* print results */
fprintf(stdout, "%s", ex_ptr);
fflush(stdout);
+
+ /* free configuration file in memory */
free(ex_ptr);
+ /* optional node selection */
if (argc == 3) {
fprintf(stdout, "==== selection process ====\n");
if ((rc = cfg_node_select(cfg, NULL, &vec, "%s", argv[2])) != CFG_OK) {
@@ -108,6 +122,7 @@
fprintf(stdout, "==== selection end ====\n");
}
+ /* destroy configuration object */
cfg_destroy(cfg);
return 0;
|