From dd7595a3475407a7fa96a97393bae8c5220e8762 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 4 Jan 2012 18:41:13 +1000 Subject: Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje. Note that embryo wont be used, but I'm not sure yet if you can build edje without it. --- libraries/eet/src/examples/Makefile.am | 50 ++ libraries/eet/src/examples/Makefile.in | 728 ++++++++++++++++ libraries/eet/src/examples/eet-basic.c | 40 + .../eet/src/examples/eet-data-cipher_decipher.c | 119 +++ .../eet/src/examples/eet-data-file_descriptor_01.c | 529 ++++++++++++ .../eet/src/examples/eet-data-file_descriptor_02.c | 944 +++++++++++++++++++++ libraries/eet/src/examples/eet-data-nested.c | 272 ++++++ libraries/eet/src/examples/eet-data-simple.c | 224 +++++ libraries/eet/src/examples/eet-file.c | 127 +++ 9 files changed, 3033 insertions(+) create mode 100644 libraries/eet/src/examples/Makefile.am create mode 100644 libraries/eet/src/examples/Makefile.in create mode 100644 libraries/eet/src/examples/eet-basic.c create mode 100644 libraries/eet/src/examples/eet-data-cipher_decipher.c create mode 100644 libraries/eet/src/examples/eet-data-file_descriptor_01.c create mode 100644 libraries/eet/src/examples/eet-data-file_descriptor_02.c create mode 100644 libraries/eet/src/examples/eet-data-nested.c create mode 100644 libraries/eet/src/examples/eet-data-simple.c create mode 100644 libraries/eet/src/examples/eet-file.c (limited to 'libraries/eet/src/examples') diff --git a/libraries/eet/src/examples/Makefile.am b/libraries/eet/src/examples/Makefile.am new file mode 100644 index 0000000..8279445 --- /dev/null +++ b/libraries/eet/src/examples/Makefile.am @@ -0,0 +1,50 @@ +MAINTAINERCLEANFILES = Makefile.in + +pkglibdir = $(datadir)/$(PACKAGE)/examples + +if BUILD_EXAMPLES +AM_CPPFLAGS = \ +-I. \ +-I$(top_srcdir)/src/lib \ +@EINA_CFLAGS@ + +pkglib_PROGRAMS = eet_basic eet_file eet_data_simple eet_data_nested eet_data_file_descriptor_01 eet_data_file_descriptor_02 eet_data_cipher_decipher + +eet_basic_SOURCES = eet-basic.c +eet_basic_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +eet_file_SOURCES = eet-file.c +eet_file_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +eet_data_simple_SOURCES = eet-data-simple.c +eet_data_simple_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +eet_data_nested_SOURCES = eet-data-nested.c +eet_data_nested_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +eet_data_file_descriptor_01_SOURCES = eet-data-file_descriptor_01.c +eet_data_file_descriptor_01_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +eet_data_file_descriptor_02_SOURCES = eet-data-file_descriptor_02.c +eet_data_file_descriptor_02_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +eet_data_cipher_decipher_SOURCES = eet-data-cipher_decipher.c +eet_data_cipher_decipher_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ + +endif + +filesdir = $(datadir)/$(PACKAGE)/examples +files_DATA = + +if INSTALL_EXAMPLES + +files_DATA += \ +eet-basic.c \ +eet-file.c \ +eet-data-simple.c \ +eet-data-nested.c \ +eet-data-file_descriptor_01.c \ +eet-data-file_descriptor_02.c \ +eet-data-cipher_decipher.c + +endif diff --git a/libraries/eet/src/examples/Makefile.in b/libraries/eet/src/examples/Makefile.in new file mode 100644 index 0000000..d24b728 --- /dev/null +++ b/libraries/eet/src/examples/Makefile.in @@ -0,0 +1,728 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +@BUILD_EXAMPLES_TRUE@pkglib_PROGRAMS = eet_basic$(EXEEXT) \ +@BUILD_EXAMPLES_TRUE@ eet_file$(EXEEXT) \ +@BUILD_EXAMPLES_TRUE@ eet_data_simple$(EXEEXT) \ +@BUILD_EXAMPLES_TRUE@ eet_data_nested$(EXEEXT) \ +@BUILD_EXAMPLES_TRUE@ eet_data_file_descriptor_01$(EXEEXT) \ +@BUILD_EXAMPLES_TRUE@ eet_data_file_descriptor_02$(EXEEXT) \ +@BUILD_EXAMPLES_TRUE@ eet_data_cipher_decipher$(EXEEXT) +@INSTALL_EXAMPLES_TRUE@am__append_1 = \ +@INSTALL_EXAMPLES_TRUE@eet-basic.c \ +@INSTALL_EXAMPLES_TRUE@eet-file.c \ +@INSTALL_EXAMPLES_TRUE@eet-data-simple.c \ +@INSTALL_EXAMPLES_TRUE@eet-data-nested.c \ +@INSTALL_EXAMPLES_TRUE@eet-data-file_descriptor_01.c \ +@INSTALL_EXAMPLES_TRUE@eet-data-file_descriptor_02.c \ +@INSTALL_EXAMPLES_TRUE@eet-data-cipher_decipher.c + +subdir = src/examples +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_attribute.m4 \ + $(top_srcdir)/m4/ac_path_generic.m4 \ + $(top_srcdir)/m4/efl_binary.m4 \ + $(top_srcdir)/m4/efl_compiler_flag.m4 \ + $(top_srcdir)/m4/efl_coverage.m4 \ + $(top_srcdir)/m4/efl_doxygen.m4 \ + $(top_srcdir)/m4/efl_fnmatch.m4 \ + $(top_srcdir)/m4/efl_path_max.m4 $(top_srcdir)/m4/efl_tests.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(filesdir)" +PROGRAMS = $(pkglib_PROGRAMS) +am__eet_basic_SOURCES_DIST = eet-basic.c +@BUILD_EXAMPLES_TRUE@am_eet_basic_OBJECTS = eet-basic.$(OBJEXT) +eet_basic_OBJECTS = $(am_eet_basic_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_basic_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +am__eet_data_cipher_decipher_SOURCES_DIST = \ + eet-data-cipher_decipher.c +@BUILD_EXAMPLES_TRUE@am_eet_data_cipher_decipher_OBJECTS = \ +@BUILD_EXAMPLES_TRUE@ eet-data-cipher_decipher.$(OBJEXT) +eet_data_cipher_decipher_OBJECTS = \ + $(am_eet_data_cipher_decipher_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_data_cipher_decipher_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +am__eet_data_file_descriptor_01_SOURCES_DIST = \ + eet-data-file_descriptor_01.c +@BUILD_EXAMPLES_TRUE@am_eet_data_file_descriptor_01_OBJECTS = \ +@BUILD_EXAMPLES_TRUE@ eet-data-file_descriptor_01.$(OBJEXT) +eet_data_file_descriptor_01_OBJECTS = \ + $(am_eet_data_file_descriptor_01_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_data_file_descriptor_01_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +am__eet_data_file_descriptor_02_SOURCES_DIST = \ + eet-data-file_descriptor_02.c +@BUILD_EXAMPLES_TRUE@am_eet_data_file_descriptor_02_OBJECTS = \ +@BUILD_EXAMPLES_TRUE@ eet-data-file_descriptor_02.$(OBJEXT) +eet_data_file_descriptor_02_OBJECTS = \ + $(am_eet_data_file_descriptor_02_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_data_file_descriptor_02_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +am__eet_data_nested_SOURCES_DIST = eet-data-nested.c +@BUILD_EXAMPLES_TRUE@am_eet_data_nested_OBJECTS = \ +@BUILD_EXAMPLES_TRUE@ eet-data-nested.$(OBJEXT) +eet_data_nested_OBJECTS = $(am_eet_data_nested_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_data_nested_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +am__eet_data_simple_SOURCES_DIST = eet-data-simple.c +@BUILD_EXAMPLES_TRUE@am_eet_data_simple_OBJECTS = \ +@BUILD_EXAMPLES_TRUE@ eet-data-simple.$(OBJEXT) +eet_data_simple_OBJECTS = $(am_eet_data_simple_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_data_simple_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +am__eet_file_SOURCES_DIST = eet-file.c +@BUILD_EXAMPLES_TRUE@am_eet_file_OBJECTS = eet-file.$(OBJEXT) +eet_file_OBJECTS = $(am_eet_file_OBJECTS) +@BUILD_EXAMPLES_TRUE@eet_file_DEPENDENCIES = \ +@BUILD_EXAMPLES_TRUE@ $(top_builddir)/src/lib/libeet.la +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(eet_basic_SOURCES) $(eet_data_cipher_decipher_SOURCES) \ + $(eet_data_file_descriptor_01_SOURCES) \ + $(eet_data_file_descriptor_02_SOURCES) \ + $(eet_data_nested_SOURCES) $(eet_data_simple_SOURCES) \ + $(eet_file_SOURCES) +DIST_SOURCES = $(am__eet_basic_SOURCES_DIST) \ + $(am__eet_data_cipher_decipher_SOURCES_DIST) \ + $(am__eet_data_file_descriptor_01_SOURCES_DIST) \ + $(am__eet_data_file_descriptor_02_SOURCES_DIST) \ + $(am__eet_data_nested_SOURCES_DIST) \ + $(am__eet_data_simple_SOURCES_DIST) \ + $(am__eet_file_SOURCES_DIST) +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +DATA = $(files_DATA) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkglibdir = $(datadir)/$(PACKAGE)/examples +ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHECK_CFLAGS = @CHECK_CFLAGS@ +CHECK_LIBS = @CHECK_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EET_CFLAGS = @EET_CFLAGS@ +EET_CPPFLAGS = @EET_CPPFLAGS@ +EET_LIBS = @EET_LIBS@ +EET_PRG = @EET_PRG@ +EFL_COVERAGE_CFLAGS = @EFL_COVERAGE_CFLAGS@ +EFL_COVERAGE_LIBS = @EFL_COVERAGE_LIBS@ +EFL_EET_BUILD = @EFL_EET_BUILD@ +EFL_FNMATCH_LIBS = @EFL_FNMATCH_LIBS@ +EGREP = @EGREP@ +EINA_CFLAGS = @EINA_CFLAGS@ +EINA_LIBS = @EINA_LIBS@ +EVIL_CFLAGS = @EVIL_CFLAGS@ +EVIL_LIBS = @EVIL_LIBS@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ +OPENSSL_LIBS = @OPENSSL_LIBS@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +VMAJ = @VMAJ@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +efl_doxygen = @efl_doxygen@ +efl_have_doxygen = @efl_have_doxygen@ +exec_prefix = @exec_prefix@ +have_lcov = @have_lcov@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +lt_enable_auto_import = @lt_enable_auto_import@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgconfig_requires_private = @pkgconfig_requires_private@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +release_info = @release_info@ +requirement_eet = @requirement_eet@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +version_info = @version_info@ +MAINTAINERCLEANFILES = Makefile.in +@BUILD_EXAMPLES_TRUE@AM_CPPFLAGS = \ +@BUILD_EXAMPLES_TRUE@-I. \ +@BUILD_EXAMPLES_TRUE@-I$(top_srcdir)/src/lib \ +@BUILD_EXAMPLES_TRUE@@EINA_CFLAGS@ + +@BUILD_EXAMPLES_TRUE@eet_basic_SOURCES = eet-basic.c +@BUILD_EXAMPLES_TRUE@eet_basic_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +@BUILD_EXAMPLES_TRUE@eet_file_SOURCES = eet-file.c +@BUILD_EXAMPLES_TRUE@eet_file_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +@BUILD_EXAMPLES_TRUE@eet_data_simple_SOURCES = eet-data-simple.c +@BUILD_EXAMPLES_TRUE@eet_data_simple_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +@BUILD_EXAMPLES_TRUE@eet_data_nested_SOURCES = eet-data-nested.c +@BUILD_EXAMPLES_TRUE@eet_data_nested_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +@BUILD_EXAMPLES_TRUE@eet_data_file_descriptor_01_SOURCES = eet-data-file_descriptor_01.c +@BUILD_EXAMPLES_TRUE@eet_data_file_descriptor_01_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +@BUILD_EXAMPLES_TRUE@eet_data_file_descriptor_02_SOURCES = eet-data-file_descriptor_02.c +@BUILD_EXAMPLES_TRUE@eet_data_file_descriptor_02_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +@BUILD_EXAMPLES_TRUE@eet_data_cipher_decipher_SOURCES = eet-data-cipher_decipher.c +@BUILD_EXAMPLES_TRUE@eet_data_cipher_decipher_LDADD = $(top_builddir)/src/lib/libeet.la @EINA_LIBS@ +filesdir = $(datadir)/$(PACKAGE)/examples +files_DATA = $(am__append_1) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/examples/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/examples/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-pkglibPROGRAMS: $(pkglib_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(pkglibdir)" || $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" + @list='$(pkglib_PROGRAMS)'; test -n "$(pkglibdir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(pkglibdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(pkglibdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-pkglibPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(pkglib_PROGRAMS)'; test -n "$(pkglibdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkglibdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkglibdir)" && rm -f $$files + +clean-pkglibPROGRAMS: + @list='$(pkglib_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +eet_basic$(EXEEXT): $(eet_basic_OBJECTS) $(eet_basic_DEPENDENCIES) + @rm -f eet_basic$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_basic_OBJECTS) $(eet_basic_LDADD) $(LIBS) +eet_data_cipher_decipher$(EXEEXT): $(eet_data_cipher_decipher_OBJECTS) $(eet_data_cipher_decipher_DEPENDENCIES) + @rm -f eet_data_cipher_decipher$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_data_cipher_decipher_OBJECTS) $(eet_data_cipher_decipher_LDADD) $(LIBS) +eet_data_file_descriptor_01$(EXEEXT): $(eet_data_file_descriptor_01_OBJECTS) $(eet_data_file_descriptor_01_DEPENDENCIES) + @rm -f eet_data_file_descriptor_01$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_data_file_descriptor_01_OBJECTS) $(eet_data_file_descriptor_01_LDADD) $(LIBS) +eet_data_file_descriptor_02$(EXEEXT): $(eet_data_file_descriptor_02_OBJECTS) $(eet_data_file_descriptor_02_DEPENDENCIES) + @rm -f eet_data_file_descriptor_02$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_data_file_descriptor_02_OBJECTS) $(eet_data_file_descriptor_02_LDADD) $(LIBS) +eet_data_nested$(EXEEXT): $(eet_data_nested_OBJECTS) $(eet_data_nested_DEPENDENCIES) + @rm -f eet_data_nested$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_data_nested_OBJECTS) $(eet_data_nested_LDADD) $(LIBS) +eet_data_simple$(EXEEXT): $(eet_data_simple_OBJECTS) $(eet_data_simple_DEPENDENCIES) + @rm -f eet_data_simple$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_data_simple_OBJECTS) $(eet_data_simple_LDADD) $(LIBS) +eet_file$(EXEEXT): $(eet_file_OBJECTS) $(eet_file_DEPENDENCIES) + @rm -f eet_file$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(eet_file_OBJECTS) $(eet_file_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-basic.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-data-cipher_decipher.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-data-file_descriptor_01.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-data-file_descriptor_02.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-data-nested.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-data-simple.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eet-file.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-filesDATA: $(files_DATA) + @$(NORMAL_INSTALL) + test -z "$(filesdir)" || $(MKDIR_P) "$(DESTDIR)$(filesdir)" + @list='$(files_DATA)'; test -n "$(filesdir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(filesdir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(filesdir)" || exit $$?; \ + done + +uninstall-filesDATA: + @$(NORMAL_UNINSTALL) + @list='$(files_DATA)'; test -n "$(filesdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(filesdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(filesdir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) $(DATA) +installdirs: + for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(filesdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-generic clean-libtool clean-pkglibPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-filesDATA + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-filesDATA uninstall-pkglibPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-pkglibPROGRAMS ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-filesDATA \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-pkglibPROGRAMS \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-filesDATA \ + uninstall-pkglibPROGRAMS + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libraries/eet/src/examples/eet-basic.c b/libraries/eet/src/examples/eet-basic.c new file mode 100644 index 0000000..05ff397 --- /dev/null +++ b/libraries/eet/src/examples/eet-basic.c @@ -0,0 +1,40 @@ +#include + +int +main(void) +{ + Eet_File *ef; + char *ret; + int size; + char *entries[] = + { + "Entry 1", + "Big text string here compared to others", + "Eet is cool" + }; + + eet_init(); + + // blindly open an file for output and write strings with their NUL char + ef = eet_open("test.eet", EET_FILE_MODE_WRITE); + eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0); + eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1); + eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0); + eet_close(ef); + + // open the file again and blindly get the entries we wrote + ef = eet_open("test.eet", EET_FILE_MODE_READ); + ret = eet_read(ef, "Entry 1", &size); + printf("%s\n", ret); + free(ret); + ret = eet_read(ef, "Entry 2", &size); + printf("%s\n", ret); + free(ret); + ret = eet_read(ef, "Entry 3", &size); + printf("%s\n", ret); + free(ret); + eet_close(ef); + + eet_shutdown(); +} + diff --git a/libraries/eet/src/examples/eet-data-cipher_decipher.c b/libraries/eet/src/examples/eet-data-cipher_decipher.c new file mode 100644 index 0000000..2ef965c --- /dev/null +++ b/libraries/eet/src/examples/eet-data-cipher_decipher.c @@ -0,0 +1,119 @@ +/* + * build: gcc -o eet_data_file_cipher_decipher eet-data-file_cipher_decipher.c `pkg-config --cflags --libs eet eina` + */ + +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + const char *buffer = "Here is a string of data to save !"; + const char *key = "This is a crypto key"; + const char *key_bad = "This is another crypto key"; + + char *file = strdup("/tmp/eet_cipher_example_XXXXX"); + Eet_File *ef; + char *test; + int size; + + eet_init(); + + if (!(file = tmpnam(file))) + { + fprintf( + stderr, "ERROR: could not create temporary file (%s).\n", file); + goto panic; + } + + /* Crypt an eet file. */ + ef = eet_open(file, EET_FILE_MODE_WRITE); + if (!ef) + { + fprintf( + stderr, "ERROR: could not access file (%s).\n", file); + goto error; + } + + if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key)) + { + fprintf( + stderr, "ERROR: could not access file (%s).\n", file); + goto error; + } + + eet_close(ef); + + /* Decrypt an eet file. */ + ef = eet_open(file, EET_FILE_MODE_READ); + if (!ef) + { + fprintf( + stderr, "ERROR: could not access file (%s).\n", file); + goto error; + } + + test = eet_read_cipher(ef, "keys/tests", &size, key); + if (!test) + { + fprintf( + stderr, "ERROR: could decript contents on file %s, with key %s.\n", + file, key); + goto error; + } + + if (size != (int)strlen(buffer) + 1) + { + fprintf( + stderr, "ERROR: something is wrong with the decripted data\n"); + goto error; + } + + if (memcmp(test, buffer, strlen(buffer) + 1) != 0) + { + fprintf( + stderr, "ERROR: something is wrong with the decripted data\n"); + goto error; + } + + eet_close(ef); + + /* Decrypt an eet file, now using our BAD key!! */ + ef = eet_open(file, EET_FILE_MODE_READ); + if (!ef) + { + fprintf( + stderr, "ERROR: could not access file (%s).\n", file); + goto error; + } + + test = eet_read_cipher(ef, "keys/tests", &size, key_bad); + + if (size == (int)strlen(buffer) + 1) + if (memcmp(test, buffer, strlen(buffer) + 1) == 0) + { + fprintf( + stderr, "ERROR: something is wrong with the contents of %s, as" + " we accessed it with a different key and it decripted our" + " information right.\n", file); + goto error; + } + + eet_close(ef); + +error: + if (unlink(file) != 0) + { + fprintf( + stderr, "ERROR: could not unlink file (%s).\n", file); + } + +panic: + eet_shutdown(); +} + diff --git a/libraries/eet/src/examples/eet-data-file_descriptor_01.c b/libraries/eet/src/examples/eet-data-file_descriptor_01.c new file mode 100644 index 0000000..4b5b75f --- /dev/null +++ b/libraries/eet/src/examples/eet-data-file_descriptor_01.c @@ -0,0 +1,529 @@ +/* + * build: gcc -o eet_data_file_descriptor eet-data-file_descriptor.c `pkg-config --cflags --libs eet eina` + */ +#include +#include +#include +#include +#include +#include +#include + +// complex real-world structures based on elmdentica database +typedef struct +{ + const char *screen_name; + const char *name; + const char *message; + unsigned int id; + unsigned int status_id; + unsigned int date; + unsigned int timeline; +} My_Message; + +typedef struct +{ + const char *dm_to; + const char *message; +} My_Post; + +typedef struct +{ + unsigned int id; + const char *name; + Eina_List *messages; + My_Post *posts; + int posts_count; +} My_Account; + +typedef struct +{ + unsigned int version; // it is recommended to use versioned configuration! + Eina_Hash *accounts; +} My_Cache; + +// string that represents the entry in eet file, you might like to have +// different profiles or so in the same file, this is possible with +// different strings +static const char MY_CACHE_FILE_ENTRY[] = "cache"; + +// keep the descriptor static global, so it can be +// shared by different functions (load/save) of this and only this +// file. +static Eet_Data_Descriptor *_my_cache_descriptor; +static Eet_Data_Descriptor *_my_account_descriptor; +static Eet_Data_Descriptor *_my_message_descriptor; +static Eet_Data_Descriptor *_my_post_descriptor; + +// keep file handle alive, so mmap()ed strings are all alive as well +static Eet_File *_my_cache_file = NULL; +static Eet_Dictionary *_my_cache_dict = NULL; + +static void +_my_cache_descriptor_init(void) +{ + Eet_Data_Descriptor_Class eddc; + + // The FILE variant is good for caches and things that are just + // appended, but needs to take care when changing strings and files must + // be kept open so mmap()ed strings will be kept alive. + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Cache); + _my_cache_descriptor = eet_data_descriptor_file_new(&eddc); + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Account); + _my_account_descriptor = eet_data_descriptor_file_new(&eddc); + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Message); + _my_message_descriptor = eet_data_descriptor_file_new(&eddc); + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Post); + _my_post_descriptor = eet_data_descriptor_file_new(&eddc); + + // Describe the members to be saved: + // Use a temporary macro so we don't type a lot, also avoid errors: + +#define ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_message_descriptor, My_Message, # member, member, eet_type) + ADD_BASIC(screen_name, EET_T_STRING); + ADD_BASIC(name, EET_T_STRING); + ADD_BASIC(message, EET_T_STRING); + ADD_BASIC(id, EET_T_UINT); + ADD_BASIC(status_id, EET_T_UINT); + ADD_BASIC(date, EET_T_UINT); + ADD_BASIC(timeline, EET_T_UINT); +#undef ADD_BASIC + +#define ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_post_descriptor, My_Post, # member, member, eet_type) + ADD_BASIC(dm_to, EET_T_STRING); + ADD_BASIC(message, EET_T_STRING); +#undef ADD_BASIC + +#define ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_account_descriptor, My_Account, # member, member, eet_type) + ADD_BASIC(name, EET_T_STRING); + ADD_BASIC(id, EET_T_UINT); +#undef ADD_BASIC + + EET_DATA_DESCRIPTOR_ADD_LIST + (_my_account_descriptor, My_Account, "messages", messages, + _my_message_descriptor); + EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY + (_my_account_descriptor, My_Account, "posts", posts, + _my_post_descriptor); + +#define ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_cache_descriptor, My_Cache, # member, member, eet_type) + ADD_BASIC(version, EET_T_UINT); +#undef ADD_BASIC + + EET_DATA_DESCRIPTOR_ADD_HASH + (_my_cache_descriptor, My_Cache, "accounts", accounts, + _my_account_descriptor); +} /* _my_cache_descriptor_init */ + +static void +_my_cache_descriptor_shutdown(void) +{ + eet_data_descriptor_free(_my_cache_descriptor); + eet_data_descriptor_free(_my_account_descriptor); + eet_data_descriptor_free(_my_message_descriptor); + eet_data_descriptor_free(_my_post_descriptor); +} /* _my_cache_descriptor_shutdown */ + +// need to check if the pointer came from mmaped area in eet_dictionary +// or it was allocated with eina_stringshare_add() +static void +_eet_string_free(const char *str) +{ + if (!str) + return; + + if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str))) + return; + + eina_stringshare_del(str); +} /* _eet_string_free */ + +static My_Message * +_my_message_new(const char *message) +{ + My_Message *msg = calloc(1, sizeof(My_Message)); + if (!msg) + { + fprintf(stderr, "ERROR: could not calloc My_Message\n"); + return NULL; + } + + msg->message = eina_stringshare_add(message); + return msg; +} /* _my_message_new */ + +static void +_my_message_free(My_Message *msg) +{ + _eet_string_free(msg->screen_name); + _eet_string_free(msg->name); + _eet_string_free(msg->message); + free(msg); +} /* _my_message_free */ + +static Eina_Bool +_my_post_add(My_Account *acc, + const char *message) +{ + int new_count = acc->posts_count + 1; + My_Post *post = realloc(acc->posts, new_count * sizeof(My_Post)); + if (!post) + { + fprintf(stderr, "ERROR: could add My_Post\n"); + return EINA_FALSE; + } + + post[acc->posts_count].message = eina_stringshare_add(message); + post[acc->posts_count].dm_to = NULL; + acc->posts_count = new_count; + acc->posts = post; + return EINA_TRUE; +} /* _my_post_new */ + +static void +_my_post_free(My_Post *post) +{ + _eet_string_free(post->dm_to); + _eet_string_free(post->message); +} /* _my_post_free */ + +static My_Account * +_my_account_new(const char *name) +{ + My_Account *acc = calloc(1, sizeof(My_Account)); + if (!acc) + { + fprintf(stderr, "ERROR: could not calloc My_Account\n"); + return NULL; + } + + acc->name = eina_stringshare_add(name); + return acc; +} /* _my_account_new */ + +static void +_my_account_free(My_Account *acc) +{ + My_Message *m; + int i; + + _eet_string_free(acc->name); + + EINA_LIST_FREE(acc->messages, m) + _my_message_free(m); + + for (i = 0; i < acc->posts_count; i++) + _my_post_free(&acc->posts[i]); + free(acc->posts); + + free(acc); +} /* _my_account_free */ + +static My_Cache * +_my_cache_new(void) +{ + My_Cache *my_cache = calloc(1, sizeof(My_Cache)); + if (!my_cache) + { + fprintf(stderr, "ERROR: could not calloc My_Cache\n"); + return NULL; + } + + my_cache->accounts = eina_hash_string_small_new(NULL); + + my_cache->version = 1; + return my_cache; +} /* _my_cache_new */ + +static Eina_Bool +_my_cache_account_free_cb(const Eina_Hash *hash, + const void *key, + void *data, + void *fdata) +{ + _my_account_free(data); + return EINA_TRUE; +} + +static void +_my_cache_free(My_Cache *my_cache) +{ + My_Account *acc; + eina_hash_foreach(my_cache->accounts, _my_cache_account_free_cb, NULL); + eina_hash_free(my_cache->accounts); + free(my_cache); +} /* _my_cache_free */ + +static My_Account * +_my_cache_account_find(My_Cache *my_cache, + const char *name) +{ + return eina_hash_find(my_cache->accounts, name); +} /* _my_cache_account_find */ + +static My_Cache * +_my_cache_load(const char *filename) +{ + My_Cache *my_cache; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); + return NULL; + } + + my_cache = eet_data_read(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY); + if (!my_cache) + { + eet_close(ef); + return NULL; + } + + if (my_cache->version < 1) + { + fprintf(stderr, + "WARNING: version %#x was too old, upgrading it to %#x\n", + my_cache->version, 1); + + my_cache->version = 1; + } + + if (_my_cache_file) + eet_close(_my_cache_file); + + _my_cache_file = ef; + _my_cache_dict = eet_dictionary_get(ef); + + return my_cache; +} /* _my_cache_load */ + +static Eina_Bool +_my_cache_save(const My_Cache *my_cache, + const char *filename) +{ + char tmp[PATH_MAX]; + Eet_File *ef; + Eina_Bool ret; + unsigned int i, len; + struct stat st; + + len = eina_strlcpy(tmp, filename, sizeof(tmp)); + if (len + 12 >= (int)sizeof(tmp)) + { + fprintf(stderr, "ERROR: file name is too big: %s\n", filename); + return EINA_FALSE; + } + + i = 0; + do + { + snprintf(tmp + len, 12, ".%u", i); + i++; + } + while (stat(tmp, &st) == 0); + + ef = eet_open(tmp, EET_FILE_MODE_WRITE); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); + return EINA_FALSE; + } + + ret = eet_data_write + (ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE); + + // VERY IMPORTANT NOTE: + // after eet_close(), all strings mmaped from file will be GONE, invalid! + // you'll need to free the old cache and open the new one. + // For cache this is okay, as you should be saving not so often or just + // at end. + // + // This is a trade off, you save memory by using mmap()ed strings, but + // you have to care about this. + eet_close(ef); + + if (ret) + { + unlink(filename); + rename(tmp, filename); + } + + return ret; +} /* _my_cache_save */ + +int +main(int argc, + char *argv[]) +{ + My_Cache *my_cache; + const Eina_List *l_acc; + Eina_Iterator *it; + My_Account *acc; + int ret = 0; + + if (argc < 3) + { + fprintf(stderr, + "Usage:\n\t%s [action] [action-params]\n\n" + "Where actions and their parameters:\n" + "\tacc \n" + "\tpost \n" + "\tmessage \n" + "\n", + argv[0]); + return -1; + } + + eina_init(); + eet_init(); + _my_cache_descriptor_init(); + + my_cache = _my_cache_load(argv[1]); + if (!my_cache) + { + printf("creating new cache.\n"); + my_cache = _my_cache_new(); + if (!my_cache) + { + ret = -2; + goto end; + } + } + + if (argc > 3) + { + if (strcmp(argv[3], "acc") == 0) + { + if (argc == 5) + { + My_Account *acc = _my_cache_account_find(my_cache, argv[4]); + if (!acc) + { + acc = _my_account_new(argv[4]); + eina_hash_direct_add(my_cache->accounts, acc->name, acc); + } + else + fprintf(stderr, "ERROR: account '%s' already exists.\n", + argv[4]); + } + else + fprintf(stderr, + "ERROR: wrong number of parameters (%d).\n", + argc); + } + else if (strcmp(argv[3], "post") == 0) + { + if (argc == 6) + { + My_Account *acc = _my_cache_account_find(my_cache, argv[4]); + if (acc) + { + _my_post_add(acc, argv[5]); + } + else + fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); + } + else + fprintf(stderr, + "ERROR: wrong number of parameters (%d).\n", + argc); + } + else if (strcmp(argv[3], "message") == 0) + { + if (argc == 6) + { + My_Account *acc = _my_cache_account_find(my_cache, argv[4]); + if (acc) + { + My_Message *msg = _my_message_new(argv[5]); + acc->messages = eina_list_append(acc->messages, msg); + } + else + fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); + } + else + fprintf(stderr, + "ERROR: wrong number of parameters (%d).\n", + argc); + } + else + fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]); + } + + printf("My_Cache:\n" + "\tversion.: %#x\n" + "\taccounts: %u\n", + my_cache->version, + eina_hash_population(my_cache->accounts)); + it = eina_hash_iterator_data_new(my_cache->accounts); + EINA_ITERATOR_FOREACH(it, acc) + { + const My_Post *post; + + printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n", + acc->id, acc->name ? acc->name : "", + eina_list_count(acc->messages), + acc->posts_count); + + if (eina_list_count(acc->messages)) + { + const Eina_List *l; + const My_Message *msg; + printf("\t |messages:\n"); + + EINA_LIST_FOREACH(acc->messages, l, msg) + { + printf("\t | %-8x '%s' [%s]: '%.20s'\n", + msg->id, + msg->name ? msg->name : "", + msg->screen_name ? msg->screen_name : "", + msg->message ? msg->message : ""); + } + } + + if (acc->posts_count) + { + const My_Post *post; + int i; + printf("\t |posts:\n"); + + for (i = 0; i < acc->posts_count; i++) + { + post = &acc->posts[i]; + if (post->dm_to) + printf("\t | @%s: '%.20s'\n", post->dm_to, post->message); + else + printf("\t | '%.20s'\n", post->message); + } + } + + printf("\n"); + } + eina_iterator_free(it); + + if (!_my_cache_save(my_cache, argv[2])) + ret = -3; + + _my_cache_free(my_cache); + +end: + if (_my_cache_file) + eet_close(_my_cache_file); + _my_cache_descriptor_shutdown(); + eet_shutdown(); + eina_shutdown(); + + return ret; +} /* main */ + diff --git a/libraries/eet/src/examples/eet-data-file_descriptor_02.c b/libraries/eet/src/examples/eet-data-file_descriptor_02.c new file mode 100644 index 0000000..65ba79e --- /dev/null +++ b/libraries/eet/src/examples/eet-data-file_descriptor_02.c @@ -0,0 +1,944 @@ +/* + * build: gcc -o eet_data_file_descriptor_02 eet-data-file_descriptor_02.c `pkg-config --cflags --libs eet eina` + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef enum _Example_Data_Type Example_Data_Type; +typedef struct _Example_Variant_Type Example_Variant_Type; +typedef struct _Example_Variant Example_Variant; +typedef struct _Example_Union Example_Union; +typedef struct _Example_Struct1 Example_Struct1; +typedef struct _Example_Struct2 Example_Struct2; +typedef struct _Example_Struct3 Example_Struct3; +typedef struct _Example_Lists Example_Lists; + +enum _Example_Data_Type +{ + EET_UNKNOWN = 0, + EET_STRUCT1, + EET_STRUCT2, + EET_STRUCT3 +}; + +struct +{ + Example_Data_Type u; + const char *name; +} eet_mapping[] = { + { EET_STRUCT1, "ST1" }, + { EET_STRUCT2, "ST2" }, + { EET_STRUCT3, "ST3" }, + { EET_UNKNOWN, NULL } +}; + +struct _Example_Struct1 +{ + double val1; + int stuff; + const char *s1; +}; + +struct _Example_Struct2 +{ + Eina_Bool b1; + unsigned long long v1; +}; + +struct _Example_Struct3 +{ + int body; +}; + +struct _Example_Union +{ + Example_Data_Type type; + + union { + Example_Struct1 st1; + Example_Struct2 st2; + Example_Struct3 st3; + } u; +}; + +struct _Example_Variant_Type +{ + const char *type; + Eina_Bool unknow : 1; +}; + +struct _Example_Variant +{ + Example_Variant_Type t; + + void *data; /* differently than the union type, we + * don't need to pre-allocate the memory + * for the field*/ +}; + +struct _Example_Lists +{ + Eina_List *union_list; + Eina_List *variant_list; +}; + +static void +_st1_set(Example_Struct1 *st1, + double v1, + int v2, + const char *v3) +{ + st1->val1 = v1; + st1->stuff = v2; + st1->s1 = v3; +} /* _st1_set */ + +static void +_st2_set(Example_Struct2 *st2, + Eina_Bool v1, + unsigned long long v2) +{ + st2->b1 = v1; + st2->v1 = v2; +} /* _st2_set */ + +static void +_st3_set(Example_Struct3 *st3, + int v1) +{ + st3->body = v1; +} /* _st3_set */ + +static const char * +/* union + type_get() */ +_union_type_get(const void *data, + Eina_Bool *unknow) +{ + const Example_Data_Type *u = data; + int i; + + if (unknow) + *unknow = EINA_FALSE; + + for (i = 0; eet_mapping[i].name != NULL; ++i) + if (*u == eet_mapping[i].u) + return eet_mapping[i].name; + + if (unknow) + *unknow = EINA_TRUE; + + return NULL; +} /* _union_type_get */ + +static Eina_Bool +_union_type_set(const char *type, + void *data, + Eina_Bool unknow) +{ + Example_Data_Type *u = data; + int i; + + if (unknow) + return EINA_FALSE; + + for (i = 0; eet_mapping[i].name != NULL; ++i) + if (strcmp(eet_mapping[i].name, type) == 0) + { + *u = eet_mapping[i].u; + return EINA_TRUE; + } + + return EINA_FALSE; +} /* _union_type_set */ + +static const char * +_variant_type_get(const void *data, + Eina_Bool *unknow) +{ + const Example_Variant_Type *type = data; + int i; + + if (unknow) + *unknow = type->unknow; + + for (i = 0; eet_mapping[i].name != NULL; ++i) + if (strcmp(type->type, eet_mapping[i].name) == 0) + return eet_mapping[i].name; + + if (unknow) + *unknow = EINA_FALSE; + + return type->type; +} /* _variant_type_get */ + +static Eina_Bool +_variant_type_set(const char *type, + void *data, + Eina_Bool unknow) +{ + Example_Variant_Type *vt = data; + + vt->type = type; + vt->unknow = unknow; + return EINA_TRUE; +} /* _variant_type_set */ + +static Eet_Data_Descriptor * +_st1_dd(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *res; + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Struct1); + res = eet_data_descriptor_file_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC( + res, Example_Struct1, "val1", val1, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC( + res, Example_Struct1, "stuff", stuff, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC( + res, Example_Struct1, "s1", s1, EET_T_STRING); + + return res; +} /* _st1_dd */ + +static Eet_Data_Descriptor * +_st2_dd(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *res; + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Struct2); + res = eet_data_descriptor_file_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC( + res, Example_Struct2, "b1", b1, EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC( + res, Example_Struct2, "v1", v1, EET_T_ULONG_LONG); + + return res; +} /* _st2_dd */ + +static Eet_Data_Descriptor * +_st3_dd(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *res; + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Struct3); + res = eet_data_descriptor_file_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC( + res, Example_Struct3, "body", body, EET_T_INT); + + return res; +} /* _st3_dd */ + +/* string that represents the entry in the eet file. you might like to + * have different profiles or so in the same file, this is possible + * with different strings + */ +static const char CACHE_FILE_ENTRY[] = "cache"; + +/* keep the descriptor static global, so it can be shared by different + * functions (load/save) of this and only this file. + */ +static Eet_Data_Descriptor *_lists_descriptor; +static Eet_Data_Descriptor *_struct_1_descriptor; +static Eet_Data_Descriptor *_struct_2_descriptor; +static Eet_Data_Descriptor *_struct_3_descriptor; +static Eet_Data_Descriptor *_union_descriptor; +static Eet_Data_Descriptor *_variant_descriptor; +static Eet_Data_Descriptor *_union_unified_descriptor; +static Eet_Data_Descriptor *_variant_unified_descriptor; + +/* keep file handle alive, so mmap()ed strings are all alive as + * well */ +static Eet_File *_cache_file = NULL; +static Eet_Dictionary *_cache_dict = NULL; + +static void +/* declaring types */ +_data_descriptors_init(void) +{ + Eet_Data_Descriptor_Class eddc; + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Lists); + _lists_descriptor = eet_data_descriptor_file_new(&eddc); + + _struct_1_descriptor = _st1_dd(); + _struct_2_descriptor = _st2_dd(); + _struct_3_descriptor = _st3_dd(); + + /* for union */ + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Union); + _union_descriptor = eet_data_descriptor_file_new(&eddc); + + eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION; + eddc.func.type_get = _union_type_get; + eddc.func.type_set = _union_type_set; + _union_unified_descriptor = eet_data_descriptor_file_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_MAPPING( + _union_unified_descriptor, "ST1", _struct_1_descriptor); + EET_DATA_DESCRIPTOR_ADD_MAPPING( + _union_unified_descriptor, "ST2", _struct_2_descriptor); + EET_DATA_DESCRIPTOR_ADD_MAPPING( + _union_unified_descriptor, "ST3", _struct_3_descriptor); + + EET_DATA_DESCRIPTOR_ADD_UNION( + _union_descriptor, Example_Union, "u", u, type, + _union_unified_descriptor); + + EET_DATA_DESCRIPTOR_ADD_LIST( + _lists_descriptor, Example_Lists, "union_list", union_list, + _union_descriptor); + + /* for variant */ + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Variant); + _variant_descriptor = eet_data_descriptor_file_new(&eddc); + + eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION; + eddc.func.type_get = _variant_type_get; + eddc.func.type_set = _variant_type_set; + _variant_unified_descriptor = eet_data_descriptor_stream_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_MAPPING( + _variant_unified_descriptor, "ST1", _struct_1_descriptor); + EET_DATA_DESCRIPTOR_ADD_MAPPING( + _variant_unified_descriptor, "ST2", _struct_2_descriptor); + EET_DATA_DESCRIPTOR_ADD_MAPPING( + _variant_unified_descriptor, "ST3", _struct_3_descriptor); + + EET_DATA_DESCRIPTOR_ADD_VARIANT( + _variant_descriptor, Example_Variant, "data", data, t, + _variant_unified_descriptor); + + EET_DATA_DESCRIPTOR_ADD_LIST( + _lists_descriptor, Example_Lists, "variant_list", variant_list, + _variant_descriptor); +} /* _data_descriptors_init */ + +static void +_data_descriptors_shutdown(void) +{ + eet_data_descriptor_free(_lists_descriptor); + eet_data_descriptor_free(_struct_1_descriptor); + eet_data_descriptor_free(_struct_2_descriptor); + eet_data_descriptor_free(_struct_3_descriptor); + eet_data_descriptor_free(_union_descriptor); + eet_data_descriptor_free(_variant_descriptor); + eet_data_descriptor_free(_union_unified_descriptor); + eet_data_descriptor_free(_variant_unified_descriptor); +} /* _data_descriptors_shutdown */ + +/* need to check if the pointer came from mmap()ed area in + * eet_dictionary or it was allocated with eina_stringshare_add() + */ +static void +_string_free(const char *str) +{ + if (!str) + return; + + if ((_cache_dict) && (eet_dictionary_string_check(_cache_dict, str))) + return; + + eina_stringshare_del(str); +} /* _string_free */ + +static Example_Union * +_union_1_new(const char *v1, + const char *v2, + const char *v3) +{ + Example_Union *un = calloc(1, sizeof(Example_Union)); + if (!un) + { + fprintf( + stderr, "ERROR: could not allocate an Example_Union struct.\n"); + return NULL; + } + + un->type = EET_STRUCT1; + _st1_set(&(un->u.st1), atof(v1), atoi(v2), eina_stringshare_add(v3)); + + return un; +} + +static Example_Union * +_union_2_new(const char *v1, + const char *v2) +{ + Example_Union *un = calloc(1, sizeof(Example_Union)); + if (!un) + { + fprintf( + stderr, "ERROR: could not allocate an Example_Union struct.\n"); + return NULL; + } + + un->type = EET_STRUCT2; + _st2_set(&(un->u.st2), atoi(v1), atoi(v2)); + + return un; +} + +static Example_Union * +_union_3_new(const char *v1) +{ + Example_Union *un = calloc(1, sizeof(Example_Union)); + if (!un) + { + fprintf( + stderr, "ERROR: could not allocate an Example_Union struct.\n"); + return NULL; + } + + un->type = EET_STRUCT3; + _st3_set(&(un->u.st3), atoi(v1)); + + return un; +} + +static Example_Variant * +_variant_1_new(const char *v1, + const char *v2, + const char *v3) +{ + Example_Struct1 *st1; + Example_Variant *va = calloc(1, sizeof(Example_Variant)); + if (!va) + { + fprintf( + stderr, "ERROR: could not allocate an Example_Variant struct.\n"); + return NULL; + } + + va = calloc(1, sizeof (Example_Variant)); + va->t.type = eet_mapping[0].name; + st1 = calloc(1, sizeof (Example_Struct1)); + _st1_set(st1, atof(v1), atoi(v2), eina_stringshare_add(v3)); + va->data = st1; + + return va; +} + +static Example_Variant * +_variant_2_new(const char *v1, + const char *v2) +{ + printf("varinant 2 new\n"); + + Example_Struct2 *st2; + Example_Variant *va = calloc(1, sizeof(Example_Variant)); + if (!va) + { + fprintf( + stderr, "ERROR: could not allocate an Example_Variant struct.\n"); + return NULL; + } + + va = calloc(1, sizeof (Example_Variant)); + + va->t.type = eet_mapping[1].name; + + printf("type gets %s\n", va->t.type); + + st2 = calloc(1, sizeof (Example_Struct2)); + _st2_set(st2, atoi(v1), atoi(v2)); + va->data = st2; + + return va; +} + +static Example_Variant * +_variant_3_new(const char *v1) +{ + Example_Struct3 *st3; + Example_Variant *va = calloc(1, sizeof(Example_Variant)); + if (!va) + { + fprintf( + stderr, "ERROR: could not allocate an Example_Variant struct.\n"); + return NULL; + } + + va = calloc(1, sizeof (Example_Variant)); + va->t.type = eet_mapping[2].name; + st3 = calloc(1, sizeof (Example_Struct3)); + _st3_set(st3, atoi(v1)); + va->data = st3; + + return va; +} + +static Example_Lists * +_data_new(void) +{ + Example_Lists *example_lists = calloc(1, sizeof(Example_Lists)); + if (!example_lists) + { + fprintf(stderr, "ERROR: could not allocate a Example_Lists struct.\n"); + return NULL; + } + + return example_lists; +} /* _data_new */ + +static void +_union_free(Example_Union *un) +{ + if (un->type == EET_STRUCT1) + { + Example_Struct1 *st1 = &(un->u.st1); + _string_free(st1->s1); + } + + free(un); +} + +static void +_variant_free(Example_Variant *va) +{ + if (!strcmp(va->t.type, eet_mapping[0].name)) + { + Example_Struct1 *st1 = va->data; + _string_free(st1->s1); + } + + free(va->data); + free(va); +} + +static void +_data_free(Example_Lists *cache) +{ + Example_Union *un; + Example_Variant *va; + + EINA_LIST_FREE(cache->union_list, un) + _union_free(un); + + EINA_LIST_FREE(cache->variant_list, va) + _variant_free(va); + + free(cache); +} /* _data_free */ + +static Example_Lists * +_data_load(const char *filename) +{ + Example_Lists *data; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); + return NULL; + } + + data = eet_data_read(ef, _lists_descriptor, CACHE_FILE_ENTRY); + if (!data) + { + eet_close(ef); + return NULL; + } + + if (_cache_file) + eet_close(_cache_file); + + _cache_file = ef; + _cache_dict = eet_dictionary_get(ef); + + return data; +} /* _data_load */ + +static Eina_Bool +_data_save(const Example_Lists *cache, + const char *filename) +{ + char tmp[PATH_MAX]; + Eet_File *ef; + Eina_Bool ret; + unsigned int i, len; + struct stat st; + + len = eina_strlcpy(tmp, filename, sizeof(tmp)); + if (len + 12 >= (int)sizeof(tmp)) + { + fprintf(stderr, "ERROR: file name is too big: %s\n", filename); + return EINA_FALSE; + } + + i = 0; + do + { + snprintf(tmp + len, 12, ".%u", i); + i++; + } + while (stat(tmp, &st) == 0); + + ef = eet_open(tmp, EET_FILE_MODE_WRITE); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); + return EINA_FALSE; + } + + ret = eet_data_write + (ef, _lists_descriptor, CACHE_FILE_ENTRY, cache, EINA_TRUE); + + eet_close(ef); + + if (ret) + { + unlink(filename); + rename(tmp, filename); + } + + return ret; +} /* _data_save */ + +static void +_print_union(const Example_Union *un) +{ + printf("\t | type: %s'\n", eet_mapping[un->type - 1].name); + + switch (un->type) + { + case EET_STRUCT1: + printf("\t\t val1: %f\n", un->u.st1.val1); + printf("\t\t stuff: %d\n", un->u.st1.stuff); + printf("\t\t s1: %s\n", un->u.st1.s1); + break; + + case EET_STRUCT2: + printf("\t\t val1: %i\n", un->u.st2.b1); + printf("\t\t stuff: %lli\n", un->u.st2.v1); + break; + + case EET_STRUCT3: + printf("\t\t val1: %i\n", un->u.st3.body); + break; + + default: + return; + } +} + +static void +_print_variant(const Example_Variant *va) +{ + printf("\t | type: %s'\n", va->t.type); + + switch (va->t.type[2]) + { + case '1': + { + Example_Struct1 *st1 = va->data; + + printf("\t\t val1: %f\n", st1->val1); + printf("\t\t stuff: %d\n", st1->stuff); + printf("\t\t s1: %s\n", st1->s1); + } + break; + + case '2': + { + Example_Struct2 *st2 = va->data; + + printf("\t\t val1: %i\n", st2->b1); + printf("\t\t stuff: %lli\n", st2->v1); + } + break; + + case '3': + { + Example_Struct3 *st3 = va->data; + + printf("\t\t val1: %i\n", st3->body); + } + break; + + default: + return; + } +} + +int +main(int argc, + char *argv[]) +{ + Example_Lists *data_lists; + int ret = 0; + + if (argc < 3) + { + fprintf(stderr, + "Usage:\n\t%s [action action-params]\n\n" + "where actions and their parameters are:\n" + "\tunion [fields]\n" + "\tvariant [fields]\n" + "\n", + argv[0]); + return -1; + } + + eina_init(); + eet_init(); + _data_descriptors_init(); + + data_lists = _data_load(argv[1]); + if (!data_lists) + { + printf("Creating new data lists.\n"); + data_lists = _data_new(); + if (!data_lists) + { + ret = -2; + goto end; + } + } + + if (argc > 3) + { + if (strcmp(argv[3], "union") == 0) + { + if (argc > 4) + { + int type = atoi(argv[4]); + Example_Union *un; + + if (type < EET_STRUCT1 || type > EET_STRUCT3) + { + fprintf(stderr, + "ERROR: invalid type parameter (%s).\n", + argv[4]); + goto cont; + } + + switch (type) + { + case 1: + if (argc != 8) + { + fprintf( + stderr, "ERROR: wrong number of parameters" + " (%d).\n", argc); + goto cont; + } + + un = _union_1_new( + argv[5], argv[6], argv[7]); + if (!un) + { + fprintf( + stderr, "ERROR: could not create the " + "requested union.\n"); + goto cont; + } + data_lists->union_list = + eina_list_append(data_lists->union_list, un); + break; + + case 2: + if (argc != 7) + { + fprintf( + stderr, "ERROR: wrong number of parameters" + " (%d).\n", argc); + goto cont; + } + + un = _union_2_new(argv[5], argv[6]); + if (!un) + { + fprintf( + stderr, "ERROR: could not create the " + "requested union.\n"); + goto cont; + } + data_lists->union_list = + eina_list_append(data_lists->union_list, un); + break; + + case 3: + if (argc != 6) + { + fprintf( + stderr, "ERROR: wrong number of parameters" + " (%d).\n", argc); + goto cont; + } + + un = _union_3_new(argv[5]); + if (!un) + { + fprintf( + stderr, "ERROR: could not create the " + "requested union.\n"); + goto cont; + } + data_lists->union_list = + eina_list_append(data_lists->union_list, un); + break; + + default: + fprintf( + stderr, "ERROR: bad type of of struct passed\n"); + goto cont; + } + } + else + fprintf(stderr, + "ERROR: wrong number of parameters (%d).\n", + argc); + } + else if (strcmp(argv[3], "variant") == 0) + { + if (argc > 4) + { + int type = atoi(argv[4]); + Example_Variant *va; + + if (type < EET_STRUCT1 || type > EET_STRUCT3) + { + fprintf(stderr, + "ERROR: invalid type parameter (%s).\n", + argv[4]); + goto cont; + } + + switch (type) + { + case 1: + if (argc != 8) + { + fprintf( + stderr, "ERROR: wrong number of parameters" + " (%d).\n", argc); + goto cont; + } + + va = _variant_1_new( + argv[5], argv[6], argv[7]); + if (!va) + { + fprintf( + stderr, "ERROR: could not create the " + "requested variant.\n"); + goto cont; + } + data_lists->variant_list = + eina_list_append(data_lists->variant_list, va); + break; + + case 2: + if (argc != 7) + { + fprintf( + stderr, "ERROR: wrong number of parameters" + " (%d).\n", argc); + goto cont; + } + + va = _variant_2_new(argv[5], argv[6]); + if (!va) + { + fprintf( + stderr, "ERROR: could not create the " + "requested variant.\n"); + goto cont; + } + data_lists->variant_list = + eina_list_append(data_lists->variant_list, va); + break; + + case 3: + if (argc != 6) + { + fprintf( + stderr, "ERROR: wrong number of parameters" + " (%d).\n", argc); + goto cont; + } + + va = _variant_3_new(argv[5]); + if (!va) + { + fprintf( + stderr, "ERROR: could not create the " + "requested variant.\n"); + goto cont; + } + data_lists->variant_list = + eina_list_append(data_lists->variant_list, va); + break; + + default: + fprintf( + stderr, "ERROR: bad type of of struct passed\n"); + goto cont; + } + } + else + fprintf(stderr, + "ERROR: wrong number of parameters (%d).\n", + argc); + } + else + fprintf(stderr, "ERROR: unknown action '%s'\n", argv[3]); + } + +cont: + printf("Cached data:\n"); + + printf("\tstats: unions=%u, variants=%u\n", + eina_list_count(data_lists->union_list), + eina_list_count(data_lists->variant_list)); + + if (eina_list_count(data_lists->union_list)) + { + const Eina_List *l; + const Example_Union *un; + printf("\t * union list:\n"); + + EINA_LIST_FOREACH(data_lists->union_list, l, un) + { + _print_union(un); + } + } + + if (eina_list_count(data_lists->variant_list)) + { + const Eina_List *l; + const Example_Variant *un; + printf("\t * variant list:\n"); + + EINA_LIST_FOREACH(data_lists->variant_list, l, un) + { + _print_variant(un); + } + } + + printf("\n"); + + if (!_data_save(data_lists, argv[2])) + ret = -3; + + _data_free(data_lists); + +end: + if (_cache_file) + eet_close(_cache_file); + _data_descriptors_shutdown(); + eet_shutdown(); + eina_shutdown(); + + return ret; +} /* main */ + diff --git a/libraries/eet/src/examples/eet-data-nested.c b/libraries/eet/src/examples/eet-data-nested.c new file mode 100644 index 0000000..a6b0e12 --- /dev/null +++ b/libraries/eet/src/examples/eet-data-nested.c @@ -0,0 +1,272 @@ +/* + * build: gcc -o eet_data_nested eet-data-nested.c `pkg-config --cflags --libs eet eina` + */ +#include +#include +#include +#include +#include +#include +#include + +// The struct that will be loaded and saved. +// note that only the members described in the eet_data_descriptor +// will be automatically handled. The other members will have their +// space reserved and zeroed (as it uses calloc()), but not +// saved or loaded from eet files. +typedef struct +{ + unsigned int version; // it is recommended to use versioned configuration! + const char *name; + int id; + int not_saved_value; // example of not saved data inside! + Eina_Bool enabled; + Eina_List *subs; +} My_Conf_Type; + +typedef struct +{ + const char *server; + int port; +} My_Conf_Subtype; + +// string that represents the entry in eet file, you might like to have +// different profiles or so in the same file, this is possible with +// different strings +static const char MY_CONF_FILE_ENTRY[] = "config"; + +// keep the descriptor static global, so it can be +// shared by different functions (load/save) of this and only this +// file. +static Eet_Data_Descriptor *_my_conf_descriptor; +static Eet_Data_Descriptor *_my_conf_sub_descriptor; + +static void +_my_conf_descriptor_init(void) +{ + Eet_Data_Descriptor_Class eddc; + + // The class describe the functions to use to create the type and its + // full allocated size. + // + // Eina types are very convenient, so use them to create the descriptor, + // so we get eina_list, eina_hash and eina_stringshare automatically! + // + // The STREAM variant is better for configuration files as the values + // will likely change a lot. + // + // The other variant, FILE, is good for caches and things that are just + // appended, but needs to take care when changing strings and files must + // be kept open so mmap()ed strings will be kept alive. + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Conf_Type); + _my_conf_descriptor = eet_data_descriptor_stream_new(&eddc); + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Conf_Subtype); + _my_conf_sub_descriptor = eet_data_descriptor_stream_new(&eddc); + + // Describe the members to be saved: + // Use a temporary macro so we don't type a lot, also avoid errors: +#define MY_CONF_ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type) +#define MY_CONF_SUB_ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_conf_sub_descriptor, My_Conf_Subtype, # member, member, eet_type) + + MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING); + MY_CONF_SUB_ADD_BASIC(port, EET_T_INT); + + MY_CONF_ADD_BASIC(version, EET_T_UINT); + MY_CONF_ADD_BASIC(name, EET_T_STRING); + MY_CONF_ADD_BASIC(id, EET_T_INT); + MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); + + // And add the sub descriptor as a linked list at 'subs' in the main struct + EET_DATA_DESCRIPTOR_ADD_LIST + (_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor); + +#undef MY_CONF_ADD_BASIC +#undef MY_CONF_SUB_ADD_BASIC +} /* _my_conf_descriptor_init */ + +static void +_my_conf_descriptor_shutdown(void) +{ + eet_data_descriptor_free(_my_conf_sub_descriptor); + eet_data_descriptor_free(_my_conf_descriptor); +} /* _my_conf_descriptor_shutdown */ + +static My_Conf_Type * +_my_conf_new(void) +{ + My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type)); + My_Conf_Subtype *sub; + if (!my_conf) + { + fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); + return NULL; + } + + my_conf->version = 0x112233; + my_conf->enabled = EINA_TRUE; + + sub = calloc(1, sizeof(My_Conf_Subtype)); + if (sub) + { + sub->server = eina_stringshare_add("my-server.com"); + sub->port = 1234; + my_conf->subs = eina_list_append(my_conf->subs, sub); + } + + return my_conf; +} /* _my_conf_new */ + +static void +_my_conf_free(My_Conf_Type *my_conf) +{ + My_Conf_Subtype *sub; + EINA_LIST_FREE(my_conf->subs, sub) + { + eina_stringshare_del(sub->server); + free(sub); + } + + eina_stringshare_del(my_conf->name); + free(my_conf); +} /* _my_conf_free */ + +static My_Conf_Type * +_my_conf_load(const char *filename) +{ + My_Conf_Type *my_conf; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); + return NULL; + } + + my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); + if (!my_conf) + goto end; + + if (my_conf->version < 0x112233) + { + fprintf(stderr, + "WARNING: version %#x was too old, upgrading it to %#x\n", + my_conf->version, 0x112233); + + my_conf->version = 0x112233; + my_conf->enabled = EINA_TRUE; + } + +end: + eet_close(ef); + return my_conf; +} /* _my_conf_load */ + +static Eina_Bool +_my_conf_save(const My_Conf_Type *my_conf, + const char *filename) +{ + char tmp[PATH_MAX]; + Eet_File *ef; + Eina_Bool ret; + unsigned int i, len; + struct stat st; + + len = eina_strlcpy(tmp, filename, sizeof(tmp)); + if (len + 12 >= (int)sizeof(tmp)) + { + fprintf(stderr, "ERROR: file name is too big: %s\n", filename); + return EINA_FALSE; + } + + i = 0; + do + { + snprintf(tmp + len, 12, ".%u", i); + i++; + } + while (stat(tmp, &st) == 0); + + ef = eet_open(tmp, EET_FILE_MODE_WRITE); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); + return EINA_FALSE; + } + + ret = eet_data_write + (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); + eet_close(ef); + + if (ret) + { + unlink(filename); + rename(tmp, filename); + } + + return ret; +} /* _my_conf_save */ + +int +main(int argc, + char *argv[]) +{ + My_Conf_Type *my_conf; + const My_Conf_Subtype *sub; + const Eina_List *l; + int ret = 0; + + if (argc != 3) + { + fprintf(stderr, "Usage:\n\t%s \n\n", argv[0]); + return -1; + } + + eina_init(); + eet_init(); + _my_conf_descriptor_init(); + + my_conf = _my_conf_load(argv[1]); + if (!my_conf) + { + printf("creating new configuration.\n"); + my_conf = _my_conf_new(); + if (!my_conf) + { + ret = -2; + goto end; + } + } + + printf("My_Conf_Type:\n" + "\tversion: %#x\n" + "\tname...: '%s'\n" + "\tid.....: %d\n" + "\tenabled: %hhu\n" + "\tsubs...:\n", + my_conf->version, + my_conf->name ? my_conf->name : "", + my_conf->id, + my_conf->enabled); + + EINA_LIST_FOREACH(my_conf->subs, l, sub) + printf("\t\tserver: '%s', port: %d\n", + sub->server ? sub->server : "", + sub->port); + + if (!_my_conf_save(my_conf, argv[2])) + ret = -3; + + _my_conf_free(my_conf); + +end: + _my_conf_descriptor_shutdown(); + eet_shutdown(); + eina_shutdown(); + + return ret; +} /* main */ + diff --git a/libraries/eet/src/examples/eet-data-simple.c b/libraries/eet/src/examples/eet-data-simple.c new file mode 100644 index 0000000..1951fc0 --- /dev/null +++ b/libraries/eet/src/examples/eet-data-simple.c @@ -0,0 +1,224 @@ +/* + * build: gcc -o eet_data_simple eet-data-simple.c `pkg-config --cflags --libs eet eina` + */ +#include +#include +#include +#include +#include +#include +#include + +// The struct that will be loaded and saved. +// note that only the members described in the eet_data_descriptor +// will be automatically handled. The other members will have their +// space reserved and zeroed (as it uses calloc()), but not +// saved or loaded from eet files. +typedef struct +{ + unsigned int version; // it is recommended to use versioned configuration! + const char *name; + int id; + int not_saved_value; // example of not saved data inside! + Eina_Bool enabled; +} My_Conf_Type; + +// string that represents the entry in eet file, you might like to have +// different profiles or so in the same file, this is possible with +// different strings +static const char MY_CONF_FILE_ENTRY[] = "config"; + +// keep the descriptor static global, so it can be +// shared by different functions (load/save) of this and only this +// file. +static Eet_Data_Descriptor *_my_conf_descriptor; + +static void +_my_conf_descriptor_init(void) +{ + Eet_Data_Descriptor_Class eddc; + + // The class describe the functions to use to create the type and its + // full allocated size. + // + // Eina types are very convenient, so use them to create the descriptor, + // so we get eina_list, eina_hash and eina_stringshare automatically! + // + // The STREAM variant is better for configuration files as the values + // will likely change a lot. + // + // The other variant, FILE, is good for caches and things that are just + // appended, but needs to take care when changing strings and files must + // be kept open so mmap()ed strings will be kept alive. + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, My_Conf_Type); + _my_conf_descriptor = eet_data_descriptor_stream_new(&eddc); + + // Describe the members to be saved: + // Use a temporary macro so we don't type a lot, also avoid errors: +#define MY_CONF_ADD_BASIC(member, eet_type) \ + EET_DATA_DESCRIPTOR_ADD_BASIC \ + (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type) + + MY_CONF_ADD_BASIC(version, EET_T_UINT); + MY_CONF_ADD_BASIC(name, EET_T_STRING); + MY_CONF_ADD_BASIC(id, EET_T_INT); + MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); + +#undef MY_CONF_ADD_BASIC +} /* _my_conf_descriptor_init */ + +static void +_my_conf_descriptor_shutdown(void) +{ + eet_data_descriptor_free(_my_conf_descriptor); +} /* _my_conf_descriptor_shutdown */ + +static My_Conf_Type * +_my_conf_new(void) +{ + My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type)); + if (!my_conf) + { + fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); + return NULL; + } + + my_conf->version = 0x112233; + my_conf->enabled = EINA_TRUE; + return my_conf; +} /* _my_conf_new */ + +static void +_my_conf_free(My_Conf_Type *my_conf) +{ + eina_stringshare_del(my_conf->name); + free(my_conf); +} /* _my_conf_free */ + +static My_Conf_Type * +_my_conf_load(const char *filename) +{ + My_Conf_Type *my_conf; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); + return NULL; + } + + my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); + if (!my_conf) + goto end; + + if (my_conf->version < 0x112233) + { + fprintf(stderr, + "WARNING: version %#x was too old, upgrading it to %#x\n", + my_conf->version, 0x112233); + + my_conf->version = 0x112233; + my_conf->enabled = EINA_TRUE; + } + +end: + eet_close(ef); + return my_conf; +} /* _my_conf_load */ + +static Eina_Bool +_my_conf_save(const My_Conf_Type *my_conf, + const char *filename) +{ + char tmp[PATH_MAX]; + Eet_File *ef; + Eina_Bool ret; + unsigned int i, len; + struct stat st; + + len = eina_strlcpy(tmp, filename, sizeof(tmp)); + if (len + 12 >= (int)sizeof(tmp)) + { + fprintf(stderr, "ERROR: file name is too big: %s\n", filename); + return EINA_FALSE; + } + + i = 0; + do + { + snprintf(tmp + len, 12, ".%u", i); + i++; + } + while (stat(tmp, &st) == 0); + + ef = eet_open(tmp, EET_FILE_MODE_WRITE); + if (!ef) + { + fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); + return EINA_FALSE; + } + + ret = eet_data_write + (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); + eet_close(ef); + + if (ret) + { + unlink(filename); + rename(tmp, filename); + } + + return ret; +} /* _my_conf_save */ + +int +main(int argc, + char *argv[]) +{ + My_Conf_Type *my_conf; + int ret = 0; + + if (argc != 3) + { + fprintf(stderr, "Usage:\n\t%s \n\n", argv[0]); + return -1; + } + + eina_init(); + eet_init(); + _my_conf_descriptor_init(); + + my_conf = _my_conf_load(argv[1]); + if (!my_conf) + { + printf("creating new configuration.\n"); + my_conf = _my_conf_new(); + if (!my_conf) + { + ret = -2; + goto end; + } + } + + printf("My_Conf_Type:\n" + "\tversion: %#x\n" + "\tname...: '%s'\n" + "\tid.....: %d\n" + "\tenabled: %hhu\n", + my_conf->version, + my_conf->name ? my_conf->name : "", + my_conf->id, + my_conf->enabled); + + if (!_my_conf_save(my_conf, argv[2])) + ret = -3; + + _my_conf_free(my_conf); + +end: + _my_conf_descriptor_shutdown(); + eet_shutdown(); + eina_shutdown(); + + return ret; +} /* main */ + diff --git a/libraries/eet/src/examples/eet-file.c b/libraries/eet/src/examples/eet-file.c new file mode 100644 index 0000000..740c179 --- /dev/null +++ b/libraries/eet/src/examples/eet-file.c @@ -0,0 +1,127 @@ +/* + * build: gcc -o eet_file eet-file.c `pkg-config --cflags --libs eet` + */ +#include +#include +#include + +static int +create_eet_file(void) +{ + Eet_File *ef; + char buf[1024], *ptr; + int size, len, i; + const char *some_strings[] = { + "And some more strings", + "spread across several", + "elements of an array!" + }; + const char some_data[] = + "\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35" + "\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11" + "\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f" + "\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69" + "\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68" + "\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79" + "\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68" + "\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f" + "\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d" + "\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f" + "\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20" + "\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64" + "\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f" + "\x72\x79\x2e\x0a\x00"; + + ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE); + if (!ef) return 0; + + strcpy(buf, "Here is a string of data to save!"); + size = eet_write(ef, "/key/to_store/at", buf, sizeof(buf), 1); + if (!size) + { + fprintf(stderr, "Error writing data!\n"); + eet_close(ef); + return 0; + } + len = strlen(buf); + printf("strlen() = %d, eet_write() = %d\n", len, size); + + ptr = buf; + for (i = 0; i < 3; i++) + { + len = strlen(some_strings[i]) + 1; + memcpy(ptr, some_strings[i], len); + ptr += len; + } + eet_write(ef, "/several/strings", buf, sizeof(buf), 1); + eet_sync(ef); + + eet_write(ef, "/some/mysterious/data", some_data, sizeof(some_data) - 1, 1); + + eet_delete(ef, "/several/strings"); + + return eet_close(ef) == EET_ERROR_NONE; +} + +int +main(void) +{ + Eet_File *ef; + char *ret, **list; + int size, num, i; + + eet_init(); + + if (!create_eet_file()) + return -1; + + ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ); + if (!ef) return -1; + + list = eet_list(ef, "*", &num); + if (list) + { + for (i = 0; i < num; i++) + printf("Key stored: %s\n", list[i]); + free(list); + } + + ret = eet_read(ef, "/key/to_store/at", &size); + if (ret) + { + printf("Data read (%i bytes):\n%s\n", size, ret); + free(ret); + } + + ret = eet_read(ef, "/several/strings", &size); + if (ret) + { + printf("More data read (%i bytes):\n%s\n", size, ret); + free(ret); + } + + ret = eet_read(ef, "/some/mysterious/data", &size); + if (ret) + { + Eet_File *ef2; + + ef2 = eet_memopen_read(ret, size); + + num = eet_num_entries(ef2); + printf("Mysterious data has %d entries\n", num); + + printf("Mysterious data:\n%s\n", + (char *)eet_read_direct(ef2, "/mysterious/data", NULL)); + + eet_close(ef2); + + free(ret); + } + + eet_close(ef); + + eet_shutdown(); + + return 0; +} + -- cgit v1.1