File:  [ELWIX - Embedded LightWeight unIX -] / libelwix / example / astvar.c
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Thu Jan 17 10:05:35 2013 UTC (11 years, 4 months ago) by misho
CVS tags: MAIN, HEAD
Initial revision

#include <stdio.h>
#include <elwix.h>

int
main(int argc, char **argv)
{
	char szStr[BUFSIZ];
	ait_val_t *s;

	if (argc < 2) {
		printf("Syntax: %s <var (like {99999[:9:9]})>\n", argv[0]);
		return 1;
	}

	s = str_Ast(argv[1]);
	if (!s) {
		printf("#%d - %s\n", elwix_GetErrno(), elwix_GetError());
		return 1;
	}

	printf(">>> %s\n", AIT_GET_STR(s));

	if (av_Save(NULL, "test_av", AIT_GET_STR(s), 0, 0) == -1) {
		printf("#%d - %s\n", elwix_GetErrno(), elwix_GetError());
		ait_freeVar(&s);
		return 2;
	}
	if (av_Save(NULL, "test_av", AIT_GET_STR(s), 42, 0) == -1) {
		printf("#%d - %s\n", elwix_GetErrno(), elwix_GetError());
		ait_freeVar(&s);
		return 3;
	}

	ait_freeVar(&s);

	if (av_Load(NULL, "test_av", szStr, sizeof szStr, 0) == -1) {
		printf("#%d - %s\n", elwix_GetErrno(), elwix_GetError());
		return 4;
	} else
		printf(">>> %s\n", szStr);
	if (av_Load(NULL, "test_av", szStr, sizeof szStr, 42) == -1) {
		printf("#%d - %s\n", elwix_GetErrno(), elwix_GetError());
		return 5;
	} else
		printf(">>> %s\n", szStr);

	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>