#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "libcommon/config.h"

int main(int argc, char *argv[])
{
	char* key = "sensors.os-remotehelm.gsd.baud";
	char* str;
	int ok;

	Config * cfg = config_parse_default();

	// { int
	int val;
	ok = config_get_int(cfg, key, &val);
	if(!ok)	printf(" config result: %d\n", val);
	else	printf(" config_get_int() failed.\n");
	// } int

	// { bool
	key = "hotel.easydaq.relay8.state";
	ok = config_get_boolean(cfg, key, &val);
	if(!ok)	printf(" config result: %d\n", val);
	else	printf(" config_get_boolean() failed.\n");
	// } bool
	
	// { string
	key = "sensors.os-remotehelm.gsd.io";
	ok = config_get_string(cfg, key, &str);
	if(!ok)	printf(" config result: %s\n", str);
	else	printf(" config_get_string() failed.\n");
	// } string

	// { int array
	key = "sensors.os-remotehelm.x_vs";
	int* array;
	int len = config_get_array_len(cfg, key);
	array = malloc(sizeof(int)*len);
	printf("len: %d\n",len);
	ok = config_get_int_array(cfg, key, array, len);
	printf("ok: %d\n",ok);

	int i;
	printf(" [");
	for(i=0;i<(len-1);i++) printf("%d,",array[i]);
	printf("%d]\n",array[i]);
	
	free(array);

	// } int array

	config_free(cfg);
}
