summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--legacy/eet/.cvsignore2
-rw-r--r--legacy/eet/ChangeLog0
-rw-r--r--legacy/eet/INSTALL14
-rw-r--r--legacy/eet/Makefile.am10
-rw-r--r--legacy/eet/NEWS0
-rw-r--r--legacy/eet/acconfig.h3
-rwxr-xr-xlegacy/eet/autogen.sh137
-rw-r--r--legacy/eet/configure.ac75
-rw-r--r--legacy/eet/configure.in75
-rw-r--r--legacy/eet/debian/.cvsignore7
-rw-r--r--legacy/eet/debian/changelog6
-rw-r--r--legacy/eet/debian/control29
-rw-r--r--legacy/eet/debian/copyright32
-rw-r--r--legacy/eet/debian/eet-config.127
-rw-r--r--legacy/eet/debian/eet.161
-rw-r--r--legacy/eet/debian/libeet0-dev.files4
-rw-r--r--legacy/eet/debian/libeet0.files2
-rw-r--r--legacy/eet/debian/rules74
-rw-r--r--legacy/eet/eet-config.in59
-rw-r--r--legacy/eet/eet.spec63
-rw-r--r--legacy/eet/src/.cvsignore3
-rw-r--r--legacy/eet/src/Makefile.am3
-rw-r--r--legacy/eet/src/bin/.cvsignore3
-rw-r--r--legacy/eet/src/bin/Makefile.am12
-rw-r--r--legacy/eet/src/bin/eet_main.c420
-rw-r--r--legacy/eet/src/lib/.cvsignore3
-rw-r--r--legacy/eet/src/lib/Eet.h268
-rw-r--r--legacy/eet/src/lib/Makefile.am20
-rw-r--r--legacy/eet/src/lib/eet_data.c1765
-rw-r--r--legacy/eet/src/lib/eet_lib.c889
30 files changed, 4066 insertions, 0 deletions
diff --git a/legacy/eet/.cvsignore b/legacy/eet/.cvsignore
new file mode 100644
index 0000000000..2b9156e6be
--- /dev/null
+++ b/legacy/eet/.cvsignore
@@ -0,0 +1,2 @@
1.config
2build-stamp
diff --git a/legacy/eet/ChangeLog b/legacy/eet/ChangeLog
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/legacy/eet/ChangeLog
diff --git a/legacy/eet/INSTALL b/legacy/eet/INSTALL
new file mode 100644
index 0000000000..3a3ad7ed8f
--- /dev/null
+++ b/legacy/eet/INSTALL
@@ -0,0 +1,14 @@
1COMPILING and INSTALLING:
2
3If you got a official release tar archive do:
4 ./configure
5
6( otherwise if you got this from enlightenment cvs do: ./autogen.sh )
7
8Then to compile:
9 make
10
11To install (run this as root, or the user who handles installs):
12 make install
13
14NOTE: You MUST make install Eet for it to run properly.
diff --git a/legacy/eet/Makefile.am b/legacy/eet/Makefile.am
new file mode 100644
index 0000000000..7e766defc9
--- /dev/null
+++ b/legacy/eet/Makefile.am
@@ -0,0 +1,10 @@
1## Process this file with automake to produce Makefile.in
2
3SUBDIRS = src
4
5MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \
6 config.h.in config.sub configure install-sh \
7 ltconfig ltmain.sh missing mkinstalldirs \
8 stamp-h.in
9
10EXTRA_DIST = README AUTHORS COPYING eet.spec
diff --git a/legacy/eet/NEWS b/legacy/eet/NEWS
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/legacy/eet/NEWS
diff --git a/legacy/eet/acconfig.h b/legacy/eet/acconfig.h
new file mode 100644
index 0000000000..bd2bb91752
--- /dev/null
+++ b/legacy/eet/acconfig.h
@@ -0,0 +1,3 @@
1#undef PACKAGE_SOURCE_DIR
2#undef PACKAGE_BIN_DIR
3#undef PACKAGE_LIB_DIR
diff --git a/legacy/eet/autogen.sh b/legacy/eet/autogen.sh
new file mode 100755
index 0000000000..9226176c74
--- /dev/null
+++ b/legacy/eet/autogen.sh
@@ -0,0 +1,137 @@
1#!/bin/sh
2# Run this to generate all the initial makefiles, etc.
3
4srcdir=`dirname $0`
5PKG_NAME="the package."
6
7DIE=0
8
9(autoconf --version) < /dev/null > /dev/null 2>&1 || {
10 echo
11 echo "**Error**: You must have \`autoconf' installed to."
12 echo "Download the appropriate package for your distribution,"
13 echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
14 DIE=1
15}
16
17(grep "^AM_PROG_LIBTOOL" $srcdir/configure.in >/dev/null) && {
18 (libtool --version) < /dev/null > /dev/null 2>&1 || {
19 echo
20 echo "**Error**: You must have \`libtool' installed."
21 echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2d.tar.gz"
22 echo "(or a newer version if it is available)"
23 DIE=1
24 }
25}
26
27grep "^AM_GNU_GETTEXT" $srcdir/configure.in >/dev/null && {
28 grep "sed.*POTFILES" $srcdir/configure.in >/dev/null || \
29 (gettext --version) < /dev/null > /dev/null 2>&1 || {
30 echo
31 echo "**Error**: You must have \`gettext' installed."
32 echo "Get ftp://alpha.gnu.org/gnu/gettext-0.10.35.tar.gz"
33 echo "(or a newer version if it is available)"
34 DIE=1
35 }
36}
37
38(automake --version) < /dev/null > /dev/null 2>&1 || {
39 echo
40 echo "**Error**: You must have \`automake' installed."
41 echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz"
42 echo "(or a newer version if it is available)"
43 DIE=1
44 NO_AUTOMAKE=yes
45}
46
47
48# if no automake, don't bother testing for aclocal
49test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
50 echo
51 echo "**Error**: Missing \`aclocal'. The version of \`automake'"
52 echo "installed doesn't appear recent enough."
53 echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz"
54 echo "(or a newer version if it is available)"
55 DIE=1
56}
57
58if test "$DIE" -eq 1; then
59 exit 1
60fi
61
62if test -z "$*"; then
63 echo "**Warning**: I am going to run \`configure' with no arguments."
64 echo "If you wish to pass any to it, please specify them on the"
65 echo \`$0\'" command line."
66 echo
67fi
68
69case $CC in
70xlc )
71 am_opt=--include-deps;;
72esac
73
74for coin in `find $srcdir -name configure.in -print`
75do
76 dr=`dirname $coin`
77 if test -f $dr/NO-AUTO-GEN; then
78 echo skipping $dr -- flagged as no auto-gen
79 else
80 echo processing $dr
81 macrodirs=`sed -n -e 's,AM_ACLOCAL_INCLUDE(\(.*\)),\1,gp' < $coin`
82 ( cd $dr
83 aclocalinclude="$ACLOCAL_FLAGS"
84 for k in $macrodirs; do
85 if test -d $k; then
86 aclocalinclude="$aclocalinclude -I $k"
87 ##else
88 ## echo "**Warning**: No such directory \`$k'. Ignored."
89 fi
90 done
91 if grep "^AM_GNU_GETTEXT" configure.in >/dev/null; then
92 if grep "sed.*POTFILES" configure.in >/dev/null; then
93 : do nothing -- we still have an old unmodified configure.in
94 else
95 echo "Creating $dr/aclocal.m4 ..."
96 test -r $dr/aclocal.m4 || touch $dr/aclocal.m4
97 echo "Running gettextize... Ignore non-fatal messages."
98 echo "no" | gettextize --force --copy
99 echo "Making $dr/aclocal.m4 writable ..."
100 test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4
101 fi
102 fi
103 if grep "^AM_GNOME_GETTEXT" configure.in >/dev/null; then
104 echo "Creating $dr/aclocal.m4 ..."
105 test -r $dr/aclocal.m4 || touch $dr/aclocal.m4
106 echo "Running gettextize... Ignore non-fatal messages."
107 echo "no" | gettextize --force --copy
108 echo "Making $dr/aclocal.m4 writable ..."
109 test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4
110 fi
111 if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then
112 echo "Running libtoolize..."
113 libtoolize --force --copy
114 fi
115 echo "Running aclocal $aclocalinclude ..."
116 aclocal $aclocalinclude
117 if grep "^AM_CONFIG_HEADER" configure.in >/dev/null; then
118 echo "Running autoheader..."
119 autoheader
120 fi
121 echo "Running automake --gnu $am_opt ..."
122 automake --add-missing --gnu $am_opt
123 echo "Running autoconf ..."
124 autoconf
125 )
126 fi
127done
128
129#conf_flags="--enable-maintainer-mode --enable-compile-warnings" #--enable-iso-c
130
131if test x$NOCONFIGURE = x; then
132 echo Running $srcdir/configure $conf_flags "$@" ...
133 $srcdir/configure $conf_flags "$@" \
134 && echo Now type \`make\' to compile $PKG_NAME
135else
136 echo Skipping configure process.
137fi
diff --git a/legacy/eet/configure.ac b/legacy/eet/configure.ac
new file mode 100644
index 0000000000..a391da6e45
--- /dev/null
+++ b/legacy/eet/configure.ac
@@ -0,0 +1,75 @@
1dnl Process this file with autoconf to produce a configure script.
2
3# get rid of that stupid cache mechanism
4rm -f config.cache
5
6AC_INIT(configure.in)
7AM_INIT_AUTOMAKE(eet, 0.0.1)
8AM_CONFIG_HEADER(config.h)
9
10AC_ISC_POSIX
11AC_PROG_CC
12AM_PROG_CC_STDC
13AC_HEADER_STDC
14AC_C_CONST
15AM_ENABLE_SHARED
16AM_PROG_LIBTOOL
17
18if test "x${exec_prefix}" = "xNONE"; then
19 if test "x${prefix}" = "xNONE"; then
20 bindir="${ac_default_prefix}/bin";
21 else
22 bindir="${prefix}/bin";
23 fi
24else
25 if test "x${prefix}" = "xNONE"; then
26 bindir="${ac_default_prefix}/bin";
27 else
28 bindir="${prefix}/bin";
29 fi
30fi
31
32if test "x${exec_prefix}" = "xNONE"; then
33 if test "x${prefix}" = "xNONE"; then
34 libdir="${ac_default_prefix}/lib";
35 else
36 libdir="${prefix}/lib";
37 fi
38else
39 if test "x${prefix}" = "xNONE"; then
40 libdir="${ac_default_prefix}/lib";
41 else
42 libdir="${prefix}/lib";
43 fi
44fi
45
46dnl Set PACKAGE_BIN_DIR in config.h.
47if test "x${bindir}" = 'xNONE'; then
48 if test "x${prefix}" = "xNONE"; then
49 AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${ac_default_prefix}/bin")
50 else
51 AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${prefix}/bin")
52 fi
53else
54 AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${bindir}")
55fi
56
57dnl Set PACKAGE_LIB_DIR in config.h.
58if test "x${libdir}" = 'xNONE'; then
59 if test "x${prefix}" = "xNONE"; then
60 AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${ac_default_prefix}/lib")
61 else
62 AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${prefix}/lib")
63 fi
64else
65 AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${libdir}")
66fi
67
68dnl Set PACKAGE_SOURCE_DIR in config.h.
69packagesrcdir=`cd $srcdir && pwd`
70AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}")
71
72AC_OUTPUT([
73Makefile src/Makefile src/lib/Makefile src/bin/Makefile
74])
75
diff --git a/legacy/eet/configure.in b/legacy/eet/configure.in
new file mode 100644
index 0000000000..a391da6e45
--- /dev/null
+++ b/legacy/eet/configure.in
@@ -0,0 +1,75 @@
1dnl Process this file with autoconf to produce a configure script.
2
3# get rid of that stupid cache mechanism
4rm -f config.cache
5
6AC_INIT(configure.in)
7AM_INIT_AUTOMAKE(eet, 0.0.1)
8AM_CONFIG_HEADER(config.h)
9
10AC_ISC_POSIX
11AC_PROG_CC
12AM_PROG_CC_STDC
13AC_HEADER_STDC
14AC_C_CONST
15AM_ENABLE_SHARED
16AM_PROG_LIBTOOL
17
18if test "x${exec_prefix}" = "xNONE"; then
19 if test "x${prefix}" = "xNONE"; then
20 bindir="${ac_default_prefix}/bin";
21 else
22 bindir="${prefix}/bin";
23 fi
24else
25 if test "x${prefix}" = "xNONE"; then
26 bindir="${ac_default_prefix}/bin";
27 else
28 bindir="${prefix}/bin";
29 fi
30fi
31
32if test "x${exec_prefix}" = "xNONE"; then
33 if test "x${prefix}" = "xNONE"; then
34 libdir="${ac_default_prefix}/lib";
35 else
36 libdir="${prefix}/lib";
37 fi
38else
39 if test "x${prefix}" = "xNONE"; then
40 libdir="${ac_default_prefix}/lib";
41 else
42 libdir="${prefix}/lib";
43 fi
44fi
45
46dnl Set PACKAGE_BIN_DIR in config.h.
47if test "x${bindir}" = 'xNONE'; then
48 if test "x${prefix}" = "xNONE"; then
49 AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${ac_default_prefix}/bin")
50 else
51 AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${prefix}/bin")
52 fi
53else
54 AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${bindir}")
55fi
56
57dnl Set PACKAGE_LIB_DIR in config.h.
58if test "x${libdir}" = 'xNONE'; then
59 if test "x${prefix}" = "xNONE"; then
60 AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${ac_default_prefix}/lib")
61 else
62 AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${prefix}/lib")
63 fi
64else
65 AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${libdir}")
66fi
67
68dnl Set PACKAGE_SOURCE_DIR in config.h.
69packagesrcdir=`cd $srcdir && pwd`
70AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}")
71
72AC_OUTPUT([
73Makefile src/Makefile src/lib/Makefile src/bin/Makefile
74])
75
diff --git a/legacy/eet/debian/.cvsignore b/legacy/eet/debian/.cvsignore
new file mode 100644
index 0000000000..a0c9d092bf
--- /dev/null
+++ b/legacy/eet/debian/.cvsignore
@@ -0,0 +1,7 @@
1files
2libeet0
3libeet0-dev
4libeet0.postinst.debhelper
5libeet0.postrm.debhelper
6libeet0.substvars
7tmp
diff --git a/legacy/eet/debian/changelog b/legacy/eet/debian/changelog
new file mode 100644
index 0000000000..1201b206ea
--- /dev/null
+++ b/legacy/eet/debian/changelog
@@ -0,0 +1,6 @@
1libeet (0.0.0-0cvs20021005) unstable; urgency=low
2
3 * a CVS release
4
5 -- Sytse Wielinga <s.b.wielinga@student.utwente.nl> Sat, 5 Oct 2002 12:12:06 +0200
6
diff --git a/legacy/eet/debian/control b/legacy/eet/debian/control
new file mode 100644
index 0000000000..f8ea80e99c
--- /dev/null
+++ b/legacy/eet/debian/control
@@ -0,0 +1,29 @@
1Source: libeet
2Section: libs
3Priority: optional
4Maintainer: Sytse Wielinga <s.b.wielinga@student.utwente.nl>
5Build-Depends: debhelper (>> 3.0.0), libz-dev, libjpeg-dev
6Standards-Version: 3.5.7.0
7
8Package: libeet0-dev
9Section: devel
10Architecture: any
11Depends: libeet0 (= ${Source-Version})
12Provides: libeet-dev
13Conflicts: libeet-dev
14Description: Enlightenment file chunk reading/writing library development files
15 This package contains headers and static libraries for development with
16 libeet.
17
18Package: libeet0
19Section: libs
20Architecture: any
21Depends: ${shlibs:Depends}
22Description: Enlightenment file chunk reading/writing library
23 Eet is a tiny library designed to write an arbitary set of chunks of data to a
24 file and optionally compress each chunk (very much like a zip file) and allow
25 fast random-access reading of the file later on. It does not do zip as zip
26 itself has more complexity than we need, and it was much simpler to implement
27 this once here.
28 .
29 It's small, fast, and does a job. It's heavily commented and fully documented.
diff --git a/legacy/eet/debian/copyright b/legacy/eet/debian/copyright
new file mode 100644
index 0000000000..daf5283b6b
--- /dev/null
+++ b/legacy/eet/debian/copyright
@@ -0,0 +1,32 @@
1This package was debianized by Sytse Wielinga <s.b.wielinga@student.utwente.nl> on
2Thu, 3 Oct 2002 12:08:24 +0200.
3
4The source is downloaded from the e17/libs/eet module of the enlightenment CVS
5tree. For more information, see:
6
7 http://www.enlightenment.org/cvs.html
8
9Upstream Author(s): Enlightenment team <enlightenment-devel@lists.sourceforge.net>
10
11Copyright:
12
13Copyright (C) 2000 Carsten Haitzler and various contributors (see AUTHORS)
14
15Permission is hereby granted, free of charge, to any person obtaining a copy
16of this software and associated documentation files (the "Software"), to
17deal in the Software without restriction, including without limitation the
18rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19sell copies of the Software, and to permit persons to whom the Software is
20furnished to do so, subject to the following conditions:
21
22The above copyright notice and this permission notice shall be included in
23all copies of the Software, its documentation and marketing & publicity
24materials, and acknowledgment shall be given in the documentation, materials
25and software packages that this Software was used.
26
27THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/legacy/eet/debian/eet-config.1 b/legacy/eet/debian/eet-config.1
new file mode 100644
index 0000000000..b64bb228a5
--- /dev/null
+++ b/legacy/eet/debian/eet-config.1
@@ -0,0 +1,27 @@
1.\" Hey, EMACS: -*- nroff -*-
2.TH EET 1 "oktober 3, 2002"
3.SH NAME
4eet-config \- script to get information about the installed version of Eet
5.SH SYNOPSIS
6.B eet-config [\-\-version] [\-\-libs] [\-\-cflags]
7.SH DESCRIPTION
8\fIeet-config\fP is a tool that is used by configure to determine the
9availability of eet and the compiler and linker flags that should be used to
10compile programs using it.
11.SH OPTIONS
12\fIeet-config\fP accepts the following options:
13.TP
14.B \-\-version
15Print the currently installed version of \fIeet\fP on the standard output.
16.TP
17.B \-\-libs
18Print the linker flags that are necessary to link a \fIeet\fP\-program.
19.TP
20.B \-\-cflags
21Print the compiler flags that are necessary to link a \fIeet\fP\-program.
22.SH SEE ALSO
23.BR eet (1).
24.SH AUTHOR
25This manual page was written by Sytse Wielinga
26<s.b.wielinga@student.utwente.nl> for the Debian GNU/Linux system (but may be
27used by others).
diff --git a/legacy/eet/debian/eet.1 b/legacy/eet/debian/eet.1
new file mode 100644
index 0000000000..f0f43f7376
--- /dev/null
+++ b/legacy/eet/debian/eet.1
@@ -0,0 +1,61 @@
1.\" Hey, EMACS: -*- nroff -*-
2.TH EET 1 "oktober 3, 2002"
3.SH NAME
4eet \- program for editing eet files
5.SH SYNOPSIS
6.B eet
7-l in_file
8.br
9.B eet
10-d in_file
11.br
12.B eet
13-c out_file [-nz glob [-nz glob ...]] dir_file1 [dir_file2 ...]
14.SH DESCRIPTION
15This manual page documents briefly the
16.B eet
17command.
18This manual page was written for the Debian distribution
19because the original program does not have a manual page.
20.PP
21.B eet
22is a program for viewing, unpacking and adding files to eet files, which are
23containers for optionally compressed data, allowing for fast random-access
24reading. These files are mostly used by the enlightenment project. See
25.B www.enlightenment.org
26for more details about this project.
27.SH OPTIONS
28.TP
29.B \-l in_file
30List the contents of an eet file
31.TP
32.B \-d in_file
33Unpack an eet file
34.TP
35.B \-c out_file
36Create an eet file
37.TP
38.B \-nz match
39Store files matching match glob uncompressed
40.SH SEE ALSO
41.BR eet-config (1).
42.PP
43For more information, have a look at the sources of libeet. To get them, have
44a look at the website
45.B www.enlightenment.org
46or execute the following commands:
47.TP
48.B export CVSROOT=:pserver:anonymous@cvs.enlightenment.sourceforge.net:/cvsroot/enlightenment
49If this is command is broken among multiple lines because your terminal is not
50as wide as the command, please don't include the minus sign into the command.
51.TP
52.B cvs login
53Just hit enter if it asks about a password for anonymous.
54.TP
55.B cvs co -r SPLIT e17/libs/eet
56This command should create the directory e17/libs/eet, containing the latest
57sources of eet.
58.SH AUTHOR
59This manual page was written by Sytse Wielinga
60<s.b.wielinga@student.utwente.nl> for the Debian GNU/Linux system (but may be
61used by others).
diff --git a/legacy/eet/debian/libeet0-dev.files b/legacy/eet/debian/libeet0-dev.files
new file mode 100644
index 0000000000..606c89f00a
--- /dev/null
+++ b/legacy/eet/debian/libeet0-dev.files
@@ -0,0 +1,4 @@
1usr/bin/eet-config
2usr/include/*
3usr/lib/lib*.a
4usr/lib/lib*.so
diff --git a/legacy/eet/debian/libeet0.files b/legacy/eet/debian/libeet0.files
new file mode 100644
index 0000000000..31a86abefe
--- /dev/null
+++ b/legacy/eet/debian/libeet0.files
@@ -0,0 +1,2 @@
1usr/bin/eet
2usr/lib/lib*.so.*
diff --git a/legacy/eet/debian/rules b/legacy/eet/debian/rules
new file mode 100644
index 0000000000..171d5dc8e8
--- /dev/null
+++ b/legacy/eet/debian/rules
@@ -0,0 +1,74 @@
1#!/usr/bin/make -f
2# Sample debian/rules that uses debhelper.
3# GNU copyright 1997 to 1999 by Joey Hess.
4
5# Uncomment this to turn on verbose mode.
6#export DH_VERBOSE=1
7
8# This is the debhelper compatibility version to use.
9export DH_COMPAT=3
10
11
12ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
13 CFLAGS += -g
14endif
15ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
16 INSTALL_PROGRAM += -s
17endif
18
19version=`ls src/.libs/lib*.so.* | \
20 awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
21major=`ls src/.libs/lib*.so.* | \
22 awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`
23
24build: build-stamp
25build-stamp:
26 dh_testdir
27
28 ./configure --prefix=/usr build
29
30 touch build-stamp
31
32clean:
33 dh_testdir
34 dh_testroot
35 rm -f build-stamp
36
37 -./configure clean
38
39 dh_clean
40
41install: build
42 dh_testdir
43 dh_testroot
44 dh_clean -k
45 dh_installdirs
46
47 ./configure --prefix=$(CURDIR)/debian/tmp/usr install
48
49
50binary-indep: build install
51
52binary-arch: build install
53 dh_testdir
54 dh_testroot
55 dh_movefiles
56
57 dh_installdocs -plibeet0 README AUTHORS
58 dh_installdocs -plibeet0-dev
59 dh_installman -plibeet0 debian/eet.1
60 dh_installman -plibeet0-dev debian/eet-config.1
61 dh_installchangelogs
62 dh_link
63 dh_strip
64 dh_compress
65 dh_fixperms
66 dh_makeshlibs
67 dh_installdeb
68 dh_shlibdeps
69 dh_gencontrol
70 dh_md5sums
71 dh_builddeb
72
73binary: binary-indep binary-arch
74.PHONY: build clean binary-indep binary-arch binary install
diff --git a/legacy/eet/eet-config.in b/legacy/eet/eet-config.in
new file mode 100644
index 0000000000..d80b8724f5
--- /dev/null
+++ b/legacy/eet/eet-config.in
@@ -0,0 +1,59 @@
1#!/bin/sh
2
3prefix=@prefix@
4exec_prefix=@exec_prefix@
5exec_prefix_set=no
6
7usage="\
8Usage: evas-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--libs] [--cflags]"
9
10if test $# -eq 0; then
11 echo "${usage}" 1>&2
12 exit 1
13fi
14
15while test $# -gt 0; do
16 case "$1" in
17 -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
18 *) optarg= ;;
19 esac
20
21 case $1 in
22 --prefix=*)
23 prefix=$optarg
24 if test $exec_prefix_set = no ; then
25 exec_prefix=$optarg
26 fi
27 ;;
28 --prefix)
29 echo $prefix
30 ;;
31 --exec-prefix=*)
32 exec_prefix=$optarg
33 exec_prefix_set=yes
34 ;;
35 --exec-prefix)
36 echo $exec_prefix
37 ;;
38 --version)
39 echo @VERSION@
40 ;;
41 --cflags)
42 if test @includedir@ != /usr/include ; then
43 includes=-I@includedir@
44 fi
45 echo $includes
46 ;;
47 --libs)
48 libdirs=-L@libdir@
49 echo $libdirs -leet -ljpeg -lz
50 ;;
51 *)
52 echo "${usage}" 1>&2
53 exit 1
54 ;;
55 esac
56 shift
57done
58
59exit 0
diff --git a/legacy/eet/eet.spec b/legacy/eet/eet.spec
new file mode 100644
index 0000000000..419d95fa3c
--- /dev/null
+++ b/legacy/eet/eet.spec
@@ -0,0 +1,63 @@
1# Note that this is NOT a relocatable package
2%define ver 0.0.1
3%define rel 1
4%define prefix /usr/local
5
6Summary: eet
7Name: eet
8Version: %ver
9Release: %rel
10Copyright: BSD
11Group: Base/Group
12Source: ftp://ftp.enlightenment.org/pub/eet/eet-%{ver}.tar.gz
13BuildRoot: /var/tmp/eet-root
14Packager: The Rasterman <raster@rasterman.com>
15URL: http://www.enlightenment.org/
16Requires: libjpeg
17Requires: zlib
18
19Docdir: %{prefix}/doc
20
21%description
22Eet
23
24%prep
25%setup
26
27%build
28./configure --prefix=%prefix
29
30if [ "$SMP" != "" ]; then
31 (make "MAKE=make -k -j $SMP"; exit 0)
32 make
33else
34 make
35fi
36###########################################################################
37
38%install
39rm -rf $RPM_BUILD_ROOT
40make prefix=$RPM_BUILD_ROOT%{prefix} install
41
42%clean
43rm -rf $RPM_BUILD_ROOT
44
45%post
46
47%postun
48
49%files
50%defattr(-,root,root)
51%doc README COPYING ChangeLog
52%attr(755,root,root) %{prefix}/bin/*
53%attr(755,root,root) %{prefix}/lib/*
54%{prefix}/share/*
55
56%doc AUTHORS
57%doc COPYING
58%doc README
59
60%changelog
61* Sat Jun 23 2001 The Rasterman <raster@rasterman.com>
62- Created spec file
63
diff --git a/legacy/eet/src/.cvsignore b/legacy/eet/src/.cvsignore
new file mode 100644
index 0000000000..2fa80b7761
--- /dev/null
+++ b/legacy/eet/src/.cvsignore
@@ -0,0 +1,3 @@
1eet
2eet-config
3libeet.so.0.0.0
diff --git a/legacy/eet/src/Makefile.am b/legacy/eet/src/Makefile.am
new file mode 100644
index 0000000000..7b45af65b2
--- /dev/null
+++ b/legacy/eet/src/Makefile.am
@@ -0,0 +1,3 @@
1## Process this file with automake to produce Makefile.in
2
3SUBDIRS = lib bin
diff --git a/legacy/eet/src/bin/.cvsignore b/legacy/eet/src/bin/.cvsignore
new file mode 100644
index 0000000000..2fa80b7761
--- /dev/null
+++ b/legacy/eet/src/bin/.cvsignore
@@ -0,0 +1,3 @@
1eet
2eet-config
3libeet.so.0.0.0
diff --git a/legacy/eet/src/bin/Makefile.am b/legacy/eet/src/bin/Makefile.am
new file mode 100644
index 0000000000..49b8604e3e
--- /dev/null
+++ b/legacy/eet/src/bin/Makefile.am
@@ -0,0 +1,12 @@
1## Process this file with automake to produce Makefile.in
2
3INCLUDES = \
4 -I../lib
5
6bin_PROGRAMS = eet
7
8eet_SOURCES = \
9eet_main.c
10
11eet_LDADD = $(top_builddir)/src/lib/libeet.la
12eet_DEPENDANCIES = $(top_builddir)/src/lib/libeet.la
diff --git a/legacy/eet/src/bin/eet_main.c b/legacy/eet/src/bin/eet_main.c
new file mode 100644
index 0000000000..0bf1a717cb
--- /dev/null
+++ b/legacy/eet/src/bin/eet_main.c
@@ -0,0 +1,420 @@
1#include "Eet.h"
2#include <stdio.h>
3#include <unistd.h>
4#include <stdlib.h>
5#include <string.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <unistd.h>
9#include <dirent.h>
10#include <limits.h>
11#include <fnmatch.h>
12
13/* just some sample code on how to use encoder/decoders */
14#if 0
15#include <Evas.h>
16
17typedef struct _blah2
18{
19 char *string;
20}
21Blah2;
22
23typedef struct _blah3
24{
25 char *string;
26}
27Blah3;
28
29typedef struct _blah
30{
31 char character;
32 short sixteen;
33 int integer;
34 long long lots;
35 float floating;
36 double floating_lots;
37 char *string;
38 Blah2 *blah2;
39 Evas_List *blah3;
40}
41Blah;
42
43void
44encdectest(void)
45{
46 Blah blah;
47 Blah2 blah2;
48 Blah3 blah3;
49 Eet_Data_Descriptor *edd, *edd2, *edd3;
50 void *data;
51 int size;
52 FILE *f;
53 Blah *blah_in;
54
55 edd3 = eet_data_descriptor_new("blah3", sizeof(Blah3),
56 evas_list_next,
57 evas_list_append,
58 evas_list_data,
59 evas_hash_foreach,
60 evas_hash_add);
61 EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING);
62
63 edd2 = eet_data_descriptor_new("blah2", sizeof(Blah2),
64 evas_list_next,
65 evas_list_append,
66 evas_list_data,
67 evas_hash_foreach,
68 evas_hash_add);
69 EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING);
70
71 edd = eet_data_descriptor_new("blah", sizeof(Blah),
72 evas_list_next,
73 evas_list_append,
74 evas_list_data,
75 evas_hash_foreach,
76 evas_hash_add);
77 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "character", character, EET_T_CHAR);
78 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "sixteen", sixteen, EET_T_SHORT);
79 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "integer", integer, EET_T_INT);
80 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "lots", lots, EET_T_LONG_LONG);
81 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating", floating, EET_T_FLOAT);
82 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating_lots", floating_lots, EET_T_DOUBLE);
83 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "string", string, EET_T_STRING);
84 EET_DATA_DESCRIPTOR_ADD_SUB (edd, Blah, "blah2", blah2, edd2);
85 EET_DATA_DESCRIPTOR_ADD_LIST (edd, Blah, "blah3", blah3, edd3);
86
87 blah3.string="PANTS";
88
89 blah2.string="subtype string here!";
90
91 blah.character='7';
92 blah.sixteen=0x7777;
93 blah.integer=0xc0def00d;
94 blah.lots=0xdeadbeef31337777;
95 blah.floating=3.141592654;
96 blah.floating_lots=0.777777777777777;
97 blah.string="bite me like a turnip";
98 blah.blah2 = &blah2;
99 blah.blah3 = evas_list_append(NULL, &blah3);
100 blah.blah3 = evas_list_append(blah.blah3, &blah3);
101 blah.blah3 = evas_list_append(blah.blah3, &blah3);
102 blah.blah3 = evas_list_append(blah.blah3, &blah3);
103 blah.blah3 = evas_list_append(blah.blah3, &blah3);
104 blah.blah3 = evas_list_append(blah.blah3, &blah3);
105 blah.blah3 = evas_list_append(blah.blah3, &blah3);
106
107 data = eet_data_descriptor_encode(edd, &blah, &size);
108 f = fopen("out", "w");
109 if (f)
110 {
111 fwrite(data, size, 1, f);
112 fclose(f);
113 }
114 printf("-----DECODING\n");
115 blah_in = eet_data_descriptor_decode(edd, data, size);
116 printf("-----DECODED!\n");
117 printf("%c\n", blah_in->character);
118 printf("%x\n", (int)blah_in->sixteen);
119 printf("%x\n", blah_in->integer);
120 printf("%lx\n", blah_in->lots);
121 printf("%f\n", (double)blah_in->floating);
122 printf("%f\n", (double)blah_in->floating_lots);
123 printf("%s\n", blah_in->string);
124 printf("%p\n", blah_in->blah2);
125 printf(" %s\n", blah_in->blah2->string);
126 {
127 Evas_List *l;
128
129 for (l = blah_in->blah3; l; l = l->next)
130 {
131 Blah3 *blah3_in;
132
133 blah3_in = l->data;
134 printf("%p\n", blah3_in);
135 printf(" %s\n", blah3_in->string);
136 }
137 }
138 eet_data_descriptor_free(edd);
139 eet_data_descriptor_free(edd2);
140 eet_data_descriptor_free(edd3);
141
142 exit(0);
143}
144#endif
145
146int eet_mkdir(char *dir);
147void eet_mkdirs(char *s);
148
149void depak_file(Eet_File *ef, char *file);
150void depack(char *pak_file);
151
152void list(char *pak_file);
153
154void pak_file(Eet_File *ef, char *file, char **noz, int noz_num);
155void pak_dir(Eet_File *ef, char *dir, char **noz, int noz_num);
156void pack(char *pak_file, char **files, int count, char **noz, int noz_num);
157
158static mode_t default_mode =
159S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
160
161int
162eet_mkdir(char *dir)
163{
164 if (mkdir(dir, default_mode) < 0) return 0;
165 return 1;
166}
167
168void
169eet_mkdirs(char *s)
170{
171 char ss[PATH_MAX];
172 int i, ii;
173
174 i = 0;
175 ii = 0;
176 while (s[i])
177 {
178 ss[ii++] = s[i];
179 ss[ii] = 0;
180 if (s[i] == '/') eet_mkdir(ss);
181 i++;
182 }
183}
184
185void
186depak_file(Eet_File *ef, char *file)
187{
188 void *data;
189 int size;
190 char *last;
191
192 data = eet_read(ef, file, &size);
193 if (data)
194 {
195 FILE *f;
196 char buf[PATH_MAX];
197
198 strcpy(buf, file);
199 last = strrchr(buf, '/');
200 if (last)
201 {
202 last[1] = 0;
203 eet_mkdirs(buf);
204 }
205
206 f = fopen(file, "w");
207 if (f)
208 {
209 fwrite(data, 1, size, f);
210 fclose(f);
211 printf("exported: %s\n", file);
212 }
213 else
214 printf("error exporting: %s\n", file);
215 free(data);
216 }
217 else
218 {
219 printf("error reading: %s\n", file);
220 }
221}
222
223void
224depack(char *pak_file)
225{
226 int i, num;
227 char **list;
228 Eet_File *ef;
229
230 ef = eet_open(pak_file, EET_FILE_MODE_READ);
231 if (!ef)
232 {
233 printf("cannot open for reading: %s\n", pak_file);
234 return;
235 }
236 list = eet_list(ef, "*", &num);
237 if (list)
238 {
239 for (i = 0; i < num; i++)
240 depak_file(ef, list[i]);
241 free(list);
242 }
243 eet_close(ef);
244}
245
246void
247list(char *pak_file)
248{
249 int i, num;
250 char **list;
251 Eet_File *ef;
252
253 ef = eet_open(pak_file, EET_FILE_MODE_READ);
254 if (!ef)
255 {
256 printf("cannot open for reading: %s\n", pak_file);
257 return;
258 }
259 list = eet_list(ef, "*", &num);
260 if (list)
261 {
262 for (i = 0; i < num; i++)
263 printf("%s\n",list[i]);
264 free(list);
265 }
266 eet_close(ef);
267}
268
269void
270pak_file(Eet_File *ef, char *file, char **noz, int noz_num)
271{
272 struct stat st;
273
274 if (stat(file, &st) >= 0)
275 {
276 void *buf;
277
278 buf = malloc(st.st_size);
279 if (buf)
280 {
281 FILE *f;
282
283 f = fopen(file, "r");
284 if (f)
285 {
286 int compress = 1;
287 int i;
288
289 for (i = 0; i < noz_num; i++)
290 {
291 if (!fnmatch(noz[i], file, 0))
292 {
293 compress = 0;
294 break;
295 }
296 }
297 fread(buf, 1, st.st_size, f);
298 if (!eet_write(ef, file, buf, st.st_size, compress))
299 printf("error importing: %s\n", file);
300 else
301 {
302 if (compress)
303 printf("compress: %s\n", file);
304 else
305 printf("imported: %s\n", file);
306 }
307 fclose(f);
308 }
309 free(buf);
310 }
311 }
312}
313
314void
315pak_dir(Eet_File *ef, char *dir, char **noz, int noz_num)
316{
317 DIR *dirp;
318 struct dirent *dp;
319
320 dirp = opendir(dir);
321 if (!dirp)
322 pak_file(ef, dir, noz, noz_num);
323 else
324 {
325 while ((dp = readdir(dirp)))
326 {
327 char buf[PATH_MAX];
328
329 if ((!strcmp(".", dp->d_name)) || (!strcmp("..", dp->d_name)))
330 {
331 }
332 else
333 {
334 snprintf(buf, sizeof(buf), "%s/%s", dir, dp->d_name);
335 pak_dir(ef, buf, noz, noz_num);
336 }
337 }
338 }
339}
340
341void
342pack(char *pak_file, char **files, int count, char **noz, int noz_num)
343{
344 Eet_File *ef;
345 int i;
346
347 ef = eet_open(pak_file, EET_FILE_MODE_WRITE);
348 if (!ef)
349 {
350 printf("cannot open for writing: %s\n", pak_file);
351 return;
352 }
353 for (i = 0; i < count; i++) pak_dir(ef, files[i], noz, noz_num);
354 printf("done.\n");
355 eet_close(ef);
356}
357
358int
359main(int argc, char **argv)
360{
361 if (argc == 3)
362 {
363 if (!strcmp(argv[1], "-d"))
364 {
365 depack(argv[2]);
366 return 0;
367 }
368 else if (!strcmp(argv[1], "-l"))
369 {
370 list(argv[2]);
371 return 0;
372 }
373 }
374 else if (argc > 3)
375 {
376 char **noz = NULL;
377 int noz_num = 0;
378
379 if (!strcmp(argv[1], "-c"))
380 {
381 int i;
382
383 for (i = 3; i < argc; i++)
384 {
385 if (!strcmp(argv[i], "-nz"))
386 {
387 if (i < (argc - 1))
388 {
389 i++;
390 noz_num++;
391 noz = realloc(noz, noz_num * sizeof(char *));
392 noz[noz_num - 1] = argv[i];
393 }
394 }
395 else
396 break;
397 }
398 pack(argv[2], &(argv[i]), argc - i, noz, noz_num);
399 return 0;
400 }
401 }
402 printf("usage:\n"
403 " %s -l in_file\n"
404 " %s -d in_file\n"
405 " %s -c out_file [-nz glob [-nz glob ...]] dir_file1 [dir_file2 ...]\n"
406 "\n"
407 "where:\n"
408 " -l in_file list contents of eet file\n"
409 " -d in_file unpack eet file\n"
410 " -c out_file pack up eet file\n"
411 " -nz match don't compress files matching match glob\n"
412 "\n"
413 "example:\n"
414 " %s -c out.eet -nz \"*.jpg\" things/\n"
415 " %s -l out.eet\n"
416 " %s -d out.eet\n",
417 argv[0], argv[0], argv[0],
418 argv[0], argv[0], argv[0]);
419 return -1;
420}
diff --git a/legacy/eet/src/lib/.cvsignore b/legacy/eet/src/lib/.cvsignore
new file mode 100644
index 0000000000..2fa80b7761
--- /dev/null
+++ b/legacy/eet/src/lib/.cvsignore
@@ -0,0 +1,3 @@
1eet
2eet-config
3libeet.so.0.0.0
diff --git a/legacy/eet/src/lib/Eet.h b/legacy/eet/src/lib/Eet.h
new file mode 100644
index 0000000000..57e231f89f
--- /dev/null
+++ b/legacy/eet/src/lib/Eet.h
@@ -0,0 +1,268 @@
1#ifndef _EET_H
2#define _EET_H
3
4/***************************************************************************/
5
6/*
7 * EET - E file chunk reading/writing library
8 *
9 * What is it?
10 * It is a tiny library designed to write an arbitary set of chunks of data
11 * to a file and optionally compress each chunk (very much like a zip file)
12 * and allow fast random-access reading of the file later on. It does not
13 * do zip as zip itself has more complexity than we need, and it was much
14 * simpler to impliment this once here.
15 *
16 */
17
18/***************************************************************************/
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/***************************************************************************/
25
26#define EET_T_UNKNOW 0
27#define EET_T_CHAR 1
28#define EET_T_SHORT 2
29#define EET_T_INT 3
30#define EET_T_LONG_LONG 4
31#define EET_T_FLOAT 5
32#define EET_T_DOUBLE 6
33#define EET_T_UCHAR 7
34#define EET_T_USHORT 8
35#define EET_T_UINT 9
36#define EET_T_ULONG_LONG 10
37#define EET_T_STRING 11
38#define EET_T_LAST 12
39
40#define EET_G_UNKNOWN 100
41#define EET_G_ARRAY 101
42#define EET_G_VAR_ARRAY 102
43#define EET_G_LIST 103
44#define EET_G_HASH 104
45#define EET_G_LAST 105
46
47/***************************************************************************/
48
49 enum _Eet_File_Mode
50 {
51 EET_FILE_MODE_READ,
52 EET_FILE_MODE_WRITE
53 };
54
55 typedef enum _Eet_File_Mode Eet_File_Mode;
56
57 typedef struct _Eet_File Eet_File;
58 typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
59
60
61/***************************************************************************/
62
63 /* eet_open - Open an eet file on disk, and returns a handle to it.
64 * @file: The file path to the eet file. eg: "/tmp/file.eet".
65 * @mode: The mode for opening. Either EET_FILE_MODE_READ or EET_FILE_MODE_WRITE, but not both.
66 *
67 * This function will open an exiting eet file for reading, and build
68 * the directory table in memory and return a handle to the file, if it
69 * exists and can be read, and no memory errors occur on the way, otherwise
70 * NULL will be returned.
71 *
72 * It will also open an eet file for writing. This will, if successful,
73 * delete the original file and replace it with a new empty file, till
74 * the eet file handle is closed or flushed. If it cannot be opened for
75 * writing or a memory error occurs, NULL is returned.
76 */
77 Eet_File *eet_open (char *file, Eet_File_Mode mode);
78 /* eet_close - Close an eet file handle and flush and writes pending.
79 * @ef: A valid eet file handle.
80 *
81 * This function will flush any pending writes to disk if the eet file
82 * was opened for write, and free all data associated with the file handle
83 * and file, and close the file.
84 *
85 * If the eet file handle is not valid nothing will be done.
86 */
87 void eet_close (Eet_File *ef);
88 /* eet_read - Read a specified entry from an eet file and return data
89 * @ef: A valid eet file handle opened for reading.
90 * @name: Name of the entry. eg: "/base/file_i_want".
91 * @size_ret: Number of bytes read from entry and returned.
92 *
93 * This function finds an entry in the eet file that is stored under the
94 * name specified, and returns that data, decompressed, if successfule.
95 * NULL is retuurned if the lookup fails or if memory errors are
96 * encountered. It is the job of the calling program to call free() on
97 * the returned data. The number of bytes in the returned data chunk are
98 * placed in size_ret.
99 *
100 * If the eet file handle is not valid NULl is returned and size_ret is
101 * filled with 0.
102 */
103 void *eet_read (Eet_File *ef, char *name, int *size_ret);
104 /* eet_write - Write a specified entry to an eet file handle
105 * @ef: A valid eet file handle opened for writing.
106 * @name: Name of the entry. eg: "/base/file_i_want".
107 * @data: Pointer to the data to be stored.
108 * @size: Length in bytes in the data to be stored.
109 * @compress: Compression flags (1 == compress, 0 = don't compress).
110 *
111 * This function will write the specified chunk of data to the eet file
112 * and return 1 on success. 0 will be returned on failure.
113 *
114 * The eet file handle must be a valid file handle for an eet file opened
115 * for writing. If it is not, 0 will be returned and no action will be
116 * performed.
117 *
118 * Name, and data must not be NULL, and size must be > 0. If these
119 * conditions are not met, 0 will be returned.
120 *
121 * The data will be copied (and optionally compressed) in ram, pending
122 * a flush to disk (it will stay in ram till the eet file handle is
123 * closed though).
124 */
125 int eet_write (Eet_File *ef, char *name, void *data, int size, int compress);
126 /* eet_list - List all entries in eet file matching shell glob.
127 * @ef: A valid eet file handle.
128 * @glob: A shell glob to match against.
129 * @count_ret: number of entries foudn to match.
130 *
131 * This function will list all entries in the eet file matching the
132 * supplied shell glob and return an allocated list of their names, if
133 * there are any, and if no memory errors occur.
134 *
135 * The eet file handle must be valid and glob must not be NULL, or NULL
136 * will be returned and count_ret will be filled with 0.
137 *
138 * The calling program must call free() on the array returned, but NOT
139 * on the string pointers in the array. They are taken as read-only
140 * internals from the eet file handle. They are only valid as long as
141 * the file handle is not closed. When it is closed those pointers in the
142 * array are now not valid and should not be used.
143 *
144 * On success the array returned will have a list of string pointers
145 * that are the names of the entries that matched, and count_ret will have
146 * the number of entries in this array placed in it.
147 *
148 * Hint: an easy way to list all entries in an eet file is to use a glob
149 * value of "*".
150 */
151 char **eet_list (Eet_File *ef, char *glob, int *count_ret);
152
153/***************************************************************************/
154
155 /* eet_data_image_read - Read image data from the named key in the eet file.
156 * @ef: A valid eet file handle opened for reading.
157 * @name: Name of the entry. eg: "/base/file_i_want".
158 * @w: A pointer to the int to hold the width in pixels.
159 * @h: A pointer to the int to hold the height in pixels.
160 * @alpha: A pointer to the int to hold the alpha flag.
161 * @compress: A pointer to the int to hold the compression amount.
162 * @quality: A pointer to the int to hold the quality amount.
163 * @lossy: A pointer to the int to hold the lossiness flag.
164 *
165 * This function reads an image from an eet file stored under the named
166 * key in the eet file and return a pointer to the decompressed pixel data.
167 *
168 * The other parameters of the image (width, height etc.) are placed into
169 * the values pointed to (they must be supplied). The pixel data is a linear
170 * array of pixels starting from the top-left of the image scanning row by
171 * row from left to right. Each piel is a 32bit value, with the high byte
172 * being the alpha channel, the next being red, then green, and the low byte
173 * being blue. The width and height are measured in pixels and will be
174 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
175 * that the alpha channel is not used. 1 denoties that it is significant.
176 * Compress is fiulled with the compression value/amount the image was
177 * stored with. The quality value si fileld with the quality encoding of
178 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
179 * the image was encoded lossily or not.
180 *
181 * On success the function returns a pointer to the image data decoded. The
182 * calling application is responsible for calling free() on the image data
183 * when it is done with it. On failure NULL is returned and the parameter
184 * values may not contain any sensible data.
185 */
186 void *eet_data_image_read(Eet_File *ef, char *name, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy);
187 /* eet_data_image_write - Write image data to the named key in an eet file.
188 * @ef: A valid eet file handle opened for writing.
189 * @name: Name of the entry. eg: "/base/file_i_want".
190 * @data: A pointer to the image pixel data.
191 * @w: The width of the image in pixels.
192 * @h: The height of the image in pixels.
193 * @alpha: The alpha channel flag.
194 * @compress: The compression amount.
195 * @quality: The quality encoding amount.
196 * @lossy: The lossiness flag.
197 *
198 * This function dates image pixel data and encodes it in an eet file
199 * stored under the supplied name key, and returns how many bytes were
200 * actually written to encode the image data.
201 *
202 * The data expected is the same format as returned by eet_data_image_read.
203 * If this is not the case wierd things may happen. Width and height must
204 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
205 * the alpha values are not useful and 1 meaning they are). Compress can
206 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
207 * This is only used if the image is not lossily encoded. Quality is used on
208 * lossy compression and shoudl be a value from 0 to 100. The lossy flag
209 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
210 * image quality loss (but then have a much smaller encoding).
211 *
212 * On success this function rtuens the numebr fo bytes that were required
213 * to encode the image data, or on failure it returns 0.
214 */
215 int eet_data_image_write(Eet_File *ef, char *name, void *data, int w, int h, int alpha, int compress, int quality, int lossy);
216
217 /* To Be Documented
218 *
219 */
220 void *eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int compress, int quality, int lossy);
221 void *eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy);
222/***************************************************************************/
223
224 /* To Be Documented
225 *
226 */
227 Eet_Data_Descriptor *eet_data_descriptor_new(char *name, int size, void *(*func_list_next) (void *l), void *(*func_list_append) (void *l, void *d), void *(*func_list_data) (void *l), void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt), void *(*func_hash_add) (void *h, const char *k, void *d));
228 void eet_data_descriptor_free(Eet_Data_Descriptor *edd);
229
230 void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type, int group_type, int offset, int count, char *counter_name, Eet_Data_Descriptor *subtype);
231
232 void *eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name);
233 int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, char *name, void *data, int compress);
234
235 void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd, void *data_in, int size_in);
236 void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd, void *data_in, int *size_ret);
237
238#define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \
239 { \
240 struct_type ___ett; \
241 \
242 eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN, \
243 (char *)(&(___ett.member)) - (char *)(&(___ett)), \
244 0, NULL, NULL); \
245 }
246#define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype) \
247 { \
248 struct_type ___ett; \
249 \
250 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN, \
251 (char *)(&(___ett.member)) - (char *)(&(___ett)), \
252 0, NULL, subtype); \
253 }
254#define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \
255 { \
256 struct_type ___ett; \
257 \
258 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST, \
259 (char *)(&(___ett.member)) - (char *)(&(___ett)), \
260 0, NULL, subtype); \
261 }
262
263/***************************************************************************/
264#ifdef __cplusplus
265}
266#endif
267
268#endif
diff --git a/legacy/eet/src/lib/Makefile.am b/legacy/eet/src/lib/Makefile.am
new file mode 100644
index 0000000000..9477e0075d
--- /dev/null
+++ b/legacy/eet/src/lib/Makefile.am
@@ -0,0 +1,20 @@
1## Process this file with automake to produce Makefile.in
2
3AUTOMAKE_OPTIONS = 1.4 foreign
4
5# A list of all the files in the current directory which can be regenerated
6MAINTAINERCLEANFILES = Makefile.in
7
8LDFLAGS = -L/usr/local/lib
9INCLUDES = -I/usr/local/include \
10 -I$(includedir)
11
12lib_LTLIBRARIES = libeet.la
13include_HEADERS = Eet.h
14libeet_la_SOURCES = \
15eet_lib.c \
16eet_data.c
17
18libeet_la_LIBADD = $(LDFLAGS) -lz -ljpeg
19libeet_la_DEPENDENCIES = $(top_builddir)/config.h
20libeet_la_LDFLAGS = -version-info 0:1:0
diff --git a/legacy/eet/src/lib/eet_data.c b/legacy/eet/src/lib/eet_data.c
new file mode 100644
index 0000000000..d82b72b463
--- /dev/null
+++ b/legacy/eet/src/lib/eet_data.c
@@ -0,0 +1,1765 @@
1#include "Eet.h"
2#define _GNU_SOURCE /* need this for fmemopen & open_memstream */
3#include <stdio.h>
4#include <unistd.h>
5#include <limits.h>
6#include <stdlib.h>
7#include <time.h>
8#include <sys/types.h>
9#include <fcntl.h>
10#include <netinet/in.h>
11#include <zlib.h>
12#include <string.h>
13#include <fnmatch.h>
14#include <jpeglib.h>
15#include <setjmp.h>
16#include <zlib.h>
17#include <locale.h>
18
19
20/*
21 * rotuines for doing data -> struct and struct -> data conversion
22 *
23 * types:
24 *
25 * basic types:
26 * a sequence of...
27 *
28 * char
29 * short
30 * int
31 * long long
32 * float
33 * double
34 * unsigned char
35 * unsigned short
36 * unsigned int
37 * unsgined long long
38 * string
39 *
40 * groupings:
41 * multiple entries ordered as...
42 *
43 * fixed size array [ of basic types ]
44 * variable size array [ of basic types ]
45 * linked list [ of basic types ]
46 * hash table [ of basic types ]
47 *
48 * need to provide builder/accessor funcs for:
49 *
50 * list_next
51 * list_append
52 *
53 * hash_foreach
54 * hash_add
55 *
56 */
57
58/*---*/
59
60typedef struct _Eet_Data_Element Eet_Data_Element;
61typedef struct _Eet_Data_Basic_Type_Decoder Eet_Data_Basic_Type_Decoder;
62typedef struct _Eet_Data_Chunk Eet_Data_Chunk;
63typedef struct _Eet_Data_Stream Eet_Data_Stream;
64typedef struct _JPEG_error_mgr *emptr;
65
66/*---*/
67
68struct _Eet_Data_Basic_Type_Decoder
69{
70 int size;
71 int (*get) (void *src, void *src_end, void *dest);
72 void *(*put) (void *src, int *size_ret);
73};
74
75struct _Eet_Data_Chunk
76{
77 char *name;
78 int size;
79 void *data;
80};
81
82struct _Eet_Data_Stream
83{
84 void *data;
85 int size;
86 int pos;
87};
88
89struct _Eet_Data_Descriptor
90{
91 char *name;
92 int size;
93 struct {
94 void *(*list_next) (void *l);
95 void *(*list_append) (void *l, void *d);
96 void *(*list_data) (void *l);
97 void (*hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt);
98 void *(*hash_add) (void *h, const char *k, void *d);
99 } func;
100 struct {
101 int num;
102 Eet_Data_Element *set;
103 } elements;
104};
105
106struct _Eet_Data_Element
107{
108 char *name;
109 int type;
110 int group_type;
111 int offset;
112 int count;
113 char *counter_name;
114 Eet_Data_Descriptor *subtype;
115};
116
117struct _JPEG_error_mgr
118{
119 struct jpeg_error_mgr pub;
120 jmp_buf setjmp_buffer;
121};
122
123/*---*/
124
125static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
126static void _JPEGErrorHandler(j_common_ptr cinfo);
127static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
128
129static void *eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h);
130static void *eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, int *h);
131static void *eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha);
132static void *eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int alpha, int compression);
133static void *eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int quality);
134static void *eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha, int quality);
135
136static int eet_data_get_char(void *src, void *src_end, void *dest);
137static void *eet_data_put_char(void *src, int *size_ret);
138static int eet_data_get_short(void *src, void *src_end, void *dest);
139static void *eet_data_put_short(void *src, int *size_ret);
140static int eet_data_get_int(void *src, void *src_end, void *dest);
141static void *eet_data_put_int(void *src, int *size_ret);
142static int eet_data_get_long_long(void *src, void *src_end, void *dest);
143static void *eet_data_put_long_long(void *src, int *size_ret);
144static int eet_data_get_float(void *src, void *src_end, void *dest);
145static void *eet_data_put_float(void *src, int *size_ret);
146static int eet_data_get_double(void *src, void *src_end, void *dest);
147static void *eet_data_put_double(void *src, int *size_ret);
148static int eet_data_get_string(void *src, void *src_end, void *dest);
149static void *eet_data_put_string(void *src, int *size_ret);
150
151static int eet_data_get_type(int type, void *src, void *src_end, void *dest);
152static void *eet_data_put_type(int type, void *src, int *size_ret);
153
154static Eet_Data_Chunk *eet_data_chunk_get(void *src, int size);
155static Eet_Data_Chunk *eet_data_chunk_new(void *data, int size, char *name);
156static void eet_data_chunk_free(Eet_Data_Chunk *chnk);
157
158static Eet_Data_Stream *eet_data_stream_new(void);
159static void eet_data_stream_write(Eet_Data_Stream *ds, void *data, int size);
160static void eet_data_stream_free(Eet_Data_Stream *ds);
161
162static void eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream *ds);
163
164/*---*/
165
166const Eet_Data_Basic_Type_Decoder eet_coder[] =
167{
168 {sizeof(char), eet_data_get_char, eet_data_put_char },
169 {sizeof(short), eet_data_get_short, eet_data_put_short },
170 {sizeof(int), eet_data_get_int, eet_data_put_int },
171 {sizeof(long long), eet_data_get_long_long, eet_data_put_long_long},
172 {sizeof(float), eet_data_get_float, eet_data_put_float },
173 {sizeof(double), eet_data_get_double, eet_data_put_double },
174 {sizeof(char), eet_data_get_char, eet_data_put_char },
175 {sizeof(short), eet_data_get_short, eet_data_put_short },
176 {sizeof(int), eet_data_get_int, eet_data_put_int },
177 {sizeof(long long), eet_data_get_long_long, eet_data_put_long_long},
178 {sizeof(char *), eet_data_get_string, eet_data_put_string }
179};
180
181static int words_bigendian = -1;
182
183/*---*/
184
185#define SWAP64(x) (x) = \
186 ((((x) & 0x00000000000000ff ) << 56) |\
187 (((x) & 0x000000000000ff00 ) << 40) |\
188 (((x) & 0x0000000000ff0000 ) << 24) |\
189 (((x) & 0x00000000ff000000 ) << 8) |\
190 (((x) & 0x000000ff00000000 ) >> 8) |\
191 (((x) & 0x0000ff0000000000 ) >> 24) |\
192 (((x) & 0x00ff000000000000 ) >> 40) |\
193 (((x) & 0xff00000000000000 ) >> 56))
194#define SWAP32(x) (x) = \
195 ((((x) & 0x000000ff ) << 24) |\
196 (((x) & 0x0000ff00 ) << 8) |\
197 (((x) & 0x00ff0000 ) >> 8) |\
198 (((x) & 0xff000000 ) >> 24))
199#define SWAP16(x) (x) = \
200 ((((x) & 0x00ff ) << 8) |\
201 (((x) & 0xff00 ) >> 8))
202
203#define CONV8(x)
204#define CONV16(x) {if (words_bigendian) SWAP16(x);}
205#define CONV32(x) {if (words_bigendian) SWAP32(x);}
206#define CONV64(x) {if (words_bigendian) SWAP64(x);}
207
208/*---*/
209
210static void
211_JPEGFatalErrorHandler(j_common_ptr cinfo)
212{
213 emptr errmgr;
214
215 errmgr = (emptr) cinfo->err;
216 /* cinfo->err->output_message(cinfo);*/
217 longjmp(errmgr->setjmp_buffer, 1);
218 return;
219}
220
221static void
222_JPEGErrorHandler(j_common_ptr cinfo)
223{
224 emptr errmgr;
225
226 errmgr = (emptr) cinfo->err;
227 /* cinfo->err->output_message(cinfo);*/
228 /* longjmp(errmgr->setjmp_buffer, 1);*/
229 return;
230}
231
232static void
233_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level)
234{
235 emptr errmgr;
236
237 errmgr = (emptr) cinfo->err;
238 /* cinfo->err->output_message(cinfo);*/
239 /* longjmp(errmgr->setjmp_buffer, 1);*/
240 return;
241 msg_level = 0;
242}
243
244static void *
245eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h)
246{
247 unsigned int *d;
248 struct jpeg_decompress_struct cinfo;
249 struct _JPEG_error_mgr jerr;
250 unsigned char *ptr, *line[16], *tdata;
251 unsigned int *ptr2;
252 int x, y, l, i, scans, count, prevy;
253 FILE *f;
254
255 f = fmemopen(data, (size_t)size, "r");
256 if (!f) return NULL;
257 cinfo.err = jpeg_std_error(&(jerr.pub));
258 jerr.pub.error_exit = _JPEGFatalErrorHandler;
259 jerr.pub.emit_message = _JPEGErrorHandler2;
260 jerr.pub.output_message = _JPEGErrorHandler;
261 if (setjmp(jerr.setjmp_buffer))
262 {
263 jpeg_destroy_decompress(&cinfo);
264 fclose(f);
265 return NULL;
266 }
267 jpeg_create_decompress(&cinfo);
268 jpeg_stdio_src(&cinfo, f);
269 jpeg_read_header(&cinfo, TRUE);
270 cinfo.do_fancy_upsampling = FALSE;
271 cinfo.do_block_smoothing = FALSE;
272 jpeg_start_decompress(&cinfo);
273
274 /* head decoding */
275 *w = cinfo.output_width;
276 *h = cinfo.output_height;
277 /* end head decoding */
278 /* data decoding */
279 if (cinfo.rec_outbuf_height > 16)
280 {
281 jpeg_destroy_decompress(&cinfo);
282 fclose(f);
283 return NULL;
284 }
285 tdata = malloc((*w) * 16 * 3);
286 if (!tdata)
287 {
288 jpeg_destroy_decompress(&cinfo);
289 fclose(f);
290 return NULL;
291 }
292 d = malloc((*w) * (*h) * 4);
293 if (!d)
294 {
295 free(tdata);
296 jpeg_destroy_decompress(&cinfo);
297 fclose(f);
298 return NULL;
299 }
300 ptr2 = d;
301 count = 0;
302 prevy = 0;
303 if (cinfo.output_components == 3)
304 {
305 for (i = 0; i < cinfo.rec_outbuf_height; i++)
306 line[i] = tdata + (i * (*w) * 3);
307 for (l = 0; l < (*h); l += cinfo.rec_outbuf_height)
308 {
309 jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
310 scans = cinfo.rec_outbuf_height;
311 if (((*h) - l) < scans) scans = (*h) - l;
312 ptr = tdata;
313 for (y = 0; y < scans; y++)
314 {
315 for (x = 0; x < (*w); x++)
316 {
317 *ptr2 =
318 (0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]);
319 ptr += 3;
320 ptr2++;
321 }
322 }
323 }
324 }
325 else if (cinfo.output_components == 1)
326 {
327 for (i = 0; i < cinfo.rec_outbuf_height; i++)
328 line[i] = tdata + (i * (*w));
329 for (l = 0; l < (*h); l += cinfo.rec_outbuf_height)
330 {
331 jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
332 scans = cinfo.rec_outbuf_height;
333 if (((*h) - l) < scans) scans = (*h) - l;
334 ptr = tdata;
335 for (y = 0; y < scans; y++)
336 {
337 for (x = 0; x < (*w); x++)
338 {
339 *ptr2 =
340 (0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]);
341 ptr++;
342 ptr2++;
343 }
344 }
345 }
346 }
347 free(tdata);
348 fclose(f);
349 /* end data decoding */
350 jpeg_finish_decompress(&cinfo);
351 jpeg_destroy_decompress(&cinfo);
352 return d;
353}
354
355static void *
356eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, int *h)
357{
358 struct jpeg_decompress_struct cinfo;
359 struct _JPEG_error_mgr jerr;
360 unsigned char *ptr, *line[16], *tdata;
361 unsigned int *ptr2;
362 int x, y, l, i, scans, count, prevy;
363 FILE *f;
364
365 f = fmemopen(data, (size_t)size, "r");
366 if (!f) return NULL;
367 cinfo.err = jpeg_std_error(&(jerr.pub));
368 jerr.pub.error_exit = _JPEGFatalErrorHandler;
369 jerr.pub.emit_message = _JPEGErrorHandler2;
370 jerr.pub.output_message = _JPEGErrorHandler;
371 if (setjmp(jerr.setjmp_buffer))
372 {
373 jpeg_destroy_decompress(&cinfo);
374 fclose(f);
375 return NULL;
376 }
377 jpeg_create_decompress(&cinfo);
378 jpeg_stdio_src(&cinfo, f);
379 jpeg_read_header(&cinfo, TRUE);
380 cinfo.do_fancy_upsampling = FALSE;
381 cinfo.do_block_smoothing = FALSE;
382 jpeg_start_decompress(&cinfo);
383
384 /* head decoding */
385 if ((*w) != cinfo.output_width)
386 {
387 jpeg_destroy_decompress(&cinfo);
388 fclose(f);
389 return NULL;
390 }
391 if ((*h) != cinfo.output_height)
392 {
393 jpeg_destroy_decompress(&cinfo);
394 fclose(f);
395 return NULL;
396 }
397 *w = cinfo.output_width;
398 *h = cinfo.output_height;
399 /* end head decoding */
400 /* data decoding */
401 if (cinfo.rec_outbuf_height > 16)
402 {
403 jpeg_destroy_decompress(&cinfo);
404 fclose(f);
405 return NULL;
406 }
407 tdata = malloc((*w) * 16 * 3);
408 if (!tdata)
409 {
410 jpeg_destroy_decompress(&cinfo);
411 fclose(f);
412 return NULL;
413 }
414 ptr2 = d;
415 count = 0;
416 prevy = 0;
417 if (cinfo.output_components == 3)
418 {
419 for (i = 0; i < cinfo.rec_outbuf_height; i++)
420 line[i] = tdata + (i * (*w) * 3);
421 for (l = 0; l < (*h); l += cinfo.rec_outbuf_height)
422 {
423 jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
424 scans = cinfo.rec_outbuf_height;
425 if (((*h) - l) < scans) scans = (*h) - l;
426 ptr = tdata;
427 for (y = 0; y < scans; y++)
428 {
429 for (x = 0; x < (*w); x++)
430 {
431 *ptr2 =
432 ((*ptr2) & 0x00ffffff) |
433 (((ptr[0] + ptr[1] + ptr[2]) / 3) << 24);
434 ptr += 3;
435 ptr2++;
436 }
437 }
438 }
439 }
440 else if (cinfo.output_components == 1)
441 {
442 for (i = 0; i < cinfo.rec_outbuf_height; i++)
443 line[i] = tdata + (i * (*w));
444 for (l = 0; l < (*h); l += cinfo.rec_outbuf_height)
445 {
446 jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
447 scans = cinfo.rec_outbuf_height;
448 if (((*h) - l) < scans) scans = (*h) - l;
449 ptr = tdata;
450 for (y = 0; y < scans; y++)
451 {
452 for (x = 0; x < (*w); x++)
453 {
454 *ptr2 =
455 ((*ptr2) & 0x00ffffff) |
456 ((ptr[0]) << 24);
457 ptr++;
458 ptr2++;
459 }
460 }
461 }
462 }
463 free(tdata);
464 fclose(f);
465 /* end data decoding */
466 jpeg_finish_decompress(&cinfo);
467 jpeg_destroy_decompress(&cinfo);
468 return d;
469}
470
471static void *
472eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha)
473{
474 if (words_bigendian == -1)
475 {
476 unsigned long int v;
477
478 v = htonl(0x12345678);
479 if (v == 0x12345678) words_bigendian = 1;
480 else words_bigendian = 0;
481 }
482 {
483 unsigned char *d;
484 int *header;
485
486 d = malloc((w * h * 4) + (8 * 4));
487 if (!d) return NULL;
488 header = (int *)d;
489 header[0] = 0xac1dfeed;
490 header[1] = w;
491 header[2] = h;
492 header[3] = alpha;
493 header[4] = 0;
494 memcpy(d + 32, data, w * h * 4);
495
496 if (words_bigendian)
497 {
498 int i;
499
500 for (i = 0; i < ((w * h) + 8); i++) SWAP32(header[i]);
501 }
502 *size = ((w * h * 4) + (8 * 4));
503 return d;
504 }
505}
506
507static void *
508eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int alpha, int compression)
509{
510 if (words_bigendian == -1)
511 {
512 unsigned long int v;
513
514 v = htonl(0x12345678);
515 if (v == 0x12345678) words_bigendian = 1;
516 else words_bigendian = 0;
517 }
518
519 {
520 unsigned char *d;
521 unsigned char *comp;
522 int *header;
523 int ret;
524 uLongf buflen;
525
526 d = malloc((w * h * 4) + (8 * 4));
527 if (!d) return NULL;
528 buflen = (((w * h * 101) / 100) + 3) * 4;
529 comp = malloc(buflen);
530 if (!comp)
531 {
532 free(d);
533 return NULL;
534 }
535 header = (int *)d;
536 header[0] = 0xac1dfeed;
537 header[1] = w;
538 header[2] = h;
539 header[3] = alpha;
540 header[4] = compression;
541 memcpy(d + 32, data, w * h * 4);
542
543 if (words_bigendian)
544 {
545 int i;
546
547 for (i = 0; i < ((w * h) + 8); i++) SWAP32(header[i]);
548 }
549 ret = compress2((Bytef *)comp, &buflen,
550 (Bytef *)(d + 32),
551 (uLong)(w * h * 4),
552 compression);
553 if (buflen > (w * h * 4))
554 {
555 free(comp);
556 *size = ((w * h * 4) + (8 * 4));
557 return d;
558 }
559 memcpy(d + 32, comp, buflen);
560 *size = (8 * 4) + buflen;
561 free(comp);
562 return d;
563 }
564}
565
566static void *
567eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int quality)
568{
569 int *ptr;
570 char *d = NULL;
571 size_t sz = 0;
572 struct _JPEG_error_mgr jerr;
573 JSAMPROW *jbuf;
574 struct jpeg_compress_struct cinfo;
575 FILE *f;
576 unsigned char *buf;
577
578 f = open_memstream(&d, &sz);
579 if (!f) return NULL;
580
581 buf = malloc(3 * w);
582 if (!buf)
583 {
584 fclose(f);
585 if (d) free(d);
586 return NULL;
587 }
588
589 cinfo.err = jpeg_std_error(&(jerr.pub));
590 jerr.pub.error_exit = _JPEGFatalErrorHandler;
591 jerr.pub.emit_message = _JPEGErrorHandler2;
592 jerr.pub.output_message = _JPEGErrorHandler;
593 if (setjmp(jerr.setjmp_buffer))
594 {
595 jpeg_destroy_compress(&cinfo);
596 if (buf) free(buf);
597 fclose(f);
598 if (d) free(d);
599 return NULL;
600 }
601 jpeg_create_compress(&cinfo);
602 jpeg_stdio_dest(&cinfo, f);
603 cinfo.image_width = w;
604 cinfo.image_height = h;
605 cinfo.input_components = 3;
606 cinfo.in_color_space = JCS_RGB;
607 jpeg_set_defaults(&cinfo);
608 jpeg_set_quality(&cinfo, quality, TRUE);
609 jpeg_start_compress(&cinfo, TRUE);
610
611 ptr = data;
612 while (cinfo.next_scanline < cinfo.image_height)
613 {
614 int i, j;
615
616 /* convert scaline from ARGB to RGB packed */
617 for (j = 0, i = 0; i < w; i++)
618 {
619 buf[j++] = ((*ptr) >> 16) & 0xff;
620 buf[j++] = ((*ptr) >> 8) & 0xff;
621 buf[j++] = ((*ptr)) & 0xff;
622 ptr++;
623 }
624 jbuf = (JSAMPROW *) (&buf);
625 jpeg_write_scanlines(&cinfo, jbuf, 1);
626 }
627
628 jpeg_finish_compress(&cinfo);
629 jpeg_destroy_compress(&cinfo);
630
631 *size = sz;
632 if (buf) free(buf);
633 fclose(f);
634 return d;
635}
636
637static void *
638eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha, int quality)
639{
640 unsigned char *d1, *d2;
641 unsigned char *d;
642 int *header;
643 int sz1, sz2;
644
645 if (words_bigendian == -1)
646 {
647 unsigned long int v;
648
649 v = htonl(0x12345678);
650 if (v == 0x12345678) words_bigendian = 1;
651 else words_bigendian = 0;
652 }
653
654 {
655 int *ptr;
656 char *d = NULL;
657 size_t sz = 0;
658 struct _JPEG_error_mgr jerr;
659 JSAMPROW *jbuf;
660 struct jpeg_compress_struct cinfo;
661 FILE *f;
662 unsigned char *buf;
663
664 f = open_memstream(&d, &sz);
665 if (!f) return NULL;
666
667 buf = malloc(3 * w);
668 if (!buf)
669 {
670 fclose(f);
671 if (d) free(d);
672 return NULL;
673 }
674
675 cinfo.err = jpeg_std_error(&(jerr.pub));
676 jerr.pub.error_exit = _JPEGFatalErrorHandler;
677 jerr.pub.emit_message = _JPEGErrorHandler2;
678 jerr.pub.output_message = _JPEGErrorHandler;
679 if (setjmp(jerr.setjmp_buffer))
680 {
681 jpeg_destroy_compress(&cinfo);
682 if (buf) free(buf);
683 fclose(f);
684 if (d) free(d);
685 return NULL;
686 }
687 jpeg_create_compress(&cinfo);
688 jpeg_stdio_dest(&cinfo, f);
689 cinfo.image_width = w;
690 cinfo.image_height = h;
691 cinfo.input_components = 3;
692 cinfo.in_color_space = JCS_RGB;
693 jpeg_set_defaults(&cinfo);
694 jpeg_set_quality(&cinfo, quality, TRUE);
695 jpeg_start_compress(&cinfo, TRUE);
696
697 ptr = data;
698 while (cinfo.next_scanline < cinfo.image_height)
699 {
700 int i, j;
701
702 /* convert scaline from ARGB to RGB packed */
703 for (j = 0, i = 0; i < w; i++)
704 {
705 buf[j++] = ((*ptr) >> 16) & 0xff;
706 buf[j++] = ((*ptr) >> 8) & 0xff;
707 buf[j++] = ((*ptr)) & 0xff;
708 ptr++;
709 }
710 jbuf = (JSAMPROW *) (&buf);
711 jpeg_write_scanlines(&cinfo, jbuf, 1);
712 }
713
714 jpeg_finish_compress(&cinfo);
715 jpeg_destroy_compress(&cinfo);
716
717 if (buf) free(buf);
718 fclose(f);
719 d1 = d;
720 sz1 = sz;
721 }
722 {
723 int *ptr;
724 char *d = NULL;
725 size_t sz = 0;
726 struct _JPEG_error_mgr jerr;
727 JSAMPROW *jbuf;
728 struct jpeg_compress_struct cinfo;
729 FILE *f;
730 unsigned char *buf;
731
732 f = open_memstream(&d, &sz);
733 if (!f)
734 {
735 free(d1);
736 return NULL;
737 }
738
739 buf = malloc(3 * w);
740 if (!buf)
741 {
742 fclose(f);
743 if (d) free(d);
744 free(d1);
745 return NULL;
746 }
747
748 cinfo.err = jpeg_std_error(&(jerr.pub));
749 jerr.pub.error_exit = _JPEGFatalErrorHandler;
750 jerr.pub.emit_message = _JPEGErrorHandler2;
751 jerr.pub.output_message = _JPEGErrorHandler;
752 if (setjmp(jerr.setjmp_buffer))
753 {
754 jpeg_destroy_compress(&cinfo);
755 if (buf) free(buf);
756 fclose(f);
757 if (d) free(d);
758 free(d1);
759 return NULL;
760 }
761 jpeg_create_compress(&cinfo);
762 jpeg_stdio_dest(&cinfo, f);
763 cinfo.image_width = w;
764 cinfo.image_height = h;
765 cinfo.input_components = 1;
766 cinfo.in_color_space = JCS_GRAYSCALE;
767 jpeg_set_defaults(&cinfo);
768 jpeg_set_quality(&cinfo, quality, TRUE);
769 jpeg_start_compress(&cinfo, TRUE);
770
771 ptr = data;
772 while (cinfo.next_scanline < cinfo.image_height)
773 {
774 int i, j;
775
776 /* convert scaline from ARGB to RGB packed */
777 for (j = 0, i = 0; i < w; i++)
778 {
779 buf[j++] = ((*ptr) >> 24) & 0xff;
780 ptr++;
781 }
782 jbuf = (JSAMPROW *) (&buf);
783 jpeg_write_scanlines(&cinfo, jbuf, 1);
784 }
785
786 jpeg_finish_compress(&cinfo);
787 jpeg_destroy_compress(&cinfo);
788
789 if (buf) free(buf);
790 fclose(f);
791 d2 = d;
792 sz2 = sz;
793 }
794 d = malloc(12 + sz1 + sz2);
795 if (!d)
796 {
797 free(d1);
798 free(d2);
799 return NULL;
800 }
801 header = (int *)d;
802 header[0] = 0xbeeff00d;
803 header[1] = sz1;
804 header[2] = sz2;
805 if (words_bigendian)
806 {
807 int i;
808
809 for (i = 0; i < ((w * h) + 3); i++) SWAP32(header[i]);
810 }
811 memcpy(d + 12, d1, sz1);
812 memcpy(d + 12 + sz1, d2, sz2);
813
814 free(d1);
815 free(d2);
816 *size = 12 + sz1 + sz2;
817 return d;
818}
819
820
821/* CHAR TYPE */
822static int
823eet_data_get_char(void *src, void *src_end, void *dst)
824{
825 char *s, *d;
826
827 if ((src + sizeof(char)) > src_end) return -1;
828 s = (char *)src;
829 d = (char *)dst;
830 *s = *d;
831 CONV8(*s);
832 return sizeof(char);
833}
834
835static void *
836eet_data_put_char(void *src, int *size_ret)
837{
838 char *s, *d;
839
840 d = (char *)malloc(sizeof(char));
841 if (!d) return NULL;
842 s = (char *)src;
843 *d = *s;
844 CONV8(*d);
845 *size_ret = sizeof(char);
846 return d;
847}
848
849/* SHORT TYPE */
850static int
851eet_data_get_short(void *src, void *src_end, void *dst)
852{
853 short *s, *d;
854 short tmp;
855
856 if ((src + sizeof(short)) > src_end) return -1;
857 s = (short *)src;
858 d = (short *)dst;
859 /* alignment fixup */
860 if ((int)s & (sizeof(short) - 1))
861 {
862 memcpy(&tmp, s, sizeof(short));
863 s = &tmp;
864 }
865 *d = *s;
866 CONV16(*d);
867 return sizeof(short);
868}
869
870static void *
871eet_data_put_short(void *src, int *size_ret)
872{
873 short *s, *d;
874
875 d = (short *)malloc(sizeof(short));
876 if (!d) return NULL;
877 s = (short *)src;
878 *d = *s;
879 CONV16(*d);
880 *size_ret = sizeof(short);
881 return d;
882}
883
884/* INT TYPE */
885static int
886eet_data_get_int(void *src, void *src_end, void *dst)
887{
888 int *s, *d;
889 int tmp;
890
891 if ((src + sizeof(int)) > src_end) return -1;
892 s = (int *)src;
893 d = (int *)dst;
894 /* alignment fixup */
895 if ((int)s & (sizeof(int) - 1))
896 {
897 memcpy(&tmp, s, sizeof(int));
898 s = &tmp;
899 }
900 *d = *s;
901 CONV32(*d);
902 return sizeof(int);
903}
904
905static void *
906eet_data_put_int(void *src, int *size_ret)
907{
908 int *s, *d;
909
910 d = (int *)malloc(sizeof(int));
911 if (!d) return NULL;
912 s = (int *)src;
913 *d = *s;
914 CONV32(*d);
915 *size_ret = sizeof(int);
916 return d;
917}
918
919/* LONG LONG TYPE */
920static int
921eet_data_get_long_long(void *src, void *src_end, void *dst)
922{
923 long long *s, *d;
924 long long tmp;
925
926 if ((src + sizeof(long long)) > src_end) return -1;
927 s = (long long *)src;
928 d = (long long *)dst;
929 /* alignment fixup */
930 if ((int)s & (sizeof(long long) - 1))
931 {
932 memcpy(&tmp, s, sizeof(long long));
933 s = &tmp;
934 }
935 *d = *s;
936 CONV64(*d);
937 return sizeof(long long);
938}
939
940static void *
941eet_data_put_long_long(void *src, int *size_ret)
942{
943 long long *s, *d;
944
945 d = (long long *)malloc(sizeof(long long));
946 if (!d) return NULL;
947 s = (long long *)src;
948 *d = *s;
949 CONV64(*d);
950 *size_ret = sizeof(long long);
951 return d;
952}
953
954/* STRING TYPE */
955static int
956eet_data_get_string(void *src, void *src_end, void *dst)
957{
958 char *s, **d, *p;
959 int len;
960
961 s = (char *)src;
962 d = (char **)dst;
963 p = s;
964 len = 0;
965 while ((p < (char *)src_end) && (*p != 0)) {len++; p++;}
966 *d = malloc(len + 1);
967 if (!(*d)) return -1;
968 memcpy(*d, s, len);
969 (*d)[len] = 0;
970 return len + 1;
971}
972
973static void *
974eet_data_put_string(void *src, int *size_ret)
975{
976 char *s, *d;
977 int len;
978
979 if (!src) src = "";
980 s = (char *)(*((char **)src));
981 len = strlen(s);
982 d = malloc(len + 1);
983 if (!d) return NULL;
984 strcpy(d, s);
985 *size_ret = len + 1;
986 return d;
987}
988
989/* FLOAT TYPE */
990static int
991eet_data_get_float(void *src, void *src_end, void *dst)
992{
993 float *d;
994 char *s, *str, *p, *prev_locale;
995 int len;
996
997 s = (char *)src;
998 d = (float *)dst;
999 p = s;
1000 len = 0;
1001 while ((p < (char *)src_end) && (*p != 0)) {len++; p++;}
1002 str = malloc(len + 1);
1003 if (!str) return -1;
1004 memcpy(str, s, len);
1005 str[len] = 0;
1006
1007 prev_locale = setlocale(LC_NUMERIC, "C");
1008 *d = (float)atof(str);
1009 if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
1010
1011 free(str);
1012 return len + 1;
1013}
1014
1015static void *
1016eet_data_put_float(void *src, int *size_ret)
1017{
1018 float *s;
1019 char *d, buf[64], *prev_locale;
1020 int len;
1021
1022 s = (float *)src;
1023 prev_locale = setlocale(LC_NUMERIC, "C");
1024 snprintf(buf, sizeof(buf), "%16.16f", (double)(*s));
1025 if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
1026 len = strlen(buf);
1027 d = malloc(len + 1);
1028 if (!d) return NULL;
1029 strcpy(d, buf);
1030 *size_ret = len + 1;
1031 return d;
1032}
1033
1034/* DOUBLE TYPE */
1035static int
1036eet_data_get_double(void *src, void *src_end, void *dst)
1037{
1038 double *d;
1039 char *s, *str, *p, *prev_locale;
1040 int len;
1041
1042 s = (char *)src;
1043 d = (double *)dst;
1044 p = s;
1045 len = 0;
1046 while ((p < (char *)src_end) && (*p != 0)) {len++; p++;}
1047 str = malloc(len + 1);
1048 if (!str) return -1;
1049 memcpy(str, s, len);
1050 str[len] = 0;
1051
1052 prev_locale = setlocale(LC_NUMERIC, "C");
1053 *d = (double)atof(str);
1054 if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
1055
1056 free(str);
1057 return len + 1;
1058}
1059
1060static void *
1061eet_data_put_double(void *src, int *size_ret)
1062{
1063 double *s;
1064 char *d, buf[128], *prev_locale;
1065 int len;
1066
1067 s = (double *)src;
1068 prev_locale = setlocale(LC_NUMERIC, "C");
1069 snprintf(buf, sizeof(buf), "%32.32f", (double)(*s));
1070 if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
1071 len = strlen(buf);
1072 d = malloc(len + 1);
1073 if (!d) return NULL;
1074 strcpy(d, buf);
1075 *size_ret = len + 1;
1076 return d;
1077}
1078
1079static int
1080eet_data_get_type(int type, void *src, void *src_end, void *dest)
1081{
1082 int ret;
1083
1084 ret = eet_coder[type - 1].get(src, src_end, dest);
1085 return ret;
1086}
1087
1088static void *
1089eet_data_put_type(int type, void *src, int *size_ret)
1090{
1091 void *ret;
1092
1093 ret = eet_coder[type - 1].put(src, size_ret);
1094 return ret;
1095}
1096
1097/* chunk format...
1098 *
1099 * char[4] = "CHnK";
1100 * int = chunk size (including magic string);
1101 * char[] = chuck magic/name string (0 byte terminated);
1102 * ... sub-chunks (a chunk can contain chuncks recusrively) ...
1103 * or
1104 * ... payload data ...
1105 *
1106 */
1107
1108static Eet_Data_Chunk *
1109eet_data_chunk_get(void *src, int size)
1110{
1111 Eet_Data_Chunk *chnk;
1112 char *s;
1113 int ret1, ret2;
1114
1115 if (!src) return NULL;
1116 if (size <= 8) return NULL;
1117
1118 chnk = calloc(1, sizeof(Eet_Data_Chunk));
1119 if (!chnk) return NULL;
1120
1121 s = src;
1122 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
1123 {
1124 free(chnk);
1125 return NULL;
1126 }
1127 ret1 = eet_data_get_type(EET_T_INT, (void *)(s + 4), (void *)(s + size), &(chnk->size));
1128 if (ret1 <= 0)
1129 {
1130 free(chnk);
1131 return NULL;
1132 }
1133 if ((chnk->size < 0) || ((chnk->size + 8) > size))
1134 {
1135 free(chnk);
1136 return NULL;
1137 }
1138 ret2 = eet_data_get_type(EET_T_STRING, (void *)(s + 8), (void *)(s + size), &(chnk->name));
1139 if (ret2 <= 0)
1140 {
1141 free(chnk);
1142 return NULL;
1143 }
1144 chnk->data = src + 4 + ret1 + ret2;
1145 chnk->size -= ret2;
1146 return chnk;
1147}
1148
1149static Eet_Data_Chunk *
1150eet_data_chunk_new(void *data, int size, char *name)
1151{
1152 Eet_Data_Chunk *chnk;
1153
1154 if (!name) return NULL;
1155 chnk = calloc(1, sizeof(Eet_Data_Chunk));
1156 if (!chnk) return NULL;
1157
1158 chnk->name = strdup(name);
1159 chnk->size = size;
1160 chnk->data = data;
1161
1162 return chnk;
1163}
1164
1165static void
1166eet_data_chunk_free(Eet_Data_Chunk *chnk)
1167{
1168 if (chnk->name) free(chnk->name);
1169 free(chnk);
1170}
1171
1172static Eet_Data_Stream *
1173eet_data_stream_new(void)
1174{
1175 Eet_Data_Stream *ds;
1176
1177 ds = calloc(1, sizeof(Eet_Data_Stream));
1178 if (!ds) return NULL;
1179 return ds;
1180}
1181
1182static void
1183eet_data_stream_free(Eet_Data_Stream *ds)
1184{
1185 if (ds->data) free(ds->data);
1186 free(ds);
1187}
1188
1189static void
1190eet_data_stream_write(Eet_Data_Stream *ds, void *data, int size)
1191{
1192 char *p;
1193
1194 if ((ds->pos + size) > ds->size)
1195 {
1196 ds->data = realloc(ds->data, ds->size + size + 256);
1197 if (!ds->data)
1198 {
1199 ds->pos = 0;
1200 ds->size = 0;
1201 return;
1202 }
1203 ds->size = ds->size + size + 256;
1204 }
1205 p = ds->data;
1206 memcpy(p + ds->pos, data, size);
1207 ds->pos += size;
1208}
1209
1210static void
1211eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
1212{
1213 int *size;
1214 int s;
1215 int size_ret;
1216
1217 if (!chnk->data) return;
1218 /* chunk head */
1219 eet_data_stream_write(ds, "CHnK", 4);
1220 /* size of chunk payload data + name */
1221 s = strlen(chnk->name) + 1 + chnk->size;
1222 size = eet_data_put_int(&s, &size_ret);
1223 if (size)
1224 {
1225 eet_data_stream_write(ds, size, size_ret);
1226 free(size);
1227 }
1228 /* write chunk name */
1229 eet_data_stream_write(ds, chnk->name, strlen(chnk->name) + 1);
1230 /* write payload */
1231 eet_data_stream_write(ds, chnk->data, chnk->size);
1232}
1233
1234/*---*/
1235
1236int
1237eet_data_image_write(Eet_File *ef, char *name,
1238 void *data, int w, int h, int alpha,
1239 int compress, int quality, int lossy)
1240{
1241 void *d = NULL;
1242 int size = 0;
1243
1244 d = eet_data_image_encode(data, &size, w, h, alpha, compress, quality, lossy);
1245 if (d)
1246 {
1247 int v;
1248
1249 v = eet_write(ef, name, d, size, 0);
1250 free(d);
1251 return v;
1252 }
1253 return 0;
1254}
1255
1256void *
1257eet_data_image_read(Eet_File *ef, char *name,
1258 int *w, int *h, int *alpha,
1259 int *compress, int *quality, int *lossy)
1260{
1261 void *data;
1262 int size;
1263 unsigned int *d = NULL;
1264 int header[8];
1265
1266 data = eet_read(ef, name, &size);
1267 if (!data) return NULL;
1268 d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy);
1269 free(data);
1270 return d;
1271}
1272
1273void *
1274eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int compress, int quality, int lossy)
1275{
1276 void *d = NULL;
1277 int size = 0;
1278
1279 if (lossy == 0)
1280 {
1281 if (compress <= 0)
1282 d = eet_data_image_lossless_convert(&size, data, w, h, alpha);
1283 else
1284 d = eet_data_image_lossless_compressed_convert(&size, data, w, h, alpha, compress);
1285 }
1286 else
1287 {
1288 if (!alpha)
1289 d = eet_data_image_jpeg_convert(&size, data, w, h, alpha, quality);
1290 else
1291 d = eet_data_image_jpeg_alpha_convert(&size, data, w, h, alpha, quality);
1292 }
1293 if (size_ret) *size_ret = size;
1294 return d;
1295}
1296
1297void *
1298eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy)
1299{
1300 unsigned int *d = NULL;
1301 int header[8];
1302
1303 if (words_bigendian == -1)
1304 {
1305 unsigned long int v;
1306
1307 v = htonl(0x12345678);
1308 if (v == 0x12345678) words_bigendian = 1;
1309 else words_bigendian = 0;
1310 }
1311
1312 if (size < 32) return NULL;
1313
1314 memcpy(header, data, 32);
1315 if (words_bigendian)
1316 {
1317 int i;
1318
1319 for (i = 0; i < 8; i++) SWAP32(header[i]);
1320 }
1321 if (header[0] == 0xac1dfeed)
1322 {
1323 int iw, ih, al, cp;
1324 unsigned int *body;
1325
1326 iw = header[1];
1327 ih = header[2];
1328 al = header[3];
1329 cp = header[4];
1330 if ((iw > 8192) || (ih > 8192)) return NULL;
1331 if ((cp == 0) && (size < ((iw * ih * 4) + 32))) return NULL;
1332 body = ((unsigned int *)data) + 8;
1333 d = malloc(iw * ih * 4);
1334 if (!d) return NULL;
1335 if (!cp)
1336 {
1337 memcpy(d, body, iw * ih * 4);
1338 if (words_bigendian)
1339 {
1340 int x;
1341
1342 for (x = 0; x < (iw * ih); x++) SWAP32(d[x]);
1343 }
1344 }
1345 else
1346 {
1347 uLongf dlen;
1348
1349 dlen = iw * ih * 4;
1350 uncompress((Bytef *)d, &dlen, (Bytef *)body,
1351 (uLongf)(size - 32));
1352 if (words_bigendian)
1353 {
1354 int x;
1355
1356 for (x = 0; x < (iw * ih); x++) SWAP32(d[x]);
1357 }
1358 }
1359 if (d)
1360 {
1361 if (w) *w = iw;
1362 if (h) *h = ih;
1363 if (alpha) *alpha = al;
1364 if (compress) *compress = cp;
1365 if (lossy) *lossy = 0;
1366 if (quality) *quality = 100;
1367 }
1368 }
1369 else if (header[0] == 0xbeeff00d)
1370 {
1371 int iw = 0, ih = 0;
1372 int sz1, sz2;
1373 unsigned char *dt;
1374
1375 sz1 = header[1];
1376 sz2 = header[2];
1377 dt = data;
1378 dt += 12;
1379 d = eet_data_image_jpeg_rgb_decode(dt, sz1, &iw, &ih);
1380 if (d)
1381 {
1382 dt += sz1;
1383 eet_data_image_jpeg_alpha_decode(dt, sz2, d, &iw, &ih);
1384 }
1385 if (d)
1386 {
1387 if (w) *w = iw;
1388 if (h) *h = ih;
1389 if (alpha) *alpha = 1;
1390 if (compress) *compress = 0;
1391 if (lossy) *lossy = 1;
1392 if (quality) *quality = 75;
1393 }
1394 }
1395 else
1396 {
1397 int iw = 0, ih = 0;
1398
1399 d = eet_data_image_jpeg_rgb_decode(data, size, &iw, &ih);
1400 if (d)
1401 {
1402 if (w) *w = iw;
1403 if (h) *h = ih;
1404 if (alpha) *alpha = 0;
1405 if (compress) *compress = 0;
1406 if (lossy) *lossy = 1;
1407 if (quality) *quality = 75;
1408 }
1409 }
1410 return d;
1411}
1412
1413Eet_Data_Descriptor *
1414eet_data_descriptor_new(char *name,
1415 int size,
1416 void *(*func_list_next) (void *l),
1417 void *(*func_list_append) (void *l, void *d),
1418 void *(*func_list_data) (void *l),
1419 void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt),
1420 void *(*func_hash_add) (void *h, const char *k, void *d))
1421{
1422 Eet_Data_Descriptor *edd;
1423
1424 edd = calloc(1, sizeof(Eet_Data_Descriptor));
1425 edd->name = strdup(name);
1426 edd->size = size;
1427 edd->func.list_next = func_list_next;
1428 edd->func.list_append = func_list_append;
1429 edd->func.list_data = func_list_data;
1430 edd->func.hash_foreach = func_hash_foreach;
1431 edd->func.hash_add = func_hash_add;
1432 return edd;
1433}
1434
1435void
1436eet_data_descriptor_free(Eet_Data_Descriptor *edd)
1437{
1438 int i;
1439
1440 if (edd->name) free(edd->name);
1441 for (i = 0; i < edd->elements.num; i++)
1442 {
1443 if (edd->elements.set[i].name) free(edd->elements.set[i].name);
1444 if (edd->elements.set[i].counter_name) free(edd->elements.set[i].counter_name);
1445 }
1446 if (edd->elements.set) free(edd->elements.set);
1447 free(edd);
1448}
1449
1450void
1451eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type,
1452 int group_type,
1453 int offset,
1454 int count, char *counter_name,
1455 Eet_Data_Descriptor *subtype)
1456{
1457 Eet_Data_Element *ede;
1458
1459 edd->elements.num++;
1460 edd->elements.set = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element));
1461 if (!edd->elements.set) return;
1462 ede = &(edd->elements.set[edd->elements.num - 1]);
1463 ede->name = strdup(name);
1464 ede->type = type;
1465 ede->group_type = group_type;
1466 ede->offset = offset;
1467 ede->count = count;
1468 if (counter_name)
1469 ede->counter_name = strdup(counter_name);
1470 else ede->counter_name = NULL;
1471 ede->subtype = subtype;
1472}
1473
1474void *
1475eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name)
1476{
1477 void *data_dec;
1478 void *data;
1479 int size;
1480
1481 data = eet_read(ef, name, &size);
1482 if (!data) return NULL;
1483 data_dec = eet_data_descriptor_decode(edd, data, size);
1484 free(data);
1485 return data_dec;
1486}
1487
1488int
1489eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, char *name, void *data, int compress)
1490{
1491 void *data_enc;
1492 int size;
1493 int val;
1494
1495 data_enc = eet_data_descriptor_encode(edd, data, &size);
1496 if (!data_enc) return 0;
1497 val = eet_write(ef, name, data_enc, size, compress);
1498 free(data_enc);
1499 return val;
1500}
1501
1502void *
1503eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
1504 void *data_in,
1505 int size_in)
1506{
1507 void *data;
1508 char *p;
1509 int size;
1510 Eet_Data_Chunk *chnk;
1511
1512 if (words_bigendian == -1)
1513 {
1514 unsigned long int v;
1515
1516 v = htonl(0x12345678);
1517 if (v == 0x12345678) words_bigendian = 1;
1518 else words_bigendian = 0;
1519 }
1520
1521 data = calloc(1, edd->size);
1522 if (!data) return NULL;
1523 chnk = eet_data_chunk_get(data_in, size_in);
1524 if (!chnk)
1525 {
1526 free(data);
1527 return NULL;
1528 }
1529 if (strcmp(chnk->name, edd->name))
1530 {
1531 eet_data_chunk_free(chnk);
1532 free(data);
1533 return NULL;
1534 }
1535 p = chnk->data;
1536 size = size_in - (4 + 4 + strlen(chnk->name) + 1);
1537 while (size > 0)
1538 {
1539 Eet_Data_Chunk *echnk;
1540 int i;
1541
1542 /* get next data chunk */
1543 echnk = eet_data_chunk_get(p, size);
1544 if (!echnk)
1545 {
1546 /* FIXME: partially built data struct - leak!!!! */
1547 free(data);
1548 eet_data_chunk_free(chnk);
1549 return NULL;
1550 }
1551 for (i = 0; i < edd->elements.num; i++)
1552 {
1553 Eet_Data_Element *ede;
1554
1555 ede = &(edd->elements.set[i]);
1556 if (!strcmp(echnk->name, ede->name))
1557 {
1558 if (ede->group_type == EET_G_UNKNOWN)
1559 {
1560 int ret;
1561 void *data_ret;
1562
1563 if ((ede->type >= EET_T_CHAR) &&
1564 (ede->type <= EET_T_STRING))
1565 {
1566 ret = eet_data_get_type(ede->type,
1567 echnk->data,
1568 ((char *)echnk->data) + echnk->size,
1569 ((char *)data) + ede->offset);
1570 }
1571 else if (ede->subtype)
1572 {
1573 void **ptr;
1574
1575 data_ret = eet_data_descriptor_decode(ede->subtype,
1576 echnk->data,
1577 echnk->size);
1578 ptr = (void **)(((char *)data) + ede->offset);
1579 *ptr = (void *)data_ret;
1580 }
1581 }
1582 else
1583 {
1584 switch (ede->group_type)
1585 {
1586 case EET_G_ARRAY:
1587 case EET_G_VAR_ARRAY:
1588 {
1589 printf("ARRAY TYPE NOT IMPLIMENTED YET!!!\n");
1590 }
1591 break;
1592 case EET_G_LIST:
1593 {
1594 int ret;
1595 void *list = NULL;
1596 void **ptr;
1597 void *data_ret;
1598
1599 ptr = (void **)(((char *)data) + ede->offset);
1600 list = *ptr;
1601 data_ret = NULL;
1602 if ((ede->type >= EET_T_CHAR) &&
1603 (ede->type <= EET_T_STRING))
1604 {
1605 data_ret = calloc(1, eet_coder[ede->type].size);
1606 if (data_ret)
1607 {
1608 ret = eet_data_get_type(ede->type,
1609 echnk->data,
1610 ((char *)echnk->data) + echnk->size,
1611 data_ret);
1612 if (ret <= 0)
1613 {
1614 free(data_ret);
1615 data_ret = NULL;
1616 }
1617 }
1618 }
1619 else if (ede->subtype)
1620 {
1621 data_ret = eet_data_descriptor_decode(ede->subtype,
1622 echnk->data,
1623 echnk->size);
1624 }
1625 if (data_ret)
1626 {
1627 list = edd->func.list_append(list, data_ret);
1628 *ptr = list;
1629 }
1630 }
1631 break;
1632 case EET_G_HASH:
1633 printf("HASH TYPE NOT IMPLIMENTED YET!!!\n");
1634 break;
1635 default:
1636 break;
1637 }
1638 }
1639 break;
1640 }
1641 }
1642 /* advance to next chunk */
1643 p += (4 + 4 + strlen(echnk->name) + 1 + echnk->size);
1644 size -= (4 + 4 + strlen(echnk->name) + 1 + echnk->size);
1645 eet_data_chunk_free(echnk);
1646 }
1647 eet_data_chunk_free(chnk);
1648 return data;
1649}
1650
1651void *
1652eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
1653 void *data_in,
1654 int *size_ret)
1655{
1656 Eet_Data_Chunk *chnk;
1657 Eet_Data_Stream *ds;
1658 int i;
1659 void *cdata;
1660 int csize;
1661
1662 if (words_bigendian == -1)
1663 {
1664 unsigned long int v;
1665
1666 v = htonl(0x12345678);
1667 if (v == 0x12345678) words_bigendian = 1;
1668 else words_bigendian = 0;
1669 }
1670
1671 ds = eet_data_stream_new();
1672 for (i = 0; i < edd->elements.num; i++)
1673 {
1674 Eet_Data_Element *ede;
1675 Eet_Data_Chunk *echnk;
1676 void *data;
1677 int size;
1678
1679 ede = &(edd->elements.set[i]);
1680 data = NULL;
1681 if (ede->group_type == EET_G_UNKNOWN)
1682 {
1683 if ((ede->type >= EET_T_CHAR) &&
1684 (ede->type <= EET_T_STRING))
1685 data = eet_data_put_type(ede->type,
1686 ((char *)data_in) + ede->offset,
1687 &size);
1688 else if (ede->subtype)
1689 data = eet_data_descriptor_encode(ede->subtype,
1690 *((char **)(((char *)data_in) + ede->offset)),
1691 &size);
1692 if (data)
1693 {
1694 echnk = eet_data_chunk_new(data, size, ede->name);
1695 eet_data_chunk_put(echnk, ds);
1696 eet_data_chunk_free(echnk);
1697 free(data);
1698 data = NULL;
1699 }
1700 }
1701 else
1702 {
1703 switch (ede->group_type)
1704 {
1705 case EET_G_ARRAY:
1706 case EET_G_VAR_ARRAY:
1707 {
1708 printf("ARRAY TYPE NOT IMPLIMENTED YET!!!\n");
1709 }
1710 break;
1711 case EET_G_LIST:
1712 {
1713 void *l;
1714
1715 l = *((void **)(((char *)data_in) + ede->offset));
1716 for (; l; l = edd->func.list_next(l))
1717 {
1718 if ((ede->type >= EET_T_CHAR) &&
1719 (ede->type <= EET_T_STRING))
1720 data = eet_data_put_type(ede->type,
1721 edd->func.list_data(l),
1722 &size);
1723 else if (ede->subtype)
1724 data = eet_data_descriptor_encode(ede->subtype,
1725 edd->func.list_data(l),
1726 &size);
1727 if (data)
1728 {
1729 echnk = eet_data_chunk_new(data, size, ede->name);
1730 eet_data_chunk_put(echnk, ds);
1731 eet_data_chunk_free(echnk);
1732 free(data);
1733 data = NULL;
1734 }
1735 }
1736 }
1737 break;
1738 case EET_G_HASH:
1739 {
1740 printf("HASH TYPE NOT IMPLIMENTED YET!!!\n");
1741 }
1742 break;
1743 default:
1744 break;
1745 }
1746 }
1747 }
1748 chnk = eet_data_chunk_new(ds->data, ds->pos, edd->name);
1749 ds->data = NULL;
1750 ds->size = 0;
1751 eet_data_stream_free(ds);
1752
1753 ds = eet_data_stream_new();
1754 eet_data_chunk_put(chnk, ds);
1755 cdata = ds->data;
1756 csize = ds->pos;
1757
1758 ds->data = NULL;
1759 ds->size = 0;
1760 eet_data_stream_free(ds);
1761 *size_ret = csize;
1762 eet_data_chunk_free(chnk);
1763
1764 return cdata;
1765}
diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c
new file mode 100644
index 0000000000..e1cef9d880
--- /dev/null
+++ b/legacy/eet/src/lib/eet_lib.c
@@ -0,0 +1,889 @@
1#include "Eet.h"
2#include <stdio.h>
3#include <unistd.h>
4#include <limits.h>
5#include <stdlib.h>
6#include <time.h>
7#include <sys/types.h>
8#include <fcntl.h>
9#include <netinet/in.h>
10#include <zlib.h>
11#include <string.h>
12#include <fnmatch.h>
13
14#define EET_MAGIC_FILE 0x1ee7ff00
15#define EET_MAGIC_FILE_HEADER 0x1ee7ff01
16#define EET_MAGIC_FILE_NODE 0x1ee7ff02
17#define EET_MAGIC_FILE_DIRECTORY 0x1ee7ff03
18#define EET_MAGIC_FILE_DIRECTORY_HASH 0x1ee7ff04
19
20typedef struct _Eet_File_Header Eet_File_Header;
21typedef struct _Eet_File_Node Eet_File_Node;
22typedef struct _Eet_File_Directory Eet_File_Directory;
23typedef struct _Eet_File_Directory_Hash Eet_File_Directory_Hash;
24
25struct _Eet_File
26{
27 int magic;
28 int references;
29
30 char *path;
31 char *real_path;
32
33 FILE *fp;
34 Eet_File_Mode mode;
35
36 int writes_pending : 1;
37
38 Eet_File_Header *header;
39};
40struct _Eet_File_Header
41{
42 int magic;
43 Eet_File_Directory *directory;
44};
45struct _Eet_File_Node
46{
47 char *name;
48 int offset;
49 int compression;
50 int size;
51 int data_size;
52 void *data;
53};
54struct _Eet_File_Directory
55{
56 int size;
57 Eet_File_Directory_Hash *hash;
58};
59struct _Eet_File_Directory_Hash
60{
61 int size;
62 Eet_File_Node *node;
63};
64
65#if 0
66/* NB: all int's are stored in network byte order on disk */
67/* file format: */
68int magic; /* magic number ie 0x1ee7ff00 */
69int num_directory_entries; /* number of directory entries to follow */
70int bytes_directory_entries; /* bytes of directory entries to follow */
71struct
72{
73 int offset; /* bytes offset into file for data chunk */
74 int flags; /* flags - for now 0 = uncompressed, 1 = compressed */
75 int size; /* size of the data chunk */
76 int data_size; /* size of the (uncompressed) data chunk */
77 int name_size; /* length in bytes of the name field */
78 char name[name_size]; /* name string (variable length) */
79} directory[num_directory_entries];
80/* and now startes the data stream... */
81#endif
82
83/* prototypes of internal calls */
84static Eet_File *eet_cache_find(char *real_path, Eet_File **cache, int cache_num);
85static void eet_cache_add(Eet_File *ef, Eet_File ***cache, int *cache_num);
86static void eet_cache_del(Eet_File *ef, Eet_File ***cache, int *cache_num);
87static int eet_string_match(char *s1, char *s2);
88static int eet_hash_gen(char *key, int hash_size);
89static void eet_flush(Eet_File *ef);
90
91/* cache. i don't expect this to ever be large, so arrays will do */
92static int eet_writers_num = 0;
93static Eet_File **eet_writers = NULL;
94static int eet_readers_num = 0;
95static Eet_File **eet_readers = NULL;
96
97/* find an eet file in the currently in use cache */
98static Eet_File *
99eet_cache_find(char *real_path, Eet_File **cache, int cache_num)
100{
101 int i;
102
103 /* walk list */
104 for (i = 0; i < cache_num; i++)
105 {
106 /* if matches real path - return it */
107 if (eet_string_match(cache[i]->real_path, real_path)) return cache[i];
108 }
109 /* not found */
110 return NULL;
111}
112
113/* add to end of cache */
114static void
115eet_cache_add(Eet_File *ef, Eet_File ***cache, int *cache_num)
116{
117 Eet_File **new_cache;
118 int new_cache_num;
119
120 new_cache_num = *cache_num;
121 new_cache = *cache;
122 new_cache_num++;
123 new_cache = realloc(new_cache, new_cache_num * sizeof(Eet_File *));
124 if (!new_cache) return;
125 new_cache[new_cache_num - 1] = ef;
126 *cache = new_cache;
127 *cache_num = new_cache_num;
128}
129
130/* delete from cache */
131static void
132eet_cache_del(Eet_File *ef, Eet_File ***cache, int *cache_num)
133{
134 Eet_File **new_cache;
135 int new_cache_num;
136 int i, j;
137
138 new_cache_num = *cache_num;
139 new_cache = *cache;
140 if (new_cache_num <= 0) return;
141 for (i = 0; i < new_cache_num; i++)
142 {
143 if (new_cache[i] == ef) break;
144 }
145 if (i >= new_cache_num) return;
146 new_cache_num--;
147 for (j = i; j < new_cache_num; j++) new_cache[j] = new_cache[j + 1];
148 new_cache = realloc(new_cache, new_cache_num * sizeof(Eet_File *));
149 *cache_num = new_cache_num;
150 if ((new_cache_num > 0) && (!new_cache)) return;
151 *cache = new_cache;
152}
153
154/* internal string match. bails out at first mismatch - not comparing all */
155/* bytes in strings */
156static int
157eet_string_match(char *s1, char *s2)
158{
159 /* both null- no match */
160 if ((!s1) || (!s2)) return 0;
161 /* go thru - first mismatch - exit with 0 */
162 do
163 {
164 if (*s1 != *s2) return 0;
165 s1++;
166 s2++;
167 }
168 while ((*s1) || (*s2));
169 /* got this far. match */
170 return 1;
171}
172
173/* caluclate hash table entry valu with bitmask size of hash_size */
174static int
175eet_hash_gen(char *key, int hash_size)
176{
177 int hash_num = 0;
178 unsigned char *ptr;
179 const int masks[9] =
180 {
181 0x00,
182 0x01,
183 0x03,
184 0x07,
185 0x0f,
186 0x1f,
187 0x3f,
188 0x7f,
189 0xff
190 };
191
192 /* no string - index 0 */
193 if (!key) return 0;
194
195 /* calc hash num */
196 for (ptr = key; *ptr; ptr++) hash_num ^= (int)(*ptr);
197
198 /* mask it */
199 hash_num &= masks[hash_size];
200 /* return it */
201 return hash_num;
202}
203
204/* flush out writes to an eet file */
205static void
206eet_flush(Eet_File *ef)
207{
208 int i, j, count, size, num, offset;
209 int head[3];
210 unsigned long int i1, i2;
211
212 /* check to see its' an eet file pointer */
213 if ((!ef) || (ef->magic != EET_MAGIC_FILE))
214 return;
215 if (ef->mode != EET_FILE_MODE_WRITE) return;
216 if (!ef->writes_pending) return;
217
218 /* calculate total size in bytes of directory block */
219 size = 0;
220 count = 0;
221 num = (1 << (ef->header->directory->size - 1));
222 for (i = 0; i < num; i++)
223 {
224 for (j = 0; j < ef->header->directory->hash[i].size; j++)
225 {
226 size += 20 + strlen(ef->header->directory->hash[i].node[j].name);
227 count++;
228 }
229 }
230 /* caluclate offsets per entry */
231 offset = 0;
232 for (i = 0; i < num; i++)
233 {
234 for (j = 0; j < ef->header->directory->hash[i].size; j++)
235 {
236 ef->header->directory->hash[i].node[j].offset = 12 + size + offset;
237 offset += ef->header->directory->hash[i].node[j].size;
238 }
239 }
240 /* go thru and write the header */
241 i1 = (unsigned long int)EET_MAGIC_FILE;
242 i2 = htonl(i1);
243 head[0] = (int)i2;
244 i1 = (unsigned long int)count;
245 i2 = htonl(i1);
246 head[1] = (int)i2;
247 i1 = (unsigned long int)size;
248 i2 = htonl(i1);
249 head[2] = (int)i2;
250 fseek(ef->fp, 0, SEEK_SET);
251 if (fwrite(head, 12, 1, ef->fp) != 1) return;
252 offset = 12;
253 for (i = 0; i < num; i++)
254 {
255 for (j = 0; j < ef->header->directory->hash[i].size; j++)
256 {
257 unsigned char *buf;
258 int buf_size;
259 int name_size;
260
261 name_size = strlen(ef->header->directory->hash[i].node[j].name);
262 buf_size = 20 + name_size;
263 buf = malloc(buf_size);
264 if (!buf) return;
265 i1 = (unsigned long int)ef->header->directory->hash[i].node[j].offset;
266 i2 = htonl(i1);
267 *((int *)(buf + 0)) = (int)i2;
268 i1 = (unsigned long int)ef->header->directory->hash[i].node[j].compression;
269 i2 = htonl(i1);
270 *((int *)(buf + 4)) = (int)i2;
271 i1 = (unsigned long int)ef->header->directory->hash[i].node[j].size;
272 i2 = htonl(i1);
273 *((int *)(buf + 8)) = (int)i2;
274 i1 = (unsigned long int)ef->header->directory->hash[i].node[j].data_size;
275 i2 = htonl(i1);
276 *((int *)(buf + 12)) = (int)i2;
277 i1 = (unsigned long int)name_size;
278 i2 = htonl(i1);
279 *((int *)(buf + 16)) = (int)i2;
280 memcpy(buf + 20, ef->header->directory->hash[i].node[j].name, name_size);
281 if (fwrite(buf, buf_size, 1, ef->fp) != 1)
282 {
283 free(buf);
284 return;
285 }
286 offset += buf_size;
287 free(buf);
288 }
289 }
290 /* write data */
291 for (i = 0; i < num; i++)
292 {
293 for (j = 0; j < ef->header->directory->hash[i].size; j++)
294 {
295 if (fwrite(ef->header->directory->hash[i].node[j].data,
296 ef->header->directory->hash[i].node[j].size,
297 1, ef->fp) != 1)
298 return;
299 }
300 }
301 /* no more writes pending */
302 ef->writes_pending = 0;
303}
304
305Eet_File *
306eet_open(char *file, Eet_File_Mode mode)
307{
308 Eet_File *ef;
309 char buf[PATH_MAX];
310
311 /* in case this is a symlink... find out where it REALLY points */
312 if (!realpath(file, buf))
313 {
314 if (mode == EET_FILE_MODE_READ) return NULL;
315 }
316
317 /* find the current file handle in cache*/
318 ef = NULL;
319 if (mode == EET_FILE_MODE_READ)
320 ef = eet_cache_find(buf, eet_readers, eet_readers_num);
321 else if (mode == EET_FILE_MODE_WRITE)
322 ef = eet_cache_find(buf, eet_writers, eet_writers_num);
323 /* we found one */
324 if (ef)
325 {
326 /* reference it up and return it */
327 ef->references++;
328 return ef;
329 }
330
331 /* allocate struct for eet file and have it zero'd out */
332 ef = calloc(sizeof(Eet_File), 1);
333 if (!ef) return NULL;
334
335 /* fill some of the members */
336 ef->path = strdup(file);
337 ef->real_path = strdup(buf);
338 ef->magic = EET_MAGIC_FILE;
339 ef->references = 1;
340 ef->mode = mode;
341
342 /* try open the file based on mode */
343 if (ef->mode == EET_FILE_MODE_READ)
344 ef->fp = fopen(ef->path, "r");
345 else if (ef->mode == EET_FILE_MODE_WRITE)
346 {
347 /* opening for write - delete old copy of file right away */
348 unlink(ef->real_path);
349 ef->fp = fopen(ef->path, "w");
350 }
351 else
352 {
353 eet_close(ef);
354 return NULL;
355 }
356
357 /* if we can't open - bail out */
358 if (!ef->fp)
359 {
360 eet_close(ef);
361 return NULL;
362 }
363
364 /* if we opened for read */
365 if (mode == EET_FILE_MODE_READ)
366 {
367 unsigned char buf[12];
368 unsigned char *dyn_buf, *p;
369 unsigned long int i1, i2;
370 int num_entries, byte_entries, i;
371 size_t count;
372
373 /* build header table if read mode */
374 /* geat header */
375 count = fread(buf, 12, 1, ef->fp);
376 if (count != 1)
377 {
378 eet_close(ef);
379 return NULL;
380 }
381 /* get magic no */
382 i1 = *((int *)(buf + 0));
383 i2 = ntohl(i1);
384 if (i2 != EET_MAGIC_FILE)
385 {
386 eet_close(ef);
387 return NULL;
388 }
389 /* get entries count and byte count */
390 i1 = *((int *)(buf + 4));
391 i2 = ntohl(i1);
392 num_entries = (int)i2;
393 i1 = *((int *)(buf + 8));
394 i2 = ntohl(i1);
395 byte_entries = (int)i2;
396 /* we cant have <= 0 values here - invalid */
397 if ((num_entries <= 0) || (byte_entries <= 0))
398 {
399 eet_close(ef);
400 return NULL;
401 }
402 /* we can't have more entires than minimum bytes for those! invalid! */
403 if ((num_entries * 20) > byte_entries)
404 {
405 eet_close(ef);
406 return NULL;
407 }
408 /* allocate dynamic buffer for entire directory block */
409 dyn_buf = malloc(byte_entries);
410 if (!dyn_buf)
411 {
412 eet_close(ef);
413 return NULL;
414 }
415 /* allocate header */
416 ef->header = calloc(sizeof(Eet_File_Header), 1);
417 if (!ef->header)
418 {
419 free(dyn_buf);
420 eet_close(ef);
421 return NULL;
422 }
423 ef->header->magic = EET_MAGIC_FILE_HEADER;
424 /* allocate directory block in ram */
425 ef->header->directory = calloc(sizeof(Eet_File_Directory), 1);
426 if (!ef->header->directory)
427 {
428 free(dyn_buf);
429 eet_close(ef);
430 return NULL;
431 }
432 /* 8 bit hash table (256 buckets) */
433 ef->header->directory->size = 8;
434 /* allocate base hash table */
435 ef->header->directory->hash = calloc(sizeof(Eet_File_Directory_Hash), (1 << (ef->header->directory->size - 1)));
436 if (!ef->header->directory->hash)
437 {
438 free(dyn_buf);
439 eet_close(ef);
440 return NULL;
441 }
442 /* actually read the directory block - all of it, into ram */
443 count = fread(dyn_buf, byte_entries, 1, ef->fp);
444 if (count != 1)
445 {
446 free(dyn_buf);
447 eet_close(ef);
448 return NULL;
449 }
450 /* parse directory block */
451 p = dyn_buf;
452 for (i = 0; i < num_entries; i++)
453 {
454 int offset;
455 int flags;
456 int size;
457 int data_size;
458 int name_size;
459 char *name;
460 int hash;
461 Eet_File_Node *node;
462 int node_size;
463
464 /* out directory block is inconsistent - we have oveerun our */
465 /* dynamic block buffer before we finished scanning dir entries */
466 if (p >= (dyn_buf + byte_entries))
467 {
468 free(dyn_buf);
469 eet_close(ef);
470 return NULL;
471 }
472 /* get entrie header */
473 i1 = *((int *)(p + 0));
474 i2 = ntohl(i1);
475 offset = (int)i2;
476 i1 = *((int *)(p + 4));
477 i2 = ntohl(i1);
478 flags = (int)i2;
479 i1 = *((int *)(p + 8));
480 i2 = ntohl(i1);
481 size = (int)i2;
482 i1 = *((int *)(p + 12));
483 i2 = ntohl(i1);
484 data_size = (int)i2;
485 i1 = *((int *)(p + 16));
486 i2 = ntohl(i1);
487 name_size = (int)i2;
488 /* invalid size */
489 if (size <= 0)
490 {
491 free(dyn_buf);
492 eet_close(ef);
493 return NULL;
494 }
495 /* invalid name_size */
496 if (name_size <= 0)
497 {
498 free(dyn_buf);
499 eet_close(ef);
500 return NULL;
501 }
502 /* reading name would mean falling off end of dyn_buf - invalid */
503 if ((p + 16 + name_size) > (dyn_buf + byte_entries))
504 {
505 free(dyn_buf);
506 eet_close(ef);
507 return NULL;
508 }
509 /* allocate name string */
510 name = malloc(name_size + 1);
511 if (!name)
512 {
513 free(dyn_buf);
514 eet_close(ef);
515 return NULL;
516 }
517 /* copy name in and terminate it */
518 strncpy(name, p + 20, name_size);
519 name[name_size] = 0;
520
521 /* get hask bucket it should go in */
522 hash = eet_hash_gen(name, ef->header->directory->size);
523 /* resize hask bucket */
524 node = realloc(ef->header->directory->hash[hash].node,
525 (ef->header->directory->hash[hash].size + 1) *
526 sizeof(Eet_File_Node));
527 if (!node)
528 {
529 free(dyn_buf);
530 eet_close(ef);
531 return NULL;
532 }
533 /* current node size */
534 node_size = ef->header->directory->hash[hash].size;
535 /* resized node list set up */
536 ef->header->directory->hash[hash].node = node;
537 /* new node at end */
538 ef->header->directory->hash[hash].node[node_size].name = name;
539 ef->header->directory->hash[hash].node[node_size].offset = offset;
540 ef->header->directory->hash[hash].node[node_size].compression = flags;
541 ef->header->directory->hash[hash].node[node_size].size = size;
542 ef->header->directory->hash[hash].node[node_size].data_size = data_size;
543 /* currently we have no data loaded */
544 ef->header->directory->hash[hash].node[node_size].data = NULL;
545 /* increment number of nodes */
546 ef->header->directory->hash[hash].size++;
547 /* advance */
548 p += 20 + name_size;
549 }
550 /* done - free dynamic buffer */
551 free(dyn_buf);
552 }
553 /* add to cache */
554 if (ef->mode == EET_FILE_MODE_READ)
555 eet_cache_add(ef, &eet_readers, &eet_readers_num);
556 else if (ef->mode == EET_FILE_MODE_WRITE)
557 eet_cache_add(ef, &eet_writers, &eet_writers_num);
558 return ef;
559}
560
561void
562eet_close(Eet_File *ef)
563{
564 /* check to see its' an eet file pointer */
565 if ((!ef) || (ef->magic != EET_MAGIC_FILE))
566 return;
567 /* deref */
568 ef->references--;
569 /* if its still referenced - dont go any further */
570 if (ef->references > 0) return;
571 /* remove from cache */
572 if (ef->mode == EET_FILE_MODE_READ)
573 eet_cache_del(ef, &eet_readers, &eet_readers_num);
574 else if (ef->mode == EET_FILE_MODE_WRITE)
575 eet_cache_del(ef, &eet_writers, &eet_writers_num);
576 /* flush any writes */
577 eet_flush(ef);
578
579 /* free up members */
580 if (ef->fp) fclose(ef->fp);
581 if (ef->path) free(ef->path);
582 if (ef->real_path) free(ef->real_path);
583
584 /* free up data */
585 if (ef->header)
586 {
587 if (ef->header->directory)
588 {
589 if (ef->header->directory->hash)
590 {
591 int i, num;
592
593 num = (1 << (ef->header->directory->size - 1));
594 for (i = 0; i < num; i++)
595 {
596 if (ef->header->directory->hash[i].node)
597 {
598 int j;
599 int num2;
600
601 num2 = ef->header->directory->hash[i].size;
602 for (j = 0; j < num2; j++)
603 {
604 if (ef->header->directory->hash[i].node[j].name)
605 free(ef->header->directory->hash[i].node[j].name);
606 if (ef->header->directory->hash[i].node[j].data)
607 free(ef->header->directory->hash[i].node[j].data);
608 }
609 free(ef->header->directory->hash[i].node);
610 }
611 }
612 free(ef->header->directory->hash);
613 }
614 free(ef->header->directory);
615 }
616 free(ef->header);
617 }
618
619 /* zero out ram for struct - caution tactic against stale memory use */
620 memset(ef, 0, sizeof(Eet_File));
621 /* free it */
622 free(ef);
623}
624
625void *
626eet_read(Eet_File *ef, char *name, int *size_ret)
627{
628 void *data = NULL;
629 int size = 0, tmp_size;
630 int hash, i, num;
631
632 /* check to see its' an eet file pointer */
633 if ((!ef) || (ef->magic != EET_MAGIC_FILE))
634 {
635 if (size_ret) *size_ret = 0;
636 return NULL;
637 }
638 /* get hash bucket this should be in */
639 hash = eet_hash_gen(name, ef->header->directory->size);
640 /* hunt hash bucket */
641 num = ef->header->directory->hash[hash].size;
642 for (i = 0; i < num; i++)
643 {
644 /* if it matches */
645 if (eet_string_match(ef->header->directory->hash[hash].node[i].name, name))
646 {
647 /* uncompressed data */
648 if (ef->header->directory->hash[hash].node[i].compression == 0)
649 {
650 /* get size */
651 size = ef->header->directory->hash[hash].node[i].size;
652 /* allocate data */
653 data = malloc(size);
654 if (data)
655 {
656 /* if we alreayd have the data in ram... copy that */
657 if (ef->header->directory->hash[hash].node[i].data)
658 memcpy(data,
659 ef->header->directory->hash[hash].node[i].data,
660 ef->header->directory->hash[hash].node[i].size);
661 /* or get data from disk */
662 else
663 {
664 /* seek to data location */
665 if (fseek(ef->fp, ef->header->directory->hash[hash].node[i].offset, SEEK_SET) < 0)
666 {
667 free(data);
668 data = NULL;
669 break;
670 }
671 /* read it */
672 if (fread(data, size, 1, ef->fp) != 1)
673 {
674 free(data);
675 data = NULL;
676 break;
677 }
678 }
679 }
680 break;
681 }
682 /* compressed data */
683 else
684 {
685 void *tmp_data;
686
687 /* get size of data in file */
688 tmp_size = ef->header->directory->hash[hash].node[i].size;
689 tmp_data = malloc(tmp_size);
690 if (!tmp_data) break;
691 /* get size uncompressed */
692 size = ef->header->directory->hash[hash].node[i].data_size;
693 /* allocate data */
694 data = malloc(size);
695 if (data)
696 {
697 uLongf dlen;
698
699 /* if we already have the data in ram... copy that */
700 if (ef->header->directory->hash[hash].node[i].data)
701 memcpy(tmp_data,
702 ef->header->directory->hash[hash].node[i].data,
703 tmp_size);
704 /* or get data from disk */
705 else
706 {
707 /* seek to data location */
708 if (fseek(ef->fp, ef->header->directory->hash[hash].node[i].offset, SEEK_SET) < 0)
709 {
710 free(tmp_data);
711 free(data);
712 data = NULL;
713 break;
714 }
715 /* read it */
716 if (fread(tmp_data, tmp_size, 1, ef->fp) != 1)
717 {
718 free(tmp_data);
719 free(data);
720 data = NULL;
721 break;
722 }
723 }
724 /* decompress it */
725 dlen = size;
726 if (uncompress((Bytef *)data, &dlen,
727 tmp_data, (uLongf)tmp_size))
728 {
729 free(tmp_data);
730 free(data);
731 data = NULL;
732 break;
733 }
734 }
735 free(tmp_data);
736 break;
737 }
738 }
739 }
740 /* fill in return values */
741 *size_ret = size;
742 /* update access time */
743 return data;
744}
745
746int
747eet_write(Eet_File *ef, char *name, void *data, int size, int compress)
748{
749 int data_size;
750 int hash, node_size;
751 Eet_File_Node *node;
752 char *name2;
753 void *data2;
754
755 /* check to see its' an eet file pointer */
756 if ((!ef) || (ef->magic != EET_MAGIC_FILE)
757 || (!name) || (!data) || (size <= 0) ||
758 (ef->mode != EET_FILE_MODE_WRITE))
759 return 0;