Browse Source

* first patch of Darius patch. Moving of demoes and dewinification still to do

git-svn-id: trunk@7870 -
marco 18 years ago
parent
commit
18118d54cc

+ 5 - 0
.gitattributes

@@ -1449,6 +1449,8 @@ packages/base/paszlib/Makefile svneol=native#text/plain
 packages/base/paszlib/Makefile.fpc svneol=native#text/plain
 packages/base/paszlib/adler.pas svneol=native#text/plain
 packages/base/paszlib/changes.txt svneol=native#text/plain
+packages/base/paszlib/demo/miniunz.pas svneol=native#text/plain
+packages/base/paszlib/demo/minizip.pas svneol=native#text/plain
 packages/base/paszlib/example.pas svneol=native#text/plain
 packages/base/paszlib/fpmake.inc svneol=native#text/plain
 packages/base/paszlib/fpmake.pp svneol=native#text/plain
@@ -1462,11 +1464,14 @@ packages/base/paszlib/minigzip.pas svneol=native#text/plain
 packages/base/paszlib/paszlib.pas svneol=native#text/plain
 packages/base/paszlib/readme.txt svneol=native#text/plain
 packages/base/paszlib/trees.pas svneol=native#text/plain
+packages/base/paszlib/unzip.pas svneol=native#text/plain
 packages/base/paszlib/zbase.pas svneol=native#text/plain
 packages/base/paszlib/zcompres.pas svneol=native#text/plain
 packages/base/paszlib/zconf.inc svneol=native#text/plain
 packages/base/paszlib/zdeflate.pas svneol=native#text/plain
 packages/base/paszlib/zinflate.pas svneol=native#text/plain
+packages/base/paszlib/zip.pas svneol=native#text/plain
+packages/base/paszlib/ziputils.pas svneol=native#text/plain
 packages/base/paszlib/zuncompr.pas svneol=native#text/plain
 packages/base/postgres/Makefile svneol=native#text/plain
 packages/base/postgres/Makefile.fpc svneol=native#text/plain

+ 107 - 106
packages/base/paszlib/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2007/03/04]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2007/06/20]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded
@@ -233,316 +233,316 @@ PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(F
 override PACKAGE_NAME=paszlib
 override PACKAGE_VERSION=2.0.0
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
+override TARGET_UNITS+=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
 endif
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_EXAMPLES+=example minigzip
+override TARGET_EXAMPLES+=demo
 endif
 override INSTALL_FPCPACKAGE=y
 ifdef REQUIRE_UNITSDIR
@@ -1567,7 +1567,7 @@ override FPCOPT+=-FD$(NEW_BINUTILS_PATH)
 endif
 ifndef CROSSBOOTSTRAP
 ifneq ($(BINUTILSPREFIX),)
-override FPCOPT+=-XP$(BINUTILSPREFIX) -Xc
+override FPCOPT+=-XP$(BINUTILSPREFIX) 
 endif
 ifneq ($(BINUTILSPREFIX),)
 override FPCOPT+=-Xr$(RLINKPATH)
@@ -1772,6 +1772,7 @@ vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
 vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
 vpath %.lpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
 vpath %.dpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.inc $(COMPILER_INCLUDEDIR)
 vpath %$(OEXT) $(COMPILER_UNITTARGETDIR)
 vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
 .PHONY: fpc_shared

+ 2 - 2
packages/base/paszlib/Makefile.fpc

@@ -10,8 +10,8 @@ version=2.0.0
 packages=hash
 
 [target]
-units=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr
-examples=example minigzip
+units=paszlib adler gzio infblock infcodes inffast inftrees infutil trees zcompres zdeflate zinflate zbase zuncompr zip ziputils unzip
+examples=demo
 
 [install]
 fpcpackage=y

+ 579 - 0
packages/base/paszlib/demo/miniunz.pas

@@ -0,0 +1,579 @@
+program MiniUnz;
+
+{ mini unzip demo package by Gilles Vollant
+
+  Usage : miniunz [-exvlo] file.zip [file_to_extract]
+
+  -l or -v list the content of the zipfile.
+        -e extract a specific file or all files if [file_to_extract] is missing
+        -x like -e, but extract without path information
+        -o overwrite an existing file without warning
+
+  Pascal tranlastion
+  Copyright (C) 2000 by Jacques Nomssi Nzali
+  For conditions of distribution and use, see copyright notice in readme.txt
+}{$ifdef WIN32}
+  {$define Delphi}
+  {$ifndef FPC}
+    {$define Delphi32}
+  {$endif}
+{$endif}
+
+uses {$ifdef Delphi}
+  SysUtils,
+  Windows,
+ {$else}
+   {$endif}
+  zutil,
+  //zlib,
+  ziputils,
+  unzip;
+
+const
+  CASESENSITIVITY = 0;
+  WRITEBUFFERSIZE = 8192;
+
+
+{ change_file_date : change the date/time of a file
+    filename : the filename of the file where date/time must be modified
+    dosdate : the new date at the MSDos format (4 bytes)
+    tmu_date : the SAME new date at the tm_unz format }
+
+  procedure change_file_date(const filename: PChar; dosdate: longword; tmu_date: tm_unz);
+{$ifdef Delphi32}
+  var
+    hFile: THandle;
+    ftm, ftLocal, ftCreate, ftLastAcc, ftLastWrite: TFileTime;
+  begin
+    hFile := CreateFile(filename, GENERIC_READ or GENERIC_WRITE,
+      0, nil, OPEN_EXISTING, 0, 0);
+    GetFileTime(hFile, @ftCreate, @ftLastAcc, @ftLastWrite);
+    DosDateTimeToFileTime(word((dosdate shl 16)), word(dosdate), ftLocal);
+    LocalFileTimeToFileTime(ftLocal, ftm);
+    SetFileTime(hFile, @ftm, @ftLastAcc, @ftm);
+    CloseHandle(hFile);
+  end;
+
+{$else}
+  {$ifdef FPC}
+var
+  hFile : THandle;
+  ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite : TFileTime;
+begin
+  hFile := CreateFile(filename,GENERIC_READ or GENERIC_WRITE,
+                      0,NIL,OPEN_EXISTING,0,0);
+  GetFileTime(hFile, @ftCreate, @ftLastAcc, @ftLastWrite);
+  DosDateTimeToFileTime(WORD((dosdate shl 16)), WORD(dosdate), @ftLocal);
+  LocalFileTimeToFileTime(ftLocal, @ftm);
+  SetFileTime(hFile,ftm, ftLastAcc, ftm);
+  CloseHandle(hFile);
+end;
+  {$else} {  msdos }
+var
+  f: file;
+begin
+  Assign(f, filename);
+  Reset(f, 1); { open file for reading }
+   { (Otherwise, close will update time) }
+  SetFTime(f,dosDate);
+  Close(f);
+end;
+  {$endif}
+{$endif}
+
+
+{ mymkdir and change_file_date are not 100 % portable
+  As I don't know well Unix, I wait feedback for the unix portion }
+
+  function mymkdir(dirname: PChar): boolean;
+  var
+    S: string;
+  begin
+    S := StrPas(dirname);
+  {$I-}
+    mkdir(S);
+    mymkdir := IOresult = 0;
+  end;
+
+  function makedir(newdir: PChar): boolean;
+  var
+    buffer: PChar;
+    p:      PChar;
+    len:    int;
+  var
+    hold:   char;
+  begin
+    makedir := False;
+    len     := strlen(newdir);
+
+    if (len <= 0) then
+      exit;
+
+    buffer := PChar(zcalloc(nil, len + 1, 1));
+
+    strcopy(buffer, newdir);
+
+    if (buffer[len - 1] = '/') then
+      buffer[len - 1] := #0;
+
+    if mymkdir(buffer) then
+    begin
+      if Assigned(buffer) then
+        zcfree(nil, buffer);
+      makedir := True;
+      exit;
+    end;
+
+    p := buffer + 1;
+    while True do
+    begin
+      while ((p^ <> #0) and (p^ <> '\') and (p^ <> '/')) do
+        Inc(p);
+      hold := p^;
+      p^   := #0;
+      if (not mymkdir(buffer)) {and (errno = ENOENT)} then
+      begin
+        WriteLn('couldn''t create directory ', buffer);
+        if Assigned(buffer) then
+          zcfree(nil, buffer);
+        exit;
+      end;
+      if (hold = #0) then
+        break;
+      p^ := hold;
+      Inc(p);
+    end;
+    if Assigned(buffer) then
+      zcfree(nil, buffer);
+    makedir := True;
+  end;
+
+  procedure do_banner;
+  begin
+    WriteLn('MiniUnz 0.15, demo package written by Gilles Vollant');
+    WriteLn('Pascal port by Jacques Nomssi Nzali');
+    WriteLn('more info at http://wwww.tu-chemnitz.de/~nomssi/paszlib.html');
+    WriteLn;
+  end;
+
+  procedure do_help;
+  begin
+    WriteLn('Usage : miniunz [-exvlo] file.zip [file_to_extract]');
+    WriteLn;
+  end;
+
+  function LeadingZero(w: word): string;
+  var
+    s: string;
+  begin
+    Str(w: 0, s);
+    if Length(s) = 1 then
+      s := '0' + s;
+    LeadingZero := s;
+  end;
+
+  function HexToStr(w: long): string;
+  const
+    ByteToChar: array[0..$F] of char = '0123456789ABCDEF';
+  var
+    s: string;
+    i: int;
+    x: long;
+  begin
+    s := '';
+    x := w;
+    for i := 0 to 3 do
+    begin
+      s := ByteToChar[byte(x) shr 4] + ByteToChar[byte(x) and $F] + s;
+      x := x shr 8;
+    end;
+    HexToStr := s;
+  end;
+
+  function do_list(uf: unzFile): int;
+  var
+    i:      longword;
+    gi:     unz_global_info;
+    err:    int;
+  var
+    filename_inzip: array[0..255] of char;
+    file_info: unz_file_info;
+    ratio:  longword;
+    string_method: string[255];
+  var
+    iLevel: uInt;
+  begin
+    err := unzGetGlobalInfo(uf, gi);
+    if (err <> UNZ_OK) then
+      WriteLn('error ', err, ' with zipfile in unzGetGlobalInfo');
+    WriteLn(' Length  Method   Size  Ratio   Date    Time   CRC-32     Name');
+    WriteLn(' ------  ------   ----  -----   ----    ----   ------     ----');
+    for i := 0 to gi.number_entry - 1 do
+    begin
+      ratio := 0;
+      err   := unzGetCurrentFileInfo(uf, @file_info, filename_inzip, sizeof(filename_inzip), nil, 0, nil, 0);
+      if (err <> UNZ_OK) then
+      begin
+        WriteLn('error ', err, ' with zipfile in unzGetCurrentFileInfo');
+        break;
+      end;
+      if (file_info.uncompressed_size > 0) then
+        ratio := (file_info.compressed_size * 100) div file_info.uncompressed_size;
+
+      if (file_info.compression_method = 0) then
+        string_method := 'Stored'
+      else
+      if (file_info.compression_method = Z_DEFLATED) then
+      begin
+        iLevel := uInt((file_info.flag and $06) div 2);
+        case iLevel of
+          0: string_method    := 'Defl:N';
+          1: string_method    := 'Defl:X';
+          2, 3: string_method := 'Defl:F'; { 2:fast , 3 : extra fast}
+          else
+            string_method := 'Unkn. ';
+        end;
+      end;
+
+      WriteLn(file_info.uncompressed_size: 7, '  ',
+        string_method: 6, ' ',
+        file_info.compressed_size: 7, ' ',
+        ratio: 3, '%  ', LeadingZero(longword(file_info.tmu_date.tm_mon) + 1), '-',
+        LeadingZero(longword(file_info.tmu_date.tm_mday)): 2, '-',
+        LeadingZero(longword(file_info.tmu_date.tm_year mod 100)): 2, '  ',
+        LeadingZero(longword(file_info.tmu_date.tm_hour)), ':',
+        LeadingZero(longword(file_info.tmu_date.tm_min)), '  ',
+        HexToStr(longword(file_info.crc)), '  ',
+        filename_inzip);
+
+      if ((i + 1) < gi.number_entry) then
+      begin
+        err := unzGoToNextFile(uf);
+        if (err <> UNZ_OK) then
+        begin
+          WriteLn('error ', err, ' with zipfile in unzGoToNextFile');
+          break;
+        end;
+      end;
+    end;
+
+    do_list := 0;
+  end;
+
+
+  function do_extract_currentfile(uf: unzFile; const popt_extract_without_path: int; var popt_overwrite: int): int;
+  var
+    filename_inzip: packed array[0..255] of char;
+    filename_withoutpath: PChar;
+    p:      PChar;
+    err:    int;
+    fout:   FILEptr;
+    buf:    pointer;
+    size_buf: uInt;
+    file_info: unz_file_info;
+  var
+    write_filename: PChar;
+    skip:   int;
+  var
+    rep:    char;
+    ftestexist: FILEptr;
+  var
+    answer: string[127];
+  var
+    c:      char;
+  begin
+    fout := nil;
+
+    err := unzGetCurrentFileInfo(uf, @file_info, filename_inzip,
+      sizeof(filename_inzip), nil, 0, nil, 0);
+
+    if (err <> UNZ_OK) then
+    begin
+      WriteLn('error ', err, ' with zipfile in unzGetCurrentFileInfo');
+      do_extract_currentfile := err;
+      exit;
+    end;
+
+    size_buf := WRITEBUFFERSIZE;
+    buf      := zcalloc(nil, size_buf, 1);
+    if (buf = nil) then
+    begin
+      WriteLn('Error allocating memory');
+      do_extract_currentfile := UNZ_INTERNALERROR;
+      exit;
+    end;
+
+    filename_withoutpath := filename_inzip;
+    p := filename_withoutpath;
+    while (p^ <> #0) do
+    begin
+      if (p^ = '/') or (p^ = '\') then
+        filename_withoutpath := p + 1;
+      Inc(p);
+    end;
+
+    if (filename_withoutpath^ = #0) then
+    begin
+      if (popt_extract_without_path = 0) then
+      begin
+        WriteLn('creating directory: ', filename_inzip);
+        mymkdir(filename_inzip);
+      end;
+    end
+    else
+    begin
+
+      skip := 0;
+      if (popt_extract_without_path = 0) then
+        write_filename := filename_inzip
+      else
+        write_filename := filename_withoutpath;
+
+      err := unzOpenCurrentFile(uf);
+      if (err <> UNZ_OK) then
+        WriteLn('error ', err, ' with zipfile in unzOpenCurrentFile');
+
+
+      if ((popt_overwrite = 0) and (err = UNZ_OK)) then
+      begin
+        rep := #0;
+
+        ftestexist := fopen(write_filename, fopenread);
+        if (ftestexist <> nil) then
+        begin
+          fclose(ftestexist);
+          repeat
+            Write('The file ', write_filename,
+              ' exist. Overwrite ? [y]es, [n]o, [A]ll: ');
+            ReadLn(answer);
+
+            rep := answer[1];
+            if ((rep >= 'a') and (rep <= 'z')) then
+              Dec(rep, $20);
+          until (rep = 'Y') or (rep = 'N') or (rep = 'A');
+        end;
+
+        if (rep = 'N') then
+          skip := 1;
+
+        if (rep = 'A') then
+          popt_overwrite := 1;
+      end;
+
+      if (skip = 0) and (err = UNZ_OK) then
+      begin
+        fout := fopen(write_filename, fopenwrite);
+
+        { some zipfile don't contain directory alone before file }
+        if (fout = nil) and (popt_extract_without_path = 0) and
+          (filename_withoutpath <> PChar(@filename_inzip)) then
+        begin
+          c := (filename_withoutpath - 1)^;
+          (filename_withoutpath -1)^ := #0;
+          makedir(write_filename);
+          (filename_withoutpath -1)^ := c;
+          fout := fopen(write_filename, fopenwrite);
+        end;
+
+        if (fout = nil) then
+          WriteLn('error opening ', write_filename);
+      end;
+
+      if (fout <> nil) then
+      begin
+        WriteLn(' extracting: ', write_filename);
+
+        repeat
+          err := unzReadCurrentFile(uf, buf, size_buf);
+          if (err < 0) then
+          begin
+            WriteLn('error ', err, ' with zipfile in unzReadCurrentFile');
+            break;
+          end;
+          if (err > 0) then
+            if (fwrite(buf, err, 1, fout) <> 1) then
+            begin
+              WriteLn('error in writing extracted file');
+              err := UNZ_ERRNO;
+              break;
+            end;
+        until (err = 0);
+        fclose(fout);
+        if (err = 0) then
+          change_file_date(write_filename, file_info.dosDate,
+            file_info.tmu_date);
+      end;
+
+      if (err = UNZ_OK) then
+      begin
+        err := unzCloseCurrentFile(uf);
+        if (err <> UNZ_OK) then
+          WriteLn('error ', err, ' with zipfile in unzCloseCurrentFile')
+        else
+          unzCloseCurrentFile(uf); { don't lose the error }
+      end;
+    end;
+
+    if buf <> nil then
+      zcfree(nil, buf);
+    do_extract_currentfile := err;
+  end;
+
+
+  function do_extract(uf: unzFile; opt_extract_without_path: int; opt_overwrite: int): int;
+  var
+    i:   longword;
+    gi:  unz_global_info;
+    err: int;
+  begin
+    err := unzGetGlobalInfo(uf, gi);
+    if (err <> UNZ_OK) then
+      WriteLn('error ', err, ' with zipfile in unzGetGlobalInfo ');
+
+    for i := 0 to gi.number_entry - 1 do
+    begin
+      if (do_extract_currentfile(uf, opt_extract_without_path,
+        opt_overwrite) <> UNZ_OK) then
+        break;
+
+      if ((i + 1) < gi.number_entry) then
+      begin
+        err := unzGoToNextFile(uf);
+        if (err <> UNZ_OK) then
+        begin
+          WriteLn('error ', err, ' with zipfile in unzGoToNextFile');
+          break;
+        end;
+      end;
+    end;
+
+    do_extract := 0;
+  end;
+
+  function do_extract_onefile(uf: unzFile; const filename: PChar; opt_extract_without_path: int; opt_overwrite: int): int;
+  begin
+    if (unzLocateFile(uf, filename, CASESENSITIVITY) <> UNZ_OK) then
+    begin
+      WriteLn('file ', filename, ' not found in the zipfile');
+      do_extract_onefile := 2;
+      exit;
+    end;
+
+    if (do_extract_currentfile(uf, opt_extract_without_path,
+      opt_overwrite) = UNZ_OK) then
+      do_extract_onefile := 0
+    else
+      do_extract_onefile := 1;
+  end;
+
+  { -------------------------------------------------------------------- }
+  function main: int;
+  const
+    zipfilename: PChar = nil;
+    filename_to_extract: PChar = nil;
+  var
+    i:    int;
+    opt_do_list: int;
+    opt_do_extract: int;
+    opt_do_extract_withoutpath: int;
+    opt_overwrite: int;
+    filename_try: array[0..512 - 1] of char;
+    uf:   unzFile;
+  var
+    p:    int;
+    pstr: string[255];
+    c:    char;
+  begin
+    opt_do_list := 0;
+    opt_do_extract := 1;
+    opt_do_extract_withoutpath := 0;
+    opt_overwrite := 0;
+    uf := nil;
+
+    do_banner;
+    if (ParamCount = 0) then
+    begin
+      do_help;
+      Halt(0);
+    end
+    else
+      for i := 1 to ParamCount do
+      begin
+        pstr := ParamStr(i);
+        if pstr[1] = '-' then
+          for p := 2 to Length(pstr) do
+          begin
+            c := pstr[p];
+            case UpCase(c) of
+              'L',
+              'V': opt_do_list    := 1;
+              'X': opt_do_extract := 1;
+              'E':
+              begin
+                opt_do_extract := 1;
+                opt_do_extract_withoutpath := 1;
+              end;
+              'O': opt_overwrite := 1;
+            end;
+          end
+        else
+        begin
+          pstr := pstr + #0;
+          if (zipfilename = nil) then
+            zipfilename := StrNew(PChar(@pstr[1]))
+          else
+          if (filename_to_extract = nil) then
+            filename_to_extract := StrNew(PChar(@pstr[1]));
+        end;
+      end{ for };
+
+    if (zipfilename <> nil) then
+    begin
+      strcopy(filename_try, zipfilename);
+      uf := unzOpen(zipfilename);
+      if (uf = nil) then
+      begin
+        strcat(filename_try, '.zip');
+        uf := unzOpen(filename_try);
+      end;
+    end;
+
+    if (uf = nil) then
+    begin
+      WriteLn('Cannot open ', zipfilename, ' or ', zipfilename, '.zip');
+      Halt(1);
+    end;
+
+    WriteLn(filename_try, ' opened');
+
+    if (opt_do_list = 1) then
+    begin
+      main := do_list(uf);
+      exit;
+    end
+    else
+    if (opt_do_extract = 1) then
+      if (filename_to_extract = nil) then
+      begin
+        main := do_extract(uf, opt_do_extract_withoutpath, opt_overwrite);
+        exit;
+      end
+      else
+      begin
+        main := do_extract_onefile(uf, filename_to_extract,
+          opt_do_extract_withoutpath, opt_overwrite);
+        exit;
+      end;
+
+    unzCloseCurrentFile(uf);
+
+    strDispose(zipfilename);
+    strDispose(filename_to_extract);
+    main := 0;
+  end;
+
+begin
+  main;
+  Write('Done...');
+  Readln;
+end.

+ 344 - 0
packages/base/paszlib/demo/minizip.pas

@@ -0,0 +1,344 @@
+program MiniZip;
+
+{ minizip demo package by Gilles Vollant
+
+  Usage : minizip [-o] file.zip [files_to_add]
+
+  a file.zip file is created, all files listed in [files_to_add] are added
+  to the new .zip file.
+  -o an existing .zip file with be overwritten without warning
+
+  Pascal tranlastion
+  Copyright (C) 2000 by Jacques Nomssi Nzali
+  For conditions of distribution and use, see copyright notice in readme.txt
+}{$ifdef WIN32}
+  {$define Delphi}
+  {$ifndef FPC}
+    {$define Delphi32}
+  {$endif}
+{$endif}
+
+uses {$ifdef Delphi}
+  SysUtils,
+//  Windows,
+ {$else}
+   {$endif}
+  //zutil,
+  //zlib,
+  ziputils,
+  zip;
+
+const
+  WRITEBUFFERSIZE = Z_BUFSIZE;
+  MAXFILENAME     = Z_MAXFILENAMEINZIP;
+
+{$ifdef Delphi32}
+  function filetime(f: PChar;               { name of file to get info on }
+  var tmzip: tm_zip; { return value: access, modific. and creation times }
+  var dt: uLong): uLong;                { dostime }
+  var
+    ret:     int;
+  var
+    ftLocal: TFileTime; // FILETIME;
+    hFind:   THandle;   // HANDLE;
+    ff32:    TWIN32FindData; //  WIN32_FIND_DATA;
+  begin
+    ret   := 0;
+    hFind := FindFirstFile(f, ff32);
+    if (hFind <> INVALID_HANDLE_VALUE) then
+    begin
+      FileTimeToLocalFileTime(ff32.ftLastWriteTime, ftLocal);
+      FileTimeToDosDateTime(ftLocal, LongRec(dt).hi, LongRec(dt).lo);
+      FindClose(hFind);
+      ret := 1;
+    end;
+    filetime := ret;
+  end;
+
+{$else}
+{$ifdef FPC}
+function filetime(f : PChar;               { name of file to get info on }
+   var tmzip : tm_zip; { return value: access, modific. and creation times }
+   var dt : uLong) : uLong;                { dostime }
+var
+  ret : longint;
+var
+  ftLocal : TFileTime; // FILETIME;
+  hFind : THandle; // HANDLE;
+  ff32 : TWIN32FindData; //  WIN32_FIND_DATA;
+begin
+  ret := 0;
+  hFind := FindFirstFile(f, @ff32);
+  if (hFind <> INVALID_HANDLE_VALUE) then
+  begin
+    FileTimeToLocalFileTime(ff32.ftLastWriteTime,ftLocal);
+    FileTimeToDosDateTime(ftLocal,LongRec(dt).hi,LongRec(dt).lo);
+    FindClose(hFind);
+    ret := 1;
+  end;
+  filetime := ret;
+end;
+{$else}
+function filetime(f : PChar;               { name of file to get info on }
+   var tmzip : tm_zip; { return value: access, modific. and creation times }
+   var dt : uLong) : uLong;                { dostime }
+var
+  fl : file;
+  yy, mm, dd, dow : Word;
+  h, m, s, hund : Word; { For GetTime}
+  dtrec : TDateTime; { For Pack/UnpackTime}
+begin
+  {$i-}
+  Assign(fl, f);
+  Reset(fl, 1);
+  if IOresult = 0 then
+  begin
+    GetFTime(fl,dt); { Get creation time }
+    UnpackTime(dt, dtrec);
+    Close(fl);
+    tmzip.tm_sec  := dtrec.sec;
+    tmzip.tm_min  := dtrec.min;
+    tmzip.tm_hour := dtrec.hour;
+    tmzip.tm_mday := dtrec.day;
+    tmzip.tm_mon  := dtrec.month;
+    tmzip.tm_year := dtrec.year;
+  end;
+
+  filetime := 0;
+end;
+{$endif}
+{$endif}
+
+  function check_exist_file(const filename: PChar): longint;
+  var
+    ftestexist: file;
+    ret: longint;
+  begin
+    ret := 1;
+    Assign(ftestexist, filename);
+  {$i-}
+    reset(ftestexist);
+    if IOresult <> 0 then
+      ret := 0
+    else
+      system.Close(ftestexist);
+    check_exist_file := ret;
+  end;
+
+  procedure do_banner;
+  begin
+    WriteLn('MiniZip 0.15, demo package written by Gilles Vollant');
+    WriteLn('Pascal port by Jacques Nomssi Nzali');
+    WriteLn('more info at http://www.tu-chemnitz.de/~nomssi/paszlib.html');
+    WriteLn;
+  end;
+
+  procedure do_help;
+  begin
+    WriteLn('Usage : minizip [-o] file.zip [files_to_add]');
+    WriteLn;
+  end;
+
+  function main: longint;
+  var
+    argstr: string;
+    i:      longint;
+    opt_overwrite: longint;
+    opt_compress_level: longint;
+    zipfilenamearg: longint;
+    filename_try: array[0..MAXFILENAME - 1] of char;
+    zipok:  longint;
+    err:    longint;
+    size_buf: longint;
+    buf:    pointer;
+  var
+    p:      PChar;
+    c:      char;
+  var
+    len:    longint;
+    dot_found: longint;
+  var
+    rep:    char;
+    answer: string[128];
+  var
+    zf:     zipFile;
+    errclose: longint;
+  var
+    fin:    FILEptr;
+    size_read: longint;
+    filenameinzip: {const} PChar;
+    zi:     zip_fileinfo;
+  begin
+    opt_overwrite := 0;
+    opt_compress_level := Z_DEFAULT_COMPRESSION;
+    zipfilenamearg := 0;
+    err  := 0;
+    main := 0;
+
+    do_banner;
+    if (ParamCount = 0) then
+    begin
+      do_help;
+      main := 0;
+      exit;
+    end
+    else
+      for i := 1 to ParamCount - 1 + 1 do
+      begin
+        argstr := ParamStr(i) + #0;
+        if (argstr[1] = '-') then
+        begin
+          p := @argstr[1 + 1];       {const char *p=argv[i]+1;}
+
+          while (p^ <> #0) do
+          begin
+            c := p^;
+            Inc(p);
+            if (c = 'o') or (c = 'O') then
+              opt_overwrite := 1;
+            if (c >= '0') and (c <= '9') then
+              opt_compress_level := byte(c) - byte('0');
+          end;
+        end
+        else
+        if (zipfilenamearg = 0) then
+          zipfilenamearg := i;
+      end;
+
+    size_buf := WRITEBUFFERSIZE;
+    buf      := AllocMem(size_buf);
+    if (buf = nil) then
+    begin
+      WriteLn('Error allocating memory');
+      main := ZIP_INTERNALERROR;
+      exit;
+    end;
+
+    if (zipfilenamearg = 0) then
+      zipok := 0
+    else
+    begin
+      dot_found := 0;
+
+      zipok  := 1;
+      argstr := ParamStr(zipfilenamearg) + #0;
+      strcopy(filename_try, PChar(@argstr[1]));
+      len := strlen(filename_try);
+      for i := 0 to len - 1 do
+        if (filename_try[i] = '.') then
+          dot_found := 1;
+
+      if (dot_found = 0) then
+        strcat(filename_try, '.zip');
+
+      if (opt_overwrite = 0) then
+        if (check_exist_file(filename_try) <> 0) then
+        begin
+          repeat
+            WriteLn('The file ', filename_try,
+              ' exist. Overwrite ? [y]es, [n]o : ');
+            ReadLn(answer);
+            rep := answer[1];
+            if (rep >= 'a') and (rep <= 'z') then
+              Dec(rep, $20);
+          until (rep = 'Y') or (rep = 'N');
+          if (rep = 'N') then
+            zipok := 0;
+        end;
+    end;
+
+    if (zipok = 1) then
+    begin
+      zf := zipOpen(filename_try, 0);
+      if (zf = nil) then
+      begin
+        WriteLn('error opening ', filename_try);
+        err := ZIP_ERRNO;
+      end
+      else
+        WriteLn('creating ', filename_try);
+
+      i := zipfilenamearg + 1;
+      while (i <= ParamCount) and (err = ZIP_OK) do
+      begin
+        argstr := ParamStr(i) + #0;
+        if (argstr[1] <> '-') and (argstr[1] <> '/') then
+        begin
+          filenameinzip := PChar(@argstr[1]);
+
+          zi.tmz_date.tm_sec := 0;
+          zi.tmz_date.tm_min := 0;
+          zi.tmz_date.tm_hour := 0;
+          zi.tmz_date.tm_mday := 0;
+          zi.tmz_date.tm_min := 0;
+          zi.tmz_date.tm_year := 0;
+          zi.dosDate     := 0;
+          zi.internal_fa := 0;
+          zi.external_fa := 0;
+          filetime(filenameinzip, zi.tmz_date, zi.dosDate);
+
+          if (opt_compress_level <> 0) then
+            err := zipOpenNewFileInZip(zf, filenameinzip, @zi,
+              nil, 0, nil, 0, nil { comment}, Z_DEFLATED, opt_compress_level)
+          else
+            err := zipOpenNewFileInZip(zf, filenameinzip, @zi,
+              nil, 0, nil, 0, nil, 0, opt_compress_level);
+
+          if (err <> ZIP_OK) then
+            WriteLn('error in opening ', filenameinzip, ' in zipfile')
+          else
+          begin
+            fin := fopen(filenameinzip, fopenread);
+            if (fin = nil) then
+            begin
+              err := ZIP_ERRNO;
+              WriteLn('error in opening ', filenameinzip, ' for reading');
+            end;
+
+            if (err = ZIP_OK) then
+              repeat
+                err := ZIP_OK;
+                size_read := fread(buf, 1, size_buf, fin);
+
+                if (size_read < size_buf) then
+                  if feof(fin) = 0 then
+                  begin
+                    WriteLn('error in reading ', filenameinzip);
+                    err := ZIP_ERRNO;
+                  end;
+
+                if (size_read > 0) then
+                begin
+                  err := zipWriteInFileInZip(zf, buf, size_read);
+                  if (err < 0) then
+                    WriteLn('error in writing ', filenameinzip, ' in the zipfile');
+                end;
+              until (err <> ZIP_OK) or (size_read = 0);
+
+            fclose(fin);
+          end;
+          if (err < 0) then
+            err := ZIP_ERRNO
+          else
+          begin
+            err := zipCloseFileInZip(zf);
+            if (err <> ZIP_OK) then
+              WriteLn('error in closing ', filenameinzip, ' in the zipfile');
+          end;
+          Inc(i);
+        end; { while }
+      end; { if }
+
+      errclose := zipClose(zf, nil);
+      if (errclose <> ZIP_OK) then
+        WriteLn('error in closing ', filename_try);
+    end;
+
+    FreeMem(buf); {FreeMem(buf, size_buf);}
+  end;
+
+begin
+  main;
+  Write('Done...');
+  ReadLn;
+end.

+ 1559 - 0
packages/base/paszlib/unzip.pas

@@ -0,0 +1,1559 @@
+unit Unzip;
+
+{ ----------------------------------------------------------------- }
+{ unzip.c -- IO on .zip files using zlib
+   Version 0.15 beta, Mar 19th, 1998,
+  unzip.h -- IO for uncompress .zip files using zlib
+  Version 0.15 beta, Mar 19th, 1998,
+
+  Copyright (C) 1998 Gilles Vollant <[email protected]>
+  http://www.winimage.com/zLibDll/zip.htm
+
+   This unzip package allow extract file from .ZIP file, compatible
+   with PKZip 2.04g, WinZip, InfoZip tools and compatible.
+   Encryption and multi volume ZipFile (span) are not supported.
+   Old compressions used by old PKZip 1.x are not supported
+
+  Pascal tranlastion
+  Copyright (C) 2000 by Jacques Nomssi Nzali
+  For conditions of distribution and use, see copyright notice in readme.txt }
+
+
+interface
+
+{$ifdef WIN32}
+  {$define Delphi}
+{$endif}
+
+uses
+  //zutil,
+  zbase,
+  //zLib,
+  ziputils;
+
+const
+  UNZ_OK    = (0);
+  UNZ_END_OF_LIST_OF_FILE = (-100);
+  UNZ_ERRNO = (Z_ERRNO);
+  UNZ_EOF   = (0);
+  UNZ_PARAMERROR = (-102);
+  UNZ_BADZIPFILE = (-103);
+  UNZ_INTERNALERROR = (-104);
+  UNZ_CRCERROR = (-105);
+(*
+{ tm_unz contain date/time info }
+type
+ tm_unz = record
+   tm_sec : integer;       { seconds after the minute - [0,59] }
+   tm_min : integer;       { minutes after the hour - [0,59] }
+   tm_hour : integer;      { hours since midnight - [0,23] }
+   tm_mday : integer;      { day of the month - [1,31] }
+   tm_mon : integer;       { months since January - [0,11] }
+   tm_year : integer;      { years - [1980..2044] }
+  end;
+*)
+{ unz_global_info structure contain global data about the ZIPfile
+  These data comes from the end of central dir }
+type
+  unz_global_info = record
+    number_entry: longint;   { total number of entries in
+                              the central dir on this disk }
+    size_comment: longint;   { size of the global comment of the zipfile }
+  end;
+
+
+{ unz_file_info contain information about a file in the zipfile }
+type
+  unz_file_info = record
+    version: longint;                  { version made by                 2 bytes }
+    version_needed: longint;           { version needed to extract       2 bytes }
+    flag:    longint;                  { general purpose bit flag        2 bytes }
+    compression_method: longint;       { compression method              2 bytes }
+    dosDate: longint;                  { last mod file date in Dos fmt   4 bytes }
+    crc:     longint;                  { crc-32                          4 bytes }
+    compressed_size: longint;          { compressed size                 4 bytes }
+    uncompressed_size: longint;        { uncompressed size               4 bytes }
+    size_filename: longint;            { filename length                 2 bytes }
+    size_file_extra: longint;          { extra field length              2 bytes }
+    size_file_comment: longint;        { file comment length             2 bytes }
+
+    disk_num_start: longint;          { disk number start               2 bytes }
+    internal_fa:    longint;          { internal file attributes        2 bytes }
+    external_fa:    longint;          { external file attributes        4 bytes }
+
+    tmu_date: tm_unz;
+  end;
+  unz_file_info_ptr = ^unz_file_info;
+
+
+function unzStringFileNameCompare(const fileName1: PChar; const fileName2: PChar; iCaseSensitivity: longint): longint;
+{ Compare two filename (fileName1,fileName2).
+  If iCaseSenisivity = 1 (1=true),
+    comparision is case sensitive (like strcmp)
+  If iCaseSenisivity = 2 (0=false),
+    comparision is not case sensitive (like strcmpi or strcasecmp)
+  If iCaseSenisivity = 0, case sensitivity is defaut of your
+    operating system like 1 on Unix, 2 on Windows)
+}
+
+
+function unzOpen(const path: PChar): unzFile;
+
+{ Open a Zip file. path contain the full pathname (by example,
+  on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
+  "zlib/zlib111.zip".
+  If the zipfile cannot be opened (file don't exist or in not valid), the
+  return value is NIL.
+  Else, the return value is a unzFile Handle, usable with other function
+     of this unzip package.
+}
+
+function unzClose(afile: unzFile): longint;
+
+{ Close a ZipFile opened with unzipOpen.
+  If there are files inside the .Zip opened with unzOpenCurrentFile()
+  (see later), these files MUST be closed with unzipCloseCurrentFile()
+  before a call unzipClose.
+  return UNZ_OK if there is no problem. }
+
+function unzGetGlobalInfo(afile: unzFile; var pglobal_info: unz_global_info): longint;
+
+{ Write info about the ZipFile in the *pglobal_info structure.
+  No preparation of the structure is needed
+  return UNZ_OK if there is no problem. }
+
+function unzGetGlobalComment(afile: unzFile; szComment: PChar; uSizeBuf: longint): longint;
+
+{ Get the global comment string of the ZipFile, in the szComment buffer.
+  uSizeBuf is the size of the szComment buffer.
+  return the number of byte copied or an error code <0 }
+
+ {***************************************************************************}
+ { Unzip package allow you browse the directory of the zipfile }
+
+function unzGoToFirstFile(afile: unzFile): longint;
+
+{ Set the current file of the zipfile to the first file.
+  return UNZ_OK if there is no problem }
+
+function unzGoToNextFile(afile: unzFile): longint;
+
+{ Set the current file of the zipfile to the next file.
+  return UNZ_OK if there is no problem
+  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. }
+
+
+function unzLocateFile(afile: unzFile; const szFileName: PChar; iCaseSensitivity: longint): longint; { ZEXPORT }
+
+{ Try locate the file szFileName in the zipfile.
+  For the iCaseSensitivity signification, see unzStringFileNameCompare
+
+  return value :
+  UNZ_OK if the file is found. It becomes the current file.
+  UNZ_END_OF_LIST_OF_FILE if the file is not found }
+
+
+function unzGetCurrentFileInfo(afile: unzFile; pfile_info: unz_file_info_ptr; szFileName: PChar; fileNameBufferSize: longint; extraField: pointer; extraFieldBufferSize: longint; szComment: PChar; commentBufferSize: longint): longint; { ZEXPORT }
+
+{ Get Info about the current file
+  if pfile_info<>NIL, the pfile_info^ structure will contain somes
+  info about the current file
+  if szFileName<>NIL, the filemane string will be copied in szFileName
+      (fileNameBufferSize is the size of the buffer)
+  if extraField<>NIL, the extra field information will be copied in
+    extraField  (extraFieldBufferSize is the size of the buffer).
+    This is the Central-header version of the extra field
+  if szComment<>NIL, the comment string of the file will be copied in
+    szComment (commentBufferSize is the size of the buffer) }
+
+
+{***************************************************************************}
+{* for reading the content of the current zipfile, you can open it, read data
+   from it, and close it (you can close it before reading all the file) }
+
+
+function unzOpenCurrentFile(afile: unzFile): longint; { ZEXPORT }
+
+{ Open for reading data the current file in the zipfile.
+  If there is no error, the return value is UNZ_OK. }
+
+
+function unzCloseCurrentFile(afile: unzFile): longint; { ZEXPORT }
+
+{ Close the file in zip opened with unzOpenCurrentFile
+  Return UNZ_CRCERROR if all the file was read but the CRC is not good }
+
+
+function unzReadCurrentFile(afile: unzFile; buf: pointer; len: cardinal): longint; { ZEXPORT }
+
+{ Read bytes from the current file (opened by unzOpenCurrentFile)
+  buf contain buffer where data must be copied
+  len the size of buf.
+
+  return the number of byte copied if somes bytes are copied
+  return 0 if the end of file was reached
+  return <0 with error code if there is an error
+    (UNZ_ERRNO for IO error, or zLib error for uncompress error) }
+
+function unztell(afile: unzFile): z_off_t;
+
+{ Give the current position in uncompressed data }
+
+function unzeof(afile: unzFile): longint;
+
+{ return 1 if the end of file was reached, 0 elsewhere
+  ! checks for valid params }
+
+function unzGetLocalExtrafield(afile: unzFile; buf: pointer; len: cardinal): longint;
+{ Read extra field from the current file (opened by unzOpenCurrentFile)
+  This is the local-header version of the extra field (sometimes, there is
+    more info in the local-header version than in the central-header)
+
+  if buf=NIL, it return the size of the local extra field
+
+  if buf<>NIL, len is the size of the buffer, the extra header is copied in
+  buf.
+  the return value is the number of bytes copied in buf, or (if <0)
+  the error code }
+
+
+{ ----------------------------------------------------------------- }
+
+implementation
+
+uses
+  {$ifdef Delphi}
+  SysUtils,
+  {$else}
+  strings,
+  {$endif}
+  zInflate, crc;
+
+{$ifdef unix and not def (CASESENSITIVITYDEFAULT_YES) and \
+                      !defined(CASESENSITIVITYDEFAULT_NO)}
+{$define CASESENSITIVITYDEFAULT_NO}
+{$endif}
+
+
+const
+  UNZ_BUFSIZE = Z_BUFSIZE;
+  UNZ_MAXFILENAMEINZIP = Z_MAXFILENAMEINZIP;
+
+const
+  unz_copyright: PChar = ' unzip 0.15 Copyright 1998 Gilles Vollant ';
+
+{ unz_file_info_internal contain internal info about a file in zipfile }
+type
+  unz_file_info_internal = record
+    offset_curfile: longint; { relative offset of local header 4 bytes }
+  end;
+  unz_file_info_internal_ptr = ^unz_file_info_internal;
+
+
+{ file_in_zip_read_info_s contain internal information about a file
+  in zipfile, when reading and decompress it }
+type
+  file_in_zip_read_info_s = record
+    read_buffer: PChar;       { internal buffer for compressed data }
+    stream:      z_stream;    { zLib stream structure for inflate }
+
+    pos_in_zipfile:     longint;       { position in byte on the zipfile, for fseek}
+    stream_initialised: boolean;     { flag set if stream structure is initialised}
+
+    offset_local_extrafield: longint;   { offset of the local extra field }
+    size_local_extrafield:   integer;    { size of the local extra field }
+    pos_local_extrafield:    longint;   { position in the local extra field in read}
+
+    crc32:      longint;                { crc32 of all data uncompressed }
+    crc32_wait: longint;                { crc32 we must obtain after decompress all }
+    rest_read_compressed: longint;      { number of byte to be decompressed }
+    rest_read_uncompressed: longint;    {number of byte to be obtained after decomp}
+    afile:      FILEptr;              { io structure of the zipfile }
+    compression_method: longint;        { compression method (0=store) }
+    byte_before_the_zipfile: longint;   { byte before the zipfile, (>0 for sfx) }
+  end;
+  file_in_zip_read_info_s_ptr = ^file_in_zip_read_info_s;
+
+
+{ unz_s contain internal information about the zipfile }
+type
+  unz_s = record
+    afile: FILEptr;                 { io structore of the zipfile }
+    gi:    unz_global_info;         { public global information }
+    byte_before_the_zipfile: longint; { byte before the zipfile, (>0 for sfx)}
+    num_file: longint;                { number of the current file in the zipfile}
+    pos_in_central_dir: longint;      { pos of the current file in the central dir}
+    current_file_ok: boolean;       { flag about the usability of the current file}
+    central_pos: longint;             { position of the beginning of the central dir}
+
+    size_central_dir:   longint;     { size of the central directory  }
+    offset_central_dir: longint;   { offset of start of central directory with
+                                   respect to the starting disk number }
+
+    cur_file_info:     unz_file_info; { public info about the current file in zip}
+    cur_file_info_internal: unz_file_info_internal; { private info about it}
+    pfile_in_zip_read: file_in_zip_read_info_s_ptr; { structure about the current
+                                      file if we are decompressing it }
+  end;
+  unz_s_ptr = ^unz_s;
+
+
+{ ===========================================================================
+  Read a byte from a gz_stream; update next_in and avail_in. Return EOF
+  for end of file.
+  IN assertion: the stream s has been sucessfully opened for reading. }
+
+
+function unzlocal_getByte(fin: FILEptr; var pi: longint): longint;
+var
+  c:   byte;
+  err: longint;
+begin
+  err := fread(@c, 1, 1, fin);
+
+  if (err = 1) then
+  begin
+    pi := longint(c);
+    unzlocal_getByte := UNZ_OK;
+    {exit;}
+  end
+  else
+  if feof(fin) = 1 then    {if ferror(fin) then}
+    unzlocal_getByte := UNZ_ERRNO
+  else
+    unzlocal_getByte := UNZ_EOF{exit;};
+end;
+
+
+{ ===========================================================================
+   Reads a long in LSB order from the given gz_stream. Sets }
+
+function unzlocal_getShort(fin: FILEptr; var pX: longint): longint;
+var
+  x:   longint;
+  i:   longint;
+  err: longint;
+begin
+  err := unzlocal_getByte(fin, i);
+  x   := longint(i);
+
+  if (err = UNZ_OK) then
+    err := unzlocal_getByte(fin, i);
+  Inc(x, longint(i) shl 8);
+
+  if (err = UNZ_OK) then
+    pX := x
+  else
+    pX := 0;
+  unzlocal_getShort := err;
+end;
+
+function unzlocal_getLong(fin: FILEptr; var pX: longint): longint;
+var
+  x:   longint;
+  i:   longint;
+  err: longint;
+begin
+  err := unzlocal_getByte(fin, i);
+  x   := longint(i);
+
+  if (err = UNZ_OK) then
+    err := unzlocal_getByte(fin, i);
+  Inc(x, longint(i) shl 8);
+
+  if (err = UNZ_OK) then
+    err := unzlocal_getByte(fin, i);
+  Inc(x, longint(i) shl 16);
+
+  if (err = UNZ_OK) then
+    err := unzlocal_getByte(fin, i);
+  Inc(x, longint(i) shl 24);
+
+  if (err = UNZ_OK) then
+    pX := x
+  else
+    pX := 0;
+  unzlocal_getLong := err;
+end;
+
+
+{ My own strcmpi / strcasecmp }
+function strcmpcasenosensitive_internal(fileName1: PChar; fileName2: PChar): longint;
+var
+  c1, c2: char;
+begin
+  repeat
+    c1 := fileName1^;
+    Inc(fileName1);
+    c2 := fileName2^;
+    Inc(fileName2);
+    if (c1 >= 'a') and (c1 <= 'z') then
+      Dec(c1, $20);
+    if (c2 >= 'a') and (c2 <= 'z') then
+      Dec(c2, $20);
+    if (c1 = #0) then
+    begin
+      if c2 = #0 then
+        strcmpcasenosensitive_internal := 0
+      else
+        strcmpcasenosensitive_internal := -1;
+      exit;
+    end;
+    if (c2 = #0) then
+    begin
+      strcmpcasenosensitive_internal := 1;
+      exit;
+    end;
+    if (c1 < c2) then
+    begin
+      strcmpcasenosensitive_internal := -1;
+      exit;
+    end;
+    if (c1 > c2) then
+    begin
+      strcmpcasenosensitive_internal := 1;
+      exit;
+    end;
+  until False;
+end;
+
+
+const
+  CASESENSITIVITYDEFAULTVALUE = 2;
+
+function unzStringFileNameCompare(const fileName1: PChar; const fileName2: PChar; iCaseSensitivity: longint): longint; { ZEXPORT }
+{ Compare two filename (fileName1,fileName2).
+  If iCaseSenisivity = 1 (1=true),
+    comparision is case sensitive (like strcmp)
+  If iCaseSenisivity = 2 (0=false),
+    comparision is not case sensitive (like strcmpi or strcasecmp)
+  If iCaseSenisivity = 0, case sensitivity is defaut of your
+    operating system like 1 on Unix, 2 on Windows)
+}
+begin
+  if (iCaseSensitivity = 0) then
+    iCaseSensitivity := CASESENSITIVITYDEFAULTVALUE;
+
+  if (iCaseSensitivity = 1) then
+  begin
+    unzStringFileNameCompare := strComp(fileName1, fileName2);
+    exit;
+  end;
+
+  unzStringFileNameCompare := strcmpcasenosensitive_internal(fileName1, fileName2);
+end;
+
+const
+  BUFREADCOMMENT = $400;
+
+{ Locate the Central directory of a zipfile (at the end, just before
+  the global comment) }
+
+function unzlocal_SearchCentralDir(fin: FILEptr): longint;
+var
+  buf: Pbytearray;
+  uSizeFile: longint;
+  uBackRead: longint;
+  uMaxBack: longint;
+  uPosFound: longint;
+var
+  uReadSize, uReadPos: longint;
+  i: longint;
+begin
+  uMaxBack  := $ffff; { maximum size of global comment }
+  uPosFound := 0;
+
+  if (fseek(fin, 0, SEEK_END) <> 0) then
+  begin
+    unzlocal_SearchCentralDir := 0;
+    exit;
+  end;
+
+  uSizeFile := ftell(fin);
+
+  if (uMaxBack > uSizeFile) then
+    uMaxBack := uSizeFile;
+
+  buf := Pbytearray(AllocMem(BUFREADCOMMENT + 4));
+  if (buf = nil) then
+  begin
+    unzlocal_SearchCentralDir := 0;
+    exit;
+  end;
+
+  uBackRead := 4;
+  while (uBackRead < uMaxBack) do
+  begin
+
+    if (uBackRead + BUFREADCOMMENT > uMaxBack) then
+      uBackRead := uMaxBack
+    else
+      Inc(uBackRead, BUFREADCOMMENT);
+    uReadPos := uSizeFile - uBackRead;
+
+    if ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) then
+      uReadSize := (BUFREADCOMMENT + 4)
+    else
+      uReadSize := (uSizeFile - uReadPos);
+
+    if fseek(fin, uReadPos, SEEK_SET) <> 0 then
+      break;
+
+    if fread(buf, integer(uReadSize), 1, fin) <> 1 then
+      break;
+
+    i := longint(uReadSize) - 3;
+    while (i > 0) do
+    begin
+      Dec(i);
+      if (buf^[i] = $50) and (buf^[i + 1] = $4b) and    { ENDHEADERMAGIC }
+        (buf^[i + 2] = $05) and (buf^[i + 3] = $06) then
+      begin
+        uPosFound := uReadPos + integer(i);
+        break;
+      end;
+    end;
+
+    if (uPosFound <> 0) then
+      break;
+  end;
+  FreeMem(buf);
+  unzlocal_SearchCentralDir := uPosFound;
+end;
+
+
+{ Open a Zip file. path contain the full pathname (by example,
+  on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
+  "zlib/zlib111.zip".
+  If the zipfile cannot be opened (file don't exist or in not valid), the
+  return value is NIL.
+  Else, the return value is a unzFile Handle, usable with other function
+     of this unzip package.
+}
+
+function unzOpen(const path: PChar): unzFile; { ZEXPORT }
+var
+  us:  unz_s;
+  s:   unz_s_ptr;
+  central_pos, uL: longint;
+  fin: FILEptr;
+
+  number_disk:     longint; { number of the current dist, used for spaning ZIP,
+                         unsupported, always 0 }
+  number_disk_with_CD: longint; { number the the disk with central dir,
+                        used for spaning ZIP, unsupported, always 0 }
+  number_entry_CD: longint; { total number of entries in the central dir
+                                 (same than number_entry on nospan) }
+
+  err: longint;
+begin
+  err := UNZ_OK;
+
+  if (unz_copyright[0] <> ' ') then
+  begin
+    unzOpen := nil;
+    exit;
+  end;
+
+  fin := fopen(path, fopenread);
+  if (fin = nil) then
+  begin
+    unzOpen := nil;
+    exit;
+  end;
+
+  central_pos := unzlocal_SearchCentralDir(fin);
+  if (central_pos = 0) then
+    err := UNZ_ERRNO;
+
+  if (fseek(fin, central_pos, SEEK_SET) <> 0) then
+    err := UNZ_ERRNO;
+
+  { the signature, already checked }
+  if (unzlocal_getLong(fin, uL) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  { number of this disk }
+  if (unzlocal_getShort(fin, number_disk) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  { number of the disk with the start of the central directory }
+  if (unzlocal_getShort(fin, number_disk_with_CD) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  { total number of entries in the central dir on this disk }
+  if (unzlocal_getShort(fin, us.gi.number_entry) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  { total number of entries in the central dir }
+  if (unzlocal_getShort(fin, number_entry_CD) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if ((number_entry_CD <> us.gi.number_entry) or
+    (number_disk_with_CD <> 0) or
+    (number_disk <> 0)) then
+    err := UNZ_BADZIPFILE;
+
+  { size of the central directory }
+  if (unzlocal_getLong(fin, us.size_central_dir) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  { offset of start of central directory with respect to the
+        starting disk number }
+  if (unzlocal_getLong(fin, us.offset_central_dir) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  { zipfile comment length }
+  if (unzlocal_getShort(fin, us.gi.size_comment) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if ((central_pos < us.offset_central_dir + us.size_central_dir) and
+    (err = UNZ_OK)) then
+    err := UNZ_BADZIPFILE;
+
+  if (err <> UNZ_OK) then
+  begin
+    fclose(fin);
+    unzOpen := nil;
+    exit;
+  end;
+
+  us.afile := fin;
+  us.byte_before_the_zipfile := central_pos -
+    (us.offset_central_dir + us.size_central_dir);
+  us.central_pos := central_pos;
+  us.pfile_in_zip_read := nil;
+
+  s  := unz_s_ptr(AllocMem(sizeof(unz_s)));
+  s^ := us;
+  unzGoToFirstFile(unzFile(s));
+  unzOpen := unzFile(s);
+end;
+
+
+{ Close a ZipFile opened with unzipOpen.
+  If there are files inside the .Zip opened with unzOpenCurrentFile()
+  (see later), these files MUST be closed with unzipCloseCurrentFile()
+  before a call unzipClose.
+  return UNZ_OK if there is no problem. }
+
+function unzClose(afile: unzFile): longint; { ZEXPORT }
+var
+  s: unz_s_ptr;
+begin
+  if (afile = nil) then
+  begin
+    unzClose := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+
+  if (s^.pfile_in_zip_read <> nil) then
+    unzCloseCurrentFile(afile);
+
+  fclose(s^.afile);
+  FreeMem(s);
+  unzClose := UNZ_OK;
+end;
+
+{ Write info about the ZipFile in the pglobal_info structure.
+  No preparation of the structure is needed
+  return UNZ_OK if there is no problem. }
+
+function unzGetGlobalInfo(afile: unzFile; var pglobal_info: unz_global_info): longint; { ZEXPORT }
+var
+  s: unz_s_ptr;
+begin
+  if (afile = nil) then
+  begin
+    unzGetGlobalInfo := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+  pglobal_info := s^.gi;
+  unzGetGlobalInfo := UNZ_OK;
+end;
+
+
+{ Translate date/time from Dos format to tm_unz (more easily readable) }
+procedure unzlocal_DosDateToTmuDate(ulDosDate: longint; var ptm: tm_unz);
+var
+  uDate: longint;
+begin
+  uDate      := longint(ulDosDate shr 16);
+  ptm.tm_mday := integer(uDate and $1f);
+  ptm.tm_mon := integer((((uDate) and $1E0) div $20) - 1);
+  ptm.tm_year := integer(((uDate and $0FE00) div $0200) + 1980);
+
+  ptm.tm_hour := integer((ulDosDate and $F800) div $800);
+  ptm.tm_min  := integer((ulDosDate and $7E0) div $20);
+  ptm.tm_sec  := integer(2 * (ulDosDate and $1f));
+end;
+
+{ Get Info about the current file in the zipfile, with internal only info }
+function unzlocal_GetCurrentFileInfoInternal(afile: unzFile; pfile_info: unz_file_info_ptr; pfile_info_internal: unz_file_info_internal_ptr; szFileName: PChar; fileNameBufferSize: longint; extraField: pointer; extraFieldBufferSize: longint; szComment: PChar; commentBufferSize: longint): longint;
+var
+  s:      unz_s_ptr;
+  file_info: unz_file_info;
+  file_info_internal: unz_file_info_internal;
+  err:    longint;
+  uMagic: longint;
+  lSeek:  longint;
+var
+  uSizeRead: longint;
+begin
+  err   := UNZ_OK;
+  lSeek := 0;
+  if (afile = nil) then
+  begin
+    unzlocal_GetCurrentFileInfoInternal := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+
+  if (fseek(s^.afile,
+    s^.pos_in_central_dir + s^.byte_before_the_zipfile, SEEK_SET) <> 0) then
+    err := UNZ_ERRNO;
+
+  { we check the magic }
+  if (err = UNZ_OK) then
+    if (unzlocal_getLong(s^.afile, uMagic) <> UNZ_OK) then
+      err := UNZ_ERRNO
+    else
+    if (uMagic <> CENTRALHEADERMAGIC) then
+      err := UNZ_BADZIPFILE;
+
+  if (unzlocal_getShort(s^.afile, file_info.version) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.version_needed) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.flag) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.compression_method) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getLong(s^.afile, file_info.dosDate) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  unzlocal_DosDateToTmuDate(file_info.dosDate, file_info.tmu_date);
+
+  if (unzlocal_getLong(s^.afile, file_info.crc) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getLong(s^.afile, file_info.compressed_size) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getLong(s^.afile, file_info.uncompressed_size) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.size_filename) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.size_file_extra) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.size_file_comment) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.disk_num_start) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, file_info.internal_fa) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getLong(s^.afile, file_info.external_fa) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getLong(s^.afile, file_info_internal.offset_curfile) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  Inc(lSeek, file_info.size_filename);
+  if ((err = UNZ_OK) and (szFileName <> nil)) then
+  begin
+    if (file_info.size_filename < fileNameBufferSize) then
+    begin
+      (szFileName +file_info.size_filename)^ := #0;
+      uSizeRead := file_info.size_filename;
+    end
+    else
+      uSizeRead := fileNameBufferSize;
+
+    if (file_info.size_filename > 0) and (fileNameBufferSize > 0) then
+      if fread(szFileName, integer(uSizeRead), 1, s^.afile) <> 1 then
+        err := UNZ_ERRNO;
+    Dec(lSeek, uSizeRead);
+  end;
+
+  if ((err = UNZ_OK) and (extraField <> nil)) then
+  begin
+    if (file_info.size_file_extra < extraFieldBufferSize) then
+      uSizeRead := file_info.size_file_extra
+    else
+      uSizeRead := extraFieldBufferSize;
+
+    if (lSeek <> 0) then
+      if (fseek(s^.afile, lSeek, SEEK_CUR) = 0) then
+        lSeek := 0
+      else
+        err   := UNZ_ERRNO;
+
+    if ((file_info.size_file_extra > 0) and (extraFieldBufferSize > 0)) then
+      if fread(extraField, integer(uSizeRead), 1, s^.afile) <> 1 then
+        err := UNZ_ERRNO;
+    Inc(lSeek, file_info.size_file_extra - uSizeRead);
+  end
+  else
+    Inc(lSeek, file_info.size_file_extra);
+
+  if ((err = UNZ_OK) and (szComment <> nil)) then
+  begin
+    if (file_info.size_file_comment < commentBufferSize) then
+    begin
+      (szComment +file_info.size_file_comment)^ := #0;
+      uSizeRead := file_info.size_file_comment;
+    end
+    else
+      uSizeRead := commentBufferSize;
+
+    if (lSeek <> 0) then
+      if (fseek(s^.afile, lSeek, SEEK_CUR) = 0) then
+        lSeek := 0
+      else
+        err   := UNZ_ERRNO;
+    if ((file_info.size_file_comment > 0) and (commentBufferSize > 0)) then
+      if fread(szComment, integer(uSizeRead), 1, s^.afile) <> 1 then
+        err := UNZ_ERRNO;
+    Inc(lSeek, file_info.size_file_comment - uSizeRead);
+  end
+  else
+    Inc(lSeek, file_info.size_file_comment);
+
+  if ((err = UNZ_OK) and (pfile_info <> nil)) then
+    pfile_info^ := file_info;
+
+  if ((err = UNZ_OK) and (pfile_info_internal <> nil)) then
+    pfile_info_internal^ := file_info_internal;
+
+  unzlocal_GetCurrentFileInfoInternal := err;
+end;
+
+
+{ Write info about the ZipFile in the *pglobal_info structure.
+  No preparation of the structure is needed
+  return UNZ_OK if there is no problem. }
+
+function unzGetCurrentFileInfo(afile: unzFile; pfile_info: unz_file_info_ptr; szFileName: PChar; fileNameBufferSize: longint; extraField: pointer; extraFieldBufferSize: longint; szComment: PChar; commentBufferSize: longint): longint; { ZEXPORT }
+
+{ Get Info about the current file
+  if pfile_info<>NIL, the pfile_info^ structure will contain somes
+  info about the current file
+  if szFileName<>NIL, the filemane string will be copied in szFileName
+      (fileNameBufferSize is the size of the buffer)
+  if extraField<>NIL, the extra field information will be copied in
+    extraField  (extraFieldBufferSize is the size of the buffer).
+    This is the Central-header version of the extra field
+  if szComment<>NIL, the comment string of the file will be copied in
+    szComment (commentBufferSize is the size of the buffer) }
+
+begin
+  unzGetCurrentFileInfo := unzlocal_GetCurrentFileInfoInternal(afile,
+    pfile_info, nil, szFileName, fileNameBufferSize, extraField,
+    extraFieldBufferSize, szComment, commentBufferSize);
+end;
+
+
+{ Set the current file of the zipfile to the first file.
+  return UNZ_OK if there is no problem }
+
+function unzGoToFirstFile(afile: unzFile): longint;  { ZEXPORT }
+var
+  err: longint;
+  s:   unz_s_ptr;
+begin
+  if (afile = nil) then
+  begin
+    unzGoToFirstFile := UNZ_PARAMERROR;
+    exit;
+  end;
+  s   := unz_s_ptr(afile);
+  s^.pos_in_central_dir := s^.offset_central_dir;
+  s^.num_file := 0;
+  err := unzlocal_GetCurrentFileInfoInternal(afile, @s^.cur_file_info, @s^.cur_file_info_internal, nil, 0, nil, 0, nil, 0);
+  s^.current_file_ok := (err = UNZ_OK);
+  unzGoToFirstFile := err;
+end;
+
+
+{ Set the current file of the zipfile to the next file.
+  return UNZ_OK if there is no problem
+  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. }
+
+function unzGoToNextFile(afile: unzFile): longint; { ZEXPORT }
+var
+  s:   unz_s_ptr;
+  err: longint;
+begin
+  if (afile = nil) then
+  begin
+    unzGoToNextFile := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+  if not s^.current_file_ok then
+  begin
+    unzGoToNextFile := UNZ_END_OF_LIST_OF_FILE;
+    exit;
+  end;
+  if (s^.num_file + 1 = s^.gi.number_entry) then
+  begin
+    unzGoToNextFile := UNZ_END_OF_LIST_OF_FILE;
+    exit;
+  end;
+
+  Inc(s^.pos_in_central_dir,
+    SIZECENTRALDIRITEM + s^.cur_file_info.size_filename +
+    s^.cur_file_info.size_file_extra + s^.cur_file_info.size_file_comment);
+  Inc(s^.num_file);
+  err := unzlocal_GetCurrentFileInfoInternal(afile, @s^.cur_file_info, @s^.cur_file_info_internal, nil, 0, nil, 0, nil, 0);
+  s^.current_file_ok := (err = UNZ_OK);
+  unzGoToNextFile := err;
+end;
+
+
+{ Try locate the file szFileName in the zipfile.
+  For the iCaseSensitivity signification, see unzStringFileNameCompare
+
+  return value :
+  UNZ_OK if the file is found. It becomes the current file.
+  UNZ_END_OF_LIST_OF_FILE if the file is not found }
+
+function unzLocateFile(afile: unzFile; const szFileName: PChar; iCaseSensitivity: longint): longint; { ZEXPORT }
+var
+  s:   unz_s_ptr;
+  err: longint;
+  num_fileSaved: longint;
+  pos_in_central_dirSaved: longint;
+var
+  szCurrentFileName: array[0..UNZ_MAXFILENAMEINZIP + 1 - 1] of char;
+begin
+  if (afile = nil) then
+  begin
+    unzLocateFile := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  if (strlen(szFileName) >= UNZ_MAXFILENAMEINZIP) then
+  begin
+    unzLocateFile := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  s := unz_s_ptr(afile);
+  if (not s^.current_file_ok) then
+  begin
+    unzLocateFile := UNZ_END_OF_LIST_OF_FILE;
+    exit;
+  end;
+  num_fileSaved := s^.num_file;
+  pos_in_central_dirSaved := s^.pos_in_central_dir;
+
+  err := unzGoToFirstFile(afile);
+
+  while (err = UNZ_OK) do
+  begin
+    unzGetCurrentFileInfo(afile, nil,
+      szCurrentFileName, sizeof(szCurrentFileName) - 1, nil, 0, nil, 0);
+    if (unzStringFileNameCompare(szCurrentFileName,
+      szFileName, iCaseSensitivity) = 0) then
+    begin
+      unzLocateFile := UNZ_OK;
+      exit;
+    end;
+    err := unzGoToNextFile(afile);
+  end;
+
+  s^.num_file   := num_fileSaved;
+  s^.pos_in_central_dir := pos_in_central_dirSaved;
+  unzLocateFile := err;
+end;
+
+
+{ Read the local header of the current zipfile
+  Check the coherency of the local header and info in the end of central
+        directory about this file
+  store in *piSizeVar the size of extra info in local header
+        (filename and size of extra field data) }
+
+function unzlocal_CheckCurrentFileCoherencyHeader(s: unz_s_ptr; var piSizeVar: integer; var poffset_local_extrafield: longint; var psize_local_extrafield: integer): longint;
+var
+  uMagic, uData, uFlags: longint;
+  size_filename: longint;
+  size_extra_field: longint;
+  err: longint;
+begin
+  err := UNZ_OK;
+
+  piSizeVar := 0;
+  poffset_local_extrafield := 0;
+  psize_local_extrafield := 0;
+
+  if (fseek(s^.afile, s^.cur_file_info_internal.offset_curfile +
+    s^.byte_before_the_zipfile, SEEK_SET) <> 0) then
+  begin
+    unzlocal_CheckCurrentFileCoherencyHeader := UNZ_ERRNO;
+    exit;
+  end;
+
+  if (err = UNZ_OK) then
+    if (unzlocal_getLong(s^.afile, uMagic) <> UNZ_OK) then
+      err := UNZ_ERRNO
+    else
+    if (uMagic <> $04034b50) then
+      err := UNZ_BADZIPFILE;
+
+  if (unzlocal_getShort(s^.afile, uData) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+{
+  else
+    if ((err=UNZ_OK) and (uData<>s^.cur_file_info.wVersion)) then
+      err := UNZ_BADZIPFILE;
+}
+  if (unzlocal_getShort(s^.afile, uFlags) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getShort(s^.afile, uData) <> UNZ_OK) then
+    err := UNZ_ERRNO
+  else
+  if ((err = UNZ_OK) and (uData <> s^.cur_file_info.compression_method)) then
+    err := UNZ_BADZIPFILE;
+
+  if ((err = UNZ_OK) and (s^.cur_file_info.compression_method <> 0) and
+    (s^.cur_file_info.compression_method <> Z_DEFLATED)) then
+    err := UNZ_BADZIPFILE;
+
+  if (unzlocal_getLong(s^.afile, uData) <> UNZ_OK) then { date/time }
+    err := UNZ_ERRNO;
+
+  if (unzlocal_getLong(s^.afile, uData) <> UNZ_OK) then { crc }
+    err := UNZ_ERRNO
+  else
+  if ((err = UNZ_OK) and (uData <> s^.cur_file_info.crc) and
+    ((uFlags and 8) = 0)) then
+    err := UNZ_BADZIPFILE;
+
+  if (unzlocal_getLong(s^.afile, uData) <> UNZ_OK) then { size compr }
+    err := UNZ_ERRNO
+  else
+  if ((err = UNZ_OK) and (uData <> s^.cur_file_info.compressed_size) and
+    ((uFlags and 8) = 0)) then
+    err := UNZ_BADZIPFILE;
+
+  if (unzlocal_getLong(s^.afile, uData) <> UNZ_OK) then { size uncompr }
+    err := UNZ_ERRNO
+  else
+  if ((err = UNZ_OK) and (uData <> s^.cur_file_info.uncompressed_size) and
+    ((uFlags and 8) = 0)) then
+    err := UNZ_BADZIPFILE;
+
+
+  if (unzlocal_getShort(s^.afile, size_filename) <> UNZ_OK) then
+    err := UNZ_ERRNO
+  else
+  if ((err = UNZ_OK) and (size_filename <> s^.cur_file_info.size_filename)) then
+    err := UNZ_BADZIPFILE;
+
+  Inc(piSizeVar, integer(size_filename));
+
+  if (unzlocal_getShort(s^.afile, size_extra_field) <> UNZ_OK) then
+    err := UNZ_ERRNO;
+  poffset_local_extrafield := s^.cur_file_info_internal.offset_curfile +
+    SIZEZIPLOCALHEADER + size_filename;
+  psize_local_extrafield := integer(size_extra_field);
+
+  Inc(piSizeVar, integer(size_extra_field));
+
+  unzlocal_CheckCurrentFileCoherencyHeader := err;
+end;
+
+{ Open for reading data the current file in the zipfile.
+  If there is no error, the return value is UNZ_OK. }
+
+function unzOpenCurrentFile(afile: unzFile): longint; { ZEXPORT }
+var
+  err: longint;
+  Store: boolean;
+  iSizeVar: integer;
+  s: unz_s_ptr;
+  pfile_in_zip_read_info: file_in_zip_read_info_s_ptr;
+  offset_local_extrafield: longint;  { offset of the local extra field }
+  size_local_extrafield: integer;     { size of the local extra field }
+begin
+  err := UNZ_OK;
+
+  if (afile = nil) then
+  begin
+    unzOpenCurrentFile := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+  if not s^.current_file_ok then
+  begin
+    unzOpenCurrentFile := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  if (s^.pfile_in_zip_read <> nil) then
+    unzCloseCurrentFile(afile);
+
+  if (unzlocal_CheckCurrentFileCoherencyHeader(s, iSizeVar,
+    offset_local_extrafield, size_local_extrafield) <> UNZ_OK) then
+  begin
+    unzOpenCurrentFile := UNZ_BADZIPFILE;
+    exit;
+  end;
+
+  pfile_in_zip_read_info := file_in_zip_read_info_s_ptr(
+    AllocMem(sizeof(file_in_zip_read_info_s)));
+  if (pfile_in_zip_read_info = nil) then
+  begin
+    unzOpenCurrentFile := UNZ_INTERNALERROR;
+    exit;
+  end;
+
+  pfile_in_zip_read_info^.read_buffer := PChar(AllocMem(UNZ_BUFSIZE));
+  pfile_in_zip_read_info^.offset_local_extrafield := offset_local_extrafield;
+  pfile_in_zip_read_info^.size_local_extrafield := size_local_extrafield;
+  pfile_in_zip_read_info^.pos_local_extrafield := 0;
+
+  if (pfile_in_zip_read_info^.read_buffer = nil) then
+  begin
+    FreeMem(pfile_in_zip_read_info);
+    unzOpenCurrentFile := UNZ_INTERNALERROR;
+    exit;
+  end;
+
+  pfile_in_zip_read_info^.stream_initialised := False;
+
+  if ((s^.cur_file_info.compression_method <> 0) and
+    (s^.cur_file_info.compression_method <> Z_DEFLATED)) then
+    err := UNZ_BADZIPFILE;
+  Store := s^.cur_file_info.compression_method = 0;
+
+  pfile_in_zip_read_info^.crc32_wait := s^.cur_file_info.crc;
+  pfile_in_zip_read_info^.crc32      := 0;
+  pfile_in_zip_read_info^.compression_method := s^.cur_file_info.compression_method;
+  pfile_in_zip_read_info^.afile      := s^.afile;
+  pfile_in_zip_read_info^.byte_before_the_zipfile := s^.byte_before_the_zipfile;
+
+  pfile_in_zip_read_info^.stream.total_out := 0;
+
+  if (not Store) then
+  begin
+    err := inflateInit2(pfile_in_zip_read_info^.stream, -MAX_WBITS);
+
+    if (err = Z_OK) then
+      pfile_in_zip_read_info^.stream_initialised := True;
+        { windowBits is passed < 0 to tell that there is no zlib header.
+          Note that in this case inflate *requires* an extra "dummy" byte
+          after the compressed stream in order to complete decompression and
+          return Z_STREAM_END.
+          In unzip, i don't wait absolutely Z_STREAM_END because I known the
+          size of both compressed and uncompressed data }
+  end;
+  pfile_in_zip_read_info^.rest_read_compressed   := s^.cur_file_info.compressed_size;
+  pfile_in_zip_read_info^.rest_read_uncompressed := s^.cur_file_info.uncompressed_size;
+
+
+  pfile_in_zip_read_info^.pos_in_zipfile :=
+    s^.cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + iSizeVar;
+
+  pfile_in_zip_read_info^.stream.avail_in := integer(0);
+
+
+  s^.pfile_in_zip_read := pfile_in_zip_read_info;
+  unzOpenCurrentFile   := UNZ_OK;
+end;
+
+
+{ Read bytes from the current file (opened by unzOpenCurrentFile)
+  buf contain buffer where data must be copied
+  len the size of buf.
+
+  return the number of byte copied if somes bytes are copied
+  return 0 if the end of file was reached
+  return <0 with error code if there is an error
+    (UNZ_ERRNO for IO error, or zLib error for uncompress error) }
+
+function unzReadCurrentFile(afile: unzFile; buf: pointer; len: cardinal): longint; { ZEXPORT }
+
+var
+  err:   longint;
+  iRead: integer;
+  s:     unz_s_ptr;
+  pfile_in_zip_read_info: file_in_zip_read_info_s_ptr;
+var
+  uReadThis: integer;
+var
+  uDoCopy, i: integer;
+var
+  uTotalOutBefore, uTotalOutAfter: longint;
+  bufBefore: pbyte;
+  uOutThis: longint;
+  flush: longint;
+begin
+  err   := UNZ_OK;
+  iRead := 0;
+  if (afile = nil) then
+  begin
+    unzReadCurrentFile := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+  pfile_in_zip_read_info := s^.pfile_in_zip_read;
+
+  if (pfile_in_zip_read_info = nil) then
+  begin
+    unzReadCurrentFile := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  if ((pfile_in_zip_read_info^.read_buffer = nil)) then
+  begin
+    unzReadCurrentFile := UNZ_END_OF_LIST_OF_FILE;
+    exit;
+  end;
+
+  if (len = 0) then
+  begin
+    unzReadCurrentFile := 0;
+    exit;
+  end;
+
+  pfile_in_zip_read_info^.stream.next_out := pbyte(buf);
+
+  pfile_in_zip_read_info^.stream.avail_out := integer(len);
+
+  if (len > pfile_in_zip_read_info^.rest_read_uncompressed) then
+    pfile_in_zip_read_info^.stream.avail_out :=
+      integer(pfile_in_zip_read_info^.rest_read_uncompressed);
+
+  while (pfile_in_zip_read_info^.stream.avail_out > 0) do
+  begin
+    if ((pfile_in_zip_read_info^.stream.avail_in = 0) and
+      (pfile_in_zip_read_info^.rest_read_compressed > 0)) then
+    begin
+      uReadThis := UNZ_BUFSIZE;
+      if (pfile_in_zip_read_info^.rest_read_compressed < uReadThis) then
+        uReadThis := integer(pfile_in_zip_read_info^.rest_read_compressed);
+      if (uReadThis = 0) then
+      begin
+        unzReadCurrentFile := UNZ_EOF;
+        exit;
+      end;
+      if (fseek(pfile_in_zip_read_info^.afile,
+        pfile_in_zip_read_info^.pos_in_zipfile +
+        pfile_in_zip_read_info^.byte_before_the_zipfile, SEEK_SET) <> 0) then
+      begin
+        unzReadCurrentFile := UNZ_ERRNO;
+        exit;
+      end;
+      if fread(pfile_in_zip_read_info^.read_buffer, uReadThis, 1,
+        pfile_in_zip_read_info^.afile) <> 1 then
+      begin
+        unzReadCurrentFile := UNZ_ERRNO;
+        exit;
+      end;
+      Inc(pfile_in_zip_read_info^.pos_in_zipfile, uReadThis);
+
+      Dec(pfile_in_zip_read_info^.rest_read_compressed, uReadThis);
+
+      pfile_in_zip_read_info^.stream.next_in  :=
+        pbyte(pfile_in_zip_read_info^.read_buffer);
+      pfile_in_zip_read_info^.stream.avail_in := integer(uReadThis);
+    end;
+
+    if (pfile_in_zip_read_info^.compression_method = 0) then
+    begin
+      if (pfile_in_zip_read_info^.stream.avail_out <
+        pfile_in_zip_read_info^.stream.avail_in) then
+        uDoCopy := pfile_in_zip_read_info^.stream.avail_out
+      else
+        uDoCopy := pfile_in_zip_read_info^.stream.avail_in;
+
+      for i := 0 to uDoCopy - 1 do
+        Pbytearray(pfile_in_zip_read_info^.stream.next_out)^[i] :=
+          Pbytearray(pfile_in_zip_read_info^.stream.next_in)^[i];
+
+      pfile_in_zip_read_info^.crc32 := crc32(pfile_in_zip_read_info^.crc32,
+        pfile_in_zip_read_info^.stream.next_out, uDoCopy);
+      Dec(pfile_in_zip_read_info^.rest_read_uncompressed, uDoCopy);
+      Dec(pfile_in_zip_read_info^.stream.avail_in, uDoCopy);
+      Dec(pfile_in_zip_read_info^.stream.avail_out, uDoCopy);
+      Inc(pfile_in_zip_read_info^.stream.next_out, uDoCopy);
+      Inc(pfile_in_zip_read_info^.stream.next_in, uDoCopy);
+      Inc(pfile_in_zip_read_info^.stream.total_out, uDoCopy);
+      Inc(iRead, uDoCopy);
+    end
+    else
+    begin
+      flush := Z_SYNC_FLUSH;
+
+      uTotalOutBefore := pfile_in_zip_read_info^.stream.total_out;
+      bufBefore := pfile_in_zip_read_info^.stream.next_out;
+
+      {
+      if ((pfile_in_zip_read_info^.rest_read_uncompressed =
+     pfile_in_zip_read_info^.stream.avail_out) and
+    (pfile_in_zip_read_info^.rest_read_compressed = 0)) then
+        flush := Z_FINISH;
+      }
+      err := inflate(pfile_in_zip_read_info^.stream, flush);
+
+      uTotalOutAfter := pfile_in_zip_read_info^.stream.total_out;
+      uOutThis := uTotalOutAfter - uTotalOutBefore;
+
+      pfile_in_zip_read_info^.crc32 :=
+        crc32(pfile_in_zip_read_info^.crc32, bufBefore, integer(uOutThis));
+
+      Dec(pfile_in_zip_read_info^.rest_read_uncompressed, uOutThis);
+
+      Inc(iRead, integer(uTotalOutAfter - uTotalOutBefore));
+
+      if (err = Z_STREAM_END) then
+      begin
+        if iRead = 0 then
+          unzReadCurrentFile := UNZ_EOF
+        else
+          unzReadCurrentFile := iRead;
+        exit;
+      end;
+      if (err <> Z_OK) then
+        break;
+    end;
+  end; { while }
+
+  if (err = Z_OK) then
+  begin
+    unzReadCurrentFile := iRead;
+    exit;
+  end;
+  unzReadCurrentFile := err;
+end;
+
+{ Give the current position in uncompressed data }
+
+function unztell(afile: unzFile): z_off_t; { ZEXPORT }
+var
+  s: unz_s_ptr;
+  pfile_in_zip_read_info: file_in_zip_read_info_s_ptr;
+begin
+  if (afile = nil) then
+  begin
+    unztell := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  s := unz_s_ptr(afile);
+  pfile_in_zip_read_info := s^.pfile_in_zip_read;
+
+  if (pfile_in_zip_read_info = nil) then
+  begin
+    unztell := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  unztell := z_off_t(pfile_in_zip_read_info^.stream.total_out);
+end;
+
+
+{ return 1 (TRUE) if the end of file was reached, 0 elsewhere }
+
+function unzeof(afile: unzFile): longint;
+var
+  s: unz_s_ptr;
+  pfile_in_zip_read_info: file_in_zip_read_info_s_ptr;
+begin
+  if (afile = nil) then
+  begin
+    unzeof := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  s := unz_s_ptr(afile);
+  pfile_in_zip_read_info := s^.pfile_in_zip_read;
+
+  if (pfile_in_zip_read_info = nil) then
+  begin
+    unzeof := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  if (pfile_in_zip_read_info^.rest_read_uncompressed = 0) then
+    unzeof := 1
+  else
+    unzeof := 0;
+end;
+
+
+{ Read extra field from the current file (opened by unzOpenCurrentFile)
+  This is the local-header version of the extra field (sometimes, there is
+    more info in the local-header version than in the central-header)
+
+  if buf=NIL, it return the size of the local extra field
+
+  if buf<>NIL, len is the size of the buffer, the extra header is copied in
+  buf.
+  the return value is the number of bytes copied in buf, or (if <0)
+  the error code }
+
+function unzGetLocalExtrafield(afile: unzFile; buf: pointer; len: cardinal): longint;
+var
+  s: unz_s_ptr;
+  pfile_in_zip_read_info: file_in_zip_read_info_s_ptr;
+  read_now: integer;
+  size_to_read: longint;
+begin
+  if (afile = nil) then
+  begin
+    unzGetLocalExtrafield := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  s := unz_s_ptr(afile);
+  pfile_in_zip_read_info := s^.pfile_in_zip_read;
+
+  if (pfile_in_zip_read_info = nil) then
+  begin
+    unzGetLocalExtrafield := UNZ_PARAMERROR;
+    exit;
+  end;
+
+  size_to_read := (pfile_in_zip_read_info^.size_local_extrafield -
+    pfile_in_zip_read_info^.pos_local_extrafield);
+
+  if (buf = nil) then
+  begin
+    unzGetLocalExtrafield := longint(size_to_read);
+    exit;
+  end;
+
+  if (len > size_to_read) then
+    read_now := integer(size_to_read)
+  else
+    read_now := integer(len);
+
+  if (read_now = 0) then
+  begin
+    unzGetLocalExtrafield := 0;
+    exit;
+  end;
+
+  if (fseek(pfile_in_zip_read_info^.afile,
+    pfile_in_zip_read_info^.offset_local_extrafield +
+    pfile_in_zip_read_info^.pos_local_extrafield, SEEK_SET) <> 0) then
+  begin
+    unzGetLocalExtrafield := UNZ_ERRNO;
+    exit;
+  end;
+
+  if fread(buf, integer(size_to_read), 1, pfile_in_zip_read_info^.afile) <> 1 then
+  begin
+    unzGetLocalExtrafield := UNZ_ERRNO;
+    exit;
+  end;
+
+  unzGetLocalExtrafield := longint(read_now);
+end;
+
+{ Close the file in zip opened with unzOpenCurrentFile
+  Return UNZ_CRCERROR if all the file was read but the CRC is not good }
+
+function unzCloseCurrentFile(afile: unzFile): longint; { ZEXPORT }
+var
+  err: longint;
+  s:   unz_s_ptr;
+  pfile_in_zip_read_info: file_in_zip_read_info_s_ptr;
+begin
+  err := UNZ_OK;
+
+  if (afile = nil) then
+  begin
+    unzCloseCurrentFile := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+  pfile_in_zip_read_info := s^.pfile_in_zip_read;
+
+  if (pfile_in_zip_read_info = nil) then
+  begin
+    unzCloseCurrentFile := UNZ_PARAMERROR;
+    exit;
+  end;
+
+
+  if (pfile_in_zip_read_info^.rest_read_uncompressed = 0) then
+    if (pfile_in_zip_read_info^.crc32 <> pfile_in_zip_read_info^.crc32_wait) then
+      err := UNZ_CRCERROR;
+
+
+  FreeMem(pfile_in_zip_read_info^.read_buffer);
+  pfile_in_zip_read_info^.read_buffer := nil;
+  if (pfile_in_zip_read_info^.stream_initialised) then
+    inflateEnd(pfile_in_zip_read_info^.stream);
+
+  pfile_in_zip_read_info^.stream_initialised := False;
+  FreeMem(pfile_in_zip_read_info);
+
+  s^.pfile_in_zip_read := nil;
+
+  unzCloseCurrentFile := err;
+end;
+
+
+{ Get the global comment string of the ZipFile, in the szComment buffer.
+  uSizeBuf is the size of the szComment buffer.
+  return the number of byte copied or an error code <0 }
+
+function unzGetGlobalComment(afile: unzFile; szComment: PChar; uSizeBuf: longint): longint; { ZEXPORT }
+
+var
+  s: unz_s_ptr;
+  uReadThis: longint;
+begin
+  if (afile = nil) then
+  begin
+    unzGetGlobalComment := UNZ_PARAMERROR;
+    exit;
+  end;
+  s := unz_s_ptr(afile);
+
+  uReadThis := uSizeBuf;
+  if (uReadThis > s^.gi.size_comment) then
+    uReadThis := s^.gi.size_comment;
+
+  if (fseek(s^.afile, s^.central_pos + 22, SEEK_SET) <> 0) then
+  begin
+    unzGetGlobalComment := UNZ_ERRNO;
+    exit;
+  end;
+
+  if (uReadThis > 0) then
+  begin
+    szComment^ := #0;
+    if fread(szComment, integer(uReadThis), 1, s^.afile) <> 1 then
+    begin
+      unzGetGlobalComment := UNZ_ERRNO;
+      exit;
+    end;
+  end;
+
+  if ((szComment <> nil) and (uSizeBuf > s^.gi.size_comment)) then
+    (szComment +s^.gi.size_comment)^ := #0;
+
+  unzGetGlobalComment := longint(uReadThis);
+end;
+
+end.

+ 792 - 0
packages/base/paszlib/zip.pas

@@ -0,0 +1,792 @@
+unit zip;
+
+{ zip.c -- IO on .zip files using zlib
+  zip.h -- IO for compress .zip files using zlib
+   Version 0.15 alpha, Mar 19th, 1998,
+
+   Copyright (C) 1998 Gilles Vollant
+
+   This package allows to create .ZIP file, compatible with PKZip 2.04g
+     WinZip, InfoZip tools and compatible.
+   Encryption and multi volume ZipFile (span) are not supported.
+   Old compressions used by old PKZip 1.x are not supported
+
+  For decompression of .zip files, look at unzip.pas
+
+  Pascal tranlastion
+  Copyright (C) 2000 by Jacques Nomssi Nzali
+  For conditions of distribution and use, see copyright notice in readme.txt }
+
+
+interface
+
+{$ifdef WIN32}
+  {$define Delphi}
+{$endif}
+
+uses
+  //zutil,
+  zbase,
+  //zLib,
+  ziputils;
+
+const
+  ZIP_OK    = (0);
+  ZIP_ERRNO = (Z_ERRNO);
+  ZIP_PARAMERROR = (-102);
+  ZIP_INTERNALERROR = (-104);
+  Z_DEFAULT_COMPRESSION = -(1);
+  Z_DEFLATED = 8;
+
+(*
+{ tm_zip contain date/time info }
+type
+  tm_zip = record
+     tm_sec : integer;            { seconds after the minute - [0,59] }
+     tm_min : integer;            { minutes after the hour - [0,59] }
+     tm_hour : integer;           { hours since midnight - [0,23] }
+     tm_mday : integer;           { day of the month - [1,31] }
+     tm_mon : integer;            { months since January - [0,11] }
+     tm_year : integer;           { years - [1980..2044] }
+  end;
+*)
+type
+  zip_fileinfo = record
+    tmz_date: tm_zip;        { date in understandable format           }
+    dosDate:  longword;         { if dos_date = 0, tmu_date is used       }
+    {   flag : longint;       }{ general purpose bit flag        2 bytes }
+
+    internal_fa: longint;    { internal file attributes        2 bytes }
+    external_fa: longint;    { external file attributes        4 bytes }
+  end;
+  zip_fileinfo_ptr = ^zip_fileinfo;
+
+function zipOpen(const pathname: PChar; append: longint): zipFile; {ZEXPORT}
+{ Create a zipfile.
+  pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on
+  an Unix computer "zlib/zlib111.zip".
+  if the file pathname exist and append=1, the zip will be created at the end
+  of the file. (useful if the file contain a self extractor code)
+  If the zipfile cannot be opened, the return value is NIL.
+  Else, the return value is a zipFile Handle, usable with other function
+  of this zip package. }
+
+function zipOpenNewFileInZip(afile: zipFile;
+  {const} filename: PChar; const zipfi: zip_fileinfo_ptr; const extrafield_local: pointer; size_extrafield_local: integer; const extrafield_global: pointer; size_extrafield_global: integer; const comment: PChar; method: longint; level: longint): longint; {ZEXPORT}
+{ Open a file in the ZIP for writing.
+  filename : the filename in zip (if NIL, '-' without quote will be used
+  zipfi^ contain supplemental information
+  if extrafield_local<>NIL and size_extrafield_local>0, extrafield_local
+    contains the extrafield data the the local header
+  if extrafield_global<>NIL and size_extrafield_global>0, extrafield_global
+    contains the extrafield data the the local header
+  if comment <> NIL, comment contain the comment string
+  method contain the compression method (0 for store, Z_DEFLATED for deflate)
+  level contain the level of compression (can be Z_DEFAULT_COMPRESSION) }
+
+function zipWriteInFileInZip(afile: zipFile; const buf: pointer; len: cardinal): longint; {ZEXPORT}
+{ Write data in the zipfile }
+
+function zipCloseFileInZip(afile: zipFile): longint; {ZEXPORT}
+ { Close the current file in the zipfile }
+
+function zipClose(afile: zipFile; const global_comment: PChar): longint; {ZEXPORT}
+ { Close the zipfile }
+
+implementation
+
+uses
+  {$ifdef Delphi}
+  SysUtils,
+  {$else}
+  strings,
+  {$endif}
+  zDeflate, crc;
+
+const
+  VERSIONMADEBY = ($0); { platform depedent }
+
+const
+  zip_copyright: PChar = ' zip 0.15 Copyright 1998 Gilles Vollant ';
+
+
+const
+  SIZEDATA_INDATABLOCK = (4096 - (4 * 4));
+
+  LOCALHEADERMAGIC = $04034b50;
+  {CENTRALHEADERMAGIC = $02014b50;}
+  ENDHEADERMAGIC   = $06054b50;
+
+  FLAG_LOCALHEADER_OFFSET = $06;
+  CRC_LOCALHEADER_OFFSET  = $0e;
+
+  SIZECENTRALHEADER = $2e; { 46 }
+
+type
+  linkedlist_datablock_internal_ptr = ^linkedlist_datablock_internal;
+
+  linkedlist_datablock_internal = record
+    next_datablock: linkedlist_datablock_internal_ptr;
+    avail_in_this_block: longint;
+    filled_in_this_block: longint;
+    unused: longint; { for future use and alignement }
+    Data:   array[0..SIZEDATA_INDATABLOCK - 1] of byte;
+  end;
+
+type
+  linkedlist_data = record
+    first_block: linkedlist_datablock_internal_ptr;
+    last_block:  linkedlist_datablock_internal_ptr;
+  end;
+  linkedlist_data_ptr = ^linkedlist_data;
+
+type
+  curfile_info = record
+    stream: z_stream;            { zLib stream structure for inflate }
+    stream_initialised: boolean; { TRUE is stream is initialised }
+    pos_in_buffered_data: integer;  { last written byte in buffered_data }
+
+    pos_local_header: longint;     { offset of the local header of the file
+                                    currenty writing }
+    central_header: PChar;       { central header data for the current file }
+    size_centralheader: longint;   { size of the central header for cur file }
+    flag: longint;                 { flag of the file currently writing }
+
+    method:  longint;                { compression method of file currenty wr.}
+    buffered_data: array[0..Z_BUFSIZE - 1] of byte;{ buffer contain compressed data to be written}
+    dosDate: longint;
+    crc32:   longint;
+  end;
+
+type
+  zip_internal = record
+    filezip: FILEptr;
+    central_dir: linkedlist_data;  { datablock with central dir in construction}
+    in_opened_file_inzip: boolean; { TRUE if a file in the zip is currently writ.}
+    ci: curfile_info;              { info on the file curretly writing }
+
+    begin_pos:    longint;            { position of the beginning of the zipfile }
+    number_entry: longint;
+  end;
+  zip_internal_ptr = ^zip_internal;
+
+function allocate_new_datablock: linkedlist_datablock_internal_ptr;
+var
+  ldi: linkedlist_datablock_internal_ptr;
+begin
+  ldi := linkedlist_datablock_internal_ptr(GetMem(sizeof(linkedlist_datablock_internal)));
+  if (ldi <> nil) then
+  begin
+    ldi^.next_datablock      := nil;
+    ldi^.filled_in_this_block := 0;
+    ldi^.avail_in_this_block := SIZEDATA_INDATABLOCK;
+  end;
+  allocate_new_datablock := ldi;
+end;
+
+procedure free_datablock(ldi: linkedlist_datablock_internal_ptr);
+var
+  ldinext: linkedlist_datablock_internal_ptr;
+begin
+  while (ldi <> nil) do
+  begin
+    ldinext := ldi^.next_datablock;
+    FreeMem(ldi);
+    ldi := ldinext;
+  end;
+end;
+
+procedure init_linkedlist(var ll: linkedlist_data);
+begin
+  ll.last_block  := nil;
+  ll.first_block := nil;
+end;
+
+procedure free_linkedlist(var ll: linkedlist_data);
+begin
+  free_datablock(ll.first_block);
+  ll.last_block  := nil;
+  ll.first_block := nil;
+end;
+
+function add_data_in_datablock(ll: linkedlist_data_ptr; const buf: pointer; len: longint): longint;
+var
+  ldi: linkedlist_datablock_internal_ptr;
+  from_copy: {const} Pbyte;
+var
+  copy_this: integer;
+  i:   integer;
+  to_copy: Pbyte;
+begin
+  if (ll = nil) then
+  begin
+    add_data_in_datablock := ZIP_INTERNALERROR;
+    exit;
+  end;
+
+  if (ll^.last_block = nil) then
+  begin
+    ll^.last_block  := allocate_new_datablock;
+    ll^.first_block := ll^.last_block;
+    if (ll^.first_block = nil) then
+    begin
+      add_data_in_datablock := ZIP_INTERNALERROR;
+      exit;
+    end;
+  end;
+
+  ldi := ll^.last_block;
+  from_copy := Pbyte(buf);
+
+  while (len > 0) do
+  begin
+    if (ldi^.avail_in_this_block = 0) then
+    begin
+      ldi^.next_datablock := allocate_new_datablock;
+      if (ldi^.next_datablock = nil) then
+      begin
+        add_data_in_datablock := ZIP_INTERNALERROR;
+        exit;
+      end;
+      ldi := ldi^.next_datablock;
+      ll^.last_block := ldi;
+    end;
+
+    if (ldi^.avail_in_this_block < len) then
+      copy_this := integer(ldi^.avail_in_this_block)
+    else
+      copy_this := integer(len);
+
+    to_copy := @(ldi^.Data[ldi^.filled_in_this_block]);
+
+    for i := 0 to copy_this - 1 do
+      Pbytearray(to_copy)^[i] := Pbytearray(from_copy)^[i];
+
+    Inc(ldi^.filled_in_this_block, copy_this);
+    Dec(ldi^.avail_in_this_block, copy_this);
+    Inc(from_copy, copy_this);
+    Dec(len, copy_this);
+  end;
+  add_data_in_datablock := ZIP_OK;
+end;
+
+
+function write_datablock(fout: FILEptr; ll: linkedlist_data_ptr): longint;
+var
+  ldi: linkedlist_datablock_internal_ptr;
+begin
+  ldi := ll^.first_block;
+  while (ldi <> nil) do
+  begin
+    if (ldi^.filled_in_this_block > 0) then
+      if (fwrite(@ldi^.Data, integer(ldi^.filled_in_this_block), 1, fout) <> 1) then
+      begin
+        write_datablock := ZIP_ERRNO;
+        exit;
+      end;
+    ldi := ldi^.next_datablock;
+  end;
+  write_datablock := ZIP_OK;
+end;
+
+{**************************************************************************}
+
+{ ===========================================================================
+   Outputs a long in LSB order to the given file
+   nbByte = 1, 2 or 4 (byte, short or long)  }
+
+function ziplocal_putValue(afile: FILEptr; x: longint; nbByte: longint): longint;
+var
+  buf: array[0..4 - 1] of byte;
+  n:   longint;
+begin
+  for n := 0 to nbByte - 1 do
+  begin
+    buf[n] := byte(x and $ff);
+    x      := x shr 8;
+  end;
+  if (fwrite(@buf, nbByte, 1, afile) <> 1) then
+    ziplocal_putValue := ZIP_ERRNO
+  else
+    ziplocal_putValue := ZIP_OK;
+end;
+
+procedure ziplocal_putValue_inmemory(dest: pointer; x: longint; nbByte: longint);
+var
+  buf: Pbytearray;
+  n:   longint;
+begin
+  buf := Pbytearray(dest);
+  for n := 0 to nbByte - 1 do
+  begin
+    buf^[n] := Byte(x and $ff);
+    x := x shr 8;
+  end;
+end;
+
+{**************************************************************************}
+
+
+function ziplocal_TmzDateToDosDate(var ptm: tm_zip; dosDate: longint): longint;
+var
+  year: longint;
+begin
+  year := longint(ptm.tm_year);
+  if (year > 1980) then
+    Dec(year, 1980)
+  else
+  if (year > 80) then
+    Dec(year, 80);
+  ziplocal_TmzDateToDosDate := longint(
+    ((ptm.tm_mday) + (32 * (ptm.tm_mon + 1)) + (512 * year)) shl 16) or
+    ((ptm.tm_sec div 2) + (32 * ptm.tm_min) + (2048 * longint(ptm.tm_hour)));
+end;
+
+
+{**************************************************************************}
+
+function zipOpen(const pathname: PChar; append: longint): zipFile; {ZEXPORT}
+var
+  ziinit: zip_internal;
+  zi:     zip_internal_ptr;
+begin
+  if (append = 0) then
+    ziinit.filezip := fopen(pathname, fopenwrite)
+  else
+    ziinit.filezip := fopen(pathname, fappendwrite);
+
+  if (ziinit.filezip = nil) then
+  begin
+    zipOpen := nil;
+    exit;
+  end;
+  ziinit.begin_pos    := ftell(ziinit.filezip);
+  ziinit.in_opened_file_inzip := False;
+  ziinit.ci.stream_initialised := False;
+  ziinit.number_entry := 0;
+  init_linkedlist(ziinit.central_dir);
+
+  zi := zip_internal_ptr(AllocMem(sizeof(zip_internal)));
+  if (zi = nil) then
+  begin
+    fclose(ziinit.filezip);
+    zipOpen := nil;
+    exit;
+  end;
+
+  zi^     := ziinit;
+  zipOpen := zipFile(zi);
+end;
+
+function zipOpenNewFileInZip(afile: zipFile;
+  {const} filename: PChar; const zipfi: zip_fileinfo_ptr; const extrafield_local: pointer; size_extrafield_local: integer; const extrafield_global: pointer; size_extrafield_global: integer; const comment: PChar; method: longint; level: longint): longint; {ZEXPORT}
+var
+  zi:  zip_internal_ptr;
+  size_filename: integer;
+  size_comment: integer;
+  i:   integer;
+  err: longint;
+begin
+  err := ZIP_OK;
+  if (afile = nil) then
+  begin
+    zipOpenNewFileInZip := ZIP_PARAMERROR;
+    exit;
+  end;
+  if ((method <> 0) and (method <> Z_DEFLATED)) then
+  begin
+    zipOpenNewFileInZip := ZIP_PARAMERROR;
+    exit;
+  end;
+
+  zi := zip_internal_ptr(afile);
+
+  if (zi^.in_opened_file_inzip = True) then
+  begin
+    err := zipCloseFileInZip(afile);
+    if (err <> ZIP_OK) then
+    begin
+      zipOpenNewFileInZip := err;
+      exit;
+    end;
+  end;
+
+  if (filename = nil) then
+    filename := '-';
+
+  if (comment = nil) then
+    size_comment := 0
+  else
+    size_comment := strlen(comment);
+
+  size_filename := strlen(filename);
+
+  if (zipfi = nil) then
+    zi^.ci.dosDate := 0
+  else
+  if (zipfi^.dosDate <> 0) then
+    zi^.ci.dosDate := zipfi^.dosDate
+  else
+    zi^.ci.dosDate := ziplocal_TmzDateToDosDate(zipfi^.tmz_date, zipfi^.dosDate);
+  zi^.ci.flag := 0;
+  if ((level = 8) or (level = 9)) then
+    zi^.ci.flag := zi^.ci.flag or 2;
+  if ((level = 2)) then
+    zi^.ci.flag := zi^.ci.flag or 4;
+  if ((level = 1)) then
+    zi^.ci.flag := zi^.ci.flag or 6;
+
+  zi^.ci.crc32  := 0;
+  zi^.ci.method := method;
+  zi^.ci.stream_initialised := False;
+  zi^.ci.pos_in_buffered_data := 0;
+  zi^.ci.pos_local_header := ftell(zi^.filezip);
+  zi^.ci.size_centralheader := SIZECENTRALHEADER + size_filename +
+    size_extrafield_global + size_comment;
+  zi^.ci.central_header := PChar(AllocMem(integer(zi^.ci.size_centralheader)));
+
+  ziplocal_putValue_inmemory(zi^.ci.central_header, longint(CENTRALHEADERMAGIC), 4);
+  { version info }
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 4, longint(VERSIONMADEBY), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 6, longint(20), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 8, longint(zi^.ci.flag), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 10, longint(zi^.ci.method), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 12, longint(zi^.ci.dosDate), 4);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 16, longint(0), 4); {crc}
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 20, longint(0), 4); {compr size}
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 24, longint(0), 4); {uncompr size}
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 28, longint(size_filename), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 30, longint(size_extrafield_global), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 32, longint(size_comment), 2);
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 34, longint(0), 2); {disk nm start}
+
+  if (zipfi = nil) then
+    ziplocal_putValue_inmemory(zi^.ci.central_header + 36, longint(0), 2)
+  else
+    ziplocal_putValue_inmemory(zi^.ci.central_header + 36, longint(zipfi^.internal_fa), 2);
+
+  if (zipfi = nil) then
+    ziplocal_putValue_inmemory(zi^.ci.central_header + 38, longint(0), 4)
+  else
+    ziplocal_putValue_inmemory(zi^.ci.central_header + 38, longint(zipfi^.external_fa), 4);
+
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 42, longint(zi^.ci.pos_local_header), 4);
+
+  i := 0;
+  while (i < size_filename) do
+  begin
+    (zi^.ci.central_header +SIZECENTRALHEADER + i)^ := (filename + i)^;
+    Inc(i);
+  end;
+
+  i := 0;
+  while (i < size_extrafield_global) do
+  begin
+    (zi^.ci.central_header +SIZECENTRALHEADER + size_filename + i)^ :=
+      ({const} PChar(extrafield_global) + i)^;
+    Inc(i);
+  end;
+
+  i := 0;
+  while (i < size_comment) do
+  begin
+    (zi^.ci.central_header +SIZECENTRALHEADER + size_filename + size_extrafield_global + i)^ := (filename + i)^;
+    Inc(i);
+  end;
+  if (zi^.ci.central_header = nil) then
+  begin
+    zipOpenNewFileInZip := ZIP_INTERNALERROR;
+    exit;
+  end;
+
+  { write the local header }
+  err := ziplocal_putValue(zi^.filezip, longint(LOCALHEADERMAGIC), 4);
+
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(20), 2); { version needed to extract }
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(zi^.ci.flag), 2);
+
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(zi^.ci.method), 2);
+
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(zi^.ci.dosDate), 4);
+
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(0), 4); { crc 32, unknown }
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(0), 4); { compressed size, unknown }
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(0), 4); { uncompressed size, unknown }
+
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(size_filename), 2);
+
+  if (err = ZIP_OK) then
+    err := ziplocal_putValue(zi^.filezip, longint(size_extrafield_local), 2);
+
+  if ((err = ZIP_OK) and (size_filename > 0)) then
+    if (fwrite(filename, integer(size_filename), 1, zi^.filezip) <> 1) then
+      err := ZIP_ERRNO;
+
+  if ((err = ZIP_OK) and (size_extrafield_local > 0)) then
+    if (fwrite(extrafield_local, integer(size_extrafield_local), 1, zi^.filezip) <> 1) then
+      err := ZIP_ERRNO;
+
+  zi^.ci.stream.avail_in  := integer(0);
+  zi^.ci.stream.avail_out := integer(Z_BUFSIZE);
+  zi^.ci.stream.next_out  := Pbyte(@zi^.ci.buffered_data);
+  zi^.ci.stream.total_in  := 0;
+  zi^.ci.stream.total_out := 0;
+
+  if ((err = ZIP_OK) and (zi^.ci.method = Z_DEFLATED)) then
+  begin
+    err := deflateInit2(zi^.ci.stream, level,
+      Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
+
+    if (err = Z_OK) then
+      zi^.ci.stream_initialised := True;
+  end;
+
+  if (err = Z_OK) then
+    zi^.in_opened_file_inzip := True;
+  zipOpenNewFileInZip := err;
+end;
+
+function zipWriteInFileInZip(afile: zipFile; const buf: pointer; len: cardinal): longint; {ZEXPORT}
+var
+  zi:  zip_internal_ptr;
+  err: longint;
+var
+  uTotalOutBefore: longint;
+var
+  copy_this, i: integer;
+begin
+  err := ZIP_OK;
+
+  if (afile = nil) then
+  begin
+    zipWriteInFileInZip := ZIP_PARAMERROR;
+    exit;
+  end;
+  zi := zip_internal_ptr(afile);
+
+  if (zi^.in_opened_file_inzip = False) then
+  begin
+    zipWriteInFileInZip := ZIP_PARAMERROR;
+    exit;
+  end;
+
+  zi^.ci.stream.next_in := buf;
+  zi^.ci.stream.avail_in := len;
+  zi^.ci.crc32 := crc32(zi^.ci.crc32, buf, len);
+
+  while ((err = ZIP_OK) and (zi^.ci.stream.avail_in > 0)) do
+  begin
+    if (zi^.ci.stream.avail_out = 0) then
+    begin
+      if fwrite(@zi^.ci.buffered_data, integer(zi^.ci.pos_in_buffered_data), 1, zi^.filezip) <> 1 then
+        err := ZIP_ERRNO;
+      zi^.ci.pos_in_buffered_data := 0;
+      zi^.ci.stream.avail_out := integer(Z_BUFSIZE);
+      zi^.ci.stream.next_out  := Pbyte(@zi^.ci.buffered_data);
+    end;
+
+    if (zi^.ci.method = Z_DEFLATED) then
+    begin
+      uTotalOutBefore := zi^.ci.stream.total_out;
+      err := deflate(zi^.ci.stream, Z_NO_FLUSH);
+      Inc(zi^.ci.pos_in_buffered_data, integer(zi^.ci.stream.total_out - uTotalOutBefore));
+    end
+    else
+    begin
+      if (zi^.ci.stream.avail_in < zi^.ci.stream.avail_out) then
+        copy_this := zi^.ci.stream.avail_in
+      else
+        copy_this := zi^.ci.stream.avail_out;
+
+      for i := 0 to copy_this - 1 do
+        (PChar(zi^.ci.stream.next_out) +i)^ :=
+          ( {const} PChar(zi^.ci.stream.next_in) + i)^;
+
+
+      Dec(zi^.ci.stream.avail_in, copy_this);
+      Dec(zi^.ci.stream.avail_out, copy_this);
+      Inc(zi^.ci.stream.next_in, copy_this);
+      Inc(zi^.ci.stream.next_out, copy_this);
+      Inc(zi^.ci.stream.total_in, copy_this);
+      Inc(zi^.ci.stream.total_out, copy_this);
+      Inc(zi^.ci.pos_in_buffered_data, copy_this);
+    end;
+  end;
+
+  zipWriteInFileInZip := 0;
+end;
+
+function zipCloseFileInZip(afile: zipFile): longint; {ZEXPORT}
+var
+  zi:  zip_internal_ptr;
+  err: longint;
+var
+  uTotalOutBefore: longint;
+var
+  cur_pos_inzip: longint;
+begin
+  err := ZIP_OK;
+
+  if (afile = nil) then
+  begin
+    zipCloseFileInZip := ZIP_PARAMERROR;
+    exit;
+  end;
+  zi := zip_internal_ptr(afile);
+
+  if (zi^.in_opened_file_inzip = False) then
+  begin
+    zipCloseFileInZip := ZIP_PARAMERROR;
+    exit;
+  end;
+  zi^.ci.stream.avail_in := 0;
+
+  if (zi^.ci.method = Z_DEFLATED) then
+    while (err = ZIP_OK) do
+    begin
+      if (zi^.ci.stream.avail_out = 0) then
+      begin
+        if fwrite(@zi^.ci.buffered_data, integer(zi^.ci.pos_in_buffered_data), 1, zi^.filezip) <> 1 then
+          err := ZIP_ERRNO;
+        zi^.ci.pos_in_buffered_data := 0;
+        zi^.ci.stream.avail_out := integer(Z_BUFSIZE);
+        zi^.ci.stream.next_out  := Pbyte(@zi^.ci.buffered_data);
+      end;
+      uTotalOutBefore := zi^.ci.stream.total_out;
+      err := deflate(zi^.ci.stream, Z_FINISH);
+      Inc(zi^.ci.pos_in_buffered_data, integer(zi^.ci.stream.total_out - uTotalOutBefore));
+    end;
+
+  if (err = Z_STREAM_END) then
+    err := ZIP_OK; { this is normal }
+
+  if (zi^.ci.pos_in_buffered_data > 0) and (err = ZIP_OK) then
+    if fwrite(@zi^.ci.buffered_data, integer(zi^.ci.pos_in_buffered_data), 1, zi^.filezip) <> 1 then
+      err := ZIP_ERRNO;
+
+  if ((zi^.ci.method = Z_DEFLATED) and (err = ZIP_OK)) then
+  begin
+    err := deflateEnd(zi^.ci.stream);
+    zi^.ci.stream_initialised := False;
+  end;
+
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 16, longint(zi^.ci.crc32), 4); {crc}
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 20, longint(zi^.ci.stream.total_out), 4); {compr size}
+  ziplocal_putValue_inmemory(zi^.ci.central_header + 24, longint(zi^.ci.stream.total_in), 4); {uncompr size}
+
+  if (err = ZIP_OK) then
+    err := add_data_in_datablock(@zi^.central_dir, zi^.ci.central_header, longint(zi^.ci.size_centralheader));
+
+  FreeMem(zi^.ci.central_header);
+
+  if (err = ZIP_OK) then
+  begin
+    cur_pos_inzip := ftell(zi^.filezip);
+    if fseek(zi^.filezip, zi^.ci.pos_local_header + 14, SEEK_SET) <> 0 then
+      err := ZIP_ERRNO;
+
+    if (err = ZIP_OK) then
+      err := ziplocal_putValue(zi^.filezip, longint(zi^.ci.crc32), 4); { crc 32, unknown }
+
+    if (err = ZIP_OK) then { compressed size, unknown }
+      err := ziplocal_putValue(zi^.filezip, longint(zi^.ci.stream.total_out), 4);
+
+    if (err = ZIP_OK) then { uncompressed size, unknown }
+      err := ziplocal_putValue(zi^.filezip, longint(zi^.ci.stream.total_in), 4);
+
+    if fseek(zi^.filezip, cur_pos_inzip, SEEK_SET) <> 0 then
+      err := ZIP_ERRNO;
+  end;
+
+  Inc(zi^.number_entry);
+  zi^.in_opened_file_inzip := False;
+
+  zipCloseFileInZip := err;
+end;
+
+function zipClose(afile: zipFile; const global_comment: PChar): longint; {ZEXPORT}
+var
+  zi:  zip_internal_ptr;
+  err: longint;
+  size_centraldir: longint;
+  centraldir_pos_inzip: longint;
+  size_global_comment: integer;
+var
+  ldi: linkedlist_datablock_internal_ptr;
+begin
+  err := 0;
+  size_centraldir := 0;
+  if (afile = nil) then
+  begin
+    zipClose := ZIP_PARAMERROR;
+    exit;
+  end;
+  zi := zip_internal_ptr(afile);
+
+  if (zi^.in_opened_file_inzip = True) then
+    err := zipCloseFileInZip(afile);
+
+  if (global_comment = nil) then
+    size_global_comment := 0
+  else
+    size_global_comment := strlen(global_comment);
+
+  centraldir_pos_inzip := ftell(zi^.filezip);
+  if (err = ZIP_OK) then
+  begin
+    ldi := zi^.central_dir.first_block;
+    while (ldi <> nil) do
+    begin
+      if ((err = ZIP_OK) and (ldi^.filled_in_this_block > 0)) then
+        if fwrite(@ldi^.Data, integer(ldi^.filled_in_this_block), 1, zi^.filezip) <> 1 then
+          err := ZIP_ERRNO;
+
+      Inc(size_centraldir, ldi^.filled_in_this_block);
+      ldi := ldi^.next_datablock;
+    end;
+  end;
+  free_datablock(zi^.central_dir.first_block);
+
+  if (err = ZIP_OK) then { Magic End }
+    err := ziplocal_putValue(zi^.filezip, longint(ENDHEADERMAGIC), 4);
+
+  if (err = ZIP_OK) then { number of this disk }
+    err := ziplocal_putValue(zi^.filezip, longint(0), 2);
+
+  if (err = ZIP_OK) then { number of the disk with the start of the central directory }
+    err := ziplocal_putValue(zi^.filezip, longint(0), 2);
+
+  if (err = ZIP_OK) then { total number of entries in the central dir on this disk }
+    err := ziplocal_putValue(zi^.filezip, longint(zi^.number_entry), 2);
+
+  if (err = ZIP_OK) then { total number of entries in the central dir }
+    err := ziplocal_putValue(zi^.filezip, longint(zi^.number_entry), 2);
+
+  if (err = ZIP_OK) then { size of the central directory }
+    err := ziplocal_putValue(zi^.filezip, longint(size_centraldir), 4);
+
+  if (err = ZIP_OK) then { offset of start of central directory with respect to the
+                          starting disk number }
+    err := ziplocal_putValue(zi^.filezip, longint(centraldir_pos_inzip), 4);
+
+  if (err = ZIP_OK) then { zipfile comment length }
+    err := ziplocal_putValue(zi^.filezip, longint(size_global_comment), 2);
+
+  if ((err = ZIP_OK) and (size_global_comment > 0)) then
+    if fwrite(global_comment, integer(size_global_comment), 1, zi^.filezip) <> 1 then
+      err := ZIP_ERRNO;
+  fclose(zi^.filezip);
+  FreeMem(zi);
+
+  zipClose := err;
+end;
+
+end.

+ 304 - 0
packages/base/paszlib/ziputils.pas

@@ -0,0 +1,304 @@
+unit ziputils;
+
+{ ziputils.pas - IO on .zip files using zlib
+  - definitions, declarations and routines used by both
+    zip.pas and unzip.pas
+    The file IO is implemented here.
+
+  based on work by Gilles Vollant
+
+  March 23th, 2000,
+  Copyright (C) 2000 Jacques Nomssi Nzali }
+
+interface
+
+{$undef UseStream}
+
+{$ifdef WIN32}
+  {$define Delphi}
+  {$ifdef UseStream}
+    {$define Streams}
+  {$endif}
+{$endif}
+
+//uses  Classes, SysUtils;
+
+{ -------------------------------------------------------------- }
+{$ifdef Streams}
+type
+  FILEptr = TFileStream;
+{$else}
+type
+  FILEptr = ^file;
+{$endif}
+
+type
+  seek_mode = (SEEK_SET, SEEK_CUR, SEEK_END);
+  open_mode = (fopenread, fopenwrite, fappendwrite);
+
+function fopen(filename: PChar; mode: open_mode): FILEptr;
+
+procedure fclose(fp: FILEptr);
+
+function fseek(fp: FILEptr; recPos: longint; mode: seek_mode): longint;
+
+function fread(buf: pointer; recSize: longint; recCount: longint; fp: FILEptr): longint;
+
+function fwrite(buf: pointer; recSize: longint; recCount: longint; fp: FILEptr): longint;
+
+function ftell(fp: FILEptr): longint;  { ZIP }
+
+function feof(fp: FILEptr): longint;   { MiniZIP }
+
+{ ------------------------------------------------------------------- }
+
+type
+  zipFile = pointer;
+  unzFile = pointer;
+
+type
+  z_off_t = longint;
+
+{ tm_zip contain date/time info }
+type
+  tm_zip = record
+    tm_sec:  longint;            { seconds after the minute - [0,59] }
+    tm_min:  longint;            { minutes after the hour - [0,59] }
+    tm_hour: longint;            { hours since midnight - [0,23] }
+    tm_mday: longint;            { day of the month - [1,31] }
+    tm_mon:  longint;            { months since January - [0,11] }
+    tm_year: longint;            { years - [1980..2044] }
+  end;
+
+  tm_unz = tm_zip;
+
+const
+  Z_BUFSIZE = (16384);
+  Z_MAXFILENAMEINZIP = (256);
+
+const
+  CENTRALHEADERMAGIC = $02014b50;
+
+const
+  SIZECENTRALDIRITEM = $2e;
+  SIZEZIPLOCALHEADER = $1e;
+
+const
+  Paszip_copyright: PChar = ' Paszip Copyright 2000 Jacques Nomssi Nzali ';
+
+implementation
+
+{$ifdef Streams}
+{ ---------------------------------------------------------------- }
+
+function fopen(filename: PChar; mode: open_mode): FILEptr;
+var
+  fp: FILEptr;
+begin
+  fp := nil;
+  try
+    case mode of
+      fopenread: fp  := TFileStream.Create(filename, fmOpenRead);
+      fopenwrite: fp := TFileStream.Create(filename, fmCreate);
+      fappendwrite:
+      begin
+        fp := TFileStream.Create(filename, fmOpenReadWrite);
+        fp.Seek(soFromEnd, 0);
+      end;
+    end;
+  except
+    on EFOpenError do
+      fp := nil;
+  end;
+  fopen := fp;
+end;
+
+procedure fclose(fp: FILEptr);
+begin
+  fp.Free;
+end;
+
+function fread(buf: pointer; recSize: longint; recCount: longint; fp: FILEptr): longint;
+var
+  totalSize, readcount: longint;
+begin
+  if Assigned(buf) then
+  begin
+    totalSize := recCount * longint(recSize);
+    readCount := fp.Read(buf^, totalSize);
+    if (readcount <> totalSize) then
+      fread := readcount div recSize
+    else
+      fread := recCount;
+  end
+  else
+    fread := 0;
+end;
+
+function fwrite(buf: pointer; recSize: longint; recCount: longint; fp: FILEptr): longint;
+var
+  totalSize, written: longint;
+begin
+  if Assigned(buf) then
+  begin
+    totalSize := recCount * longint(recSize);
+    written   := fp.Write(buf^, totalSize);
+    if (written <> totalSize) then
+      fwrite := written div recSize
+    else
+      fwrite := recCount;
+  end
+  else
+    fwrite := 0;
+end;
+
+function fseek(fp: FILEptr; recPos: longint; mode: seek_mode): int;
+const
+  fsmode: array[seek_mode] of word = (soFromBeginning, soFromCurrent, soFromEnd);
+begin
+  fp.Seek(recPos, fsmode[mode]);
+  fseek := 0; { = 0 for success }
+end;
+
+function ftell(fp: FILEptr): longint;
+begin
+  ftell := fp.Position;
+end;
+
+function feof(fp: FILEptr): longint;
+begin
+  feof := 0;
+  if Assigned(fp) then
+    if fp.Position = fp.Size then
+      feof := 1
+    else
+      feof := 0;
+end;
+
+{$else}
+{ ---------------------------------------------------------------- }
+
+function fopen(filename : PChar; mode : open_mode) : FILEptr;
+var
+  fp : FILEptr;
+  OldFileMode : byte;
+begin
+  fp := NIL;
+  OldFileMode := FileMode;
+
+  GetMem(fp, SizeOf(file));
+  Assign(fp^, filename);
+  {$i-}
+  Case mode of
+  fopenread:
+    begin
+      FileMode := 0;
+      Reset(fp^, 1);
+    end;
+  fopenwrite:
+    begin
+      FileMode := 1;
+      ReWrite(fp^, 1);
+    end;
+  fappendwrite :
+    begin
+      FileMode := 2;
+      Reset(fp^, 1);
+      Seek(fp^, FileSize(fp^));
+    end;
+  end;
+  FileMode := OldFileMode;
+  if IOresult<>0 then
+  begin
+    FreeMem(fp, SizeOf(file));
+    fp := NIL;
+  end;
+
+  fopen := fp;
+end;
+
+procedure fclose(fp : FILEptr);
+begin
+  if Assigned(fp) then
+  begin
+    {$i-}
+    system.close(fp^);
+    if IOresult=0 then;
+    FreeMem(fp, SizeOf(file));
+  end;
+end;
+
+function fread(buf : pointer;
+               recSize : LongInt;
+               recCount : LongInt;
+               fp : FILEptr) : LongInt;
+var
+  totalSize, readcount : LongInt;
+begin
+  if Assigned(buf) then
+  begin
+    totalSize := recCount * LongInt(recSize);
+    {$i-}
+    system.BlockRead(fp^, buf^, totalSize, readcount);
+    if (readcount <> totalSize) then
+      fread := readcount div recSize
+    else
+      fread := recCount;
+  end
+  else
+    fread := 0;
+end;
+
+function fwrite(buf : pointer;
+                recSize : LongInt;
+                recCount : LongInt;
+                fp : FILEptr) : LongInt;
+var
+  totalSize, written : LongInt;
+begin
+  if Assigned(buf) then
+  begin
+    totalSize := recCount * LongInt(recSize);
+    {$i-}
+    system.BlockWrite(fp^, buf^, totalSize, written);
+    if (written <> totalSize) then
+      fwrite := written div recSize
+    else
+      fwrite := recCount;
+  end
+  else
+    fwrite := 0;
+end;
+
+function fseek(fp : FILEptr;
+               recPos : LongInt;
+               mode : seek_mode) : longint;
+begin
+  {$i-}
+  case mode of
+    SEEK_SET : system.Seek(fp^, recPos);
+    SEEK_CUR : system.Seek(fp^, FilePos(fp^)+recPos);
+    SEEK_END : system.Seek(fp^, FileSize(fp^)-1-recPos); { ?? check }
+  end;
+  fseek := IOresult; { = 0 for success }
+end;
+
+function ftell(fp : FILEptr) : LongInt;
+begin
+  ftell := FilePos(fp^);
+end;
+
+function feof(fp : FILEptr) : LongInt;
+begin
+  feof := 0;
+  if Assigned(fp) then
+    if eof(fp^) then
+      feof := 1
+    else
+      feof := 0;
+end;
+
+{$endif}
+{ ---------------------------------------------------------------- }
+
+end.