[Pkg-electronics-commits] [gtkwave] 03/04: Imported Upstream version 3.3.52

أحمد المحمودي (Ahmed El-Mahmoudy) aelmahmoudy at sabily.org
Fri Nov 22 15:32:35 UTC 2013


This is an automated email from the git hooks/post-receive script.

aelmahmoudy-guest pushed a commit to branch master
in repository gtkwave.

commit 492b230b3992542dc402d6ea2f8753d9d1032deb
Author: أحمد المحمودي (Ahmed El-Mahmoudy) <aelmahmoudy at sabily.org>
Date:   Sun Nov 17 14:44:54 2013 +0200

    Imported Upstream version 3.3.52
---
 AUTHORS                                           |    1 +
 ChangeLog                                         |   18 +
 LICENSE.TXT                                       |    2 +-
 Makefile.in                                       |    2 +
 configure                                         |   73 +-
 configure.ac                                      |   14 +-
 contrib/Makefile.in                               |    2 +
 contrib/bundle_for_osx/Info-gtkwave.plist         |    6 +-
 contrib/bundle_for_osx/Makefile.in                |    2 +
 contrib/fst_jni/Makefile.am                       |    1 +
 contrib/fst_jni/Makefile.in                       |    3 +
 contrib/fst_jni/fstAPI.c                          |    7 +
 contrib/fst_jni/fstAPI.h                          |    8 +
 contrib/fst_jni/fstAPI.java                       |    1 +
 contrib/fst_jni/fstReader.java                    |    1 +
 contrib/fst_jni/fstWriterPackType.java            |   30 +
 contrib/fst_jni/zzz_test.csh                      |    1 +
 contrib/pccts/IBM_VISUAL_AGE_PROJECTS/Makefile.in |    2 +
 contrib/pccts/Makefile.in                         |    2 +
 contrib/pccts/antlr/Makefile.in                   |    2 +
 contrib/pccts/dlg/Makefile.in                     |    2 +
 contrib/pccts/h/Makefile.in                       |    2 +
 contrib/pccts/sorcerer/Makefile.in                |    2 +
 contrib/pccts/sorcerer/h/Makefile.in              |    2 +
 contrib/pccts/sorcerer/lib/Makefile.in            |    2 +
 contrib/pccts/sorcerer/test/Makefile.in           |    2 +
 contrib/pccts/sorcerer/test/test7/Makefile.in     |    2 +
 contrib/pccts/sorcerer/testcpp/Makefile.in        |    2 +
 contrib/pccts/support/DECmms/Makefile.in          |    2 +
 contrib/pccts/support/Makefile.in                 |    2 +
 contrib/pccts/support/genmk/Makefile.in           |    2 +
 contrib/pccts/support/rexpr/Makefile.in           |    2 +
 contrib/pccts/support/set/Makefile.in             |    2 +
 contrib/pccts/support/sym/Makefile.in             |    2 +
 contrib/pccts/testcpp/Makefile.in                 |    2 +
 contrib/rtlbrowse/Makefile.am                     |    8 +-
 contrib/rtlbrowse/Makefile.in                     |   32 +-
 contrib/vermin/Makefile.in                        |    2 +
 doc/Makefile.in                                   |    2 +
 doc/gtkwave.odt                                   |  Bin 1391267 -> 1391489 bytes
 examples/Makefile.in                              |    2 +
 man/Makefile.in                                   |    2 +
 man/fst2vcd.1                                     |    5 +-
 man/vcd2fst.1                                     |    5 +-
 share/Makefile.in                                 |    2 +
 share/applications/Makefile.in                    |    2 +
 share/icons/Makefile.in                           |    2 +
 share/icons/gnome/16x16/Makefile.in               |    2 +
 share/icons/gnome/16x16/mimetypes/Makefile.in     |    2 +
 share/icons/gnome/32x32/Makefile.in               |    2 +
 share/icons/gnome/32x32/mimetypes/Makefile.in     |    2 +
 share/icons/gnome/48x48/Makefile.in               |    2 +
 share/icons/gnome/48x48/mimetypes/Makefile.in     |    2 +
 share/icons/gnome/Makefile.in                     |    2 +
 share/mime/Makefile.in                            |    2 +
 share/mime/packages/Makefile.in                   |    2 +
 src/Makefile.am                                   |    2 +-
 src/Makefile.in                                   |    6 +-
 src/cocoa/Makefile.in                             |    2 +
 src/extload.c                                     |   17 +-
 src/file.c                                        |   82 +-
 src/file.h                                        |    4 +-
 src/fsdb_wrapper_api.cc                           |    2 +-
 src/globals.c                                     |   14 +-
 src/globals.h                                     |    1 +
 src/helpers/Makefile.am                           |    6 +-
 src/helpers/Makefile.in                           |   31 +-
 src/helpers/fst/Makefile.am                       |    2 +-
 src/helpers/fst/Makefile.in                       |    7 +-
 src/helpers/fst/block_format.txt                  |   12 +-
 src/helpers/fst/fstapi.c                          |  256 +++++--
 src/helpers/fst/fstapi.h                          |   10 +-
 src/helpers/fst/lz4.c                             |  822 +++++++++++++++++++++
 src/helpers/fst/lz4.h                             |  205 +++++
 src/helpers/fst2vcd.c                             |   15 +-
 src/helpers/vcd2fst.c                             |   84 ++-
 src/libbz2/Makefile.in                            |    2 +
 src/liblzma/Makefile.in                           |    2 +
 src/libz/Makefile.in                              |    2 +
 src/libz/README                                   |   97 ++-
 src/libz/adler32.c                                |   70 +-
 src/libz/compress.c                               |    4 +-
 src/libz/crc32.c                                  |   85 +--
 src/libz/crc32.h                                  |    2 +-
 src/libz/deflate.c                                |  265 +++++--
 src/libz/deflate.h                                |   14 +-
 src/libz/gzguts.h                                 |  103 ++-
 src/libz/gzlib.c                                  |  197 +++--
 src/libz/gzread.c                                 |  431 +++++------
 src/libz/gzwrite.c                                |  196 +++--
 src/libz/infback.c                                |   16 +-
 src/libz/inffast.c                                |    6 +-
 src/libz/inffixed.h                               |    6 +-
 src/libz/inflate.c                                |  136 ++--
 src/libz/inftrees.c                               |   54 +-
 src/libz/trees.c                                  |   56 +-
 src/libz/uncompr.c                                |    4 +-
 src/libz/zconf.h                                  |  203 +++--
 src/libz/zlib.h                                   |  345 ++++++---
 src/libz/zutil.c                                  |   28 +-
 src/libz/zutil.h                                  |  105 ++-
 src/lxt.c                                         |    4 +-
 src/main.c                                        |    4 +-
 src/menu.c                                        |    2 -
 src/signalwindow.c                                |   79 +-
 src/strace.c                                      |  110 +--
 src/vcd_partial.c                                 |   28 +
 src/wavewindow.c                                  |    6 +-
 108 files changed, 3331 insertions(+), 1201 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 15083f7..9cfe0c7 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -11,3 +11,4 @@ Some public domain clip art by contributors at http://www.sxc.hu/ website.
 Hierarchy marker icons from the Silk icons set by Mark James found at the http://www.famfamfam.com/lab/icons/silk/ website.
 Portions of the TCL implementation, tcl_np.c and tcl_np.h are copyrighted by the Regents of the University of California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState Corporation, and other parties.
 NSAlert is Copyright (C) 2011-2013 Philipp Mayerhofer.
+LZ4 is Copyright (C) 2011-2013 Yann Collet.
diff --git a/ChangeLog b/ChangeLog
index 70eebd4..83f40fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1385,3 +1385,21 @@
 		Fixed timezero in vcd2fst as it was only parsing unsigned
 		numbers.
 		Fixed Open Hierarchy crash on blank signals.
+3.3.52	11nov13	Added LZ4 as compression type for FST.  When enabled with
+		--fourpack in vcd2fst, this compresses both signal data
+		and the hierarchy using LZ4.
+		Added WLF support via wlf2vcd.  To use, specify -o
+		at the command line.  (e.g., gtkwave -o test.wlf)
+		Changed left/right arrow function in signal/wave windows to
+		find next transition of selected signal(s).
+		Re-enabled DnD scroll beyond top/bottom of Signals pane.
+		Added debounce for baseline (middle) mouse button.
+		Another partial VCD loader fix.
+		Now use libcomdlg32 file requesters on MinGW.
+		Added --extensions flag to fstvcd to enable emission of
+		FST extensions/attributes to VCD files.  This is to keep FST
+		attributes from making VCD files unparseable with other tools.
+		Fix in FsdbReader interface for version 1.x files.
+		Many warnings fixes found from gcc -Wextra flag.
+		Fixed thread-unsafe static allocations in fstapi.c.
+
diff --git a/LICENSE.TXT b/LICENSE.TXT
index b598654..03ce659 100644
--- a/LICENSE.TXT
+++ b/LICENSE.TXT
@@ -1,6 +1,6 @@
 ##########################################################################
 
-GTKWave 3.3.50 Wave Viewer is Copyright (C) 1999-2013 Tony Bybell.  
+GTKWave 3.3.52 Wave Viewer is Copyright (C) 1999-2013 Tony Bybell.  
 Portions of GTKWave are Copyright (C) 1999-2013 Udi Finkelstein. 
 Context support is Copyright (C) 2007-2013 Kermin Elliott Fleming.
 Trace group support is  Copyright (C) 2009-2013 Donald Baltus.
diff --git a/Makefile.in b/Makefile.in
index 7a78980..27afc5e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -194,6 +194,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -236,6 +237,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/configure b/configure
index 2890ed4..74ff847 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for gtkwave 3.3.51.
+# Generated by GNU Autoconf 2.69 for gtkwave 3.3.52.
 #
 # Report bugs to <bybell at rocketmail.com>.
 #
@@ -580,8 +580,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='gtkwave'
 PACKAGE_TARNAME='gtkwave'
-PACKAGE_VERSION='3.3.51'
-PACKAGE_STRING='gtkwave 3.3.51'
+PACKAGE_VERSION='3.3.52'
+PACKAGE_STRING='gtkwave 3.3.52'
 PACKAGE_BUGREPORT='bybell at rocketmail.com'
 PACKAGE_URL=''
 
@@ -629,6 +629,7 @@ LTLIBOBJS
 TK_LDADD
 TCL_DEFADD
 TCL_LDADD
+MINGW_LDADD
 POW_LIB
 LIBOBJS
 ALLOCA
@@ -661,6 +662,7 @@ LIBZ_LDADD
 LIBZ_CFLAGS
 GPERF
 EXTLOAD_CFLAGS
+EXTDEBUG4
 EXTDEBUG3
 EXTDEBUG2
 EXTDEBUG
@@ -1382,7 +1384,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures gtkwave 3.3.51 to adapt to many kinds of systems.
+\`configure' configures gtkwave 3.3.52 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1448,7 +1450,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of gtkwave 3.3.51:";;
+     short | recursive ) echo "Configuration of gtkwave 3.3.52:";;
    esac
   cat <<\_ACEOF
 
@@ -1594,7 +1596,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-gtkwave configure 3.3.51
+gtkwave configure 3.3.52
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2238,7 +2240,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by gtkwave $as_me 3.3.51, which was
+It was created by gtkwave $as_me 3.3.52, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -3105,7 +3107,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='gtkwave'
- VERSION='3.3.51'
+ VERSION='3.3.52'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -6372,6 +6374,53 @@ if test "$EXTDEBUG3" != "notfound" ; then
 	EXTLOAD_CFLAGS="$EXTLOAD_CFLAGS -DEXT2CONV_PATH=\\\"$EXTDEBUG3\\\" -DEXT2LOAD_SUFFIX=\\\"vpd\\\""
 fi
 
+# enables .wlf as input filetype in vcd2fst, and also gtkwave -o
+
+# Extract the first word of "wlf2vcd", so it can be a program name with args.
+set dummy wlf2vcd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_EXTDEBUG4+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $EXTDEBUG4 in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_EXTDEBUG4="$EXTDEBUG4" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_EXTDEBUG4="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_EXTDEBUG4" && ac_cv_path_EXTDEBUG4="notfound"
+  ;;
+esac
+fi
+EXTDEBUG4=$ac_cv_path_EXTDEBUG4
+if test -n "$EXTDEBUG4"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $EXTDEBUG4" >&5
+$as_echo "$EXTDEBUG4" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "$EXTDEBUG4" != "notfound" ; then
+	EXTLOAD_CFLAGS="$EXTLOAD_CFLAGS -DEXT3CONV_PATH=\\\"$EXTDEBUG4\\\" -DEXT3LOAD_SUFFIX=\\\"wlf\\\""
+fi
+
 
 
 #
@@ -10176,6 +10225,8 @@ if test "X$OSTYPE" = "Xdarwin" ; then
 	fi
 else
 if test "X$OSTYPE" = "Xmsys" ; then
+# add library for common dialog found in file.c
+	MINGW_LDADD="-lcomdlg32"
 # skip Tcl_CreateInterp check on mingw (until we figure out)...
 	if test "X$STUBIFY" = "Xyes" ; then
 	TCL_DEFADD="-DHAVE_LIBTCL -DWAVE_TCL_STUBIFY -DUSE_TCL_STUBS -DUSE_TK_STUBS"
@@ -10312,6 +10363,7 @@ ac_config_files="$ac_config_files Makefile doc/Makefile contrib/Makefile contrib
   LIBS                  : $LIBS
   INLINE_ASM            : $INLINE_ASM
 
+  MINGW_LDADD           : $MINGW_LDADD
   GTK_MAC_CFLAGS        : $GTK_MAC_CFLAGS
   GTK_MAC_LIBS          : $GTK_MAC_LIBS
   COCOA_GTK_CFLAGS      : $COCOA_GTK_CFLAGS
@@ -10373,6 +10425,7 @@ $as_echo "$as_me:
   LIBS                  : $LIBS
   INLINE_ASM            : $INLINE_ASM
 
+  MINGW_LDADD           : $MINGW_LDADD
   GTK_MAC_CFLAGS        : $GTK_MAC_CFLAGS
   GTK_MAC_LIBS          : $GTK_MAC_LIBS
   COCOA_GTK_CFLAGS      : $COCOA_GTK_CFLAGS
@@ -10931,7 +10984,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by gtkwave $as_me 3.3.51, which was
+This file was extended by gtkwave $as_me 3.3.52, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -10997,7 +11050,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-gtkwave config.status 3.3.51
+gtkwave config.status 3.3.52
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
diff --git a/configure.ac b/configure.ac
index ac6f9d7..4f70ca5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT(gtkwave, 3.3.51, bybell at rocketmail.com)
+AC_INIT(gtkwave, 3.3.52, bybell at rocketmail.com)
 AC_CONFIG_SRCDIR([src/vcd.c])
 AM_INIT_AUTOMAKE
 AC_CONFIG_HEADER([config.h])
@@ -451,6 +451,13 @@ if test "$EXTDEBUG3" != "notfound" ; then
 	EXTLOAD_CFLAGS="$EXTLOAD_CFLAGS -DEXT2CONV_PATH=\\\"$EXTDEBUG3\\\" -DEXT2LOAD_SUFFIX=\\\"vpd\\\""
 fi
 
+# enables .wlf as input filetype in vcd2fst, and also gtkwave -o
+
+AC_PATH_PROG(EXTDEBUG4, [wlf2vcd], [notfound])
+if test "$EXTDEBUG4" != "notfound" ; then
+	EXTLOAD_CFLAGS="$EXTLOAD_CFLAGS -DEXT3CONV_PATH=\\\"$EXTDEBUG4\\\" -DEXT3LOAD_SUFFIX=\\\"wlf\\\""
+fi
+
 AC_SUBST(EXTLOAD_CFLAGS)
 
 #
@@ -806,6 +813,8 @@ if test "X$OSTYPE" = "Xdarwin" ; then
 	fi
 else
 if test "X$OSTYPE" = "Xmsys" ; then
+# add library for common dialog found in file.c
+	MINGW_LDADD="-lcomdlg32"
 # skip Tcl_CreateInterp check on mingw (until we figure out)...
 	if test "X$STUBIFY" = "Xyes" ; then
 	TCL_DEFADD="-DHAVE_LIBTCL -DWAVE_TCL_STUBIFY -DUSE_TCL_STUBS -DUSE_TK_STUBS"
@@ -842,7 +851,7 @@ fi
 fi
 fi
 
-
+AC_SUBST(MINGW_LDADD)
 AC_SUBST(TCL_LDADD)
 AC_SUBST(TCL_DEFADD)
 AC_SUBST(TK_LDADD)
@@ -942,6 +951,7 @@ AC_MSG_NOTICE([
   LIBS                  : $LIBS
   INLINE_ASM            : $INLINE_ASM
 
+  MINGW_LDADD           : $MINGW_LDADD
   GTK_MAC_CFLAGS        : $GTK_MAC_CFLAGS
   GTK_MAC_LIBS          : $GTK_MAC_LIBS
   COCOA_GTK_CFLAGS      : $COCOA_GTK_CFLAGS
diff --git a/contrib/Makefile.in b/contrib/Makefile.in
index aa10584..239dde3 100644
--- a/contrib/Makefile.in
+++ b/contrib/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/bundle_for_osx/Info-gtkwave.plist b/contrib/bundle_for_osx/Info-gtkwave.plist
index dcd3f65..e27bd91 100644
--- a/contrib/bundle_for_osx/Info-gtkwave.plist
+++ b/contrib/bundle_for_osx/Info-gtkwave.plist
@@ -8,7 +8,7 @@
     <key>CFBundleExecutable</key>
     <string>gtkwave</string>
     <key>CFBundleGetInfoString</key>
-    <string>3.3.51, (C) 1999-2013 Tony Bybell http://gtkwave.sourceforge.net</string>
+    <string>3.3.52, (C) 1999-2013 Tony Bybell http://gtkwave.sourceforge.net</string>
     <key>CFBundleIconFile</key>
     <string>gtkwave.icns</string>
     <key>CFBundleIdentifier</key>
@@ -18,11 +18,11 @@
     <key>CFBundlePackageType</key>
     <string>APPL</string>
     <key>CFBundleShortVersionString</key>
-    <string>3.3.51</string>
+    <string>3.3.52</string>
     <key>CFBundleSignature</key>
     <string>????</string>
     <key>CFBundleVersion</key>
-    <string>3.3.51</string>
+    <string>3.3.52</string>
     <key>NSHumanReadableCopyright</key>
     <string>Copyright 1999 - 2013 Tony Bybell, GNU General Public License.</string>
     <key>LSMinimumSystemVersion</key>
diff --git a/contrib/bundle_for_osx/Makefile.in b/contrib/bundle_for_osx/Makefile.in
index 21c839a..edda6fc 100644
--- a/contrib/bundle_for_osx/Makefile.in
+++ b/contrib/bundle_for_osx/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/fst_jni/Makefile.am b/contrib/fst_jni/Makefile.am
index 45a3553..69505ae 100644
--- a/contrib/fst_jni/Makefile.am
+++ b/contrib/fst_jni/Makefile.am
@@ -21,6 +21,7 @@ EXTRA_DIST= \
 	fstVarDir.java \
 	fstVarType.java \
 	fstWriter.java \
+	fstWriterPackType.java \
 	Main.java \
 	zzz_test.csh
 
diff --git a/contrib/fst_jni/Makefile.in b/contrib/fst_jni/Makefile.in
index e9ac76c..b0629f0 100644
--- a/contrib/fst_jni/Makefile.in
+++ b/contrib/fst_jni/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
@@ -245,6 +247,7 @@ EXTRA_DIST = \
 	fstVarDir.java \
 	fstVarType.java \
 	fstWriter.java \
+	fstWriterPackType.java \
 	Main.java \
 	zzz_test.csh
 
diff --git a/contrib/fst_jni/fstAPI.c b/contrib/fst_jni/fstAPI.c
index 6e974f2..ab21f6c 100644
--- a/contrib/fst_jni/fstAPI.c
+++ b/contrib/fst_jni/fstAPI.c
@@ -459,6 +459,13 @@ fstReaderSetLimitTimeRange((void *)(long)ctx, (uint64_t)start_time, (uint64_t)en
 }
 
 
+JNIEXPORT void JNICALL Java_fstAPI_fstReaderSetVcdExtensions
+  (JNIEnv *env, jobject obj, jlong ctx, jboolean enable)
+{
+fstReaderSetVcdExtensions((void *)(long)ctx, (int)enable);
+}
+
+
 JNIEXPORT jint JNICALL Java_fstAPI_fstReaderGetNumberDumpActivityChanges
   (JNIEnv *env, jobject obj, jlong ctx)
 {
diff --git a/contrib/fst_jni/fstAPI.h b/contrib/fst_jni/fstAPI.h
index dd22430..085b018 100644
--- a/contrib/fst_jni/fstAPI.h
+++ b/contrib/fst_jni/fstAPI.h
@@ -401,6 +401,14 @@ JNIEXPORT void JNICALL Java_fstAPI_fstReaderSetLimitTimeRange
 
 /*
  * Class:     fstAPI
+ * Method:    fstReaderSetVcdExtensions
+ * Signature: (JZ)V
+ */
+JNIEXPORT void JNICALL Java_fstAPI_fstReaderSetVcdExtensions
+  (JNIEnv *, jobject, jlong, jboolean);
+
+/*
+ * Class:     fstAPI
  * Method:    fstReaderGetNumberDumpActivityChanges
  * Signature: (J)I
  */
diff --git a/contrib/fst_jni/fstAPI.java b/contrib/fst_jni/fstAPI.java
index 4963431..a46b370 100644
--- a/contrib/fst_jni/fstAPI.java
+++ b/contrib/fst_jni/fstAPI.java
@@ -91,6 +91,7 @@ protected native long fstReaderGetValueChangeSectionCount(long ctx);
 protected native boolean fstReaderGetFseekFailed(long ctx);
 protected native void fstReaderSetUnlimitedTimeRange(long ctx);
 protected native void fstReaderSetLimitTimeRange(long ctx, long start_time, long end_time);
+protected native void fstReaderSetVcdExtensions(long ctx, boolean enable);
 protected native int fstReaderGetNumberDumpActivityChanges(long ctx);
 protected native long fstReaderGetDumpActivityChangeTime(long ctx, int idx);
 protected native boolean fstReaderGetFacProcessMask(long ctx, int facidx); 
diff --git a/contrib/fst_jni/fstReader.java b/contrib/fst_jni/fstReader.java
index 1c284d2..e2667fe 100644
--- a/contrib/fst_jni/fstReader.java
+++ b/contrib/fst_jni/fstReader.java
@@ -73,6 +73,7 @@ public String 	fstReaderPushScope(String nam, long user_info) { return(fstReader
 public void 	fstReaderResetScope() { fstReaderResetScope(ctx); }
 public void 	fstReaderSetFacProcessMaskAll() { fstReaderSetFacProcessMaskAll(ctx); }
 public void 	fstReaderSetFacProcessMask(int facidx) { fstReaderSetFacProcessMask(ctx, facidx); }
+public void     fstReaderSetVcdExtensions(boolean enable) { fstReaderSetVcdExtensions(ctx, enable); }
 public void 	fstReaderSetLimitTimeRange(long start_time, long end_time) { fstReaderSetLimitTimeRange(ctx, start_time, end_time); }
 public void 	fstReaderSetUnlimitedTimeRange() { fstReaderSetUnlimitedTimeRange(ctx); }
 
diff --git a/contrib/fst_jni/fstWriterPackType.java b/contrib/fst_jni/fstWriterPackType.java
new file mode 100644
index 0000000..6167c54
--- /dev/null
+++ b/contrib/fst_jni/fstWriterPackType.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2013 Tony Bybell.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+public class fstWriterPackType
+{
+private fstWriterPackType( ) { }
+
+public static final int FST_WR_PT_ZLIB = 0;
+public static final int FST_WR_PT_FASTLZ = 1;
+public static final int FST_WR_PT_LZ4 = 2;
+};
diff --git a/contrib/fst_jni/zzz_test.csh b/contrib/fst_jni/zzz_test.csh
index ef0f8e2..2098515 100755
--- a/contrib/fst_jni/zzz_test.csh
+++ b/contrib/fst_jni/zzz_test.csh
@@ -17,6 +17,7 @@ javac \
 	fstVarDir.java \
 	fstVarType.java \
 	fstWriter.java \
+	fstWriterPackType.java \
 	fstReader.java
 			 
 javac \
diff --git a/contrib/pccts/IBM_VISUAL_AGE_PROJECTS/Makefile.in b/contrib/pccts/IBM_VISUAL_AGE_PROJECTS/Makefile.in
index 34e86f2..df70ac7 100644
--- a/contrib/pccts/IBM_VISUAL_AGE_PROJECTS/Makefile.in
+++ b/contrib/pccts/IBM_VISUAL_AGE_PROJECTS/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/Makefile.in b/contrib/pccts/Makefile.in
index 8b68ec4..67ece1f 100644
--- a/contrib/pccts/Makefile.in
+++ b/contrib/pccts/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/antlr/Makefile.in b/contrib/pccts/antlr/Makefile.in
index 696edbf..89cb943 100644
--- a/contrib/pccts/antlr/Makefile.in
+++ b/contrib/pccts/antlr/Makefile.in
@@ -159,6 +159,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -201,6 +202,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/dlg/Makefile.in b/contrib/pccts/dlg/Makefile.in
index 8ac539c..6b181e4 100644
--- a/contrib/pccts/dlg/Makefile.in
+++ b/contrib/pccts/dlg/Makefile.in
@@ -157,6 +157,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -199,6 +200,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/h/Makefile.in b/contrib/pccts/h/Makefile.in
index 4d03526..2c3cb93 100644
--- a/contrib/pccts/h/Makefile.in
+++ b/contrib/pccts/h/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/sorcerer/Makefile.in b/contrib/pccts/sorcerer/Makefile.in
index ddbc8b1..f3af7ce 100644
--- a/contrib/pccts/sorcerer/Makefile.in
+++ b/contrib/pccts/sorcerer/Makefile.in
@@ -199,6 +199,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -241,6 +242,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/sorcerer/h/Makefile.in b/contrib/pccts/sorcerer/h/Makefile.in
index e70e491..01f1fc7 100644
--- a/contrib/pccts/sorcerer/h/Makefile.in
+++ b/contrib/pccts/sorcerer/h/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/sorcerer/lib/Makefile.in b/contrib/pccts/sorcerer/lib/Makefile.in
index 3de0c4f..ed45b7d 100644
--- a/contrib/pccts/sorcerer/lib/Makefile.in
+++ b/contrib/pccts/sorcerer/lib/Makefile.in
@@ -114,6 +114,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -156,6 +157,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/sorcerer/test/Makefile.in b/contrib/pccts/sorcerer/test/Makefile.in
index 621cdde..2df23f0 100644
--- a/contrib/pccts/sorcerer/test/Makefile.in
+++ b/contrib/pccts/sorcerer/test/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/sorcerer/test/test7/Makefile.in b/contrib/pccts/sorcerer/test/test7/Makefile.in
index d822901..de1772e 100644
--- a/contrib/pccts/sorcerer/test/test7/Makefile.in
+++ b/contrib/pccts/sorcerer/test/test7/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/sorcerer/testcpp/Makefile.in b/contrib/pccts/sorcerer/testcpp/Makefile.in
index 998d14b..55e23ba 100644
--- a/contrib/pccts/sorcerer/testcpp/Makefile.in
+++ b/contrib/pccts/sorcerer/testcpp/Makefile.in
@@ -183,6 +183,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -225,6 +226,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/support/DECmms/Makefile.in b/contrib/pccts/support/DECmms/Makefile.in
index 682a7c3..7f310f8 100644
--- a/contrib/pccts/support/DECmms/Makefile.in
+++ b/contrib/pccts/support/DECmms/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/support/Makefile.in b/contrib/pccts/support/Makefile.in
index 717f35c..1ae8fc7 100644
--- a/contrib/pccts/support/Makefile.in
+++ b/contrib/pccts/support/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/support/genmk/Makefile.in b/contrib/pccts/support/genmk/Makefile.in
index aa6f4da..fed39f0 100644
--- a/contrib/pccts/support/genmk/Makefile.in
+++ b/contrib/pccts/support/genmk/Makefile.in
@@ -151,6 +151,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -193,6 +194,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/support/rexpr/Makefile.in b/contrib/pccts/support/rexpr/Makefile.in
index aaa500c..7ca285f 100644
--- a/contrib/pccts/support/rexpr/Makefile.in
+++ b/contrib/pccts/support/rexpr/Makefile.in
@@ -151,6 +151,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -193,6 +194,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/support/set/Makefile.in b/contrib/pccts/support/set/Makefile.in
index dd2cd1a..aa2a585 100644
--- a/contrib/pccts/support/set/Makefile.in
+++ b/contrib/pccts/support/set/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/support/sym/Makefile.in b/contrib/pccts/support/sym/Makefile.in
index 018f8b3..26211af 100644
--- a/contrib/pccts/support/sym/Makefile.in
+++ b/contrib/pccts/support/sym/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/pccts/testcpp/Makefile.in b/contrib/pccts/testcpp/Makefile.in
index 424a226..63b56b4 100644
--- a/contrib/pccts/testcpp/Makefile.in
+++ b/contrib/pccts/testcpp/Makefile.in
@@ -110,6 +110,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -152,6 +153,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/contrib/rtlbrowse/Makefile.am b/contrib/rtlbrowse/Makefile.am
index 6deaf62..aaf4452 100644
--- a/contrib/rtlbrowse/Makefile.am
+++ b/contrib/rtlbrowse/Makefile.am
@@ -17,10 +17,14 @@ bin_PROGRAMS= rtlbrowse
 
 rtlbrowse_SOURCES = definehash.c fgetdynamic.c fgetdynamic.h \
 	logfile.c splay.c tcl_helper.c tree_widget.c \
+	$(srcdir)/../../src/helpers/fst/lz4.c \
+	$(srcdir)/../../src/helpers/fst/lz4.h \
 	$(srcdir)/../../src/helpers/fst/fastlz.c \
+	$(srcdir)/../../src/helpers/fst/fastlz.h \
 	$(srcdir)/../../src/helpers/fst/fstapi.c \
-	stem_recurse.c jrb.c jrb.h $(srcdir)/../../src/helpers/vzt_read.c \
-	$(srcdir)/../../src/helpers/lxt2_read.c splay.h \
+	$(srcdir)/../../src/helpers/fst/fstapi.h \
+	stem_recurse.c jrb.c jrb.h $(srcdir)/../../src/helpers/vzt_read.c $(srcdir)/../../src/helpers/vzt_read.h \
+	$(srcdir)/../../src/helpers/lxt2_read.c $(srcdir)/../../src/helpers/lxt2_read.h splay.h \
 	vlex.l vlex.h wavelink.h $(srcdir)/../../src/liblzma/LzmaLib.c $(srcdir)/../../src/liblzma/LzmaLib.h
 
 LDADD= $(GTK_LIBS) $(LIBZ_LDADD) $(LIBBZ2_LDADD) $(LIBLZMA_LDADD) $(AET2_LDADD) \
diff --git a/contrib/rtlbrowse/Makefile.in b/contrib/rtlbrowse/Makefile.in
index 7ad40c9..f15a44a 100644
--- a/contrib/rtlbrowse/Makefile.in
+++ b/contrib/rtlbrowse/Makefile.in
@@ -64,9 +64,10 @@ am__installdirs = "$(DESTDIR)$(bindir)"
 PROGRAMS = $(bin_PROGRAMS)
 am_rtlbrowse_OBJECTS = definehash.$(OBJEXT) fgetdynamic.$(OBJEXT) \
 	logfile.$(OBJEXT) splay.$(OBJEXT) tcl_helper.$(OBJEXT) \
-	tree_widget.$(OBJEXT) fastlz.$(OBJEXT) fstapi.$(OBJEXT) \
-	stem_recurse.$(OBJEXT) jrb.$(OBJEXT) vzt_read.$(OBJEXT) \
-	lxt2_read.$(OBJEXT) vlex.$(OBJEXT) LzmaLib.$(OBJEXT)
+	tree_widget.$(OBJEXT) lz4.$(OBJEXT) fastlz.$(OBJEXT) \
+	fstapi.$(OBJEXT) stem_recurse.$(OBJEXT) jrb.$(OBJEXT) \
+	vzt_read.$(OBJEXT) lxt2_read.$(OBJEXT) vlex.$(OBJEXT) \
+	LzmaLib.$(OBJEXT)
 rtlbrowse_OBJECTS = $(am_rtlbrowse_OBJECTS)
 rtlbrowse_LDADD = $(LDADD)
 am__DEPENDENCIES_1 =
@@ -215,6 +216,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -257,6 +259,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
@@ -342,10 +345,14 @@ LIBLZMA_CFLAGS = -I$(srcdir)/../../src/liblzma $(LIBXZ_CFLAGS)
 LIBLZMA_LDADD = $(LIBXZ_LDADD)
 rtlbrowse_SOURCES = definehash.c fgetdynamic.c fgetdynamic.h \
 	logfile.c splay.c tcl_helper.c tree_widget.c \
+	$(srcdir)/../../src/helpers/fst/lz4.c \
+	$(srcdir)/../../src/helpers/fst/lz4.h \
 	$(srcdir)/../../src/helpers/fst/fastlz.c \
+	$(srcdir)/../../src/helpers/fst/fastlz.h \
 	$(srcdir)/../../src/helpers/fst/fstapi.c \
-	stem_recurse.c jrb.c jrb.h $(srcdir)/../../src/helpers/vzt_read.c \
-	$(srcdir)/../../src/helpers/lxt2_read.c splay.h \
+	$(srcdir)/../../src/helpers/fst/fstapi.h \
+	stem_recurse.c jrb.c jrb.h $(srcdir)/../../src/helpers/vzt_read.c $(srcdir)/../../src/helpers/vzt_read.h \
+	$(srcdir)/../../src/helpers/lxt2_read.c $(srcdir)/../../src/helpers/lxt2_read.h splay.h \
 	vlex.l vlex.h wavelink.h $(srcdir)/../../src/liblzma/LzmaLib.c $(srcdir)/../../src/liblzma/LzmaLib.h
 
 LDADD = $(GTK_LIBS) $(LIBZ_LDADD) $(LIBBZ2_LDADD) $(LIBLZMA_LDADD) $(AET2_LDADD) \
@@ -453,6 +460,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/jrb.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/logfile.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lxt2_read.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lz4.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/splay.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/stem_recurse.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/tcl_helper.Po at am__quote@
@@ -474,6 +482,20 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
+lz4.o: $(srcdir)/../../src/helpers/fst/lz4.c
+ at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lz4.o -MD -MP -MF $(DEPDIR)/lz4.Tpo -c -o lz4.o `test -f '$(srcdir)/../../src/helpers/fst/lz4.c' || echo '$(srcdir)/'`$(srcdir)/../../src/helpers/fst/lz4.c
+ at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/lz4.Tpo $(DEPDIR)/lz4.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(srcdir)/../../src/helpers/fst/lz4.c' object='lz4.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lz4.o `test -f '$(srcdir)/../../src/helpers/fst/lz4.c' || echo '$(srcdir)/'`$(srcdir)/../../src/helpers/fst/lz4.c
+
+lz4.obj: $(srcdir)/../../src/helpers/fst/lz4.c
+ at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lz4.obj -MD -MP -MF $(DEPDIR)/lz4.Tpo -c -o lz4.obj `if test -f '$(srcdir)/../../src/helpers/fst/lz4.c'; then $(CYGPATH_W) '$(srcdir)/../../src/helpers/fst/lz4.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../../src/helpers/fst/lz4.c'; fi`
+ at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/lz4.Tpo $(DEPDIR)/lz4.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(srcdir)/../../src/helpers/fst/lz4.c' object='lz4.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lz4.obj `if test -f '$(srcdir)/../../src/helpers/fst/lz4.c'; then $(CYGPATH_W) '$(srcdir)/../../src/helpers/fst/lz4.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../../src/helpers/fst/lz4.c'; fi`
+
 fastlz.o: $(srcdir)/../../src/helpers/fst/fastlz.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT fastlz.o -MD -MP -MF $(DEPDIR)/fastlz.Tpo -c -o fastlz.o `test -f '$(srcdir)/../../src/helpers/fst/fastlz.c' || echo '$(srcdir)/'`$(srcdir)/../../src/helpers/fst/fastlz.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/fastlz.Tpo $(DEPDIR)/fastlz.Po
diff --git a/contrib/vermin/Makefile.in b/contrib/vermin/Makefile.in
index ea8072b..9a867b4 100644
--- a/contrib/vermin/Makefile.in
+++ b/contrib/vermin/Makefile.in
@@ -155,6 +155,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -197,6 +198,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/doc/Makefile.in b/doc/Makefile.in
index a7ce848..f3aabcf 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -141,6 +141,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -183,6 +184,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/doc/gtkwave.odt b/doc/gtkwave.odt
index bc41927..99b7ae8 100644
Binary files a/doc/gtkwave.odt and b/doc/gtkwave.odt differ
diff --git a/examples/Makefile.in b/examples/Makefile.in
index 9b029cf..a0b92d8 100644
--- a/examples/Makefile.in
+++ b/examples/Makefile.in
@@ -141,6 +141,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -183,6 +184,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/man/Makefile.in b/man/Makefile.in
index a64f542..f6cadff 100644
--- a/man/Makefile.in
+++ b/man/Makefile.in
@@ -143,6 +143,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -185,6 +186,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/man/fst2vcd.1 b/man/fst2vcd.1
index 91aa0cf..d4445e9 100644
--- a/man/fst2vcd.1
+++ b/man/fst2vcd.1
@@ -1,4 +1,4 @@
-.TH "FST2VCD" "1" "3.3.29" "Anthony Bybell" "Filetype Conversion"
+.TH "FST2VCD" "1" "3.3.52" "Anthony Bybell" "Filetype Conversion"
 .SH "NAME"
 .LP 
 fst2vcd \- Converts FST files to VCD
@@ -18,6 +18,9 @@ Specify FST input filename.
 \fB\-o,\-\-output\fR <\fIfilename\fP>
 Specify optional VCD output filename.
 .TP
+\fB\-e,\-\-extensions\Fr
+Emit FST extensions to VCD.  Enabling this may create VCD files unreadable by other tools.  This is generally intended to be used as a debugging tool when developing FST writer interfaces to simulators.
+.TP
 \fB\-h,\-\-help\fR
 Display help then exit.
 
diff --git a/man/vcd2fst.1 b/man/vcd2fst.1
index 2ef9929..b58a5f5 100644
--- a/man/vcd2fst.1
+++ b/man/vcd2fst.1
@@ -1,4 +1,4 @@
-.TH "VCD2FST" "1" "3.3.35" "Anthony Bybell" "Filetype Conversion"
+.TH "VCD2FST" "1" "3.3.52" "Anthony Bybell" "Filetype Conversion"
 .SH "NAME"
 .LP 
 vcd2fst \- Converts VCD files to FST files
@@ -20,6 +20,9 @@ Specify FST output filename.
 \fB\-F,\-\-fastpack\fR
 Indicates that fastlz should be used instead of gzip for block data.
 .TP 
+\fB\-4,\-\-fourpack\fR
+Indicates that LZ4 should be used instead of gzip/fastlz for block data and hierarchy data.
+.TP 
 \fB\-c,\-\-compress\fR
 Indicates that the entire file should be run through gzip on close.  This
 results in much smaller files at the expense of a one-time decompression
diff --git a/share/Makefile.in b/share/Makefile.in
index 917b281..a9c7ce5 100644
--- a/share/Makefile.in
+++ b/share/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/applications/Makefile.in b/share/applications/Makefile.in
index 4716504..e1f180b 100644
--- a/share/applications/Makefile.in
+++ b/share/applications/Makefile.in
@@ -140,6 +140,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -182,6 +183,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/Makefile.in b/share/icons/Makefile.in
index cead50d..e33e707 100644
--- a/share/icons/Makefile.in
+++ b/share/icons/Makefile.in
@@ -200,6 +200,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -242,6 +243,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/16x16/Makefile.in b/share/icons/gnome/16x16/Makefile.in
index 4a8b5dd..d7c1623 100644
--- a/share/icons/gnome/16x16/Makefile.in
+++ b/share/icons/gnome/16x16/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/16x16/mimetypes/Makefile.in b/share/icons/gnome/16x16/mimetypes/Makefile.in
index daca6d7..89d0114 100644
--- a/share/icons/gnome/16x16/mimetypes/Makefile.in
+++ b/share/icons/gnome/16x16/mimetypes/Makefile.in
@@ -140,6 +140,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -182,6 +183,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/32x32/Makefile.in b/share/icons/gnome/32x32/Makefile.in
index 11fb5c2..3fd1a18 100644
--- a/share/icons/gnome/32x32/Makefile.in
+++ b/share/icons/gnome/32x32/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/32x32/mimetypes/Makefile.in b/share/icons/gnome/32x32/mimetypes/Makefile.in
index 5e7e4f8..2272602 100644
--- a/share/icons/gnome/32x32/mimetypes/Makefile.in
+++ b/share/icons/gnome/32x32/mimetypes/Makefile.in
@@ -140,6 +140,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -182,6 +183,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/48x48/Makefile.in b/share/icons/gnome/48x48/Makefile.in
index 7b5b1da..00ad668 100644
--- a/share/icons/gnome/48x48/Makefile.in
+++ b/share/icons/gnome/48x48/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/48x48/mimetypes/Makefile.in b/share/icons/gnome/48x48/mimetypes/Makefile.in
index 9bd4644..f3574d3 100644
--- a/share/icons/gnome/48x48/mimetypes/Makefile.in
+++ b/share/icons/gnome/48x48/mimetypes/Makefile.in
@@ -140,6 +140,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -182,6 +183,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/icons/gnome/Makefile.in b/share/icons/gnome/Makefile.in
index 7fc6163..7388dc0 100644
--- a/share/icons/gnome/Makefile.in
+++ b/share/icons/gnome/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/mime/Makefile.in b/share/mime/Makefile.in
index 8472dfb..0036b9d 100644
--- a/share/mime/Makefile.in
+++ b/share/mime/Makefile.in
@@ -170,6 +170,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -212,6 +213,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/share/mime/packages/Makefile.in b/share/mime/packages/Makefile.in
index 727c81c..2626ced 100644
--- a/share/mime/packages/Makefile.in
+++ b/share/mime/packages/Makefile.in
@@ -140,6 +140,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -182,6 +183,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/src/Makefile.am b/src/Makefile.am
index b5644ad..f7c0af4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,7 +52,7 @@ gtkwave_SOURCES= \
 	vcd_partial.c vcd_recoder.c vcd_saver.c vcd_saver.h version.h vlist.c vlist.h vzt.c vzt.h wavealloca.h \
 	wavewindow.c zoombuttons.c
 
-gtkwave_LDADD= $(LIBCOCOA_LDADD) $(GTK_LIBS) $(LIBLZMA_LDADD) $(LIBZ_LDADD) $(LIBBZ2_LDADD) $(LIBFST_LDADD) $(AET2_LDADD) $(FSDB_LDADD) $(TCL_LDADD) $(TK_LDADD) $(LIBJUDY_LDADD) $(GTK_MAC_LIBS) $(GCONF_LIBS) $(GTK_UNIX_PRINT_LIBS)
+gtkwave_LDADD= $(LIBCOCOA_LDADD) $(GTK_LIBS) $(LIBLZMA_LDADD) $(LIBZ_LDADD) $(LIBBZ2_LDADD) $(LIBFST_LDADD) $(AET2_LDADD) $(FSDB_LDADD) $(TCL_LDADD) $(TK_LDADD) $(LIBJUDY_LDADD) $(GTK_MAC_LIBS) $(GCONF_LIBS) $(GTK_UNIX_PRINT_LIBS) $(MINGW_LDADD)
 gtkwave_LDFLAGS = $(COCOA_GTK_LDFLAGS)
 
 twinwave_SOURCES= twinwave.c
diff --git a/src/Makefile.in b/src/Makefile.in
index 8bc3587..85809ab 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -101,7 +101,7 @@ gtkwave_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1)
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 gtkwave_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(gtkwave_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_twinwave_OBJECTS = twinwave.$(OBJEXT)
@@ -253,6 +253,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -295,6 +296,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
@@ -407,7 +409,7 @@ gtkwave_SOURCES = \
 	vcd_partial.c vcd_recoder.c vcd_saver.c vcd_saver.h version.h vlist.c vlist.h vzt.c vzt.h wavealloca.h \
 	wavewindow.c zoombuttons.c
 
-gtkwave_LDADD = $(LIBCOCOA_LDADD) $(GTK_LIBS) $(LIBLZMA_LDADD) $(LIBZ_LDADD) $(LIBBZ2_LDADD) $(LIBFST_LDADD) $(AET2_LDADD) $(FSDB_LDADD) $(TCL_LDADD) $(TK_LDADD) $(LIBJUDY_LDADD) $(GTK_MAC_LIBS) $(GCONF_LIBS) $(GTK_UNIX_PRINT_LIBS)
+gtkwave_LDADD = $(LIBCOCOA_LDADD) $(GTK_LIBS) $(LIBLZMA_LDADD) $(LIBZ_LDADD) $(LIBBZ2_LDADD) $(LIBFST_LDADD) $(AET2_LDADD) $(FSDB_LDADD) $(TCL_LDADD) $(TK_LDADD) $(LIBJUDY_LDADD) $(GTK_MAC_LIBS) $(GCONF_LIBS) $(GTK_UNIX_PRINT_LIBS) $(MINGW_LDADD)
 gtkwave_LDFLAGS = $(COCOA_GTK_LDFLAGS)
 twinwave_SOURCES = twinwave.c
 twinwave_LDADD = $(GTK_LIBS) $(GTK_MAC_LIBS) $(GCONF_LIBS)
diff --git a/src/cocoa/Makefile.in b/src/cocoa/Makefile.in
index 91aceff..1afd04a 100644
--- a/src/cocoa/Makefile.in
+++ b/src/cocoa/Makefile.in
@@ -163,6 +163,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -205,6 +206,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/src/extload.c b/src/extload.c
index 18cff3c..c259f87 100644
--- a/src/extload.c
+++ b/src/extload.c
@@ -782,18 +782,23 @@ if(GLOBALS->extload_ffr_ctx)
 		}
 
 	attempt_count++;
+	gs = fsdbReaderGetStatistics(GLOBALS->extload_ffr_ctx);
+	if(gs)
+		{
+		GLOBALS->numfacs = gs->varCount;
+		free(gs);
+		success_count++;
+		}
+
+	attempt_count++;
 	max_idcode = fsdbReaderGetMaxVarIdcode(GLOBALS->extload_ffr_ctx);
 	if(max_idcode)
 		{
 		success_count++;
 		}
-	
-	attempt_count++;
-	gs = fsdbReaderGetStatistics(GLOBALS->extload_ffr_ctx);
-	if(gs)
+	else
 		{
-		GLOBALS->numfacs = gs->varCount;
-		free(gs);
+		max_idcode = GLOBALS->numfacs; /* for 1.x format files */
 		success_count++;
 		}
 
diff --git a/src/file.c b/src/file.c
index a1e67c7..58432f4 100644
--- a/src/file.c
+++ b/src/file.c
@@ -1,5 +1,5 @@
 /* 
- * Copyright (c) Tony Bybell 1999-2009.
+ * Copyright (c) Tony Bybell 1999-2013.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -21,6 +21,10 @@
 #include <cocoa_misc.h>
 #endif
 
+#if defined __MINGW32__
+#include <windows.h>
+#endif
+
 #if GTK_CHECK_VERSION(2,4,0)
 
 #ifndef MAC_INTEGRATION
@@ -136,13 +140,83 @@ gtkwave_main_iteration();
 if(GLOBALS->bad_cleanup_file_c_1) GLOBALS->bad_cleanup_file_c_1();
 }
 
-void fileselbox_old(char *title, char **filesel_path, GtkSignalFunc ok_func, GtkSignalFunc notok_func, char *pattn)
+void fileselbox_old(char *title, char **filesel_path, GtkSignalFunc ok_func, GtkSignalFunc notok_func, char *pattn, int is_writemode)
 {
+#if defined __MINGW32__
+OPENFILENAME ofn;
+char szFile[260];       /* buffer for file name */
+char szPath[260];       /* buffer for path name */
+char lpstrFilter[260];	/* more than enough room for some patterns */
+BOOL rc;
+#endif
+
 GLOBALS->fileselbox_text=filesel_path;
 GLOBALS->filesel_ok=0;
 GLOBALS->cleanup_file_c_2=ok_func;
 GLOBALS->bad_cleanup_file_c_1=notok_func;
 
+#if defined __MINGW32__
+ZeroMemory(&ofn, sizeof(ofn));
+ofn.lStructSize = sizeof(ofn);
+ofn.lpstrFile = szFile;
+ofn.lpstrFile[0] = '\0';
+ofn.lpstrFilter = lpstrFilter;
+ofn.nMaxFile = sizeof(szFile);
+ofn.lpstrFileTitle = NULL;
+ofn.nMaxFileTitle = 0;
+ofn.lpstrInitialDir = NULL;
+ofn.Flags = is_writemode ? (OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT) : (OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST);
+
+if((!pattn)||(!strcmp(pattn, "*")))
+	{
+	sprintf(lpstrFilter, "%s%c%s%c", "All", 0, "*.*", 0);
+	ofn.nFilterIndex = 0;
+	}
+	else
+	{
+	sprintf(lpstrFilter, "%s%c%s%c%s%c%s%c", pattn, 0, pattn, 0, "All", 0, "*.*"); 
+	ofn.nFilterIndex = 0;
+	}
+
+if(*filesel_path) 
+	{
+	char *fsp = *filesel_path;
+	int ch_idx = 0;
+	char ch = 0;
+
+	while(*fsp)
+		{
+		ch = *fsp;
+		szFile[ch_idx++] = (ch != '/') ? ch : '\\';
+		fsp++;
+		} 
+
+	szFile[ch_idx] = 0;
+
+	if((ch == '/') || (ch == '\\'))
+		{
+		strcpy(szPath, szFile);
+		szFile[0] = 0;
+		ofn.lpstrInitialDir = szPath;
+		}
+	}
+
+rc = is_writemode ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn);
+
+if (rc==TRUE) 
+	{
+	GLOBALS->filesel_ok=1;
+        if(*GLOBALS->fileselbox_text) free_2(*GLOBALS->fileselbox_text);
+        *GLOBALS->fileselbox_text=(char *)strdup_2(szFile);
+	GLOBALS->cleanup_file_c_2();
+	}
+	else
+	{
+	if(GLOBALS->bad_cleanup_file_c_1) GLOBALS->bad_cleanup_file_c_1();
+	}
+
+#else
+
 GLOBALS->fs_file_c_1=gtk_file_selection_new(title);
 gtkwave_signal_connect(GTK_OBJECT(GLOBALS->fs_file_c_1), "destroy", (GtkSignalFunc) destroy_callback, NULL);
 gtkwave_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(GLOBALS->fs_file_c_1)->ok_button), "clicked", (GtkSignalFunc) enter_callback, GTK_OBJECT(GLOBALS->fs_file_c_1));
@@ -157,6 +231,8 @@ if(*GLOBALS->fileselbox_text) gtk_file_selection_set_filename(GTK_FILE_SELECTION
 
 gtk_widget_show(GLOBALS->fs_file_c_1);
 wave_gtk_grab_add(GLOBALS->fs_file_c_1);
+
+#endif
 }
 
 
@@ -245,7 +321,7 @@ return;
 
 #if defined __MINGW32__ || !GTK_CHECK_VERSION(2,4,0)
 
-fileselbox_old(title, filesel_path, ok_func, notok_func, pattn);
+fileselbox_old(title, filesel_path, ok_func, notok_func, pattn, is_writemode);
 return;
 
 #else
diff --git a/src/file.h b/src/file.h
index 901499c..2fe75ad 100644
--- a/src/file.h
+++ b/src/file.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) Tony Bybell 2010
+ * Copyright (c) Tony Bybell 2010-2013
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -10,7 +10,7 @@
 #ifndef WAVE_FILESEL_H
 #define WAVE_FILESEL_H
 
-void fileselbox_old(char *title, char **filesel_path, GtkSignalFunc ok_func, GtkSignalFunc notok_func, char *pattn);
+void fileselbox_old(char *title, char **filesel_path, GtkSignalFunc ok_func, GtkSignalFunc notok_func, char *pattn, int is_writemode);
 void fileselbox(char *title, char **filesel_path, GtkSignalFunc ok_func, GtkSignalFunc notok_func, char *pattn, int is_writemode);
 
 #endif
diff --git a/src/fsdb_wrapper_api.cc b/src/fsdb_wrapper_api.cc
index ea0e0b6..68625ec 100644
--- a/src/fsdb_wrapper_api.cc
+++ b/src/fsdb_wrapper_api.cc
@@ -313,7 +313,7 @@ fsdbRC rc = fsdb_obj->ffrExtractScaleUnit(su, digit, unit);
 
 if(rc == FSDB_RC_SUCCESS)
 	{
-	*mult = ((int)digit);
+	*mult = digit ? ((int)digit) : 1; /* in case digit is zero */
 	*scale = unit[0];
 	}
 
diff --git a/src/globals.c b/src/globals.c
index c4a856e..a68079b 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -104,8 +104,8 @@ NULL, /* ae2_time_xlate */
  * analyzer.c
  */
 TR_RJUSTIFY, /* default_flags 5 */
-{0, 0, 0, 0, 0, 0, 0}, /* tims 6 */
-{0, 0, NULL, NULL, NULL, NULL, 0, NULL, NULL}, /* traces 9 */
+{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0}, /* tims 6 */
+{0, 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0}, /* traces 9 */
 0, /* hier_max_level 8 */
 0, /* hier_max_level_shadow */
 0, /* timestart_from_savefile */
@@ -369,7 +369,7 @@ NULL, /* gtk_context_bridge_ptr */
 0, /* text_help_c_1 111 */
 0, /* vscrollbar_help_c_1 112 */
 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
-{0}, /* iter_help_c_1 113 */
+{NULL, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, NULL}, /* iter_help_c_1 113 */
 0, /* bold_tag_help_c_1 114 */
 #endif
 0, /* window_help_c_2 115 */
@@ -416,7 +416,7 @@ NULL, /* logfiles */
 NULL, /* fontname_logfile 133 */
 NULL, /* font_logfile_c_1 134 */
 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
-{0}, /* iter_logfile_c_2 135 */
+{NULL, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, NULL}, /* iter_logfile_c_2 135 */
 NULL, /* bold_tag_logfile_c_2 136 */
 NULL, /* mono_tag_logfile_c_1 137 */
 NULL, /* size_tag_logfile_c_1 138 */
@@ -875,6 +875,8 @@ NULL, /* signalarea_event_box */
 0, /* cached_mouseover_x */
 0, /* cached_mouseover_y */
 0, /* mouseover_counter */
+0, /* button2_debounce_flag */
+
 
 /*
  * simplereq.c
@@ -906,7 +908,7 @@ NULL, /* gt_splash_c_1 393 */
 NULL, /* text_status_c_2 398 */
 NULL, /* vscrollbar_status_c_2 399 */
 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
-{0}, /* iter_status_c_3 400 */
+{NULL, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, NULL}, /* iter_status_c_3 400 */
 NULL, /* bold_tag_status_c_3 401 */
 #endif
 
@@ -1079,7 +1081,7 @@ NULL, /* tree_treesearch_gtk2_c_1 466 */
 0, /* bundle_direction_treesearch_gtk2_c_3 467 */
 NULL, /* cleanup_treesearch_gtk2_c_8 468 */
 0, /* pre_import_treesearch_gtk2_c_1 469 */
-{0,0,0,NULL,NULL,NULL,0}, /* tcache_treesearch_gtk2_c_2 470 */
+{0,0,NULL,NULL,NULL,NULL,0,NULL,NULL,0}, /* tcache_treesearch_gtk2_c_2 470 */
 0, /* dnd_tgt_on_signalarea_treesearch_gtk2_c_1 471 */
 0, /* dnd_tgt_on_wavearea_treesearch_gtk2_c_1 */
 NULL, /* dnd_sigview */
diff --git a/src/globals.h b/src/globals.h
index 03ec0a3..6e19a36 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -872,6 +872,7 @@ gint keypress_handler_id; /* from signalwindow.c */
 gint cached_mouseover_x; /* from signalwindow.c */
 gint cached_mouseover_y; /* from signalwindow.c */
 gint mouseover_counter; /* from signalwindow.c */
+unsigned button2_debounce_flag : 1;
 
 
 /*
diff --git a/src/helpers/Makefile.am b/src/helpers/Makefile.am
index a81229c..a8b273c 100644
--- a/src/helpers/Makefile.am
+++ b/src/helpers/Makefile.am
@@ -12,13 +12,13 @@ bin_PROGRAMS= evcd2vcd fst2vcd vcd2fst fstminer ghwdump lxt2miner lxt2vcd \
 	shmidcat vcd2lxt vcd2lxt2 vcd2vzt \
 	vzt2vcd vztminer
 
-vcd2fst_SOURCES= vcd2fst.c $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h $(srcdir)/../../contrib/rtlbrowse/jrb.h $(srcdir)/../../contrib/rtlbrowse/jrb.c
+vcd2fst_SOURCES= vcd2fst.c $(srcdir)/fst/lz4.c $(srcdir)/fst/lz4.h $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h $(srcdir)/../../contrib/rtlbrowse/jrb.h $(srcdir)/../../contrib/rtlbrowse/jrb.c
 vcd2fst_LDADD= $(LIBZ_LDADD) $(LIBJUDY_LDADD)
 
-fst2vcd_SOURCES= fst2vcd.c $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
+fst2vcd_SOURCES= fst2vcd.c $(srcdir)/fst/lz4.c $(srcdir)/fst/lz4.h $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
 fst2vcd_LDADD= $(LIBZ_LDADD) $(LIBJUDY_LDADD)
 
-fstminer_SOURCES= fstminer.c $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
+fstminer_SOURCES= fstminer.c $(srcdir)/fst/lz4.c $(srcdir)/fst/lz4.h $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
 fstminer_LDADD= $(LIBZ_LDADD) $(LIBJUDY_LDADD)
 
 vcd2lxt_SOURCES= vcd2lxt.c lxt_write.c lxt_write.h v2l_analyzer.h v2l_debug.c v2l_debug.h
diff --git a/src/helpers/Makefile.in b/src/helpers/Makefile.in
index fa4f541..2b3b776 100644
--- a/src/helpers/Makefile.in
+++ b/src/helpers/Makefile.in
@@ -69,13 +69,13 @@ PROGRAMS = $(bin_PROGRAMS)
 am_evcd2vcd_OBJECTS = evcd2vcd.$(OBJEXT) jrb.$(OBJEXT)
 evcd2vcd_OBJECTS = $(am_evcd2vcd_OBJECTS)
 evcd2vcd_LDADD = $(LDADD)
-am_fst2vcd_OBJECTS = fst2vcd.$(OBJEXT) fastlz.$(OBJEXT) \
+am_fst2vcd_OBJECTS = fst2vcd.$(OBJEXT) lz4.$(OBJEXT) fastlz.$(OBJEXT) \
 	fstapi.$(OBJEXT)
 fst2vcd_OBJECTS = $(am_fst2vcd_OBJECTS)
 am__DEPENDENCIES_1 =
 fst2vcd_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
-am_fstminer_OBJECTS = fstminer.$(OBJEXT) fastlz.$(OBJEXT) \
-	fstapi.$(OBJEXT)
+am_fstminer_OBJECTS = fstminer.$(OBJEXT) lz4.$(OBJEXT) \
+	fastlz.$(OBJEXT) fstapi.$(OBJEXT)
 fstminer_OBJECTS = $(am_fstminer_OBJECTS)
 fstminer_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_ghwdump_OBJECTS = ghwdump.$(OBJEXT) ghwlib.$(OBJEXT)
@@ -91,7 +91,7 @@ lxt2vcd_DEPENDENCIES = $(am__DEPENDENCIES_1)
 shmidcat_SOURCES = shmidcat.c
 shmidcat_OBJECTS = shmidcat.$(OBJEXT)
 shmidcat_LDADD = $(LDADD)
-am_vcd2fst_OBJECTS = vcd2fst.$(OBJEXT) fastlz.$(OBJEXT) \
+am_vcd2fst_OBJECTS = vcd2fst.$(OBJEXT) lz4.$(OBJEXT) fastlz.$(OBJEXT) \
 	fstapi.$(OBJEXT) jrb.$(OBJEXT)
 vcd2fst_OBJECTS = $(am_vcd2fst_OBJECTS)
 vcd2fst_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
@@ -218,6 +218,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -260,6 +261,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
@@ -338,11 +340,11 @@ AIXFLAGS = -bmaxdata:0xd0000000/dsa
 LIBLZMA_CFLAGS = -I$(srcdir)/../liblzma $(LIBXZ_CFLAGS)
 LIBLZMA_LDADD = $(LIBXZ_LDADD)
 AM_CFLAGS = -I$(srcdir)/.. -I$(srcdir)/../.. $(LIBZ_CFLAGS) $(LIBBZ2_CFLAGS) $(LIBLZMA_CFLAGS) $(LIBJUDY_CFLAGS) $(INLINE_ASM) $(EXTLOAD_CFLAGS) -I$(srcdir)/fst -I$(srcdir)/../../contrib/rtlbrowse
-vcd2fst_SOURCES = vcd2fst.c $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h $(srcdir)/../../contrib/rtlbrowse/jrb.h $(srcdir)/../../contrib/rtlbrowse/jrb.c
+vcd2fst_SOURCES = vcd2fst.c $(srcdir)/fst/lz4.c $(srcdir)/fst/lz4.h $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h $(srcdir)/../../contrib/rtlbrowse/jrb.h $(srcdir)/../../contrib/rtlbrowse/jrb.c
 vcd2fst_LDADD = $(LIBZ_LDADD) $(LIBJUDY_LDADD)
-fst2vcd_SOURCES = fst2vcd.c $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
+fst2vcd_SOURCES = fst2vcd.c $(srcdir)/fst/lz4.c $(srcdir)/fst/lz4.h $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
 fst2vcd_LDADD = $(LIBZ_LDADD) $(LIBJUDY_LDADD)
-fstminer_SOURCES = fstminer.c $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
+fstminer_SOURCES = fstminer.c $(srcdir)/fst/lz4.c $(srcdir)/fst/lz4.h $(srcdir)/fst/fastlz.c $(srcdir)/fst/fastlz.h $(srcdir)/fst/fstapi.c $(srcdir)/fst/fstapi.h
 fstminer_LDADD = $(LIBZ_LDADD) $(LIBJUDY_LDADD)
 vcd2lxt_SOURCES = vcd2lxt.c lxt_write.c lxt_write.h v2l_analyzer.h v2l_debug.c v2l_debug.h
 vcd2lxt_LDADD = $(LIBZ_LDADD) $(LIBBZ2_LDADD)
@@ -496,6 +498,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lxt2miner.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lxt2vcd.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lxt_write.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lz4.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/scopenav.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/shmidcat.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/v2l_debug.Po at am__quote@
@@ -537,6 +540,20 @@ jrb.obj: $(srcdir)/../../contrib/rtlbrowse/jrb.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jrb.obj `if test -f '$(srcdir)/../../contrib/rtlbrowse/jrb.c'; then $(CYGPATH_W) '$(srcdir)/../../contrib/rtlbrowse/jrb.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../../contrib/rtlbrowse/jrb.c'; fi`
 
+lz4.o: $(srcdir)/fst/lz4.c
+ at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lz4.o -MD -MP -MF $(DEPDIR)/lz4.Tpo -c -o lz4.o `test -f '$(srcdir)/fst/lz4.c' || echo '$(srcdir)/'`$(srcdir)/fst/lz4.c
+ at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/lz4.Tpo $(DEPDIR)/lz4.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(srcdir)/fst/lz4.c' object='lz4.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lz4.o `test -f '$(srcdir)/fst/lz4.c' || echo '$(srcdir)/'`$(srcdir)/fst/lz4.c
+
+lz4.obj: $(srcdir)/fst/lz4.c
+ at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lz4.obj -MD -MP -MF $(DEPDIR)/lz4.Tpo -c -o lz4.obj `if test -f '$(srcdir)/fst/lz4.c'; then $(CYGPATH_W) '$(srcdir)/fst/lz4.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/fst/lz4.c'; fi`
+ at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/lz4.Tpo $(DEPDIR)/lz4.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(srcdir)/fst/lz4.c' object='lz4.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lz4.obj `if test -f '$(srcdir)/fst/lz4.c'; then $(CYGPATH_W) '$(srcdir)/fst/lz4.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/fst/lz4.c'; fi`
+
 fastlz.o: $(srcdir)/fst/fastlz.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT fastlz.o -MD -MP -MF $(DEPDIR)/fastlz.Tpo -c -o fastlz.o `test -f '$(srcdir)/fst/fastlz.c' || echo '$(srcdir)/'`$(srcdir)/fst/fastlz.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/fastlz.Tpo $(DEPDIR)/fastlz.Po
diff --git a/src/helpers/fst/Makefile.am b/src/helpers/fst/Makefile.am
index 6056c67..1d6e857 100644
--- a/src/helpers/fst/Makefile.am
+++ b/src/helpers/fst/Makefile.am
@@ -5,6 +5,6 @@ AM_CFLAGS=      $(LIBZ_CFLAGS) $(LIBJUDY_CFLAGS)
 
 noinst_LIBRARIES=       libfst.a
 
-libfst_a_SOURCES= fastlz.c fastlz.h fstapi.c fstapi.h
+libfst_a_SOURCES= fastlz.c fastlz.h lz4.c lz4.h fstapi.c fstapi.h
 
 EXTRA_DIST=     block_format.txt
diff --git a/src/helpers/fst/Makefile.in b/src/helpers/fst/Makefile.in
index 34836a8..57a8b84 100644
--- a/src/helpers/fst/Makefile.in
+++ b/src/helpers/fst/Makefile.in
@@ -68,7 +68,7 @@ am__v_AR_0 = @echo "  AR      " $@;
 am__v_AR_1 = 
 libfst_a_AR = $(AR) $(ARFLAGS)
 libfst_a_LIBADD =
-am_libfst_a_OBJECTS = fastlz.$(OBJEXT) fstapi.$(OBJEXT)
+am_libfst_a_OBJECTS = fastlz.$(OBJEXT) lz4.$(OBJEXT) fstapi.$(OBJEXT)
 libfst_a_OBJECTS = $(am_libfst_a_OBJECTS)
 AM_V_P = $(am__v_P_ at AM_V@)
 am__v_P_ = $(am__v_P_ at AM_DEFAULT_V@)
@@ -157,6 +157,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -199,6 +200,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
@@ -274,7 +276,7 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 AM_CFLAGS = $(LIBZ_CFLAGS) $(LIBJUDY_CFLAGS)
 noinst_LIBRARIES = libfst.a
-libfst_a_SOURCES = fastlz.c fastlz.h fstapi.c fstapi.h
+libfst_a_SOURCES = fastlz.c fastlz.h lz4.c lz4.h fstapi.c fstapi.h
 EXTRA_DIST = block_format.txt
 all: all-am
 
@@ -326,6 +328,7 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/fastlz.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/fstapi.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lz4.Po at am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/helpers/fst/block_format.txt b/src/helpers/fst/block_format.txt
index e26d195..5f6f613 100644
--- a/src/helpers/fst/block_format.txt
+++ b/src/helpers/fst/block_format.txt
@@ -46,7 +46,14 @@ hierarchy block
 uint8_t         FST_BL_HIER
 uint64_t        section length
 uint64_t        length of uncompressed hier data
-[compressed data]
+[zlib compressed data]
+
+or
+
+uint8_t         FST_BL_HIER_LZ4
+uint64_t        section length
+uint64_t        length of uncompressed hier data
+[lz4 compressed data]
 
 ===========================================================================
 
@@ -81,7 +88,8 @@ varint		maxhandle associated with this checkpoint data
 // value changes
 
 varint		maxhandle associated with the value change data
-uint8_t		pack type ('F' is fastlz, 'Z' is zlib)
+uint8_t		pack type ('F' is fastlz, '4' is lz4, 
+			others ['Z'/'!'] are zlib)
 
 varint		chain 0 compressed data length (0 = uncompressed)
 [compressed data]	
diff --git a/src/helpers/fst/fstapi.c b/src/helpers/fst/fstapi.c
index a2d0045..d25dc81 100644
--- a/src/helpers/fst/fstapi.c
+++ b/src/helpers/fst/fstapi.c
@@ -24,6 +24,7 @@
 
 #include "fstapi.h"
 #include "fastlz.h"
+#include "lz4.h"
 
 #ifndef HAVE_LIBPTHREAD
 #undef FST_WRITER_PARALLEL
@@ -544,6 +545,7 @@ uint32_t maxvalpos;
 
 unsigned vc_emitted : 1;
 unsigned is_initial_time : 1;
+unsigned fourpack : 1;
 unsigned fastpack : 1;
 
 int64_t timezero;
@@ -1064,7 +1066,7 @@ vchg_mem = xc->vchg_mem;
 
 f = xc->handle;
 fstWriterVarint(f, xc->maxhandle);	/* emit current number of handles */
-fputc(xc->fastpack ? 'F' : 'Z', f);
+fputc(xc->fourpack ? '4' : (xc->fastpack ? 'F' : 'Z'), f);
 fpos = 1;
 
 packmemlen = 1024;			/* maintain a running "longest" allocation to */
@@ -1283,7 +1285,7 @@ for(i=0;i<xc->maxhandle;i++)
 					dmem = packmem = malloc(packmemlen = (wrlen * 2) + 2);
 					}
 
-				rc = fastlz_compress(scratchpnt, wrlen, dmem);
+				rc = (xc->fourpack) ? LZ4_compress((char *)scratchpnt, (char *)dmem, wrlen) : fastlz_compress(scratchpnt, wrlen, dmem);
 				if(rc < destlen)
         				{
 #ifndef FST_DYNAMIC_ALIAS_DISABLE
@@ -1708,7 +1710,6 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
 
 	if(xc->compress_hier)
 		{
-		unsigned char *mem = malloc(FST_GZIO_LEN);
 		off_t hl, eos;
 		gzFile zhandle;
 		int zfd;
@@ -1722,25 +1723,46 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
 		fstWriterUint64(xc->handle, 0);			/* section length */
 		fstWriterUint64(xc->handle, xc->hier_file_len);	/* uncompressed length */
 		
-		fflush(xc->handle);
-		zfd = dup(fileno(xc->handle));
-		zhandle = gzdopen(zfd, "wb4");
-		if(zhandle)
+		if(!xc->fourpack)
 			{
-			fstWriterFseeko(xc, xc->hier_handle, 0, SEEK_SET);
-			for(hl = 0; hl < xc->hier_file_len; hl += FST_GZIO_LEN)
+			unsigned char *mem = malloc(FST_GZIO_LEN);
+			zfd = dup(fileno(xc->handle));
+			fflush(xc->handle);
+			zhandle = gzdopen(zfd, "wb4");
+			if(zhandle)
+				{
+				fstWriterFseeko(xc, xc->hier_handle, 0, SEEK_SET);
+				for(hl = 0; hl < xc->hier_file_len; hl += FST_GZIO_LEN)
+					{
+					unsigned len = ((xc->hier_file_len - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (xc->hier_file_len - hl);
+					fstFread(mem, len, 1, xc->hier_handle);
+					gzwrite(zhandle, mem, len);
+					}
+				gzclose(zhandle);
+				}
+				else
 				{
-				unsigned len = ((xc->hier_file_len - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (xc->hier_file_len - hl);
-				fstFread(mem, len, 1, xc->hier_handle);
-				gzwrite(zhandle, mem, len);
+				close(zfd);
 				}
-			gzclose(zhandle);
+			free(mem);
 			}
 			else
 			{
-			close(zfd);
+			int lz4_maxlen;
+			unsigned char *mem;
+			unsigned char *hmem;
+			int packed_len;
+
+			fflush(xc->handle);
+
+			lz4_maxlen = LZ4_compressBound(xc->hier_file_len);
+			mem = malloc(lz4_maxlen);
+			hmem = fstMmap(NULL, xc->hier_file_len, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->hier_handle), 0);
+			packed_len = LZ4_compress((char *)hmem, (char *)mem, xc->hier_file_len);
+			fstFwrite(mem, packed_len, 1, xc->handle);
+			fstMunmap(hmem, xc->hier_file_len);
+			free(mem);			
 			}
-		free(mem);
 
 		fstWriterFseeko(xc, xc->handle, 0, SEEK_END);
 		eos = ftello(xc->handle);
@@ -1749,7 +1771,7 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
 		fflush(xc->handle);
 
 		fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
-		fputc(FST_BL_HIER, xc->handle);		/* actual tag */
+		fputc(xc->fourpack ? FST_BL_HIER_LZ4 : FST_BL_HIER, xc->handle); /* actual tag now also == compression type */
 
 		fstWriterFseeko(xc, xc->handle, 0, SEEK_END);	/* move file pointer to end for any section adds */
 		fflush(xc->handle);
@@ -2129,12 +2151,13 @@ if(xc)
 }
 
 
-void fstWriterSetPackType(void *ctx, int typ)
+void fstWriterSetPackType(void *ctx, enum fstWriterPackType typ)
 {
 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
 if(xc)
 	{
-	xc->fastpack = (typ != 0);
+	xc->fastpack = (typ != FST_WR_PT_ZLIB);
+	xc->fourpack = (typ == FST_WR_PT_LZ4);
 	}
 }
 
@@ -2720,10 +2743,12 @@ unsigned char *temp_signal_value_buf;	/* malloced for len in longest_signal_valu
 signed char timescale;
 unsigned char filetype;
 
+unsigned use_vcd_extensions : 1;
 unsigned double_endian_match : 1;
 unsigned native_doubles_for_cb : 1;
 unsigned contains_geom_section : 1;
 unsigned contains_hier_section : 1;	/* valid for hier_pos */
+unsigned contains_hier_section_lz4 : 1;	/* valid for hier_pos */
 unsigned limit_range_valid : 1;		/* valid for limit_range_start, limit_range_end */
 
 char version[FST_HDR_SIM_VERSION_SIZE + 1];
@@ -3174,6 +3199,17 @@ if(xc)
 }
 
 
+void fstReaderSetVcdExtensions(void *ctx, int enable)
+{
+struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
+
+if(xc)
+	{
+	xc->use_vcd_extensions = (enable != 0);
+	}
+}
+
+
 void fstReaderIterBlocksSetNativeDoublesOnCallback(void *ctx, int enable)
 {
 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
@@ -3186,9 +3222,8 @@ if(xc)
 /*
  * hierarchy processing
  */
-static char *fstVcdID(int value)
+static void fstVcdID(char *buf, int value)
 {
-static char buf[16];
 char *pnt = buf;
 int vmod;
 
@@ -3208,12 +3243,10 @@ for(;;)
         }
 
 *pnt = 0;
-return(buf);
 }
 
-static char *fstVcdIDForFwrite(int value, int *len)
+static int fstVcdIDForFwrite(char *buf, int value)
 {
-static char buf[16];
 char *pnt = buf;
 int vmod;
 
@@ -3232,8 +3265,7 @@ for(;;)
         if(!value) { break; }
         }
 
-*len = pnt-buf;
-return(buf);
+return(pnt - buf);
 }
 
 
@@ -3247,21 +3279,50 @@ if(!xc->fh)
 	char *fnam = malloc(strlen(xc->filename) + 6 + 16 + 32 + 1);
 	unsigned char *mem = malloc(FST_GZIO_LEN);
 	off_t hl, uclen;
+	off_t clen = 0;
 	gzFile zhandle;
 	int zfd;
+	int htyp = FST_BL_SKIP;
+
+	/* can't handle both set at once should never happen in a real file */
+	if(!xc->contains_hier_section_lz4 && xc->contains_hier_section)
+		{
+		htyp = FST_BL_HIER;
+		}
+	else
+	if(xc->contains_hier_section_lz4 && !xc->contains_hier_section)
+		{
+		htyp = FST_BL_HIER_LZ4;
+		}
 
 	sprintf(fnam, "%s.hier_%d_%p", xc->filename, getpid(), (void *)xc);
 	fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
 	uclen = fstReaderUint64(xc->f);
 	fflush(xc->f);
-	zfd = dup(fileno(xc->f));
-	zhandle = gzdopen(zfd, "rb");
-	if(!zhandle)
+
+	if(htyp == FST_BL_HIER)
 		{
-		close(zfd);
-		free(mem);
-		free(fnam);
-		return(0);
+		fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
+		uclen = fstReaderUint64(xc->f);
+		fflush(xc->f);
+
+		zfd = dup(fileno(xc->f));
+		zhandle = gzdopen(zfd, "rb");
+		if(!zhandle)
+			{
+			close(zfd);
+			free(mem);
+			free(fnam);
+			return(0);
+			}
+		}
+	else
+	if(htyp == FST_BL_HIER_LZ4)
+		{
+		fstReaderFseeko(xc, xc->f, xc->hier_pos - 8, SEEK_SET); /* get section len */
+		clen =  fstReaderUint64(xc->f) - 16;
+		uclen = fstReaderUint64(xc->f);
+		fflush(xc->f);
 		}
 
 #ifndef __MINGW32__
@@ -3282,26 +3343,51 @@ if(!xc->fh)
 	if(fnam) unlink(fnam);
 #endif
 
-        for(hl = 0; hl < uclen; hl += FST_GZIO_LEN)
+	if(htyp == FST_BL_HIER)
 		{
-                size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
-		size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
-		size_t fwlen;
-
-		if(gzreadlen != len)
+	        for(hl = 0; hl < uclen; hl += FST_GZIO_LEN)
 			{
-			pass_status = 0;
-			break;
-			}
+	                size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
+			size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
+			size_t fwlen;
+	
+			if(gzreadlen != len)
+				{
+				pass_status = 0;
+				break;
+				}
+	
+			fwlen = fstFwrite(mem, len, 1, xc->fh);
+			if(fwlen != 1)
+				{
+				pass_status = 0;
+				break;
+				}
+	                }
+	        gzclose(zhandle);
+		}
+	else
+	if(htyp == FST_BL_HIER_LZ4)
+		{
+		unsigned char *lz4_cmem  = malloc(clen);		
+		unsigned char *lz4_ucmem = malloc(uclen);		
+		
+		fstFread(lz4_cmem, clen, 1, xc->f);
+		pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_cmem, (char *)lz4_ucmem, clen, uclen, uclen));
 
-		fwlen = fstFwrite(mem, len, 1, xc->fh);
-		if(fwlen != 1)
+		if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
 			{
 			pass_status = 0;
-			break;
 			}
-                }
-        gzclose(zhandle);
+
+		free(lz4_ucmem);
+		free(lz4_cmem);
+		}
+	else /* FST_BL_SKIP */
+		{
+		pass_status = 0;
+		}
+
 	free(mem);
 	free(fnam);
 
@@ -3613,7 +3699,7 @@ while(!feof(xc->fh))
 
 			attrarg = fstReaderVarint64(xc->fh);
 
-			if(fv)
+			if(fv && xc->use_vcd_extensions)
 				{
 				switch(attrtype)
 					{
@@ -3652,7 +3738,7 @@ while(!feof(xc->fh))
 			break;
 
 		case FST_ST_GEN_ATTREND:
-			if(fv) fprintf(fv, "$attrend $end\n");
+			if(fv && xc->use_vcd_extensions) fprintf(fv, "$attrend $end\n");
 			break;
 
 		case FST_VT_VCD_EVENT:
@@ -3720,8 +3806,10 @@ while(!feof(xc->fh))
 					}
 				if(fv) 
 					{
+					char vcdid_buf[16];
 					uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
-					fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, fstVcdID(xc->maxhandle+1), str);
+					fstVcdID(vcdid_buf, xc->maxhandle+1);
+					fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, vcdid_buf, str);
 					}
                 		xc->maxhandle++;
 				}
@@ -3734,8 +3822,10 @@ while(!feof(xc->fh))
 					}
 				if(fv) 
 					{
+					char vcdid_buf[16];
 					uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
-					fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, fstVcdID(alias), str);
+					fstVcdID(vcdid_buf, alias);
+					fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, vcdid_buf, str);
 					}
 				xc->num_alias++;
 				}
@@ -4029,6 +4119,11 @@ if(gzread_pass_status)
 			xc->contains_hier_section = 1;
 			xc->hier_pos = ftello(xc->f);
 			}
+		else if(sectype == FST_BL_HIER_LZ4)
+			{
+			xc->contains_hier_section_lz4 = 1;
+			xc->hier_pos = ftello(xc->f);
+			}
 		else if(sectype == FST_BL_BLACKOUT)
 			{
 			uint32_t i;
@@ -4107,7 +4202,7 @@ if((!nam)||(!(xc->f=fopen(nam, "rb"))))
 	xc->filename = strdup(nam);
 	rc = fstReaderInit(xc);
 
-	if((rc) && (xc->vc_section_count) && (xc->maxhandle) && ((xc->fh)||(xc->contains_hier_section)))
+	if((rc) && (xc->vc_section_count) && (xc->maxhandle) && ((xc->fh)||(xc->contains_hier_section||(xc->contains_hier_section_lz4))))
 		{
 		/* more init */
 		xc->do_rewind = 1;
@@ -4226,6 +4321,8 @@ uint32_t traversal_mem_offs;
 uint32_t *scatterptr, *headptr, *length_remaining;
 uint32_t cur_blackout = 0;
 int packtype;
+unsigned char *mc_mem = NULL;
+uint32_t mc_mem_len; /* corresponds to largest value encountered in chain_table_lengths[i] */
 
 if(!xc) return(0);
 
@@ -4424,8 +4521,8 @@ for(;;)
 								{
 								if(fv)
 									{
-									int vcdid_len;
-									const char *vcd_id = fstVcdIDForFwrite(idx+1, &vcdid_len);
+									char vcd_id[16];
+									int vcdid_len = fstVcdIDForFwrite(vcd_id, idx+1);
 									fputc(val, fv);
 									fstFwrite(vcd_id, vcdid_len, 1, fv);
 									fputc('\n', fv);
@@ -4451,8 +4548,8 @@ for(;;)
 								{
 								if(fv)
 									{
-									int vcdid_len;
-									const char *vcd_id = fstVcdIDForFwrite(idx+1, &vcdid_len);
+									char vcd_id[16];
+									int vcdid_len = fstVcdIDForFwrite(vcd_id, idx+1);
 									fputc((xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p', fv);
 									fstFwrite(mu+sig_offs, xc->signal_lens[idx], 1, fv);
 									fputc(' ', fv);
@@ -4511,6 +4608,7 @@ for(;;)
 								{
 								if(fv)
 									{
+									char vcdid_buf[16];
 									clone_d = (unsigned char *)&d;
 									if(xc->double_endian_match)
 										{
@@ -4526,7 +4624,8 @@ for(;;)
 											}
 										}
 						
-									fprintf(fv, "r%.16g %s\n", d, fstVcdID(idx+1));
+									fstVcdID(vcdid_buf, idx+1);
+									fprintf(fv, "r%.16g %s\n", d, vcdid_buf);
 									}
 								}
 							}
@@ -4633,6 +4732,10 @@ for(;;)
 #ifdef FST_DEBUG
 	printf("\tdecompressed chain idx len: %"PRIu32"\n", idx);
 #endif
+
+	mc_mem_len = 16384;
+	mc_mem = malloc(mc_mem_len); /* buffer for compressed reads */
+
 	/* check compressed VC data */
 	if(idx > xc->maxhandle) idx = xc->maxhandle;
 	for(i=0;i<idx;i++)
@@ -4653,21 +4756,30 @@ for(;;)
 				val = fstReaderVarint32WithSkip(xc->f, &skiplen);
 				if(val)
 					{
-					unsigned char *mu = mem_for_traversal + traversal_mem_offs;
-					unsigned char *mc = malloc(chain_table_lengths[i]);
+					unsigned char *mu = mem_for_traversal + traversal_mem_offs; /* uncomp: dst */
+					unsigned char *mc;					    /* comp:   src */
 					unsigned long destlen = val;
 					unsigned long sourcelen = chain_table_lengths[i];
-	
-					fstFread(mc, chain_table_lengths[i], 1, xc->f);
-					if(packtype == 'F')
+
+					if(mc_mem_len < chain_table_lengths[i])
 						{
-						rc = fastlz_decompress(mc, sourcelen, mu, destlen);
+						free(mc_mem);
+						mc_mem = malloc(mc_mem_len = chain_table_lengths[i]);
 						}
-						else
+					mc = mc_mem;	
+
+					fstFread(mc, chain_table_lengths[i], 1, xc->f);
+
+					switch(packtype)
 						{
-						rc = uncompress(mu, &destlen, mc, sourcelen);
+						case '4': rc = (destlen == LZ4_decompress_safe_partial((char *)mc, (char *)mu, sourcelen, destlen, destlen)) ? Z_OK : Z_DATA_ERROR;
+							  break;
+						case 'F': fastlz_decompress(mc, sourcelen, mu, destlen); /* rc appears unreliable */
+							  break;
+						default:  rc = uncompress(mu, &destlen, mc, sourcelen);
+							  break;
 						}
-					free(mc);
+
 					/* data to process is for(j=0;j<destlen;j++) in mu[j] */
 					headptr[i] = traversal_mem_offs;
 					length_remaining[i] = val;
@@ -4708,6 +4820,8 @@ for(;;)
 			}
 		}
 
+	free(mc_mem); /* there is no usage below for this, no real need to clear out mc_mem or mc_mem_len */
+
 	for(i=0;i<tsec_nitems;i++)
 		{
 		uint32_t tdelta;
@@ -4769,8 +4883,8 @@ for(;;)
 						{
 						if(fv) 
 							{
-							int vcdid_len;
-							const char *vcd_id = fstVcdIDForFwrite(idx+1, &vcdid_len);
+							char vcd_id[16];
+							int vcdid_len = fstVcdIDForFwrite(vcd_id, idx+1);
 							fputc(val, fv);
 							fstFwrite(vcd_id, vcdid_len, 1, fv);
 							fputc('\n', fv);
@@ -4814,8 +4928,8 @@ for(;;)
 							{
 							if(fv) 
 								{
-								int vcdid_len;
-								const char *vcd_id = fstVcdIDForFwrite(idx+1, &vcdid_len);
+								char vcd_id[16];
+								int vcdid_len = fstVcdIDForFwrite(vcd_id, idx+1);
 	
 								fputc('s', fv);
 								{
@@ -5003,8 +5117,8 @@ for(;;)
 
 				if(fv) 
 					{
-					int vcdid_len;
-					const char *vcd_id = fstVcdIDForFwrite(idx+1, &vcdid_len);
+					char vcd_id[16];
+					int vcdid_len = fstVcdIDForFwrite(vcd_id, idx+1);
 					fputc(' ', fv);
 					fstFwrite(vcd_id, vcdid_len, 1, fv);
 					fputc('\n', fv);
diff --git a/src/helpers/fst/fstapi.h b/src/helpers/fst/fstapi.h
index 9ace034..032fa8e 100644
--- a/src/helpers/fst/fstapi.h
+++ b/src/helpers/fst/fstapi.h
@@ -40,6 +40,12 @@ extern "C" {
 
 typedef uint32_t fstHandle;
 
+enum fstWriterPackType {
+    FST_WR_PT_ZLIB             = 0,
+    FST_WR_PT_FASTLZ           = 1,
+    FST_WR_PT_LZ4              = 2
+};
+
 enum fstFileType {
     FST_FT_MIN                 = 0,
 
@@ -57,6 +63,7 @@ enum fstBlockType {
     FST_BL_GEOM                = 3,
     FST_BL_HIER                = 4,
     FST_BL_VCDATA_DYN_ALIAS    = 5,
+    FST_BL_HIER_LZ4            = 6,
 
     FST_BL_ZWRAPPER	       = 254,   /* indicates that whole trace is gz wrapped */
     FST_BL_SKIP		       = 255	/* used while block is being written */
@@ -338,7 +345,7 @@ void 		fstWriterSetDate(void *ctx, const char *dat);
 void 		fstWriterSetDumpSizeLimit(void *ctx, uint64_t numbytes);
 void 		fstWriterSetEnvVar(void *ctx, const char *envvar);
 void 		fstWriterSetFileType(void *ctx, enum fstFileType filetype);
-void 		fstWriterSetPackType(void *ctx, int typ); 		/* type = 0 (libz), 1 (fastlz) */
+void 		fstWriterSetPackType(void *ctx, enum fstWriterPackType typ);
 void 		fstWriterSetParallelMode(void *ctx, int enable);
 void 		fstWriterSetRepackOnClose(void *ctx, int enable); 	/* type = 0 (none), 1 (libz) */
 void 		fstWriterSetScope(void *ctx, enum fstScopeType scopetype,
@@ -401,6 +408,7 @@ void 		fstReaderSetFacProcessMask(void *ctx, fstHandle facidx);
 void 		fstReaderSetFacProcessMaskAll(void *ctx);
 void 		fstReaderSetLimitTimeRange(void *ctx, uint64_t start_time, uint64_t end_time);
 void 		fstReaderSetUnlimitedTimeRange(void *ctx);
+void		fstReaderSetVcdExtensions(void *ctx, int enable);
 
 
 /*
diff --git a/src/helpers/fst/lz4.c b/src/helpers/fst/lz4.c
new file mode 100644
index 0000000..0f2c574
--- /dev/null
+++ b/src/helpers/fst/lz4.c
@@ -0,0 +1,822 @@
+/*
+   LZ4 - Fast LZ compression algorithm
+   Copyright (C) 2011-2013, Yann Collet.
+   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are
+   met:
+
+       * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above
+   copyright notice, this list of conditions and the following disclaimer
+   in the documentation and/or other materials provided with the
+   distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+   You can contact the author at :
+   - LZ4 source repository : http://code.google.com/p/lz4/
+   - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
+*/
+
+//**************************************
+// Tuning parameters
+//**************************************
+// MEMORY_USAGE :
+// Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
+// Increasing memory usage improves compression ratio
+// Reduced memory usage can improve speed, due to cache effect
+// Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
+#define MEMORY_USAGE 14
+
+// HEAPMODE :
+// Select how default compression functions will allocate memory for their hash table,
+// in memory stack (0:default, fastest), or in memory heap (1:requires memory allocation (malloc)).
+#define HEAPMODE 0
+
+
+//**************************************
+// CPU Feature Detection
+//**************************************
+// 32 or 64 bits ?
+#if (defined(__x86_64__) || defined(_M_X64) || defined(_WIN64) \
+  || defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) \
+  || defined(__64BIT__) || defined(_LP64) || defined(__LP64__) \
+  || defined(__ia64) || defined(__itanium__) || defined(_M_IA64) )   // Detects 64 bits mode
+#  define LZ4_ARCH64 1
+#else
+#  define LZ4_ARCH64 0
+#endif
+
+// Little Endian or Big Endian ?
+// Overwrite the #define below if you know your architecture endianess
+#if defined (__GLIBC__)
+#  include <endian.h>
+#  if (__BYTE_ORDER == __BIG_ENDIAN)
+#     define LZ4_BIG_ENDIAN 1
+#  endif
+#elif (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN))
+#  define LZ4_BIG_ENDIAN 1
+#elif defined(__sparc) || defined(__sparc__) \
+   || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) \
+   || defined(__hpux)  || defined(__hppa) \
+   || defined(_MIPSEB) || defined(__s390__)
+#  define LZ4_BIG_ENDIAN 1
+#else
+// Little Endian assumed. PDP Endian and other very rare endian format are unsupported.
+#endif
+
+// Unaligned memory access is automatically enabled for "common" CPU, such as x86.
+// For others CPU, such as ARM, the compiler may be more cautious, inserting unnecessary extra code to ensure aligned access property
+// If you know your target CPU supports unaligned memory access, you want to force this option manually to improve performance
+#if defined(__ARM_FEATURE_UNALIGNED)
+#  define LZ4_FORCE_UNALIGNED_ACCESS 1
+#endif
+
+// Define this parameter if your target system or compiler does not support hardware bit count
+#if defined(_MSC_VER) && defined(_WIN32_WCE)            // Visual Studio for Windows CE does not support Hardware bit count
+#  define LZ4_FORCE_SW_BITCOUNT
+#endif
+
+// BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE :
+// This option may provide a small boost to performance for some big endian cpu, although probably modest.
+// You may set this option to 1 if data will remain within closed environment.
+// This option is useless on Little_Endian CPU (such as x86)
+//#define BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE 1
+
+
+//**************************************
+// Compiler Options
+//**************************************
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)   // C99
+/* "restrict" is a known keyword */
+#else
+#  define restrict // Disable restrict
+#endif
+
+#ifdef _MSC_VER    // Visual Studio
+#  define FORCE_INLINE static __forceinline
+#  include <intrin.h>                    // For Visual 2005
+#  if LZ4_ARCH64   // 64-bits
+#    pragma intrinsic(_BitScanForward64) // For Visual 2005
+#    pragma intrinsic(_BitScanReverse64) // For Visual 2005
+#  else            // 32-bits
+#    pragma intrinsic(_BitScanForward)   // For Visual 2005
+#    pragma intrinsic(_BitScanReverse)   // For Visual 2005
+#  endif
+#  pragma warning(disable : 4127)        // disable: C4127: conditional expression is constant
+#else 
+#  ifdef __GNUC__
+#    define FORCE_INLINE static inline __attribute__((always_inline))
+#  else
+#    define FORCE_INLINE static inline
+#  endif
+#endif
+
+#ifdef _MSC_VER
+#  define lz4_bswap16(x) _byteswap_ushort(x)
+#else
+#  define lz4_bswap16(x) ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
+#endif
+
+#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+
+#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)
+#  define expect(expr,value)    (__builtin_expect ((expr),(value)) )
+#else
+#  define expect(expr,value)    (expr)
+#endif
+
+#define likely(expr)     expect((expr) != 0, 1)
+#define unlikely(expr)   expect((expr) != 0, 0)
+
+
+//**************************************
+// Memory routines
+//**************************************
+#include <stdlib.h>   // malloc, calloc, free
+#define ALLOCATOR(n,s) calloc(n,s)
+#define FREEMEM        free
+#include <string.h>   // memset, memcpy
+#define MEM_INIT       memset
+
+
+//**************************************
+// Includes
+//**************************************
+#include "lz4.h"
+
+
+//**************************************
+// Basic Types
+//**************************************
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L   // C99
+# include <stdint.h>
+  typedef  uint8_t BYTE;
+  typedef uint16_t U16;
+  typedef uint32_t U32;
+  typedef  int32_t S32;
+  typedef uint64_t U64;
+#else
+  typedef unsigned char       BYTE;
+  typedef unsigned short      U16;
+  typedef unsigned int        U32;
+  typedef   signed int        S32;
+  typedef unsigned long long  U64;
+#endif
+
+#if defined(__GNUC__)  && !defined(LZ4_FORCE_UNALIGNED_ACCESS)
+#  define _PACKED __attribute__ ((packed))
+#else
+#  define _PACKED
+#endif
+
+#if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
+#  if defined(__IBMC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+#    pragma pack(1)
+#  else
+#    pragma pack(push, 1)
+#  endif
+#endif
+
+typedef struct { U16 v; }  _PACKED U16_S;
+typedef struct { U32 v; }  _PACKED U32_S;
+typedef struct { U64 v; }  _PACKED U64_S;
+typedef struct {size_t v;} _PACKED size_t_S;
+
+#if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
+#  if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+#    pragma pack(0)
+#  else
+#    pragma pack(pop)
+#  endif
+#endif
+
+#define A16(x)   (((U16_S *)(x))->v)
+#define A32(x)   (((U32_S *)(x))->v)
+#define A64(x)   (((U64_S *)(x))->v)
+#define AARCH(x) (((size_t_S *)(x))->v)
+
+
+//**************************************
+// Constants
+//**************************************
+#define LZ4_HASHLOG   (MEMORY_USAGE-2)
+#define HASHTABLESIZE (1 << MEMORY_USAGE)
+#define HASHNBCELLS4  (1 << LZ4_HASHLOG)
+
+#define MINMATCH 4
+
+#define COPYLENGTH 8
+#define LASTLITERALS 5
+#define MFLIMIT (COPYLENGTH+MINMATCH)
+const int LZ4_minLength = (MFLIMIT+1);
+
+#define LZ4_64KLIMIT ((1<<16) + (MFLIMIT-1))
+#define SKIPSTRENGTH 6     // Increasing this value will make the compression run slower on incompressible data
+
+#define MAXD_LOG 16
+#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
+
+#define ML_BITS  4
+#define ML_MASK  ((1U<<ML_BITS)-1)
+#define RUN_BITS (8-ML_BITS)
+#define RUN_MASK ((1U<<RUN_BITS)-1)
+
+#define KB *(1U<<10)
+#define MB *(1U<<20)
+#define GB *(1U<<30)
+
+
+//**************************************
+// Structures and local types
+//**************************************
+
+typedef struct {
+    U32 hashTable[HASHNBCELLS4];
+    const BYTE* bufferStart;
+    const BYTE* base;
+    const BYTE* nextBlock;
+} LZ4_Data_Structure;
+
+typedef enum { notLimited = 0, limited = 1 } limitedOutput_directive;
+typedef enum { byPtr, byU32, byU16 } tableType_t;
+
+typedef enum { noPrefix = 0, withPrefix = 1 } prefix64k_directive;
+
+typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive;
+typedef enum { full = 0, partial = 1 } earlyEnd_directive;
+
+
+//**************************************
+// Architecture-specific macros
+//**************************************
+#define STEPSIZE                  sizeof(size_t)
+#define LZ4_COPYSTEP(d,s)         { AARCH(d) = AARCH(s); d+=STEPSIZE; s+=STEPSIZE; }
+#define LZ4_COPY8(d,s)            { LZ4_COPYSTEP(d,s); if (STEPSIZE<8) LZ4_COPYSTEP(d,s); }
+#define LZ4_SECURECOPY(d,s,e)     { if ((STEPSIZE==4)||(d<e)) LZ4_WILDCOPY(d,s,e); }
+
+#if LZ4_ARCH64   // 64-bit
+#  define HTYPE                   U32
+#  define INITBASE(base)          const BYTE* const base = ip
+#else            // 32-bit
+#  define HTYPE                   const BYTE*
+#  define INITBASE(base)          const int base = 0
+#endif
+
+#if (defined(LZ4_BIG_ENDIAN) && !defined(BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE))
+#  define LZ4_READ_LITTLEENDIAN_16(d,s,p) { U16 v = A16(p); v = lz4_bswap16(v); d = (s) - v; }
+#  define LZ4_WRITE_LITTLEENDIAN_16(p,i)  { U16 v = (U16)(i); v = lz4_bswap16(v); A16(p) = v; p+=2; }
+#else      // Little Endian
+#  define LZ4_READ_LITTLEENDIAN_16(d,s,p) { d = (s) - A16(p); }
+#  define LZ4_WRITE_LITTLEENDIAN_16(p,v)  { A16(p) = v; p+=2; }
+#endif
+
+
+//**************************************
+// Macros
+//**************************************
+#define LZ4_WILDCOPY(d,s,e)     { do { LZ4_COPY8(d,s) } while (d<e); }           // at the end, d>=e;
+
+
+//****************************
+// Private functions
+//****************************
+#if LZ4_ARCH64
+
+FORCE_INLINE int LZ4_NbCommonBytes (register U64 val)
+{
+# if defined(LZ4_BIG_ENDIAN)
+#   if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    unsigned long r = 0;
+    _BitScanReverse64( &r, val );
+    return (int)(r>>3);
+#   elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    return (__builtin_clzll(val) >> 3);
+#   else
+    int r;
+    if (!(val>>32)) { r=4; } else { r=0; val>>=32; }
+    if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }
+    r += (!val);
+    return r;
+#   endif
+# else
+#   if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    unsigned long r = 0;
+    _BitScanForward64( &r, val );
+    return (int)(r>>3);
+#   elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    return (__builtin_ctzll(val) >> 3);
+#   else
+    static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };
+    return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
+#   endif
+# endif
+}
+
+#else
+
+FORCE_INLINE int LZ4_NbCommonBytes (register U32 val)
+{
+# if defined(LZ4_BIG_ENDIAN)
+#   if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    unsigned long r = 0;
+    _BitScanReverse( &r, val );
+    return (int)(r>>3);
+#   elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    return (__builtin_clz(val) >> 3);
+#   else
+    int r;
+    if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
+    r += (!val);
+    return r;
+#   endif
+# else
+#   if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    unsigned long r;
+    _BitScanForward( &r, val );
+    return (int)(r>>3);
+#   elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
+    return (__builtin_ctz(val) >> 3);
+#   else
+    static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
+    return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
+#   endif
+# endif
+}
+
+#endif
+
+
+//****************************
+// Compression functions
+//****************************
+FORCE_INLINE int LZ4_hashSequence(U32 sequence, tableType_t tableType)
+{
+    if (tableType == byU16)
+        return (((sequence) * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1)));
+    else
+        return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG));
+}
+
+FORCE_INLINE int LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(A32(p), tableType); }
+
+FORCE_INLINE void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
+{
+    switch (tableType)
+    {
+    case byPtr: { const BYTE** hashTable = (const BYTE**) tableBase; hashTable[h] = p; break; }
+    case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); break; }
+    case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); break; }
+    }
+}
+
+FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
+{
+    U32 h = LZ4_hashPosition(p, tableType);
+    LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
+}
+
+FORCE_INLINE const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
+{
+    if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; }
+    if (tableType == byU32) { U32* hashTable = (U32*) tableBase; return hashTable[h] + srcBase; }
+    { U16* hashTable = (U16*) tableBase; return hashTable[h] + srcBase; }   // default, to ensure a return
+}
+
+FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
+{
+    U32 h = LZ4_hashPosition(p, tableType);
+    return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
+}
+
+
+FORCE_INLINE int LZ4_compress_generic(
+                 void* ctx,
+                 const char* source,
+                 char* dest,
+                 int inputSize,
+                 int maxOutputSize,
+
+                 limitedOutput_directive limitedOutput,
+                 tableType_t tableType,
+                 prefix64k_directive prefix)
+{
+    const BYTE* ip = (const BYTE*) source;
+    const BYTE* const base = (prefix==withPrefix) ? ((LZ4_Data_Structure*)ctx)->base : (const BYTE*) source;
+    const BYTE* const lowLimit = ((prefix==withPrefix) ? ((LZ4_Data_Structure*)ctx)->bufferStart : (const BYTE*)source);
+    const BYTE* anchor = (const BYTE*) source;
+    const BYTE* const iend = ip + inputSize;
+    const BYTE* const mflimit = iend - MFLIMIT;
+    const BYTE* const matchlimit = iend - LASTLITERALS;
+
+    BYTE* op = (BYTE*) dest;
+    BYTE* const oend = op + maxOutputSize;
+
+    int length;
+    const int skipStrength = SKIPSTRENGTH;
+    U32 forwardH;
+
+    // Init conditions
+    if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0;                                // Unsupported input size, too large (or negative)
+    if ((prefix==withPrefix) && (ip != ((LZ4_Data_Structure*)ctx)->nextBlock)) return 0;   // must continue from end of previous block
+    if (prefix==withPrefix) ((LZ4_Data_Structure*)ctx)->nextBlock=iend;                    // do it now, due to potential early exit
+    if ((tableType == byU16) && (inputSize>=LZ4_64KLIMIT)) return 0;                       // Size too large (not within 64K limit)
+    if (inputSize<LZ4_minLength) goto _last_literals;                                      // Input too small, no compression (all literals)
+
+    // First Byte
+    LZ4_putPosition(ip, ctx, tableType, base);
+    ip++; forwardH = LZ4_hashPosition(ip, tableType);
+
+    // Main Loop
+    for ( ; ; )
+    {
+        int findMatchAttempts = (1U << skipStrength) + 3;
+        const BYTE* forwardIp = ip;
+        const BYTE* ref;
+        BYTE* token;
+
+        // Find a match
+        do {
+            U32 h = forwardH;
+            int step = findMatchAttempts++ >> skipStrength;
+            ip = forwardIp;
+            forwardIp = ip + step;
+
+            if unlikely(forwardIp > mflimit) { goto _last_literals; }
+
+            forwardH = LZ4_hashPosition(forwardIp, tableType);
+            ref = LZ4_getPositionOnHash(h, ctx, tableType, base);
+            LZ4_putPositionOnHash(ip, h, ctx, tableType, base);
+
+        } while ((ref + MAX_DISTANCE < ip) || (A32(ref) != A32(ip)));
+
+        // Catch up
+        while ((ip>anchor) && (ref > lowLimit) && unlikely(ip[-1]==ref[-1])) { ip--; ref--; }
+
+        // Encode Literal length
+        length = (int)(ip - anchor);
+        token = op++;
+        if ((limitedOutput) && unlikely(op + length + (2 + 1 + LASTLITERALS) + (length>>8) > oend)) return 0;   // Check output limit
+        if (length>=(int)RUN_MASK) 
+        { 
+            int len = length-RUN_MASK; 
+            *token=(RUN_MASK<<ML_BITS); 
+            for(; len >= 255 ; len-=255) *op++ = 255; 
+            *op++ = (BYTE)len; 
+        }
+        else *token = (BYTE)(length<<ML_BITS);
+
+        // Copy Literals
+        { BYTE* end=(op)+(length); LZ4_WILDCOPY(op,anchor,end); op=end; }
+
+_next_match:
+        // Encode Offset
+        LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));
+
+        // Start Counting
+        ip+=MINMATCH; ref+=MINMATCH;    // MinMatch already verified
+        anchor = ip;
+        while likely(ip<matchlimit-(STEPSIZE-1))
+        {
+            size_t diff = AARCH(ref) ^ AARCH(ip);
+            if (!diff) { ip+=STEPSIZE; ref+=STEPSIZE; continue; }
+            ip += LZ4_NbCommonBytes(diff);
+            goto _endCount;
+        }
+        if (LZ4_ARCH64) if ((ip<(matchlimit-3)) && (A32(ref) == A32(ip))) { ip+=4; ref+=4; }
+        if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }
+        if ((ip<matchlimit) && (*ref == *ip)) ip++;
+_endCount:
+
+        // Encode MatchLength
+        length = (int)(ip - anchor);
+        if ((limitedOutput) && unlikely(op + (1 + LASTLITERALS) + (length>>8) > oend)) return 0;    // Check output limit
+        if (length>=(int)ML_MASK) 
+        { 
+            *token += ML_MASK; 
+            length -= ML_MASK; 
+            for (; length > 509 ; length-=510) { *op++ = 255; *op++ = 255; } 
+            if (length >= 255) { length-=255; *op++ = 255; } 
+            *op++ = (BYTE)length; 
+        }
+        else *token += (BYTE)(length);
+
+        // Test end of chunk
+        if (ip > mflimit) { anchor = ip;  break; }
+
+        // Fill table
+        LZ4_putPosition(ip-2, ctx, tableType, base);
+
+        // Test next position
+        ref = LZ4_getPosition(ip, ctx, tableType, base); 
+        LZ4_putPosition(ip, ctx, tableType, base);
+        if ((ref + MAX_DISTANCE >= ip) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
+
+        // Prepare next loop
+        anchor = ip++;
+        forwardH = LZ4_hashPosition(ip, tableType);
+    }
+
+_last_literals:
+    // Encode Last Literals
+    {
+        int lastRun = (int)(iend - anchor);
+        if ((limitedOutput) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0;  // Check output limit
+        if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun >= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
+        else *op++ = (BYTE)(lastRun<<ML_BITS);
+        memcpy(op, anchor, iend - anchor);
+        op += iend-anchor;
+    }
+
+    // End
+    return (int) (((char*)op)-dest);
+}
+
+
+int LZ4_compress(const char* source, char* dest, int inputSize)
+{
+#if (HEAPMODE)
+    void* ctx = ALLOCATOR(HASHNBCELLS4, 4);   // Aligned on 4-bytes boundaries
+#else
+    U32 ctx[1U<<(MEMORY_USAGE-2)] = {0};           // Ensure data is aligned on 4-bytes boundaries
+#endif
+    int result;
+
+    if (inputSize < (int)LZ4_64KLIMIT)
+        result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noPrefix);
+    else
+        result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
+
+#if (HEAPMODE)
+    FREEMEM(ctx);
+#endif
+    return result;
+}
+
+int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize)
+{
+    return LZ4_compress_generic(LZ4_Data, source, dest, inputSize, 0, notLimited, byU32, withPrefix);
+}
+
+
+int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize)
+{
+#if (HEAPMODE)
+    void* ctx = ALLOCATOR(HASHNBCELLS4, 4);   // Aligned on 4-bytes boundaries
+#else
+    U32 ctx[1U<<(MEMORY_USAGE-2)] = {0};           // Ensure data is aligned on 4-bytes boundaries
+#endif
+    int result;
+
+    if (inputSize < (int)LZ4_64KLIMIT)
+        result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limited, byU16, noPrefix);
+    else
+        result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
+
+#if (HEAPMODE)
+    FREEMEM(ctx);
+#endif
+    return result;
+}
+
+int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize)
+{
+    return LZ4_compress_generic(LZ4_Data, source, dest, inputSize, maxOutputSize, limited, byU32, withPrefix);
+}
+
+
+//****************************
+// Stream functions
+//****************************
+
+FORCE_INLINE void LZ4_init(LZ4_Data_Structure* lz4ds, const BYTE* base)
+{
+    MEM_INIT(lz4ds->hashTable, 0, sizeof(lz4ds->hashTable));
+    lz4ds->bufferStart = base;
+    lz4ds->base = base;
+    lz4ds->nextBlock = base;
+}
+
+
+void* LZ4_create (const char* inputBuffer)
+{
+    void* lz4ds = ALLOCATOR(1, sizeof(LZ4_Data_Structure));
+    LZ4_init ((LZ4_Data_Structure*)lz4ds, (const BYTE*)inputBuffer);
+    return lz4ds;
+}
+
+
+int LZ4_free (void* LZ4_Data)
+{
+    FREEMEM(LZ4_Data);
+    return (0);
+}
+
+
+char* LZ4_slideInputBuffer (void* LZ4_Data)
+{
+    LZ4_Data_Structure* lz4ds = (LZ4_Data_Structure*)LZ4_Data;
+    size_t delta = lz4ds->nextBlock - (lz4ds->bufferStart + 64 KB);
+
+    if ( (lz4ds->base - delta > lz4ds->base)                          // underflow control
+       || ((size_t)(lz4ds->nextBlock - lz4ds->base) > 0xE0000000) )   // close to 32-bits limit
+    {
+        size_t deltaLimit = (lz4ds->nextBlock - 64 KB) - lz4ds->base;
+        int nH;
+
+        for (nH=0; nH < HASHNBCELLS4; nH++)
+        {
+            if ((size_t)(lz4ds->hashTable[nH]) < deltaLimit) lz4ds->hashTable[nH] = 0;
+            else lz4ds->hashTable[nH] -= (U32)deltaLimit;
+        }
+        memcpy((void*)(lz4ds->bufferStart), (const void*)(lz4ds->nextBlock - 64 KB), 64 KB);
+        lz4ds->base = lz4ds->bufferStart;
+        lz4ds->nextBlock = lz4ds->base + 64 KB;
+    }
+    else
+    {
+		memcpy((void*)(lz4ds->bufferStart), (const void*)(lz4ds->nextBlock - 64 KB), 64 KB);
+		lz4ds->nextBlock -= delta;
+		lz4ds->base -= delta;
+	}
+
+    return (char*)(lz4ds->nextBlock);
+}
+
+
+//****************************
+// Decompression functions
+//****************************
+
+// This generic decompression function cover all use cases.
+// It shall be instanciated several times, using different sets of directives
+// Note that it is essential this generic function is really inlined, 
+// in order to remove useless branches during compilation optimisation.
+FORCE_INLINE int LZ4_decompress_generic(
+                 const char* source,
+                 char* dest,
+                 int inputSize,          //
+                 int outputSize,         // If endOnInput==endOnInputSize, this value is the max size of Output Buffer.
+
+                 int endOnInput,         // endOnOutputSize, endOnInputSize
+                 int prefix64k,          // noPrefix, withPrefix
+                 int partialDecoding,    // full, partial
+                 int targetOutputSize    // only used if partialDecoding==partial
+                 )
+{
+    // Local Variables
+    const BYTE* restrict ip = (const BYTE*) source;
+    const BYTE* ref;
+    const BYTE* const iend = ip + inputSize;
+
+    BYTE* op = (BYTE*) dest;
+    BYTE* const oend = op + outputSize;
+    BYTE* cpy;
+    BYTE* oexit = op + targetOutputSize;
+
+    const size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0};   // static reduces speed for LZ4_decompress_safe() on GCC64
+    static const size_t dec64table[] = {0, 0, 0, (size_t)-1, 0, 1, 2, 3};
+
+
+    // Special cases
+    if ((partialDecoding) && (oexit> oend-MFLIMIT)) oexit = oend-MFLIMIT;                        // targetOutputSize too high => decode everything
+    if ((endOnInput) && unlikely(outputSize==0)) return ((inputSize==1) && (*ip==0)) ? 0 : -1;   // Empty output buffer
+    if ((!endOnInput) && unlikely(outputSize==0)) return (*ip==0?1:-1);
+
+
+    // Main Loop
+    while (1)
+    {
+        unsigned token;
+        size_t length;
+
+        // get runlength
+        token = *ip++;
+        if ((length=(token>>ML_BITS)) == RUN_MASK)
+        { 
+            unsigned s=255; 
+            while (((endOnInput)?ip<iend:1) && (s==255))
+            { 
+                s = *ip++; 
+                length += s; 
+            } 
+        }
+
+        // copy literals
+        cpy = op+length;
+        if (((endOnInput) && ((cpy>(partialDecoding?oexit:oend-MFLIMIT)) || (ip+length>iend-(2+1+LASTLITERALS))) )
+            || ((!endOnInput) && (cpy>oend-COPYLENGTH)))
+        {
+            if (partialDecoding)
+            {
+                if (cpy > oend) goto _output_error;                           // Error : write attempt beyond end of output buffer
+                if ((endOnInput) && (ip+length > iend)) goto _output_error;   // Error : read attempt beyond end of input buffer
+            }
+            else
+            {
+                if ((!endOnInput) && (cpy != oend)) goto _output_error;       // Error : block decoding must stop exactly there
+                if ((endOnInput) && ((ip+length != iend) || (cpy > oend))) goto _output_error;   // Error : input must be consumed
+            }
+            memcpy(op, ip, length);
+            ip += length;
+            op += length;
+            break;                                       // Necessarily EOF, due to parsing restrictions
+        }
+        LZ4_WILDCOPY(op, ip, cpy); ip -= (op-cpy); op = cpy;
+
+        // get offset
+        LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;
+        if ((prefix64k==noPrefix) && unlikely(ref < (BYTE* const)dest)) goto _output_error;   // Error : offset outside destination buffer
+
+        // get matchlength
+        if ((length=(token&ML_MASK)) == ML_MASK) 
+        { 
+            while ((!endOnInput) || (ip<iend-(LASTLITERALS+1)))   // Ensure enough bytes remain for LASTLITERALS + token
+            {
+                unsigned s = *ip++; 
+                length += s; 
+                if (s==255) continue; 
+                break; 
+            }
+        }
+
+        // copy repeated sequence
+        if unlikely((op-ref)<(int)STEPSIZE)
+        {
+            const size_t dec64 = dec64table[(sizeof(void*)==4) ? 0 : op-ref];
+            op[0] = ref[0];
+            op[1] = ref[1];
+            op[2] = ref[2];
+            op[3] = ref[3];
+            op += 4, ref += 4; ref -= dec32table[op-ref];
+            A32(op) = A32(ref); 
+            op += STEPSIZE-4; ref -= dec64;
+        } else { LZ4_COPYSTEP(op,ref); }
+        cpy = op + length - (STEPSIZE-4);
+
+        if unlikely(cpy>oend-COPYLENGTH-(STEPSIZE-4))
+        {
+            if (cpy > oend-LASTLITERALS) goto _output_error;    // Error : last 5 bytes must be literals
+            LZ4_SECURECOPY(op, ref, (oend-COPYLENGTH));
+            while(op<cpy) *op++=*ref++;
+            op=cpy;
+            continue;
+        }
+        LZ4_WILDCOPY(op, ref, cpy);
+        op=cpy;   // correction
+    }
+
+    // end of decoding
+    if (endOnInput)
+       return (int) (((char*)op)-dest);     // Nb of output bytes decoded
+    else
+       return (int) (((char*)ip)-source);   // Nb of input bytes read
+
+    // Overflow error detected
+_output_error:
+    return (int) (-(((char*)ip)-source))-1;
+}
+
+
+int LZ4_decompress_safe(const char* source, char* dest, int inputSize, int maxOutputSize)
+{
+    return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, noPrefix, full, 0);
+}
+
+int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int inputSize, int maxOutputSize)
+{
+    return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, withPrefix, full, 0);
+}
+
+int LZ4_decompress_safe_partial(const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize)
+{
+    return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, noPrefix, partial, targetOutputSize);
+}
+
+int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int outputSize)
+{
+    return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, withPrefix, full, 0);
+}
+
+int LZ4_decompress_fast(const char* source, char* dest, int outputSize)
+{
+#ifdef _MSC_VER   // This version is faster with Visual
+    return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, noPrefix, full, 0);
+#else
+    return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, withPrefix, full, 0);
+#endif
+}
+
diff --git a/src/helpers/fst/lz4.h b/src/helpers/fst/lz4.h
new file mode 100644
index 0000000..2ab539f
--- /dev/null
+++ b/src/helpers/fst/lz4.h
@@ -0,0 +1,205 @@
+/*
+   LZ4 - Fast LZ compression algorithm
+   Header File
+   Copyright (C) 2011-2013, Yann Collet.
+   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are
+   met:
+
+       * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above
+   copyright notice, this list of conditions and the following disclaimer
+   in the documentation and/or other materials provided with the
+   distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+   You can contact the author at :
+   - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+   - LZ4 source repository : http://code.google.com/p/lz4/
+*/
+#pragma once
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+
+//**************************************
+// Compiler Options
+//**************************************
+#if defined(_MSC_VER) && !defined(__cplusplus)   // Visual Studio
+#  define inline __inline           // Visual C is not C99, but supports some kind of inline
+#endif
+
+
+//****************************
+// Simple Functions
+//****************************
+
+int LZ4_compress        (const char* source, char* dest, int inputSize);
+int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);
+
+/*
+LZ4_compress() :
+    Compresses 'inputSize' bytes from 'source' into 'dest'.
+    Destination buffer must be already allocated,
+    and must be sized to handle worst cases situations (input data not compressible)
+    Worst case size evaluation is provided by function LZ4_compressBound()
+    inputSize : Max supported value is LZ4_MAX_INPUT_VALUE
+    return : the number of bytes written in buffer dest
+             or 0 if the compression fails
+
+LZ4_decompress_safe() :
+    maxOutputSize : is the size of the destination buffer (which must be already allocated)
+    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+             If the source stream is detected malformed, the function will stop decoding and return a negative result.
+             This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets
+*/
+
+
+//****************************
+// Advanced Functions
+//****************************
+#define LZ4_MAX_INPUT_SIZE        0x7E000000   // 2 113 929 216 bytes
+#define LZ4_COMPRESSBOUND(isize)  ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
+static inline int LZ4_compressBound(int isize)  { return LZ4_COMPRESSBOUND(isize); }
+
+/*
+LZ4_compressBound() :
+    Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
+    primarily useful for memory allocation of output buffer.
+    inline function is recommended for the general case,
+    macro is also provided when result needs to be evaluated at compilation (such as stack memory allocation).
+
+    isize  : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE
+    return : maximum output size in a "worst case" scenario
+             or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
+*/
+
+
+int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
+
+/*
+LZ4_compress_limitedOutput() :
+    Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
+    If it cannot achieve it, compression will stop, and result of the function will be zero.
+    This function never writes outside of provided output buffer.
+
+    inputSize  : Max supported value is LZ4_MAX_INPUT_VALUE
+    maxOutputSize : is the size of the destination buffer (which must be already allocated)
+    return : the number of bytes written in buffer 'dest'
+             or 0 if the compression fails
+*/
+
+
+int LZ4_decompress_fast (const char* source, char* dest, int outputSize);
+
+/*
+LZ4_decompress_fast() :
+    outputSize : is the original (uncompressed) size
+    return : the number of bytes read from the source buffer (in other words, the compressed size)
+             If the source stream is malformed, the function will stop decoding and return a negative result.
+    note : This function is a bit faster than LZ4_decompress_safe()
+           This function never writes outside of output buffers, but may read beyond input buffer in case of malicious data packet.
+           Use this function preferably into a trusted environment (data to decode comes from a trusted source).
+           Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.
+*/
+
+int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);
+
+/*
+LZ4_decompress_safe_partial() :
+    This function decompress a compressed block of size 'inputSize' at position 'source'
+    into output buffer 'dest' of size 'maxOutputSize'.
+    The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
+    reducing decompression time.
+    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+       Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
+             Always control how many bytes were decoded.
+             If the source stream is detected malformed, the function will stop decoding and return a negative result.
+             This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
+*/
+
+
+//****************************
+// Stream Functions
+//****************************
+
+void* LZ4_create (const char* inputBuffer);
+int   LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);
+int   LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
+char* LZ4_slideInputBuffer (void* LZ4_Data);
+int   LZ4_free (void* LZ4_Data);
+
+/* 
+These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.
+In order to achieve this, it is necessary to start creating the LZ4 Data Structure, thanks to the function :
+
+void* LZ4_create (const char* inputBuffer);
+The result of the function is the (void*) pointer on the LZ4 Data Structure.
+This pointer will be needed in all other functions.
+If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.
+The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
+The input buffer must be already allocated, and size at least 192KB.
+'inputBuffer' will also be the 'const char* source' of the first block.
+
+All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.
+To compress each block, use either LZ4_compress_continue() or LZ4_compress_limitedOutput_continue().
+Their behavior are identical to LZ4_compress() or LZ4_compress_limitedOutput(), 
+but require the LZ4 Data Structure as their first argument, and check that each block starts right after the previous one.
+If next block does not begin immediately after the previous one, the compression will fail (return 0).
+
+When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to : 
+char* LZ4_slideInputBuffer(void* LZ4_Data);
+must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.
+Note that, for this function to work properly, minimum size of an input buffer must be 192KB.
+==> The memory position where the next input data block must start is provided as the result of the function.
+
+Compression can then resume, using LZ4_compress_continue() or LZ4_compress_limitedOutput_continue(), as usual.
+
+When compression is completed, a call to LZ4_free() will release the memory used by the LZ4 Data Structure.
+*/
+
+
+int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);
+int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);
+
+/*
+*_withPrefix64k() :
+    These decoding functions work the same as their "normal name" versions,
+    but can use up to 64KB of data in front of 'char* dest'.
+    These functions are necessary to decode inter-dependant blocks.
+*/
+
+
+//****************************
+// Obsolete Functions
+//****************************
+
+static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
+static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
+
+/*
+These functions are deprecated and should no longer be used.
+They are provided here for compatibility with existing user programs.
+*/
+
+
+
+#if defined (__cplusplus)
+}
+#endif
diff --git a/src/helpers/fst2vcd.c b/src/helpers/fst2vcd.c
index f47c01a..f20ab03 100644
--- a/src/helpers/fst2vcd.c
+++ b/src/helpers/fst2vcd.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2009 Tony Bybell.
+ * Copyright (c) 2003-2013 Tony Bybell.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -38,6 +38,7 @@ printf(
 "Usage: %s [OPTION]... [FSTFILE]\n\n"
 "  -f, --fstname=FILE         specify FST input filename\n"
 "  -o, --output=FILE          specify output filename\n"
+"  -e, --extensions           emit FST extensions to VCD\n"
 "  -h, --help                 display this help then exit\n\n"
 "VCD is emitted to stdout if output filename is unspecified.\n\n"
 "Report bugs to <"PACKAGE_BUGREPORT">.\n",nam);
@@ -46,6 +47,7 @@ printf(
 "Usage: %s [OPTION]... [FSTFILE]\n\n"
 "  -f                         specify FST input filename\n"
 "  -o                         specify output filename\n"
+"  -e                         emit FST extensions to VCD\n"
 "  -h                         display this help then exit\n\n"
 "VCD is emitted to stdout if output filename is unspecified.\n\n"
 "Report bugs to <"PACKAGE_BUGREPORT">.\n",nam);
@@ -64,6 +66,7 @@ char *fvbuf=NULL;
 int c;
 struct fstReaderContext *xc;
 FILE *fv;
+int use_extensions = 0;
 
 WAVE_LOCALE_FIX
 
@@ -74,21 +77,26 @@ while (1)
                         
         static struct option long_options[] =
                 {
+		{"extensions", 0, 0, 'e'},
 		{"fstname", 1, 0, 'f'},
 		{"output", 1, 0, 'o'},
                 {"help", 0, 0, 'h'},
                 {0, 0, 0, 0}  
                 };
                 
-        c = getopt_long (argc, argv, "f:o:h", long_options, &option_index);
+        c = getopt_long (argc, argv, "ef:o:h", long_options, &option_index);
 #else
-        c = getopt      (argc, argv, "f:o:h");
+        c = getopt      (argc, argv, "ef:o:h");
 #endif
                         
         if (c == -1) break;     /* no more args */
                         
         switch (c)
                 {
+		case 'e':
+			use_extensions = 1;
+			break;
+
 		case 'f':
 			if(fstname) free(fstname);
                         fstname = malloc(strlen(optarg)+1);
@@ -167,6 +175,7 @@ if(outname)
 	fv = stdout;
 	}
 
+fstReaderSetVcdExtensions(xc, use_extensions);	/* TRUE is incompatible with vfast and other tools */
 if(!fstReaderProcessHier(xc, fv))		/* these 3 lines do all the VCD writing work */
 	{
 	fprintf(stderr, "could not process hierarchy for '%s', exiting.\n", fstname);
diff --git a/src/helpers/vcd2fst.c b/src/helpers/vcd2fst.c
index 823ca51..a3b148c 100644
--- a/src/helpers/vcd2fst.c
+++ b/src/helpers/vcd2fst.c
@@ -42,7 +42,13 @@
 #endif
 #endif
 
-#if defined(VCD2FST_EXTLOAD_CONV) || defined(VCD2FST_EXT2LOAD_CONV)
+#ifdef EXT3LOAD_SUFFIX
+#ifdef EXT3CONV_PATH
+#define VCD2FST_EXT3LOAD_CONV
+#endif
+#endif
+
+#if defined(VCD2FST_EXTLOAD_CONV) || defined(VCD2FST_EXT2LOAD_CONV) || defined(VCD2FST_EXT3LOAD_CONV)
 #define VCD2FST_EXTLOADERS_CONV
 #endif
 
@@ -412,7 +418,7 @@ for(i=0;i<len;i++)
 return(val);
 }  
 
-int pack_type = 0;  /* set to 1 for fastlz */
+int pack_type = FST_WR_PT_ZLIB;  /* set to fstWriterPackType */
 int repack_all = 0; /* 0 is normal, 1 does the repack (via fstapi) at end */
 int parallel_mode = 0; /* 0 is is single threaded, 1 is multi-threaded */
 
@@ -478,6 +484,15 @@ if(!strcmp("-", vname))
 			}
 			else
 #endif
+#ifdef VCD2FST_EXT3LOAD_CONV
+		if(suffix_check(vname, "."EXT3LOAD_SUFFIX))
+			{
+			sprintf(bin_fixbuff, EXT3CONV_PATH" %s", vname);
+			f = popen(bin_fixbuff, "r");
+			is_popen = 1;
+			}
+			else
+#endif
 			{
 			f = fopen(vname, "rb");
 			}
@@ -1525,59 +1540,49 @@ return(0);
 void print_help(char *nam)
 {
 #ifdef VCD2FST_EXTLOADERS_CONV
-#if defined(VCD2FST_EXTLOAD_CONV) && defined(VCD2FST_EXT2LOAD_CONV)
 
-int slen = strlen(EXTLOAD_SUFFIX) + 1 + strlen(EXT2LOAD_SUFFIX);
-char *ucase_ext = calloc(1, slen+1);
+int slen;
+char *ucase_ext = calloc(1, 1024);
 int i;
 
-sprintf(ucase_ext, "%s/%s", EXTLOAD_SUFFIX, EXT2LOAD_SUFFIX);
+ucase_ext[0] = 0;
 
-for(i=0;i<slen;i++)
-	{
-	ucase_ext[i] = toupper(ucase_ext[i]);
-	}
+#if defined(VCD2FST_EXTLOAD_CONV)
+strcat(ucase_ext, "/");
+strcat(ucase_ext, EXTLOAD_SUFFIX);
+#endif
 
-#else
-#ifdef VCD2FST_EXTLOAD_CONV
-int slen = strlen(EXTLOAD_SUFFIX);
-char *ucase_ext = calloc(1, slen+1);
-int i;
+#if defined(VCD2FST_EXT2LOAD_CONV)
+strcat(ucase_ext, "/");
+strcat(ucase_ext, EXT2LOAD_SUFFIX);
+#endif
 
-for(i=0;i<slen;i++)
-	{
-	ucase_ext[i] = toupper(EXTLOAD_SUFFIX[i]);
-	}
+#if defined(VCD2FST_EXT3LOAD_CONV)
+strcat(ucase_ext, "/");
+strcat(ucase_ext, EXT3LOAD_SUFFIX);
 #endif
-#ifdef VCD2FST_EXT2LOAD_CONV
-int slen = strlen(EXT2LOAD_SUFFIX);
-char *ucase_ext = calloc(1, slen+1);
-int i;
+
+slen = strlen(ucase_ext);
 
 for(i=0;i<slen;i++)
 	{
-	ucase_ext[i] = toupper(EXT2LOAD_SUFFIX[i]);
+	ucase_ext[i] = toupper(ucase_ext[i]);
 	}
-#endif
-#endif
 
 #endif
 
 
-
-
-
-
 #ifdef __linux__ 
 printf(
 "Usage: %s [OPTION]... [VCDFILE] [FSTFILE]\n\n"
 #ifdef VCD2FST_EXTLOADERS_CONV
-"  -v, --vcdname=FILE         specify VCD/%s input filename\n"
+"  -v, --vcdname=FILE         specify VCD%s input filename\n"
 #else
 "  -v, --vcdname=FILE         specify VCD input filename\n"
 #endif
 "  -f, --fstname=FILE         specify FST output filename\n"
 "  -F, --fastpack             use fastlz algorithm for speed\n"
+"  -4, --fourpack             use lz4 algorithm for speed\n"
 "  -c, --compress             compress entire file on close\n"
 "  -p, --parallel             enable parallel mode\n"
 "  -h, --help                 display this help then exit\n\n"
@@ -1593,12 +1598,13 @@ printf(
 printf(
 "Usage: %s [OPTION]... [VCDFILE] [FSTFILE]\n\n"
 #ifdef VCD2FST_EXTLOADERS_CONV
-"  -v FILE                    specify VCD/%s input filename\n"
+"  -v FILE                    specify VCD%s input filename\n"
 #else
 "  -v FILE                    specify VCD input filename\n"
 #endif
 "  -f FILE                    specify FST output filename\n"
 "  -F                         use fastlz algorithm for speed\n"
+"  -4                         use lz4 algorithm for speed\n"
 "  -c                         compress entire file on close\n"
 "  -p                         enable parallel mode\n"
 "  -h                         display this help then exit\n\n"
@@ -1638,15 +1644,16 @@ while (1)
 		{"vcdname", 1, 0, 'v'},
 		{"fstname", 1, 0, 'f'},
 		{"fastpack", 0, 0, 'F'},
+		{"fourpack", 0, 0, '4'},
 		{"compress", 0, 0, 'c'},
 		{"parallel", 0, 0, 'p'},
                 {"help", 0, 0, 'h'},
                 {0, 0, 0, 0}  
                 };
                 
-        c = getopt_long (argc, argv, "v:f:Fcph", long_options, &option_index);
+        c = getopt_long (argc, argv, "v:f:F4cph", long_options, &option_index);
 #else
-        c = getopt      (argc, argv, "v:f:Fcph");
+        c = getopt      (argc, argv, "v:f:F4cph");
 #endif
                         
         if (c == -1) break;     /* no more args */
@@ -1666,7 +1673,14 @@ while (1)
 			break;
 
 		case 'F':
-			pack_type = 1;
+			if(pack_type == FST_WR_PT_ZLIB)
+				{
+				pack_type = FST_WR_PT_FASTLZ;
+				}
+			break;
+
+		case '4':
+			pack_type = FST_WR_PT_LZ4;
 			break;
 
 		case 'c':
diff --git a/src/libbz2/Makefile.in b/src/libbz2/Makefile.in
index 47192d0..9d4d1b8 100644
--- a/src/libbz2/Makefile.in
+++ b/src/libbz2/Makefile.in
@@ -159,6 +159,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -201,6 +202,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/src/liblzma/Makefile.in b/src/liblzma/Makefile.in
index a4206cc..2a8a99a 100644
--- a/src/liblzma/Makefile.in
+++ b/src/liblzma/Makefile.in
@@ -157,6 +157,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -199,6 +200,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/src/libz/Makefile.in b/src/libz/Makefile.in
index 27a0afd..a8fde49 100644
--- a/src/libz/Makefile.in
+++ b/src/libz/Makefile.in
@@ -162,6 +162,7 @@ EXEEXT = @EXEEXT@
 EXTDEBUG = @EXTDEBUG@
 EXTDEBUG2 = @EXTDEBUG2@
 EXTDEBUG3 = @EXTDEBUG3@
+EXTDEBUG4 = @EXTDEBUG4@
 EXTLOAD_CFLAGS = @EXTLOAD_CFLAGS@
 FASTTREE_CFLAGS = @FASTTREE_CFLAGS@
 FSDB_CFLAGS = @FSDB_CFLAGS@
@@ -204,6 +205,7 @@ LIBZ_LDADD = @LIBZ_LDADD@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MINGW_LDADD = @MINGW_LDADD@
 MKDIR_P = @MKDIR_P@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
diff --git a/src/libz/README b/src/libz/README
index 0f12054..5ca9d12 100644
--- a/src/libz/README
+++ b/src/libz/README
@@ -1,57 +1,52 @@
 ZLIB DATA COMPRESSION LIBRARY
 
-zlib 1.2.1 is a general purpose data compression library.  All the code is
+zlib 1.2.8 is a general purpose data compression library.  All the code is
 thread safe.  The data format used by the zlib library is described by RFCs
 (Request for Comments) 1950 to 1952 in the files
-http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
-and rfc1952.txt (gzip format). These documents are also available in other
-formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
+rfc1952 (gzip format).
 
 All functions of the compression library are documented in the file zlib.h
-(volunteer to write man pages welcome, contact zlib at gzip.org). A usage example
-of the library is given in the file example.c which also tests that the library
-is working correctly. Another example is given in the file minigzip.c. The
-compression library itself is composed of all source files except example.c and
-minigzip.c.
+(volunteer to write man pages welcome, contact zlib at gzip.org).  A usage example
+of the library is given in the file test/example.c which also tests that
+the library is working correctly.  Another example is given in the file
+test/minigzip.c.  The compression library itself is composed of all source
+files in the root directory.
 
 To compile all files and run the test program, follow the instructions given at
-the top of Makefile. In short "make test; make install" should work for most
-machines. For Unix: "./configure; make test; make install" For MSDOS, use one
-of the special makefiles such as Makefile.msc. For VMS, use Make_vms.com or
-descrip.mms.
+the top of Makefile.in.  In short "./configure; make test", and if that goes
+well, "make install" should work for most flavors of Unix.  For Windows, use
+one of the special makefiles in win32/ or contrib/vstudio/ .  For VMS, use
+make_vms.com.
 
 Questions about zlib should be sent to <zlib at gzip.org>, or to Gilles Vollant
-<info at winimage.com> for the Windows DLL version. The zlib home page is
-http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
-please check this site to verify that you have the latest version of zlib;
-otherwise get the latest version and check whether the problem still exists or
-not.
+<info at winimage.com> for the Windows DLL version.  The zlib home page is
+http://zlib.net/ .  Before reporting a problem, please check this site to
+verify that you have the latest version of zlib; otherwise get the latest
+version and check whether the problem still exists or not.
 
-PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
-for help.
+PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
 
-Mark Nelson <markn at ieee.org> wrote an article about zlib for the Jan. 1997
-issue of  Dr. Dobb's Journal; a copy of the article is available in
-http://dogma.net/markn/articles/zlibtool/zlibtool.htm
+Mark Nelson <markn at ieee.org> wrote an article about zlib for the Jan.  1997
+issue of Dr.  Dobb's Journal; a copy of the article is available at
+http://marknelson.us/1997/01/01/zlib-engine/ .
 
-The changes made in version 1.2.1 are documented in the file ChangeLog.
+The changes made in version 1.2.8 are documented in the file ChangeLog.
 
-Unsupported third party contributions are provided in directory "contrib".
+Unsupported third party contributions are provided in directory contrib/ .
 
-A Java implementation of zlib is available in the Java Development Kit
-http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/package-summary.html
-See the zlib home page http://www.zlib.org for details.
+zlib is available in Java using the java.util.zip package, documented at
+http://java.sun.com/developer/technicalArticles/Programming/compression/ .
 
-A Perl interface to zlib written by Paul Marquess <pmqs at cpan.org> is in the
-CPAN (Comprehensive Perl Archive Network) sites
-http://www.cpan.org/modules/by-module/Compress/
+A Perl interface to zlib written by Paul Marquess <pmqs at cpan.org> is available
+at CPAN (Comprehensive Perl Archive Network) sites, including
+http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
 
-A Python interface to zlib written by A.M. Kuchling <amk at magnet.com> is
+A Python interface to zlib written by A.M. Kuchling <amk at amk.ca> is
 available in Python 1.5 and later versions, see
-http://www.python.org/doc/lib/module-zlib.html
+http://docs.python.org/library/zlib.html .
 
-A zlib binding for TCL written by Andreas Kupries <a.kupries at westend.com> is
-availlable at http://www.oche.de/~akupries/soft/trf/trf_zip.html
+zlib is built into tcl: http://wiki.tcl.tk/4610 .
 
 An experimental package to read and write files in .zip format, written on top
 of zlib by Gilles Vollant <info at winimage.com>, is available in the
@@ -75,25 +70,21 @@ Notes for some targets:
 - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
   other compilers. Use "make test" to check your compiler.
 
-- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
+- gzdopen is not supported on RISCOS or BEOS.
 
 - For PalmOs, see http://palmzlib.sourceforge.net/
 
-- When building a shared, i.e. dynamic library on Mac OS X, the library must be
-  installed before testing (do "make install" before "make test"), since the
-  library location is specified in the library.
-
 
 Acknowledgments:
 
-  The deflate format used by zlib was defined by Phil Katz. The deflate
-  and zlib specifications were written by L. Peter Deutsch. Thanks to all the
-  people who reported problems and suggested various improvements in zlib;
-  they are too numerous to cite here.
+  The deflate format used by zlib was defined by Phil Katz.  The deflate and
+  zlib specifications were written by L.  Peter Deutsch.  Thanks to all the
+  people who reported problems and suggested various improvements in zlib; they
+  are too numerous to cite here.
 
 Copyright notice:
 
- (C) 1995-2003 Jean-loup Gailly and Mark Adler
+ (C) 1995-2013 Jean-loup Gailly and Mark Adler
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -114,13 +105,11 @@ Copyright notice:
   Jean-loup Gailly        Mark Adler
   jloup at gzip.org          madler at alumni.caltech.edu
 
-If you use the zlib library in a product, we would appreciate *not*
-receiving lengthy legal documents to sign. The sources are provided
-for free but without warranty of any kind.  The library has been
-entirely written by Jean-loup Gailly and Mark Adler; it does not
-include third-party code.
+If you use the zlib library in a product, we would appreciate *not* receiving
+lengthy legal documents to sign.  The sources are provided for free but without
+warranty of any kind.  The library has been entirely written by Jean-loup
+Gailly and Mark Adler; it does not include third-party code.
 
-If you redistribute modified sources, we would appreciate that you include
-in the file ChangeLog history information documenting your changes. Please
-read the FAQ for more information on the distribution of modified source
-versions.
+If you redistribute modified sources, we would appreciate that you include in
+the file ChangeLog history information documenting your changes.  Please read
+the FAQ for more information on the distribution of modified source versions.
diff --git a/src/libz/adler32.c b/src/libz/adler32.c
index 7749754..a868f07 100644
--- a/src/libz/adler32.c
+++ b/src/libz/adler32.c
@@ -1,17 +1,17 @@
 /* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-2007 Mark Adler
+ * Copyright (C) 1995-2011 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $Id: adler32.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #include "zutil.h"
 
 #define local static
 
-local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
+local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
 
-#define BASE 65521UL    /* largest prime smaller than 65536 */
+#define BASE 65521      /* largest prime smaller than 65536 */
 #define NMAX 5552
 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
 
@@ -21,39 +21,44 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
 #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
 #define DO16(buf)   DO8(buf,0); DO8(buf,8);
 
-/* use NO_DIVIDE if your processor does not do division in hardware */
+/* use NO_DIVIDE if your processor does not do division in hardware --
+   try it both ways to see which is faster */
 #ifdef NO_DIVIDE
-#  define MOD(a) \
+/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
+   (thank you to John Reiser for pointing this out) */
+#  define CHOP(a) \
+    do { \
+        unsigned long tmp = a >> 16; \
+        a &= 0xffffUL; \
+        a += (tmp << 4) - tmp; \
+    } while (0)
+#  define MOD28(a) \
     do { \
-        if (a >= (BASE << 16)) a -= (BASE << 16); \
-        if (a >= (BASE << 15)) a -= (BASE << 15); \
-        if (a >= (BASE << 14)) a -= (BASE << 14); \
-        if (a >= (BASE << 13)) a -= (BASE << 13); \
-        if (a >= (BASE << 12)) a -= (BASE << 12); \
-        if (a >= (BASE << 11)) a -= (BASE << 11); \
-        if (a >= (BASE << 10)) a -= (BASE << 10); \
-        if (a >= (BASE << 9)) a -= (BASE << 9); \
-        if (a >= (BASE << 8)) a -= (BASE << 8); \
-        if (a >= (BASE << 7)) a -= (BASE << 7); \
-        if (a >= (BASE << 6)) a -= (BASE << 6); \
-        if (a >= (BASE << 5)) a -= (BASE << 5); \
-        if (a >= (BASE << 4)) a -= (BASE << 4); \
-        if (a >= (BASE << 3)) a -= (BASE << 3); \
-        if (a >= (BASE << 2)) a -= (BASE << 2); \
-        if (a >= (BASE << 1)) a -= (BASE << 1); \
+        CHOP(a); \
         if (a >= BASE) a -= BASE; \
     } while (0)
-#  define MOD4(a) \
+#  define MOD(a) \
     do { \
-        if (a >= (BASE << 4)) a -= (BASE << 4); \
-        if (a >= (BASE << 3)) a -= (BASE << 3); \
-        if (a >= (BASE << 2)) a -= (BASE << 2); \
-        if (a >= (BASE << 1)) a -= (BASE << 1); \
+        CHOP(a); \
+        MOD28(a); \
+    } while (0)
+#  define MOD63(a) \
+    do { /* this assumes a is not negative */ \
+        z_off64_t tmp = a >> 32; \
+        a &= 0xffffffffL; \
+        a += (tmp << 8) - (tmp << 5) + tmp; \
+        tmp = a >> 16; \
+        a &= 0xffffL; \
+        a += (tmp << 4) - tmp; \
+        tmp = a >> 16; \
+        a &= 0xffffL; \
+        a += (tmp << 4) - tmp; \
         if (a >= BASE) a -= BASE; \
     } while (0)
 #else
 #  define MOD(a) a %= BASE
-#  define MOD4(a) a %= BASE
+#  define MOD28(a) a %= BASE
+#  define MOD63(a) a %= BASE
 #endif
 
 /* ========================================================================= */
@@ -92,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
         }
         if (adler >= BASE)
             adler -= BASE;
-        MOD4(sum2);             /* only added so many BASE's */
+        MOD28(sum2);            /* only added so many BASE's */
         return adler | (sum2 << 16);
     }
 
@@ -137,8 +142,13 @@ local uLong adler32_combine_(adler1, adler2, len2)
     unsigned long sum2;
     unsigned rem;
 
+    /* for negative len, return invalid adler32 as a clue for debugging */
+    if (len2 < 0)
+        return 0xffffffffUL;
+
     /* the derivation of this formula is left as an exercise for the reader */
-    rem = (unsigned)(len2 % BASE);
+    MOD63(len2);                /* assumes len2 >= 0 */
+    rem = (unsigned)len2;
     sum1 = adler1 & 0xffff;
     sum2 = rem * sum1;
     MOD(sum2);
diff --git a/src/libz/compress.c b/src/libz/compress.c
index 0c31ae0..6e97626 100644
--- a/src/libz/compress.c
+++ b/src/libz/compress.c
@@ -3,7 +3,7 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $Id: compress.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #define ZLIB_INTERNAL
 #include "zlib.h"
@@ -29,7 +29,7 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
     z_stream stream;
     int err;
 
-    stream.next_in = (Bytef*)source;
+    stream.next_in = (z_const Bytef *)source;
     stream.avail_in = (uInt)sourceLen;
 #ifdef MAXSEG_64K
     /* Check for source > 64K on 16-bit machine: */
diff --git a/src/libz/crc32.c b/src/libz/crc32.c
index 3819a9e..979a719 100644
--- a/src/libz/crc32.c
+++ b/src/libz/crc32.c
@@ -1,5 +1,5 @@
 /* crc32.c -- compute the CRC-32 of a data stream
- * Copyright (C) 1995-2006, 2010 Mark Adler
+ * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  *
  * Thanks to Rodney Brown <rbrown64 at csc.com.au> for his contribution of faster
@@ -9,7 +9,7 @@
  * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
  */
 
-/* @(#) $Id: crc32.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 /*
   Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
@@ -17,6 +17,8 @@
   of the crc tables.  Therefore, if you #define DYNAMIC_CRC_TABLE, you should
   first call get_crc_table() to initialize the tables before allowing more than
   one thread to use crc32().
+
+  DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
  */
 
 #ifdef MAKECRCH
@@ -30,31 +32,11 @@
 
 #define local static
 
-/* Find a four-byte integer type for crc32_little() and crc32_big(). */
-#ifndef NOBYFOUR
-#  ifdef STDC           /* need ANSI C limits.h to determine sizes */
-#    include <limits.h>
-#    define BYFOUR
-#    if (UINT_MAX == 0xffffffffUL)
-       typedef unsigned int u4;
-#    else
-#      if (ULONG_MAX == 0xffffffffUL)
-         typedef unsigned long u4;
-#      else
-#        if (USHRT_MAX == 0xffffffffUL)
-           typedef unsigned short u4;
-#        else
-#          undef BYFOUR     /* can't find a four-byte integer type! */
-#        endif
-#      endif
-#    endif
-#  endif /* STDC */
-#endif /* !NOBYFOUR */
-
 /* Definitions for doing the crc four data bytes at a time. */
+#if !defined(NOBYFOUR) && defined(Z_U4)
+#  define BYFOUR
+#endif
 #ifdef BYFOUR
-#  define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
-                (((w)&0xff00)<<8)+(((w)&0xff)<<24))
    local unsigned long crc32_little OF((unsigned long,
                         const unsigned char FAR *, unsigned));
    local unsigned long crc32_big OF((unsigned long,
@@ -68,16 +50,16 @@
 local unsigned long gf2_matrix_times OF((unsigned long *mat,
                                          unsigned long vec));
 local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
-local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
+local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
 
 
 #ifdef DYNAMIC_CRC_TABLE
 
 local volatile int crc_table_empty = 1;
-local unsigned long FAR crc_table[TBLS][256];
+local z_crc_t FAR crc_table[TBLS][256];
 local void make_crc_table OF((void));
 #ifdef MAKECRCH
-   local void write_table OF((FILE *, const unsigned long FAR *));
+   local void write_table OF((FILE *, const z_crc_t FAR *));
 #endif /* MAKECRCH */
 /*
   Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
@@ -107,9 +89,9 @@ local void make_crc_table OF((void));
 */
 local void make_crc_table()
 {
-    unsigned long c;
+    z_crc_t c;
     int n, k;
-    unsigned long poly;                 /* polynomial exclusive-or pattern */
+    z_crc_t poly;                       /* polynomial exclusive-or pattern */
     /* terms of polynomial defining this crc (except x^32): */
     static volatile int first = 1;      /* flag to limit concurrent making */
     static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
@@ -121,13 +103,13 @@ local void make_crc_table()
         first = 0;
 
         /* make exclusive-or pattern from polynomial (0xedb88320UL) */
-        poly = 0UL;
-        for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
-            poly |= 1UL << (31 - p[n]);
+        poly = 0;
+        for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
+            poly |= (z_crc_t)1 << (31 - p[n]);
 
         /* generate a crc for every 8-bit value */
         for (n = 0; n < 256; n++) {
-            c = (unsigned long)n;
+            c = (z_crc_t)n;
             for (k = 0; k < 8; k++)
                 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
             crc_table[0][n] = c;
@@ -138,11 +120,11 @@ local void make_crc_table()
            and then the byte reversal of those as well as the first table */
         for (n = 0; n < 256; n++) {
             c = crc_table[0][n];
-            crc_table[4][n] = REV(c);
+            crc_table[4][n] = ZSWAP32(c);
             for (k = 1; k < 4; k++) {
                 c = crc_table[0][c & 0xff] ^ (c >> 8);
                 crc_table[k][n] = c;
-                crc_table[k + 4][n] = REV(c);
+                crc_table[k + 4][n] = ZSWAP32(c);
             }
         }
 #endif /* BYFOUR */
@@ -164,7 +146,7 @@ local void make_crc_table()
         if (out == NULL) return;
         fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
         fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
-        fprintf(out, "local const unsigned long FAR ");
+        fprintf(out, "local const z_crc_t FAR ");
         fprintf(out, "crc_table[TBLS][256] =\n{\n  {\n");
         write_table(out, crc_table[0]);
 #  ifdef BYFOUR
@@ -184,12 +166,13 @@ local void make_crc_table()
 #ifdef MAKECRCH
 local void write_table(out, table)
     FILE *out;
-    const unsigned long FAR *table;
+    const z_crc_t FAR *table;
 {
     int n;
 
     for (n = 0; n < 256; n++)
-        fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : "    ", table[n],
+        fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : "    ",
+                (unsigned long)(table[n]),
                 n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
 }
 #endif /* MAKECRCH */
@@ -204,13 +187,13 @@ local void write_table(out, table)
 /* =========================================================================
  * This function can be used by asm versions of crc32()
  */
-const unsigned long FAR * ZEXPORT get_crc_table()
+const z_crc_t FAR * ZEXPORT get_crc_table()
 {
 #ifdef DYNAMIC_CRC_TABLE
     if (crc_table_empty)
         make_crc_table();
 #endif /* DYNAMIC_CRC_TABLE */
-    return (const unsigned long FAR *)crc_table;
+    return (const z_crc_t FAR *)crc_table;
 }
 
 /* ========================================================================= */
@@ -232,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
 
 #ifdef BYFOUR
     if (sizeof(void *) == sizeof(ptrdiff_t)) {
-        u4 endian;
+        z_crc_t endian;
 
         endian = 1;
         if (*((unsigned char *)(&endian)))
@@ -266,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
     const unsigned char FAR *buf;
     unsigned len;
 {
-    register u4 c;
-    register const u4 FAR *buf4;
+    register z_crc_t c;
+    register const z_crc_t FAR *buf4;
 
-    c = (u4)crc;
+    c = (z_crc_t)crc;
     c = ~c;
     while (len && ((ptrdiff_t)buf & 3)) {
         c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
         len--;
     }
 
-    buf4 = (const u4 FAR *)(const void FAR *)buf;
+    buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
     while (len >= 32) {
         DOLIT32;
         len -= 32;
@@ -306,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
     const unsigned char FAR *buf;
     unsigned len;
 {
-    register u4 c;
-    register const u4 FAR *buf4;
+    register z_crc_t c;
+    register const z_crc_t FAR *buf4;
 
-    c = REV((u4)crc);
+    c = ZSWAP32((z_crc_t)crc);
     c = ~c;
     while (len && ((ptrdiff_t)buf & 3)) {
         c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
         len--;
     }
 
-    buf4 = (const u4 FAR *)(const void FAR *)buf;
+    buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
     buf4--;
     while (len >= 32) {
         DOBIG32;
@@ -333,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
         c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
     } while (--len);
     c = ~c;
-    return (unsigned long)(REV(c));
+    return (unsigned long)(ZSWAP32(c));
 }
 
 #endif /* BYFOUR */
diff --git a/src/libz/crc32.h b/src/libz/crc32.h
index 8053b61..9e0c778 100644
--- a/src/libz/crc32.h
+++ b/src/libz/crc32.h
@@ -2,7 +2,7 @@
  * Generated automatically by crc32.c
  */
 
-local const unsigned long FAR crc_table[TBLS][256] =
+local const z_crc_t FAR crc_table[TBLS][256] =
 {
   {
     0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
diff --git a/src/libz/deflate.c b/src/libz/deflate.c
index 300330e..6969577 100644
--- a/src/libz/deflate.c
+++ b/src/libz/deflate.c
@@ -1,5 +1,5 @@
 /* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
+ * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -37,7 +37,7 @@
  *  REFERENCES
  *
  *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- *      Available in http://www.ietf.org/rfc/rfc1951.txt
+ *      Available in http://tools.ietf.org/html/rfc1951
  *
  *      A description of the Rabin and Karp algorithm is given in the book
  *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
@@ -47,12 +47,12 @@
  *
  */
 
-/* @(#) $Id: deflate.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #include "deflate.h"
 
 const char deflate_copyright[] =
-   " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
+   " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
@@ -155,6 +155,9 @@ local const config configuration_table[10] = {
 struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
 #endif
 
+/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
+#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
+
 /* ===========================================================================
  * Update a hash value with the given input byte
  * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
@@ -235,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
 
     strm->msg = Z_NULL;
     if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
         strm->zalloc = zcalloc;
         strm->opaque = (voidpf)0;
+#endif
     }
-    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+    if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zfree = zcfree;
+#endif
 
 #ifdef FASTEST
     if (level != 0) level = 1;
@@ -293,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
     if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
         s->pending_buf == Z_NULL) {
         s->status = FINISH_STATE;
-        strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
+        strm->msg = ERR_MSG(Z_MEM_ERROR);
         deflateEnd (strm);
         return Z_MEM_ERROR;
     }
@@ -314,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
     uInt  dictLength;
 {
     deflate_state *s;
-    uInt length = dictLength;
-    uInt n;
-    IPos hash_head = 0;
+    uInt str, n;
+    int wrap;
+    unsigned avail;
+    z_const unsigned char *next;
 
-    if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
-        strm->state->wrap == 2 ||
-        (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
+    if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
         return Z_STREAM_ERROR;
-
     s = strm->state;
-    if (s->wrap)
-        strm->adler = adler32(strm->adler, dictionary, dictLength);
+    wrap = s->wrap;
+    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
+        return Z_STREAM_ERROR;
 
-    if (length < MIN_MATCH) return Z_OK;
-    if (length > s->w_size) {
-        length = s->w_size;
-        dictionary += dictLength - length; /* use the tail of the dictionary */
+    /* when using zlib wrappers, compute Adler-32 for provided dictionary */
+    if (wrap == 1)
+        strm->adler = adler32(strm->adler, dictionary, dictLength);
+    s->wrap = 0;                    /* avoid computing Adler-32 in read_buf */
+
+    /* if dictionary would fill window, just replace the history */
+    if (dictLength >= s->w_size) {
+        if (wrap == 0) {            /* already empty otherwise */
+            CLEAR_HASH(s);
+            s->strstart = 0;
+            s->block_start = 0L;
+            s->insert = 0;
+        }
+        dictionary += dictLength - s->w_size;  /* use the tail */
+        dictLength = s->w_size;
     }
-    zmemcpy(s->window, dictionary, length);
-    s->strstart = length;
-    s->block_start = (long)length;
 
-    /* Insert all strings in the hash table (except for the last two bytes).
-     * s->lookahead stays null, so s->ins_h will be recomputed at the next
-     * call of fill_window.
-     */
-    s->ins_h = s->window[0];
-    UPDATE_HASH(s, s->ins_h, s->window[1]);
-    for (n = 0; n <= length - MIN_MATCH; n++) {
-        INSERT_STRING(s, n, hash_head);
+    /* insert dictionary into window and hash */
+    avail = strm->avail_in;
+    next = strm->next_in;
+    strm->avail_in = dictLength;
+    strm->next_in = (z_const Bytef *)dictionary;
+    fill_window(s);
+    while (s->lookahead >= MIN_MATCH) {
+        str = s->strstart;
+        n = s->lookahead - (MIN_MATCH-1);
+        do {
+            UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+            s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+            s->head[s->ins_h] = (Pos)str;
+            str++;
+        } while (--n);
+        s->strstart = str;
+        s->lookahead = MIN_MATCH-1;
+        fill_window(s);
     }
-    if (hash_head) hash_head = 0;  /* to make compiler happy */
+    s->strstart += s->lookahead;
+    s->block_start = (long)s->strstart;
+    s->insert = s->lookahead;
+    s->lookahead = 0;
+    s->match_length = s->prev_length = MIN_MATCH-1;
+    s->match_available = 0;
+    strm->next_in = next;
+    strm->avail_in = avail;
+    s->wrap = wrap;
     return Z_OK;
 }
 
 /* ========================================================================= */
-int ZEXPORT deflateReset (strm)
+int ZEXPORT deflateResetKeep (strm)
     z_streamp strm;
 {
     deflate_state *s;
@@ -380,12 +419,23 @@ int ZEXPORT deflateReset (strm)
     s->last_flush = Z_NO_FLUSH;
 
     _tr_init(s);
-    lm_init(s);
 
     return Z_OK;
 }
 
 /* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+    z_streamp strm;
+{
+    int ret;
+
+    ret = deflateResetKeep(strm);
+    if (ret == Z_OK)
+        lm_init(strm->state);
+    return ret;
+}
+
+/* ========================================================================= */
 int ZEXPORT deflateSetHeader (strm, head)
     z_streamp strm;
     gz_headerp head;
@@ -397,14 +447,42 @@ int ZEXPORT deflateSetHeader (strm, head)
 }
 
 /* ========================================================================= */
+int ZEXPORT deflatePending (strm, pending, bits)
+    unsigned *pending;
+    int *bits;
+    z_streamp strm;
+{
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+    if (pending != Z_NULL)
+        *pending = strm->state->pending;
+    if (bits != Z_NULL)
+        *bits = strm->state->bi_valid;
+    return Z_OK;
+}
+
+/* ========================================================================= */
 int ZEXPORT deflatePrime (strm, bits, value)
     z_streamp strm;
     int bits;
     int value;
 {
+    deflate_state *s;
+    int put;
+
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    strm->state->bi_valid = bits;
-    strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
+    s = strm->state;
+    if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
+        return Z_BUF_ERROR;
+    do {
+        put = Buf_size - s->bi_valid;
+        if (put > bits)
+            put = bits;
+        s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
+        s->bi_valid += put;
+        _tr_flush_bits(s);
+        value >>= put;
+        bits -= put;
+    } while (bits);
     return Z_OK;
 }
 
@@ -435,6 +513,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
         strm->total_in != 0) {
         /* Flush the last buffer: */
         err = deflate(strm, Z_BLOCK);
+        if (err == Z_BUF_ERROR && s->pending == 0)
+            err = Z_OK;
     }
     if (s->level != level) {
         s->level = level;
@@ -562,19 +642,22 @@ local void putShortMSB (s, b)
 local void flush_pending(strm)
     z_streamp strm;
 {
-    unsigned len = strm->state->pending;
+    unsigned len;
+    deflate_state *s = strm->state;
 
+    _tr_flush_bits(s);
+    len = s->pending;
     if (len > strm->avail_out) len = strm->avail_out;
     if (len == 0) return;
 
-    zmemcpy(strm->next_out, strm->state->pending_out, len);
+    zmemcpy(strm->next_out, s->pending_out, len);
     strm->next_out  += len;
-    strm->state->pending_out  += len;
+    s->pending_out  += len;
     strm->total_out += len;
     strm->avail_out  -= len;
-    strm->state->pending -= len;
-    if (strm->state->pending == 0) {
-        strm->state->pending_out = strm->state->pending_buf;
+    s->pending -= len;
+    if (s->pending == 0) {
+        s->pending_out = s->pending_buf;
     }
 }
 
@@ -801,7 +884,7 @@ int ZEXPORT deflate (strm, flush)
      * flushes. For repeated and useless calls with Z_FINISH, we keep
      * returning Z_STREAM_END instead of Z_BUF_ERROR.
      */
-    } else if (strm->avail_in == 0 && flush <= old_flush &&
+    } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
                flush != Z_FINISH) {
         ERR_RETURN(strm, Z_BUF_ERROR);
     }
@@ -850,6 +933,7 @@ int ZEXPORT deflate (strm, flush)
                     if (s->lookahead == 0) {
                         s->strstart = 0;
                         s->block_start = 0L;
+                        s->insert = 0;
                     }
                 }
             }
@@ -945,12 +1029,12 @@ int ZEXPORT deflateCopy (dest, source)
 
     ss = source->state;
 
-    zmemcpy(dest, source, sizeof(z_stream));
+    zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
 
     ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
     if (ds == Z_NULL) return Z_MEM_ERROR;
     dest->state = (struct internal_state FAR *) ds;
-    zmemcpy(ds, ss, sizeof(deflate_state));
+    zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
     ds->strm = dest;
 
     ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
@@ -966,8 +1050,8 @@ int ZEXPORT deflateCopy (dest, source)
     }
     /* following zmemcpy do not work for 16-bit MSDOS */
     zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
-    zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
-    zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
+    zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
+    zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
     zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
 
     ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
@@ -1001,15 +1085,15 @@ local int read_buf(strm, buf, size)
 
     strm->avail_in  -= len;
 
+    zmemcpy(buf, strm->next_in, len);
     if (strm->state->wrap == 1) {
-        strm->adler = adler32(strm->adler, strm->next_in, len);
+        strm->adler = adler32(strm->adler, buf, len);
     }
 #ifdef GZIP
     else if (strm->state->wrap == 2) {
-        strm->adler = crc32(strm->adler, strm->next_in, len);
+        strm->adler = crc32(strm->adler, buf, len);
     }
 #endif
-    zmemcpy(buf, strm->next_in, len);
     strm->next_in  += len;
     strm->total_in += len;
 
@@ -1036,6 +1120,7 @@ local void lm_init (s)
     s->strstart = 0;
     s->block_start = 0L;
     s->lookahead = 0;
+    s->insert = 0;
     s->match_length = s->prev_length = MIN_MATCH-1;
     s->match_available = 0;
     s->ins_h = 0;
@@ -1310,6 +1395,8 @@ local void fill_window(s)
     unsigned more;    /* Amount of free space at the end of the window. */
     uInt wsize = s->w_size;
 
+    Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
+
     do {
         more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
 
@@ -1362,7 +1449,7 @@ local void fill_window(s)
 #endif
             more += wsize;
         }
-        if (s->strm->avail_in == 0) return;
+        if (s->strm->avail_in == 0) break;
 
         /* If there was no sliding:
          *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
@@ -1381,12 +1468,24 @@ local void fill_window(s)
         s->lookahead += n;
 
         /* Initialize the hash value now that we have some input: */
-        if (s->lookahead >= MIN_MATCH) {
-            s->ins_h = s->window[s->strstart];
-            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+        if (s->lookahead + s->insert >= MIN_MATCH) {
+            uInt str = s->strstart - s->insert;
+            s->ins_h = s->window[str];
+            UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
 #if MIN_MATCH != 3
             Call UPDATE_HASH() MIN_MATCH-3 more times
 #endif
+            while (s->insert) {
+                UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+                s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+                s->head[s->ins_h] = (Pos)str;
+                str++;
+                s->insert--;
+                if (s->lookahead + s->insert < MIN_MATCH)
+                    break;
+            }
         }
         /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
          * but this is not important since only literal bytes will be emitted.
@@ -1427,6 +1526,9 @@ local void fill_window(s)
             s->high_water += init;
         }
     }
+
+    Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
+           "not enough room for search");
 }
 
 /* ===========================================================================
@@ -1506,8 +1608,14 @@ local block_state deflate_stored(s, flush)
             FLUSH_BLOCK(s, 0);
         }
     }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
+    s->insert = 0;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if ((long)s->strstart > s->block_start)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
 }
 
 /* ===========================================================================
@@ -1603,8 +1711,14 @@ local block_state deflate_fast(s, flush)
         }
         if (bflush) FLUSH_BLOCK(s, 0);
     }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
+    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
 }
 
 #ifndef FASTEST
@@ -1728,8 +1842,14 @@ local block_state deflate_slow(s, flush)
         _tr_tally_lit(s, s->window[s->strstart-1], bflush);
         s->match_available = 0;
     }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
+    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
 }
 #endif /* FASTEST */
 
@@ -1749,11 +1869,11 @@ local block_state deflate_rle(s, flush)
     for (;;) {
         /* Make sure that we always have enough lookahead, except
          * at the end of the input file. We need MAX_MATCH bytes
-         * for the longest encodable run.
+         * for the longest run, plus one for the unrolled loop.
          */
-        if (s->lookahead < MAX_MATCH) {
+        if (s->lookahead <= MAX_MATCH) {
             fill_window(s);
-            if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
+            if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
                 return need_more;
             }
             if (s->lookahead == 0) break; /* flush the current block */
@@ -1776,6 +1896,7 @@ local block_state deflate_rle(s, flush)
                 if (s->match_length > s->lookahead)
                     s->match_length = s->lookahead;
             }
+            Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
         }
 
         /* Emit match if have run of MIN_MATCH or longer, else emit literal */
@@ -1796,8 +1917,14 @@ local block_state deflate_rle(s, flush)
         }
         if (bflush) FLUSH_BLOCK(s, 0);
     }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
+    s->insert = 0;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
 }
 
 /* ===========================================================================
@@ -1829,6 +1956,12 @@ local block_state deflate_huff(s, flush)
         s->strstart++;
         if (bflush) FLUSH_BLOCK(s, 0);
     }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
+    s->insert = 0;
+    if (flush == Z_FINISH) {
+        FLUSH_BLOCK(s, 1);
+        return finish_done;
+    }
+    if (s->last_lit)
+        FLUSH_BLOCK(s, 0);
+    return block_done;
 }
diff --git a/src/libz/deflate.h b/src/libz/deflate.h
index a947456..ce0299e 100644
--- a/src/libz/deflate.h
+++ b/src/libz/deflate.h
@@ -1,5 +1,5 @@
 /* deflate.h -- internal compression state
- * Copyright (C) 1995-2010 Jean-loup Gailly
+ * Copyright (C) 1995-2012 Jean-loup Gailly
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -8,7 +8,7 @@
    subject to change. Applications should only use zlib.h.
  */
 
-/* @(#) $Id: deflate.h,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #ifndef DEFLATE_H
 #define DEFLATE_H
@@ -48,6 +48,9 @@
 #define MAX_BITS 15
 /* All codes must not exceed MAX_BITS bits */
 
+#define Buf_size 16
+/* size of bit buffer in bi_buf */
+
 #define INIT_STATE    42
 #define EXTRA_STATE   69
 #define NAME_STATE    73
@@ -101,7 +104,7 @@ typedef struct internal_state {
     int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
     gz_headerp  gzhead;  /* gzip header information to write */
     uInt   gzindex;      /* where in extra, name, or comment */
-    Byte  method;        /* STORED (for zip only) or DEFLATED */
+    Byte  method;        /* can only be DEFLATED */
     int   last_flush;    /* value of flush param for previous deflate call */
 
                 /* used by deflate.c: */
@@ -188,7 +191,7 @@ typedef struct internal_state {
     int nice_match; /* Stop searching when current match exceeds this */
 
                 /* used by trees.c: */
-    /* Didn't use ct_data typedef below to supress compiler warning */
+    /* Didn't use ct_data typedef below to suppress compiler warning */
     struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
     struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
     struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
@@ -244,7 +247,7 @@ typedef struct internal_state {
     ulg opt_len;        /* bit length of current block with optimal trees */
     ulg static_len;     /* bit length of current block with static trees */
     uInt matches;       /* number of string matches in current block */
-    int last_eob_len;   /* bit length of EOB code for last block */
+    uInt insert;        /* bytes at end of window left to insert */
 
 #ifdef DEBUG
     ulg compressed_len; /* total bit length of compressed file mod 2^32 */
@@ -294,6 +297,7 @@ void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
 int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
 void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
                         ulg stored_len, int last));
+void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
 void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
 void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
                         ulg stored_len, int last));
diff --git a/src/libz/gzguts.h b/src/libz/gzguts.h
index 0f8fb79..d87659d 100644
--- a/src/libz/gzguts.h
+++ b/src/libz/gzguts.h
@@ -1,5 +1,5 @@
 /* gzguts.h -- zlib internal header definitions for gz* operations
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -12,7 +12,7 @@
 #  endif
 #endif
 
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
+#ifdef HAVE_HIDDEN
 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
 #else
 #  define ZLIB_INTERNAL
@@ -27,13 +27,80 @@
 #endif
 #include <fcntl.h>
 
+#ifdef _WIN32
+#  include <stddef.h>
+#endif
+
+#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
+#  include <io.h>
+#endif
+
+#ifdef WINAPI_FAMILY
+#  define open _open
+#  define read _read
+#  define write _write
+#  define close _close
+#endif
+
 #ifdef NO_DEFLATE       /* for compatibility with old definition */
 #  define NO_GZCOMPRESS
 #endif
 
+#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
+#  ifndef HAVE_VSNPRINTF
+#    define HAVE_VSNPRINTF
+#  endif
+#endif
+
+#if defined(__CYGWIN__)
+#  ifndef HAVE_VSNPRINTF
+#    define HAVE_VSNPRINTF
+#  endif
+#endif
+
+#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
+#  ifndef HAVE_VSNPRINTF
+#    define HAVE_VSNPRINTF
+#  endif
+#endif
+
+#ifndef HAVE_VSNPRINTF
+#  ifdef MSDOS
+/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+   but for now we just assume it doesn't. */
+#    define NO_vsnprintf
+#  endif
+#  ifdef __TURBOC__
+#    define NO_vsnprintf
+#  endif
+#  ifdef WIN32
+/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+#    if !defined(vsnprintf) && !defined(NO_vsnprintf)
+#      if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
+#         define vsnprintf _vsnprintf
+#      endif
+#    endif
+#  endif
+#  ifdef __SASC
+#    define NO_vsnprintf
+#  endif
+#  ifdef VMS
+#    define NO_vsnprintf
+#  endif
+#  ifdef __OS400__
+#    define NO_vsnprintf
+#  endif
+#  ifdef __MVS__
+#    define NO_vsnprintf
+#  endif
+#endif
+
+/* unlike snprintf (which is required in C99, yet still not supported by
+   Microsoft more than a decade later!), _snprintf does not guarantee null
+   termination of the result -- however this is only used in gzlib.c where
+   the result is assured to fit in the space provided */
 #ifdef _MSC_VER
-#  include <io.h>
-#  define vsnprintf _vsnprintf
+#  define snprintf _snprintf
 #endif
 
 #ifndef local
@@ -52,7 +119,7 @@
 #  include <windows.h>
 #  define zstrerror() gz_strwinerror((DWORD)GetLastError())
 #else
-#  ifdef STDC
+#  ifndef NO_STRERROR
 #    include <errno.h>
 #    define zstrerror() strerror(errno)
 #  else
@@ -68,7 +135,15 @@
     ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
 #endif
 
-/* default i/o buffer size -- double this for output when reading */
+/* default memLevel */
+#if MAX_MEM_LEVEL >= 8
+#  define DEF_MEM_LEVEL 8
+#else
+#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
+#endif
+
+/* default i/o buffer size -- double this for output when reading (this and
+   twice this must be able to fit in an unsigned type) */
 #define GZBUFSIZE 8192
 
 /* gzip modes, also provide a little integrity check on the passed structure */
@@ -84,23 +159,25 @@
 
 /* internal gzip file state data structure */
 typedef struct {
+        /* exposed contents for gzgetc() macro */
+    struct gzFile_s x;      /* "x" for exposed */
+                            /* x.have: number of bytes available at x.next */
+                            /* x.next: next output data to deliver or write */
+                            /* x.pos: current position in uncompressed data */
         /* used for both reading and writing */
     int mode;               /* see gzip modes above */
     int fd;                 /* file descriptor */
     char *path;             /* path or fd for error messages */
-    z_off64_t pos;          /* current position in uncompressed data */
     unsigned size;          /* buffer size, zero if not allocated yet */
     unsigned want;          /* requested buffer size, default is GZBUFSIZE */
     unsigned char *in;      /* input buffer */
     unsigned char *out;     /* output buffer (double-sized when reading) */
-    unsigned char *next;    /* next output data to deliver or write */
+    int direct;             /* 0 if processing gzip, 1 if transparent */
         /* just for reading */
-    unsigned have;          /* amount of output data unused at next */
-    int eof;                /* true if end of input file reached */
-    z_off64_t start;        /* where the gzip data started, for rewinding */
-    z_off64_t raw;          /* where the raw data started, for seeking */
     int how;                /* 0: get header, 1: copy, 2: decompress */
-    int direct;             /* true if last read direct, false if gzip */
+    z_off64_t start;        /* where the gzip data started, for rewinding */
+    int eof;                /* true if end of input file reached */
+    int past;               /* true if read requested past end */
         /* just for writing */
     int level;              /* compression level */
     int strategy;           /* compression strategy */
diff --git a/src/libz/gzlib.c b/src/libz/gzlib.c
index 603e60e..fae202e 100644
--- a/src/libz/gzlib.c
+++ b/src/libz/gzlib.c
@@ -1,19 +1,23 @@
 /* gzlib.c -- zlib functions common to reading and writing gzip files
- * Copyright (C) 2004, 2010 Mark Adler
+ * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
 #include "gzguts.h"
 
+#if defined(_WIN32) && !defined(__BORLANDC__)
+#  define LSEEK _lseeki64
+#else
 #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
 #  define LSEEK lseek64
 #else
 #  define LSEEK lseek
 #endif
+#endif
 
 /* Local functions */
 local void gz_reset OF((gz_statep));
-local gzFile gz_open OF((const char *, int, const char *));
+local gzFile gz_open OF((const void *, int, const char *));
 
 #if defined UNDER_CE
 
@@ -71,28 +75,40 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
 local void gz_reset(state)
     gz_statep state;
 {
+    state->x.have = 0;              /* no output data available */
     if (state->mode == GZ_READ) {   /* for reading ... */
-        state->have = 0;            /* no output data available */
         state->eof = 0;             /* not at end of file */
+        state->past = 0;            /* have not read past end yet */
         state->how = LOOK;          /* look for gzip header */
-        state->direct = 1;          /* default for empty file */
     }
     state->seek = 0;                /* no seek request pending */
     gz_error(state, Z_OK, NULL);    /* clear error */
-    state->pos = 0;                 /* no uncompressed data yet */
+    state->x.pos = 0;               /* no uncompressed data yet */
     state->strm.avail_in = 0;       /* no input data yet */
 }
 
 /* Open a gzip file either by name or file descriptor. */
 local gzFile gz_open(path, fd, mode)
-    const char *path;
+    const void *path;
     int fd;
     const char *mode;
 {
     gz_statep state;
+    size_t len;
+    int oflag;
+#ifdef O_CLOEXEC
+    int cloexec = 0;
+#endif
+#ifdef O_EXCL
+    int exclusive = 0;
+#endif
+
+    /* check input */
+    if (path == NULL)
+        return NULL;
 
     /* allocate gzFile structure to return */
-    state = malloc(sizeof(gz_state));
+    state = (gz_statep)malloc(sizeof(gz_state));
     if (state == NULL)
         return NULL;
     state->size = 0;            /* no buffers allocated yet */
@@ -103,6 +119,7 @@ local gzFile gz_open(path, fd, mode)
     state->mode = GZ_NONE;
     state->level = Z_DEFAULT_COMPRESSION;
     state->strategy = Z_DEFAULT_STRATEGY;
+    state->direct = 0;
     while (*mode) {
         if (*mode >= '0' && *mode <= '9')
             state->level = *mode - '0';
@@ -124,6 +141,16 @@ local gzFile gz_open(path, fd, mode)
                 return NULL;
             case 'b':       /* ignore -- will request binary anyway */
                 break;
+#ifdef O_CLOEXEC
+            case 'e':
+                cloexec = 1;
+                break;
+#endif
+#ifdef O_EXCL
+            case 'x':
+                exclusive = 1;
+                break;
+#endif
             case 'f':
                 state->strategy = Z_FILTERED;
                 break;
@@ -135,6 +162,10 @@ local gzFile gz_open(path, fd, mode)
                 break;
             case 'F':
                 state->strategy = Z_FIXED;
+                break;
+            case 'T':
+                state->direct = 1;
+                break;
             default:        /* could consider as an error, but just ignore */
                 ;
             }
@@ -147,30 +178,71 @@ local gzFile gz_open(path, fd, mode)
         return NULL;
     }
 
+    /* can't force transparent read */
+    if (state->mode == GZ_READ) {
+        if (state->direct) {
+            free(state);
+            return NULL;
+        }
+        state->direct = 1;      /* for empty file */
+    }
+
     /* save the path name for error messages */
-    state->path = malloc(strlen(path) + 1);
+#ifdef _WIN32
+    if (fd == -2) {
+        len = wcstombs(NULL, path, 0);
+        if (len == (size_t)-1)
+            len = 0;
+    }
+    else
+#endif
+        len = strlen((const char *)path);
+    state->path = (char *)malloc(len + 1);
     if (state->path == NULL) {
         free(state);
         return NULL;
     }
-    strcpy(state->path, path);
+#ifdef _WIN32
+    if (fd == -2)
+        if (len)
+            wcstombs(state->path, path, len + 1);
+        else
+            *(state->path) = 0;
+    else
+#endif
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+        snprintf(state->path, len + 1, "%s", (const char *)path);
+#else
+        strcpy(state->path, path);
+#endif
 
-    /* open the file with the appropriate mode (or just use fd) */
-    state->fd = fd != -1 ? fd :
-        open(path,
+    /* compute the flags for open() */
+    oflag =
 #ifdef O_LARGEFILE
-            O_LARGEFILE |
+        O_LARGEFILE |
 #endif
 #ifdef O_BINARY
-            O_BINARY |
+        O_BINARY |
+#endif
+#ifdef O_CLOEXEC
+        (cloexec ? O_CLOEXEC : 0) |
+#endif
+        (state->mode == GZ_READ ?
+         O_RDONLY :
+         (O_WRONLY | O_CREAT |
+#ifdef O_EXCL
+          (exclusive ? O_EXCL : 0) |
+#endif
+          (state->mode == GZ_WRITE ?
+           O_TRUNC :
+           O_APPEND)));
+
+    /* open the file with the appropriate flags (or just use fd) */
+    state->fd = fd > -1 ? fd : (
+#ifdef _WIN32
+        fd == -2 ? _wopen(path, oflag, 0666) :
 #endif
-            (state->mode == GZ_READ ?
-                O_RDONLY :
-                (O_WRONLY | O_CREAT | (
-                    state->mode == GZ_WRITE ?
-                        O_TRUNC :
-                        O_APPEND))),
-            0666);
+        open((const char *)path, oflag, 0666));
     if (state->fd == -1) {
         free(state->path);
         free(state);
@@ -216,15 +288,29 @@ gzFile ZEXPORT gzdopen(fd, mode)
     char *path;         /* identifier for error messages */
     gzFile gz;
 
-    if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL)
+    if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
         return NULL;
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+    snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
+#else
     sprintf(path, "<fd:%d>", fd);   /* for debugging */
+#endif
     gz = gz_open(path, fd, mode);
     free(path);
     return gz;
 }
 
 /* -- see zlib.h -- */
+#ifdef _WIN32
+gzFile ZEXPORT gzopen_w(path, mode)
+    const wchar_t *path;
+    const char *mode;
+{
+    return gz_open(path, -2, mode);
+}
+#endif
+
+/* -- see zlib.h -- */
 int ZEXPORT gzbuffer(file, size)
     gzFile file;
     unsigned size;
@@ -243,8 +329,8 @@ int ZEXPORT gzbuffer(file, size)
         return -1;
 
     /* check and set requested size */
-    if (size == 0)
-        return -1;
+    if (size < 2)
+        size = 2;               /* need two bytes to check magic header */
     state->want = size;
     return 0;
 }
@@ -261,7 +347,8 @@ int ZEXPORT gzrewind(file)
     state = (gz_statep)file;
 
     /* check that we're reading and that there's no error */
-    if (state->mode != GZ_READ || state->err != Z_OK)
+    if (state->mode != GZ_READ ||
+            (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* back up and start over */
@@ -289,7 +376,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
         return -1;
 
     /* check that there's no error */
-    if (state->err != Z_OK)
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
         return -1;
 
     /* can only seek from start or relative to current position */
@@ -298,31 +385,32 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
 
     /* normalize offset to a SEEK_CUR specification */
     if (whence == SEEK_SET)
-        offset -= state->pos;
+        offset -= state->x.pos;
     else if (state->seek)
         offset += state->skip;
     state->seek = 0;
 
     /* if within raw area while reading, just go there */
     if (state->mode == GZ_READ && state->how == COPY &&
-        state->pos + offset >= state->raw) {
-        ret = LSEEK(state->fd, offset - state->have, SEEK_CUR);
+            state->x.pos + offset >= 0) {
+        ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
         if (ret == -1)
             return -1;
-        state->have = 0;
+        state->x.have = 0;
         state->eof = 0;
+        state->past = 0;
         state->seek = 0;
         gz_error(state, Z_OK, NULL);
         state->strm.avail_in = 0;
-        state->pos += offset;
-        return state->pos;
+        state->x.pos += offset;
+        return state->x.pos;
     }
 
     /* calculate skip amount, rewinding if needed for back seek when reading */
     if (offset < 0) {
         if (state->mode != GZ_READ)         /* writing -- can't go backwards */
             return -1;
-        offset += state->pos;
+        offset += state->x.pos;
         if (offset < 0)                     /* before start of file! */
             return -1;
         if (gzrewind(file) == -1)           /* rewind, then skip to offset */
@@ -331,11 +419,11 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
 
     /* if reading, skip what's in output buffer (one less gzgetc() check) */
     if (state->mode == GZ_READ) {
-        n = GT_OFF(state->have) || (z_off64_t)state->have > offset ?
-            (unsigned)offset : state->have;
-        state->have -= n;
-        state->next += n;
-        state->pos += n;
+        n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
+            (unsigned)offset : state->x.have;
+        state->x.have -= n;
+        state->x.next += n;
+        state->x.pos += n;
         offset -= n;
     }
 
@@ -344,7 +432,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
         state->seek = 1;
         state->skip = offset;
     }
-    return state->pos + offset;
+    return state->x.pos + offset;
 }
 
 /* -- see zlib.h -- */
@@ -373,7 +461,7 @@ z_off64_t ZEXPORT gztell64(file)
         return -1;
 
     /* return position */
-    return state->pos + (state->seek ? state->skip : 0);
+    return state->x.pos + (state->seek ? state->skip : 0);
 }
 
 /* -- see zlib.h -- */
@@ -433,8 +521,7 @@ int ZEXPORT gzeof(file)
         return 0;
 
     /* return end-of-file state */
-    return state->mode == GZ_READ ?
-        (state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
+    return state->mode == GZ_READ ? state->past : 0;
 }
 
 /* -- see zlib.h -- */
@@ -454,7 +541,8 @@ const char * ZEXPORT gzerror(file, errnum)
     /* return error information */
     if (errnum != NULL)
         *errnum = state->err;
-    return state->msg == NULL ? "" : state->msg;
+    return state->err == Z_MEM_ERROR ? "out of memory" :
+                                       (state->msg == NULL ? "" : state->msg);
 }
 
 /* -- see zlib.h -- */
@@ -471,8 +559,10 @@ void ZEXPORT gzclearerr(file)
         return;
 
     /* clear error and end-of-file */
-    if (state->mode == GZ_READ)
+    if (state->mode == GZ_READ) {
         state->eof = 0;
+        state->past = 0;
+    }
     gz_error(state, Z_OK, NULL);
 }
 
@@ -494,26 +584,33 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
         state->msg = NULL;
     }
 
+    /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
+    if (err != Z_OK && err != Z_BUF_ERROR)
+        state->x.have = 0;
+
     /* set error code, and if no message, then done */
     state->err = err;
     if (msg == NULL)
         return;
 
-    /* for an out of memory error, save as static string */
-    if (err == Z_MEM_ERROR) {
-        state->msg = (char *)msg;
+    /* for an out of memory error, return literal string when requested */
+    if (err == Z_MEM_ERROR)
         return;
-    }
 
     /* construct error message with path */
-    if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
+    if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
+            NULL) {
         state->err = Z_MEM_ERROR;
-        state->msg = (char *)"out of memory";
         return;
     }
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+    snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
+             "%s%s%s", state->path, ": ", msg);
+#else
     strcpy(state->msg, state->path);
     strcat(state->msg, ": ");
     strcat(state->msg, msg);
+#endif
     return;
 }
 
diff --git a/src/libz/gzread.c b/src/libz/gzread.c
index 548201a..bf4538e 100644
--- a/src/libz/gzread.c
+++ b/src/libz/gzread.c
@@ -1,5 +1,5 @@
 /* gzread.c -- zlib functions for reading gzip files
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -8,10 +8,9 @@
 /* Local functions */
 local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
 local int gz_avail OF((gz_statep));
-local int gz_next4 OF((gz_statep, unsigned long *));
-local int gz_head OF((gz_statep));
+local int gz_look OF((gz_statep));
 local int gz_decomp OF((gz_statep));
-local int gz_make OF((gz_statep));
+local int gz_fetch OF((gz_statep));
 local int gz_skip OF((gz_statep, z_off64_t));
 
 /* Use read() to load a buffer -- return -1 on error, otherwise 0.  Read from
@@ -46,73 +45,54 @@ local int gz_load(state, buf, len, have)
    error, 0 otherwise.  Note that the eof flag is set when the end of the input
    file is reached, even though there may be unused data in the buffer.  Once
    that data has been used, no more attempts will be made to read the file.
-   gz_avail() assumes that strm->avail_in == 0. */
+   If strm->avail_in != 0, then the current data is moved to the beginning of
+   the input buffer, and then the remainder of the buffer is loaded with the
+   available data from the input file. */
 local int gz_avail(state)
     gz_statep state;
 {
+    unsigned got;
     z_streamp strm = &(state->strm);
 
-    if (state->err != Z_OK)
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
         return -1;
     if (state->eof == 0) {
-        if (gz_load(state, state->in, state->size,
-                (unsigned *)&(strm->avail_in)) == -1)
+        if (strm->avail_in) {       /* copy what's there to the start */
+            unsigned char *p = state->in;
+            unsigned const char *q = strm->next_in;
+            unsigned n = strm->avail_in;
+            do {
+                *p++ = *q++;
+            } while (--n);
+        }
+        if (gz_load(state, state->in + strm->avail_in,
+                    state->size - strm->avail_in, &got) == -1)
             return -1;
+        strm->avail_in += got;
         strm->next_in = state->in;
     }
     return 0;
 }
 
-/* Get next byte from input, or -1 if end or error. */
-#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
-                (strm->avail_in == 0 ? -1 : \
-                 (strm->avail_in--, *(strm->next_in)++)))
-
-/* Get a four-byte little-endian integer and return 0 on success and the value
-   in *ret.  Otherwise -1 is returned and *ret is not modified. */
-local int gz_next4(state, ret)
-    gz_statep state;
-    unsigned long *ret;
-{
-    int ch;
-    unsigned long val;
-    z_streamp strm = &(state->strm);
-
-    val = NEXT();
-    val += (unsigned)NEXT() << 8;
-    val += (unsigned long)NEXT() << 16;
-    ch = NEXT();
-    if (ch == -1)
-        return -1;
-    val += (unsigned long)ch << 24;
-    *ret = val;
-    return 0;
-}
-
-/* Look for gzip header, set up for inflate or copy.  state->have must be zero.
+/* Look for gzip header, set up for inflate or copy.  state->x.have must be 0.
    If this is the first time in, allocate required memory.  state->how will be
    left unchanged if there is no more input data available, will be set to COPY
    if there is no gzip header and direct copying will be performed, or it will
-   be set to GZIP for decompression, and the gzip header will be skipped so
-   that the next available input data is the raw deflate stream.  If direct
-   copying, then leftover input data from the input buffer will be copied to
-   the output buffer.  In that case, all further file reads will be directly to
-   either the output buffer or a user buffer.  If decompressing, the inflate
-   state and the check value will be initialized.  gz_head() will return 0 on
-   success or -1 on failure.  Failures may include read errors or gzip header
-   errors.  */
-local int gz_head(state)
+   be set to GZIP for decompression.  If direct copying, then leftover input
+   data from the input buffer will be copied to the output buffer.  In that
+   case, all further file reads will be directly to either the output buffer or
+   a user buffer.  If decompressing, the inflate state will be initialized.
+   gz_look() will return 0 on success or -1 on failure. */
+local int gz_look(state)
     gz_statep state;
 {
     z_streamp strm = &(state->strm);
-    int flags;
-    unsigned len;
 
     /* allocate read buffers and inflate memory */
     if (state->size == 0) {
         /* allocate buffers */
-        state->in = malloc(state->want);
-        state->out = malloc(state->want << 1);
+        state->in = (unsigned char *)malloc(state->want);
+        state->out = (unsigned char *)malloc(state->want << 1);
         if (state->in == NULL || state->out == NULL) {
             if (state->out != NULL)
                 free(state->out);
@@ -129,7 +109,7 @@ local int gz_head(state)
         state->strm.opaque = Z_NULL;
         state->strm.avail_in = 0;
         state->strm.next_in = Z_NULL;
-        if (inflateInit2(&(state->strm), -15) != Z_OK) {    /* raw inflate */
+        if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) {    /* gunzip */
             free(state->out);
             free(state->in);
             state->size = 0;
@@ -138,83 +118,45 @@ local int gz_head(state)
         }
     }
 
-    /* get some data in the input buffer */
-    if (strm->avail_in == 0) {
+    /* get at least the magic bytes in the input buffer */
+    if (strm->avail_in < 2) {
         if (gz_avail(state) == -1)
             return -1;
         if (strm->avail_in == 0)
             return 0;
     }
 
-    /* look for the gzip magic header bytes 31 and 139 */
-    if (strm->next_in[0] == 31) {
-        strm->avail_in--;
-        strm->next_in++;
-        if (strm->avail_in == 0 && gz_avail(state) == -1)
-            return -1;
-        if (strm->avail_in && strm->next_in[0] == 139) {
-            /* we have a gzip header, woo hoo! */
-            strm->avail_in--;
-            strm->next_in++;
-
-            /* skip rest of header */
-            if (NEXT() != 8) {      /* compression method */
-                gz_error(state, Z_DATA_ERROR, "unknown compression method");
-                return -1;
-            }
-            flags = NEXT();
-            if (flags & 0xe0) {     /* reserved flag bits */
-                gz_error(state, Z_DATA_ERROR, "unknown header flags set");
-                return -1;
-            }
-            NEXT();                 /* modification time */
-            NEXT();
-            NEXT();
-            NEXT();
-            NEXT();                 /* extra flags */
-            NEXT();                 /* operating system */
-            if (flags & 4) {        /* extra field */
-                len = (unsigned)NEXT();
-                len += (unsigned)NEXT() << 8;
-                while (len--)
-                    if (NEXT() < 0)
-                        break;
-            }
-            if (flags & 8)          /* file name */
-                while (NEXT() > 0)
-                    ;
-            if (flags & 16)         /* comment */
-                while (NEXT() > 0)
-                    ;
-            if (flags & 2) {        /* header crc */
-                NEXT();
-                NEXT();
-            }
-            /* an unexpected end of file is not checked for here -- it will be
-               noticed on the first request for uncompressed data */
-
-            /* set up for decompression */
-            inflateReset(strm);
-            strm->adler = crc32(0L, Z_NULL, 0);
-            state->how = GZIP;
-            state->direct = 0;
-            return 0;
-        }
-        else {
-            /* not a gzip file -- save first byte (31) and fall to raw i/o */
-            state->out[0] = 31;
-            state->have = 1;
-        }
+    /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
+       a logical dilemma here when considering the case of a partially written
+       gzip file, to wit, if a single 31 byte is written, then we cannot tell
+       whether this is a single-byte file, or just a partially written gzip
+       file -- for here we assume that if a gzip file is being written, then
+       the header will be written in a single operation, so that reading a
+       single byte is sufficient indication that it is not a gzip file) */
+    if (strm->avail_in > 1 &&
+            strm->next_in[0] == 31 && strm->next_in[1] == 139) {
+        inflateReset(strm);
+        state->how = GZIP;
+        state->direct = 0;
+        return 0;
+    }
+
+    /* no gzip header -- if we were decoding gzip before, then this is trailing
+       garbage.  Ignore the trailing garbage and finish. */
+    if (state->direct == 0) {
+        strm->avail_in = 0;
+        state->eof = 1;
+        state->x.have = 0;
+        return 0;
     }
 
-    /* doing raw i/o, save start of raw data for seeking, copy any leftover
-       input to output -- this assumes that the output buffer is larger than
-       the input buffer, which also assures space for gzungetc() */
-    state->raw = state->pos;
-    state->next = state->out;
+    /* doing raw i/o, copy any leftover input to output -- this assumes that
+       the output buffer is larger than the input buffer, which also assures
+       space for gzungetc() */
+    state->x.next = state->out;
     if (strm->avail_in) {
-        memcpy(state->next + state->have, strm->next_in, strm->avail_in);
-        state->have += strm->avail_in;
+        memcpy(state->x.next, strm->next_in, strm->avail_in);
+        state->x.have = strm->avail_in;
         strm->avail_in = 0;
     }
     state->how = COPY;
@@ -223,19 +165,15 @@ local int gz_head(state)
 }
 
 /* Decompress from input to the provided next_out and avail_out in the state.
-   If the end of the compressed data is reached, then verify the gzip trailer
-   check value and length (modulo 2^32).  state->have and state->next are set
-   to point to the just decompressed data, and the crc is updated.  If the
-   trailer is verified, state->how is reset to LOOK to look for the next gzip
-   stream or raw data, once state->have is depleted.  Returns 0 on success, -1
-   on failure.  Failures may include invalid compressed data or a failed gzip
-   trailer verification. */
+   On return, state->x.have and state->x.next point to the just decompressed
+   data.  If the gzip stream completes, state->how is reset to LOOK to look for
+   the next gzip stream or raw data, once state->x.have is depleted.  Returns 0
+   on success, -1 on failure. */
 local int gz_decomp(state)
     gz_statep state;
 {
-    int ret;
+    int ret = Z_OK;
     unsigned had;
-    unsigned long crc, len;
     z_streamp strm = &(state->strm);
 
     /* fill output buffer up to end of deflate stream */
@@ -245,15 +183,15 @@ local int gz_decomp(state)
         if (strm->avail_in == 0 && gz_avail(state) == -1)
             return -1;
         if (strm->avail_in == 0) {
-            gz_error(state, Z_DATA_ERROR, "unexpected end of file");
-            return -1;
+            gz_error(state, Z_BUF_ERROR, "unexpected end of file");
+            break;
         }
 
         /* decompress and handle errors */
         ret = inflate(strm, Z_NO_FLUSH);
         if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
             gz_error(state, Z_STREAM_ERROR,
-                      "internal error: inflate stream corrupt");
+                     "internal error: inflate stream corrupt");
             return -1;
         }
         if (ret == Z_MEM_ERROR) {
@@ -262,67 +200,55 @@ local int gz_decomp(state)
         }
         if (ret == Z_DATA_ERROR) {              /* deflate stream invalid */
             gz_error(state, Z_DATA_ERROR,
-                      strm->msg == NULL ? "compressed data error" : strm->msg);
+                     strm->msg == NULL ? "compressed data error" : strm->msg);
             return -1;
         }
     } while (strm->avail_out && ret != Z_STREAM_END);
 
-    /* update available output and crc check value */
-    state->have = had - strm->avail_out;
-    state->next = strm->next_out - state->have;
-    strm->adler = crc32(strm->adler, state->next, state->have);
+    /* update available output */
+    state->x.have = had - strm->avail_out;
+    state->x.next = strm->next_out - state->x.have;
 
-    /* check gzip trailer if at end of deflate stream */
-    if (ret == Z_STREAM_END) {
-        if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
-            gz_error(state, Z_DATA_ERROR, "unexpected end of file");
-            return -1;
-        }
-        if (crc != strm->adler) {
-            gz_error(state, Z_DATA_ERROR, "incorrect data check");
-            return -1;
-        }
-        if (len != (strm->total_out & 0xffffffffL)) {
-            gz_error(state, Z_DATA_ERROR, "incorrect length check");
-            return -1;
-        }
-        state->how = LOOK;      /* ready for next stream, once have is 0 (leave
-                                   state->direct unchanged to remember how) */
-    }
+    /* if the gzip stream completed successfully, look for another */
+    if (ret == Z_STREAM_END)
+        state->how = LOOK;
 
     /* good decompression */
     return 0;
 }
 
-/* Make data and put in the output buffer.  Assumes that state->have == 0.
+/* Fetch data and put it in the output buffer.  Assumes state->x.have is 0.
    Data is either copied from the input file or decompressed from the input
    file depending on state->how.  If state->how is LOOK, then a gzip header is
-   looked for (and skipped if found) to determine wither to copy or decompress.
-   Returns -1 on error, otherwise 0.  gz_make() will leave state->have as COPY
-   or GZIP unless the end of the input file has been reached and all data has
-   been processed.  */
-local int gz_make(state)
+   looked for to determine whether to copy or decompress.  Returns -1 on error,
+   otherwise 0.  gz_fetch() will leave state->how as COPY or GZIP unless the
+   end of the input file has been reached and all data has been processed.  */
+local int gz_fetch(state)
     gz_statep state;
 {
     z_streamp strm = &(state->strm);
 
-    if (state->how == LOOK) {           /* look for gzip header */
-        if (gz_head(state) == -1)
-            return -1;
-        if (state->have)                /* got some data from gz_head() */
+    do {
+        switch(state->how) {
+        case LOOK:      /* -> LOOK, COPY (only if never GZIP), or GZIP */
+            if (gz_look(state) == -1)
+                return -1;
+            if (state->how == LOOK)
+                return 0;
+            break;
+        case COPY:      /* -> COPY */
+            if (gz_load(state, state->out, state->size << 1, &(state->x.have))
+                    == -1)
+                return -1;
+            state->x.next = state->out;
             return 0;
-    }
-    if (state->how == COPY) {           /* straight copy */
-        if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
-            return -1;
-        state->next = state->out;
-    }
-    else if (state->how == GZIP) {      /* decompress */
-        strm->avail_out = state->size << 1;
-        strm->next_out = state->out;
-        if (gz_decomp(state) == -1)
-            return -1;
-    }
+        case GZIP:      /* -> GZIP or LOOK (if end of gzip stream) */
+            strm->avail_out = state->size << 1;
+            strm->next_out = state->out;
+            if (gz_decomp(state) == -1)
+                return -1;
+        }
+    } while (state->x.have == 0 && (!state->eof || strm->avail_in));
     return 0;
 }
 
@@ -336,12 +262,12 @@ local int gz_skip(state, len)
     /* skip over len bytes or reach end-of-file, whichever comes first */
     while (len)
         /* skip over whatever is in output buffer */
-        if (state->have) {
-            n = GT_OFF(state->have) || (z_off64_t)state->have > len ?
-                (unsigned)len : state->have;
-            state->have -= n;
-            state->next += n;
-            state->pos += n;
+        if (state->x.have) {
+            n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
+                (unsigned)len : state->x.have;
+            state->x.have -= n;
+            state->x.next += n;
+            state->x.pos += n;
             len -= n;
         }
 
@@ -352,7 +278,7 @@ local int gz_skip(state, len)
         /* need more data to skip -- load up output buffer */
         else {
             /* get more output, looking for header if required */
-            if (gz_make(state) == -1)
+            if (gz_fetch(state) == -1)
                 return -1;
         }
     return 0;
@@ -374,14 +300,15 @@ int ZEXPORT gzread(file, buf, len)
     state = (gz_statep)file;
     strm = &(state->strm);
 
-    /* check that we're reading and that there's no error */
-    if (state->mode != GZ_READ || state->err != Z_OK)
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+            (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* since an int is returned, make sure len fits in one, otherwise return
        with an error (this avoids the flaw in the interface) */
     if ((int)len < 0) {
-        gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
+        gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
         return -1;
     }
 
@@ -400,49 +327,51 @@ int ZEXPORT gzread(file, buf, len)
     got = 0;
     do {
         /* first just try copying data from the output buffer */
-        if (state->have) {
-            n = state->have > len ? len : state->have;
-            memcpy(buf, state->next, n);
-            state->next += n;
-            state->have -= n;
+        if (state->x.have) {
+            n = state->x.have > len ? len : state->x.have;
+            memcpy(buf, state->x.next, n);
+            state->x.next += n;
+            state->x.have -= n;
         }
 
         /* output buffer empty -- return if we're at the end of the input */
-        else if (state->eof && strm->avail_in == 0)
+        else if (state->eof && strm->avail_in == 0) {
+            state->past = 1;        /* tried to read past end */
             break;
+        }
 
         /* need output data -- for small len or new stream load up our output
            buffer */
         else if (state->how == LOOK || len < (state->size << 1)) {
             /* get more output, looking for header if required */
-            if (gz_make(state) == -1)
+            if (gz_fetch(state) == -1)
                 return -1;
-            continue;       /* no progress yet -- go back to memcpy() above */
+            continue;       /* no progress yet -- go back to copy above */
             /* the copy above assures that we will leave with space in the
                output buffer, allowing at least one gzungetc() to succeed */
         }
 
         /* large len -- read directly into user buffer */
         else if (state->how == COPY) {      /* read directly */
-            if (gz_load(state, buf, len, &n) == -1)
+            if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
                 return -1;
         }
 
         /* large len -- decompress directly into user buffer */
         else {  /* state->how == GZIP */
             strm->avail_out = len;
-            strm->next_out = buf;
+            strm->next_out = (unsigned char *)buf;
             if (gz_decomp(state) == -1)
                 return -1;
-            n = state->have;
-            state->have = 0;
+            n = state->x.have;
+            state->x.have = 0;
         }
 
         /* update progress */
         len -= n;
         buf = (char *)buf + n;
         got += n;
-        state->pos += n;
+        state->x.pos += n;
     } while (len);
 
     /* return number of bytes read into user buffer (will fit in int) */
@@ -450,6 +379,11 @@ int ZEXPORT gzread(file, buf, len)
 }
 
 /* -- see zlib.h -- */
+#ifdef Z_PREFIX_SET
+#  undef z_gzgetc
+#else
+#  undef gzgetc
+#endif
 int ZEXPORT gzgetc(file)
     gzFile file;
 {
@@ -462,15 +396,16 @@ int ZEXPORT gzgetc(file)
         return -1;
     state = (gz_statep)file;
 
-    /* check that we're reading and that there's no error */
-    if (state->mode != GZ_READ || state->err != Z_OK)
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+        (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* try output buffer (no need to check for skip request) */
-    if (state->have) {
-        state->have--;
-        state->pos++;
-        return *(state->next)++;
+    if (state->x.have) {
+        state->x.have--;
+        state->x.pos++;
+        return *(state->x.next)++;
     }
 
     /* nothing there -- try gzread() */
@@ -478,6 +413,12 @@ int ZEXPORT gzgetc(file)
     return ret < 1 ? -1 : buf[0];
 }
 
+int ZEXPORT gzgetc_(file)
+gzFile file;
+{
+    return gzgetc(file);
+}
+
 /* -- see zlib.h -- */
 int ZEXPORT gzungetc(c, file)
     int c;
@@ -490,8 +431,9 @@ int ZEXPORT gzungetc(c, file)
         return -1;
     state = (gz_statep)file;
 
-    /* check that we're reading and that there's no error */
-    if (state->mode != GZ_READ || state->err != Z_OK)
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+        (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* process a skip request */
@@ -506,32 +448,34 @@ int ZEXPORT gzungetc(c, file)
         return -1;
 
     /* if output buffer empty, put byte at end (allows more pushing) */
-    if (state->have == 0) {
-        state->have = 1;
-        state->next = state->out + (state->size << 1) - 1;
-        state->next[0] = c;
-        state->pos--;
+    if (state->x.have == 0) {
+        state->x.have = 1;
+        state->x.next = state->out + (state->size << 1) - 1;
+        state->x.next[0] = c;
+        state->x.pos--;
+        state->past = 0;
         return c;
     }
 
     /* if no room, give up (must have already done a gzungetc()) */
-    if (state->have == (state->size << 1)) {
-        gz_error(state, Z_BUF_ERROR, "out of room to push characters");
+    if (state->x.have == (state->size << 1)) {
+        gz_error(state, Z_DATA_ERROR, "out of room to push characters");
         return -1;
     }
 
     /* slide output data if needed and insert byte before existing data */
-    if (state->next == state->out) {
-        unsigned char *src = state->out + state->have;
+    if (state->x.next == state->out) {
+        unsigned char *src = state->out + state->x.have;
         unsigned char *dest = state->out + (state->size << 1);
         while (src > state->out)
             *--dest = *--src;
-        state->next = dest;
+        state->x.next = dest;
     }
-    state->have++;
-    state->next--;
-    state->next[0] = c;
-    state->pos--;
+    state->x.have++;
+    state->x.next--;
+    state->x.next[0] = c;
+    state->x.pos--;
+    state->past = 0;
     return c;
 }
 
@@ -551,8 +495,9 @@ char * ZEXPORT gzgets(file, buf, len)
         return NULL;
     state = (gz_statep)file;
 
-    /* check that we're reading and that there's no error */
-    if (state->mode != GZ_READ || state->err != Z_OK)
+    /* check that we're reading and that there's no (serious) error */
+    if (state->mode != GZ_READ ||
+        (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return NULL;
 
     /* process a skip request */
@@ -569,32 +514,31 @@ char * ZEXPORT gzgets(file, buf, len)
     left = (unsigned)len - 1;
     if (left) do {
         /* assure that something is in the output buffer */
-        if (state->have == 0) {
-            if (gz_make(state) == -1)
-                return NULL;            /* error */
-            if (state->have == 0) {     /* end of file */
-                if (buf == str)         /* got bupkus */
-                    return NULL;
-                break;                  /* got something -- return it */
-            }
+        if (state->x.have == 0 && gz_fetch(state) == -1)
+            return NULL;                /* error */
+        if (state->x.have == 0) {       /* end of file */
+            state->past = 1;            /* read past end */
+            break;                      /* return what we have */
         }
 
         /* look for end-of-line in current output buffer */
-        n = state->have > left ? left : state->have;
-        eol = memchr(state->next, '\n', n);
+        n = state->x.have > left ? left : state->x.have;
+        eol = (unsigned char *)memchr(state->x.next, '\n', n);
         if (eol != NULL)
-            n = (unsigned)(eol - state->next) + 1;
+            n = (unsigned)(eol - state->x.next) + 1;
 
         /* copy through end-of-line, or remainder if not found */
-        memcpy(buf, state->next, n);
-        state->have -= n;
-        state->next += n;
-        state->pos += n;
+        memcpy(buf, state->x.next, n);
+        state->x.have -= n;
+        state->x.next += n;
+        state->x.pos += n;
         left -= n;
         buf += n;
     } while (left && eol == NULL);
 
-    /* found end-of-line or out of space -- terminate string and return it */
+    /* return terminated string, or if nothing, end of file */
+    if (buf == str)
+        return NULL;
     buf[0] = 0;
     return str;
 }
@@ -610,16 +554,12 @@ int ZEXPORT gzdirect(file)
         return 0;
     state = (gz_statep)file;
 
-    /* check that we're reading */
-    if (state->mode != GZ_READ)
-        return 0;
-
     /* if the state is not known, but we can find out, then do so (this is
        mainly for right after a gzopen() or gzdopen()) */
-    if (state->how == LOOK && state->have == 0)
-        (void)gz_head(state);
+    if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+        (void)gz_look(state);
 
-    /* return 1 if reading direct, 0 if decompressing a gzip stream */
+    /* return 1 if transparent, 0 if processing a gzip stream */
     return state->direct;
 }
 
@@ -627,7 +567,7 @@ int ZEXPORT gzdirect(file)
 int ZEXPORT gzclose_r(file)
     gzFile file;
 {
-    int ret;
+    int ret, err;
     gz_statep state;
 
     /* get internal structure */
@@ -645,9 +585,10 @@ int ZEXPORT gzclose_r(file)
         free(state->out);
         free(state->in);
     }
+    err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
     gz_error(state, Z_OK, NULL);
     free(state->path);
     ret = close(state->fd);
     free(state);
-    return ret ? Z_ERRNO : Z_OK;
+    return ret ? Z_ERRNO : err;
 }
diff --git a/src/libz/gzwrite.c b/src/libz/gzwrite.c
index e8defc6..aa767fb 100644
--- a/src/libz/gzwrite.c
+++ b/src/libz/gzwrite.c
@@ -1,5 +1,5 @@
 /* gzwrite.c -- zlib functions for writing gzip files
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -18,44 +18,55 @@ local int gz_init(state)
     int ret;
     z_streamp strm = &(state->strm);
 
-    /* allocate input and output buffers */
-    state->in = malloc(state->want);
-    state->out = malloc(state->want);
-    if (state->in == NULL || state->out == NULL) {
-        if (state->out != NULL)
-            free(state->out);
-        if (state->in != NULL)
-            free(state->in);
+    /* allocate input buffer */
+    state->in = (unsigned char *)malloc(state->want);
+    if (state->in == NULL) {
         gz_error(state, Z_MEM_ERROR, "out of memory");
         return -1;
     }
 
-    /* allocate deflate memory, set up for gzip compression */
-    strm->zalloc = Z_NULL;
-    strm->zfree = Z_NULL;
-    strm->opaque = Z_NULL;
-    ret = deflateInit2(strm, state->level, Z_DEFLATED,
-                       15 + 16, 8, state->strategy);
-    if (ret != Z_OK) {
-        free(state->in);
-        gz_error(state, Z_MEM_ERROR, "out of memory");
-        return -1;
+    /* only need output buffer and deflate state if compressing */
+    if (!state->direct) {
+        /* allocate output buffer */
+        state->out = (unsigned char *)malloc(state->want);
+        if (state->out == NULL) {
+            free(state->in);
+            gz_error(state, Z_MEM_ERROR, "out of memory");
+            return -1;
+        }
+
+        /* allocate deflate memory, set up for gzip compression */
+        strm->zalloc = Z_NULL;
+        strm->zfree = Z_NULL;
+        strm->opaque = Z_NULL;
+        ret = deflateInit2(strm, state->level, Z_DEFLATED,
+                           MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
+        if (ret != Z_OK) {
+            free(state->out);
+            free(state->in);
+            gz_error(state, Z_MEM_ERROR, "out of memory");
+            return -1;
+        }
     }
 
     /* mark state as initialized */
     state->size = state->want;
 
-    /* initialize write buffer */
-    strm->avail_out = state->size;
-    strm->next_out = state->out;
-    state->next = strm->next_out;
+    /* initialize write buffer if compressing */
+    if (!state->direct) {
+        strm->avail_out = state->size;
+        strm->next_out = state->out;
+        state->x.next = strm->next_out;
+    }
     return 0;
 }
 
 /* Compress whatever is at avail_in and next_in and write to the output file.
    Return -1 if there is an error writing to the output file, otherwise 0.
    flush is assumed to be a valid deflate() flush value.  If flush is Z_FINISH,
-   then the deflate() state is reset to start a new gzip stream. */
+   then the deflate() state is reset to start a new gzip stream.  If gz->direct
+   is true, then simply write to the output file without compressing, and
+   ignore flush. */
 local int gz_comp(state, flush)
     gz_statep state;
     int flush;
@@ -68,6 +79,17 @@ local int gz_comp(state, flush)
     if (state->size == 0 && gz_init(state) == -1)
         return -1;
 
+    /* write directly if requested */
+    if (state->direct) {
+        got = write(state->fd, strm->next_in, strm->avail_in);
+        if (got < 0 || (unsigned)got != strm->avail_in) {
+            gz_error(state, Z_ERRNO, zstrerror());
+            return -1;
+        }
+        strm->avail_in = 0;
+        return 0;
+    }
+
     /* run deflate() on provided input until it produces no more output */
     ret = Z_OK;
     do {
@@ -75,8 +97,8 @@ local int gz_comp(state, flush)
            doing Z_FINISH then don't write until we get to Z_STREAM_END */
         if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
             (flush != Z_FINISH || ret == Z_STREAM_END))) {
-            have = (unsigned)(strm->next_out - state->next);
-            if (have && ((got = write(state->fd, state->next, have)) < 0 ||
+            have = (unsigned)(strm->next_out - state->x.next);
+            if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
                          (unsigned)got != have)) {
                 gz_error(state, Z_ERRNO, zstrerror());
                 return -1;
@@ -85,7 +107,7 @@ local int gz_comp(state, flush)
                 strm->avail_out = state->size;
                 strm->next_out = state->out;
             }
-            state->next = strm->next_out;
+            state->x.next = strm->next_out;
         }
 
         /* compress */
@@ -131,7 +153,7 @@ local int gz_zero(state, len)
         }
         strm->avail_in = n;
         strm->next_in = state->in;
-        state->pos += n;
+        state->x.pos += n;
         if (gz_comp(state, Z_NO_FLUSH) == -1)
             return -1;
         len -= n;
@@ -146,7 +168,6 @@ int ZEXPORT gzwrite(file, buf, len)
     unsigned len;
 {
     unsigned put = len;
-    unsigned n;
     gz_statep state;
     z_streamp strm;
 
@@ -163,7 +184,7 @@ int ZEXPORT gzwrite(file, buf, len)
     /* since an int is returned, make sure len fits in one, otherwise return
        with an error (this avoids the flaw in the interface) */
     if ((int)len < 0) {
-        gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
+        gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
         return 0;
     }
 
@@ -186,16 +207,19 @@ int ZEXPORT gzwrite(file, buf, len)
     if (len < state->size) {
         /* copy to input buffer, compress when full */
         do {
+            unsigned have, copy;
+
             if (strm->avail_in == 0)
                 strm->next_in = state->in;
-            n = state->size - strm->avail_in;
-            if (n > len)
-                n = len;
-            memcpy(strm->next_in + strm->avail_in, buf, n);
-            strm->avail_in += n;
-            state->pos += n;
-            buf = (char *)buf + n;
-            len -= n;
+            have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
+            copy = state->size - have;
+            if (copy > len)
+                copy = len;
+            memcpy(state->in + have, buf, copy);
+            strm->avail_in += copy;
+            state->x.pos += copy;
+            buf = (const char *)buf + copy;
+            len -= copy;
             if (len && gz_comp(state, Z_NO_FLUSH) == -1)
                 return 0;
         } while (len);
@@ -207,8 +231,8 @@ int ZEXPORT gzwrite(file, buf, len)
 
         /* directly compress user buffer to file */
         strm->avail_in = len;
-        strm->next_in = (voidp)buf;
-        state->pos += len;
+        strm->next_in = (z_const Bytef *)buf;
+        state->x.pos += len;
         if (gz_comp(state, Z_NO_FLUSH) == -1)
             return 0;
     }
@@ -222,6 +246,7 @@ int ZEXPORT gzputc(file, c)
     gzFile file;
     int c;
 {
+    unsigned have;
     unsigned char buf[1];
     gz_statep state;
     z_streamp strm;
@@ -245,19 +270,23 @@ int ZEXPORT gzputc(file, c)
 
     /* try writing to input buffer for speed (state->size == 0 if buffer not
        initialized) */
-    if (strm->avail_in < state->size) {
+    if (state->size) {
         if (strm->avail_in == 0)
             strm->next_in = state->in;
-        strm->next_in[strm->avail_in++] = c;
-        state->pos++;
-        return c;
+        have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
+        if (have < state->size) {
+            state->in[have] = c;
+            strm->avail_in++;
+            state->x.pos++;
+            return c & 0xff;
+        }
     }
 
     /* no room in buffer or not initialized, use gz_write() */
     buf[0] = c;
     if (gzwrite(file, buf, 1) != 1)
         return -1;
-    return c;
+    return c & 0xff;
 }
 
 /* -- see zlib.h -- */
@@ -274,16 +303,15 @@ int ZEXPORT gzputs(file, str)
     return ret == 0 && len != 0 ? -1 : ret;
 }
 
-#ifdef STDC
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
 #include <stdarg.h>
 
 /* -- see zlib.h -- */
-int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
+int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
 {
     int size, len;
     gz_statep state;
     z_streamp strm;
-    va_list va;
 
     /* get internal structure */
     if (file == NULL)
@@ -313,25 +341,20 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
     /* do the printf() into the input buffer, put length in len */
     size = (int)(state->size);
     state->in[size - 1] = 0;
-    va_start(va, format);
 #ifdef NO_vsnprintf
 #  ifdef HAS_vsprintf_void
-    (void)vsprintf(state->in, format, va);
-    va_end(va);
+    (void)vsprintf((char *)(state->in), format, va);
     for (len = 0; len < size; len++)
         if (state->in[len] == 0) break;
 #  else
-    len = vsprintf(state->in, format, va);
-    va_end(va);
+    len = vsprintf((char *)(state->in), format, va);
 #  endif
 #else
 #  ifdef HAS_vsnprintf_void
-    (void)vsnprintf(state->in, size, format, va);
-    va_end(va);
-    len = strlen(state->in);
+    (void)vsnprintf((char *)(state->in), size, format, va);
+    len = strlen((char *)(state->in));
 #  else
     len = vsnprintf((char *)(state->in), size, format, va);
-    va_end(va);
 #  endif
 #endif
 
@@ -342,11 +365,22 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
     /* update buffer and position, defer compression until needed */
     strm->avail_in = (unsigned)len;
     strm->next_in = state->in;
-    state->pos += len;
+    state->x.pos += len;
     return len;
 }
 
-#else /* !STDC */
+int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
+{
+    va_list va;
+    int ret;
+
+    va_start(va, format);
+    ret = gzvprintf(file, format, va);
+    va_end(va);
+    return ret;
+}
+
+#else /* !STDC && !Z_HAVE_STDARG_H */
 
 /* -- see zlib.h -- */
 int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
@@ -366,6 +400,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
     state = (gz_statep)file;
     strm = &(state->strm);
 
+    /* check that can really pass pointer in ints */
+    if (sizeof(int) != sizeof(void *))
+        return 0;
+
     /* check that we're writing and that there's no error */
     if (state->mode != GZ_WRITE || state->err != Z_OK)
         return 0;
@@ -390,22 +428,23 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
     state->in[size - 1] = 0;
 #ifdef NO_snprintf
 #  ifdef HAS_sprintf_void
-    sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
+    sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
             a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
     for (len = 0; len < size; len++)
         if (state->in[len] == 0) break;
 #  else
-    len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
-                a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+    len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
+                  a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 #  endif
 #else
 #  ifdef HAS_snprintf_void
-    snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
+    snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
              a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-    len = strlen(state->in);
+    len = strlen((char *)(state->in));
 #  else
-    len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
-                 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+    len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
+                   a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
+                   a19, a20);
 #  endif
 #endif
 
@@ -416,7 +455,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
     /* update buffer and position, defer compression until needed */
     strm->avail_in = (unsigned)len;
     strm->next_in = state->in;
-    state->pos += len;
+    state->x.pos += len;
     return len;
 }
 
@@ -500,7 +539,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
 int ZEXPORT gzclose_w(file)
     gzFile file;
 {
-    int ret = 0;
+    int ret = Z_OK;
     gz_statep state;
 
     /* get internal structure */
@@ -515,17 +554,24 @@ int ZEXPORT gzclose_w(file)
     /* check for seek request */
     if (state->seek) {
         state->seek = 0;
-        ret += gz_zero(state, state->skip);
+        if (gz_zero(state, state->skip) == -1)
+            ret = state->err;
     }
 
     /* flush, free memory, and close file */
-    ret += gz_comp(state, Z_FINISH);
-    (void)deflateEnd(&(state->strm));
-    free(state->out);
-    free(state->in);
+    if (gz_comp(state, Z_FINISH) == -1)
+        ret = state->err;
+    if (state->size) {
+        if (!state->direct) {
+            (void)deflateEnd(&(state->strm));
+            free(state->out);
+        }
+        free(state->in);
+    }
     gz_error(state, Z_OK, NULL);
     free(state->path);
-    ret += close(state->fd);
+    if (close(state->fd) == -1)
+        ret = Z_ERRNO;
     free(state);
-    return ret ? Z_ERRNO : Z_OK;
+    return ret;
 }
diff --git a/src/libz/infback.c b/src/libz/infback.c
index af3a8c9..f3833c2 100644
--- a/src/libz/infback.c
+++ b/src/libz/infback.c
@@ -1,5 +1,5 @@
 /* infback.c -- inflate using a call-back interface
- * Copyright (C) 1995-2009 Mark Adler
+ * Copyright (C) 1995-2011 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -42,10 +42,19 @@ int stream_size;
         return Z_STREAM_ERROR;
     strm->msg = Z_NULL;                 /* in case we return an error */
     if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
         strm->zalloc = zcalloc;
         strm->opaque = (voidpf)0;
+#endif
     }
-    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+    if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+    strm->zfree = zcfree;
+#endif
     state = (struct inflate_state FAR *)ZALLOC(strm, 1,
                                                sizeof(struct inflate_state));
     if (state == Z_NULL) return Z_MEM_ERROR;
@@ -246,7 +255,7 @@ out_func out;
 void FAR *out_desc;
 {
     struct inflate_state FAR *state;
-    unsigned char FAR *next;    /* next input */
+    z_const unsigned char FAR *next;    /* next input */
     unsigned char FAR *put;     /* next output */
     unsigned have, left;        /* available input and output */
     unsigned long hold;         /* bit buffer */
@@ -394,7 +403,6 @@ void FAR *out_desc;
                     PULLBYTE();
                 }
                 if (here.val < 16) {
-                    NEEDBITS(here.bits);
                     DROPBITS(here.bits);
                     state->lens[state->have++] = here.val;
                 }
diff --git a/src/libz/inffast.c b/src/libz/inffast.c
index 2f1d60b..bda59ce 100644
--- a/src/libz/inffast.c
+++ b/src/libz/inffast.c
@@ -1,5 +1,5 @@
 /* inffast.c -- fast decoding
- * Copyright (C) 1995-2008, 2010 Mark Adler
+ * Copyright (C) 1995-2008, 2010, 2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -69,8 +69,8 @@ z_streamp strm;
 unsigned start;         /* inflate()'s starting value for strm->avail_out */
 {
     struct inflate_state FAR *state;
-    unsigned char FAR *in;      /* local strm->next_in */
-    unsigned char FAR *last;    /* while in < last, enough input available */
+    z_const unsigned char FAR *in;      /* local strm->next_in */
+    z_const unsigned char FAR *last;    /* have enough input while in < last */
     unsigned char FAR *out;     /* local strm->next_out */
     unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
     unsigned char FAR *end;     /* while out < end, enough space available */
diff --git a/src/libz/inffixed.h b/src/libz/inffixed.h
index 75ed4b5..d628327 100644
--- a/src/libz/inffixed.h
+++ b/src/libz/inffixed.h
@@ -2,9 +2,9 @@
      * Generated automatically by makefixed().
      */
 
-    /* WARNING: this file should *not* be used by applications. It
-       is part of the implementation of the compression library and
-       is subject to change. Applications should only use zlib.h.
+    /* WARNING: this file should *not* be used by applications.
+       It is part of the implementation of this library and is
+       subject to change. Applications should only use zlib.h.
      */
 
     static const code lenfix[512] = {
diff --git a/src/libz/inflate.c b/src/libz/inflate.c
index a8431ab..870f89b 100644
--- a/src/libz/inflate.c
+++ b/src/libz/inflate.c
@@ -1,5 +1,5 @@
 /* inflate.c -- zlib decompression
- * Copyright (C) 1995-2010 Mark Adler
+ * Copyright (C) 1995-2012 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -93,14 +93,15 @@
 
 /* function prototypes */
 local void fixedtables OF((struct inflate_state FAR *state));
-local int updatewindow OF((z_streamp strm, unsigned out));
+local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
+                           unsigned copy));
 #ifdef BUILDFIXED
    void makefixed OF((void));
 #endif
-local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
+local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
                               unsigned len));
 
-int ZEXPORT inflateReset(strm)
+int ZEXPORT inflateResetKeep(strm)
 z_streamp strm;
 {
     struct inflate_state FAR *state;
@@ -109,15 +110,13 @@ z_streamp strm;
     state = (struct inflate_state FAR *)strm->state;
     strm->total_in = strm->total_out = state->total = 0;
     strm->msg = Z_NULL;
-    strm->adler = 1;        /* to support ill-conceived Java test suite */
+    if (state->wrap)        /* to support ill-conceived Java test suite */
+        strm->adler = state->wrap & 1;
     state->mode = HEAD;
     state->last = 0;
     state->havedict = 0;
     state->dmax = 32768U;
     state->head = Z_NULL;
-    state->wsize = 0;
-    state->whave = 0;
-    state->wnext = 0;
     state->hold = 0;
     state->bits = 0;
     state->lencode = state->distcode = state->next = state->codes;
@@ -127,6 +126,19 @@ z_streamp strm;
     return Z_OK;
 }
 
+int ZEXPORT inflateReset(strm)
+z_streamp strm;
+{
+    struct inflate_state FAR *state;
+
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+    state->wsize = 0;
+    state->whave = 0;
+    state->wnext = 0;
+    return inflateResetKeep(strm);
+}
+
 int ZEXPORT inflateReset2(strm, windowBits)
 z_streamp strm;
 int windowBits;
@@ -180,10 +192,19 @@ int stream_size;
     if (strm == Z_NULL) return Z_STREAM_ERROR;
     strm->msg = Z_NULL;                 /* in case we return an error */
     if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
         strm->zalloc = zcalloc;
         strm->opaque = (voidpf)0;
+#endif
     }
-    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+    if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+        return Z_STREAM_ERROR;
+#else
+        strm->zfree = zcfree;
+#endif
     state = (struct inflate_state FAR *)
             ZALLOC(strm, 1, sizeof(struct inflate_state));
     if (state == Z_NULL) return Z_MEM_ERROR;
@@ -321,8 +342,8 @@ void makefixed()
     low = 0;
     for (;;) {
         if ((low % 7) == 0) printf("\n        ");
-        printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
-               state.lencode[low].val);
+        printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
+               state.lencode[low].bits, state.lencode[low].val);
         if (++low == size) break;
         putchar(',');
     }
@@ -355,12 +376,13 @@ void makefixed()
    output will fall in the output data, making match copies simpler and faster.
    The advantage may be dependent on the size of the processor's data caches.
  */
-local int updatewindow(strm, out)
+local int updatewindow(strm, end, copy)
 z_streamp strm;
-unsigned out;
+const Bytef *end;
+unsigned copy;
 {
     struct inflate_state FAR *state;
-    unsigned copy, dist;
+    unsigned dist;
 
     state = (struct inflate_state FAR *)strm->state;
 
@@ -380,19 +402,18 @@ unsigned out;
     }
 
     /* copy state->wsize or less output bytes into the circular window */
-    copy = out - strm->avail_out;
     if (copy >= state->wsize) {
-        zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
+        zmemcpy(state->window, end - state->wsize, state->wsize);
         state->wnext = 0;
         state->whave = state->wsize;
     }
     else {
         dist = state->wsize - state->wnext;
         if (dist > copy) dist = copy;
-        zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
+        zmemcpy(state->window + state->wnext, end - copy, dist);
         copy -= dist;
         if (copy) {
-            zmemcpy(state->window, strm->next_out - copy, copy);
+            zmemcpy(state->window, end - copy, copy);
             state->wnext = copy;
             state->whave = state->wsize;
         }
@@ -499,11 +520,6 @@ unsigned out;
         bits -= bits & 7; \
     } while (0)
 
-/* Reverse the bytes in a 32-bit value */
-#define REVERSE(q) \
-    ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
-     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
-
 /*
    inflate() uses a state machine to process as much input data and generate as
    much output data as possible before returning.  The state machine is
@@ -591,7 +607,7 @@ z_streamp strm;
 int flush;
 {
     struct inflate_state FAR *state;
-    unsigned char FAR *next;    /* next input */
+    z_const unsigned char FAR *next;    /* next input */
     unsigned char FAR *put;     /* next output */
     unsigned have, left;        /* available input and output */
     unsigned long hold;         /* bit buffer */
@@ -797,7 +813,7 @@ int flush;
 #endif
         case DICTID:
             NEEDBITS(32);
-            strm->adler = state->check = REVERSE(hold);
+            strm->adler = state->check = ZSWAP32(hold);
             INITBITS();
             state->mode = DICT;
         case DICT:
@@ -905,7 +921,7 @@ int flush;
             while (state->have < 19)
                 state->lens[order[state->have++]] = 0;
             state->next = state->codes;
-            state->lencode = (code const FAR *)(state->next);
+            state->lencode = (const code FAR *)(state->next);
             state->lenbits = 7;
             ret = inflate_table(CODES, state->lens, 19, &(state->next),
                                 &(state->lenbits), state->work);
@@ -925,7 +941,6 @@ int flush;
                     PULLBYTE();
                 }
                 if (here.val < 16) {
-                    NEEDBITS(here.bits);
                     DROPBITS(here.bits);
                     state->lens[state->have++] = here.val;
                 }
@@ -980,7 +995,7 @@ int flush;
                values here (9 and 6) without reading the comments in inftrees.h
                concerning the ENOUGH constants, which depend on those values */
             state->next = state->codes;
-            state->lencode = (code const FAR *)(state->next);
+            state->lencode = (const code FAR *)(state->next);
             state->lenbits = 9;
             ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
                                 &(state->lenbits), state->work);
@@ -989,7 +1004,7 @@ int flush;
                 state->mode = BAD;
                 break;
             }
-            state->distcode = (code const FAR *)(state->next);
+            state->distcode = (const code FAR *)(state->next);
             state->distbits = 6;
             ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
                             &(state->next), &(state->distbits), state->work);
@@ -1170,7 +1185,7 @@ int flush;
 #ifdef GUNZIP
                      state->flags ? hold :
 #endif
-                     REVERSE(hold)) != state->check) {
+                     ZSWAP32(hold)) != state->check) {
                     strm->msg = (char *)"incorrect data check";
                     state->mode = BAD;
                     break;
@@ -1214,8 +1229,9 @@ int flush;
      */
   inf_leave:
     RESTORE();
-    if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
-        if (updatewindow(strm, out)) {
+    if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
+            (state->mode < CHECK || flush != Z_FINISH)))
+        if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
             state->mode = MEM;
             return Z_MEM_ERROR;
         }
@@ -1249,13 +1265,37 @@ z_streamp strm;
     return Z_OK;
 }
 
+int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
+z_streamp strm;
+Bytef *dictionary;
+uInt *dictLength;
+{
+    struct inflate_state FAR *state;
+
+    /* check state */
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+    state = (struct inflate_state FAR *)strm->state;
+
+    /* copy dictionary */
+    if (state->whave && dictionary != Z_NULL) {
+        zmemcpy(dictionary, state->window + state->wnext,
+                state->whave - state->wnext);
+        zmemcpy(dictionary + state->whave - state->wnext,
+                state->window, state->wnext);
+    }
+    if (dictLength != Z_NULL)
+        *dictLength = state->whave;
+    return Z_OK;
+}
+
 int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
 z_streamp strm;
 const Bytef *dictionary;
 uInt dictLength;
 {
     struct inflate_state FAR *state;
-    unsigned long id;
+    unsigned long dictid;
+    int ret;
 
     /* check state */
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
@@ -1263,29 +1303,21 @@ uInt dictLength;
     if (state->wrap != 0 && state->mode != DICT)
         return Z_STREAM_ERROR;
 
-    /* check for correct dictionary id */
+    /* check for correct dictionary identifier */
     if (state->mode == DICT) {
-        id = adler32(0L, Z_NULL, 0);
-        id = adler32(id, dictionary, dictLength);
-        if (id != state->check)
+        dictid = adler32(0L, Z_NULL, 0);
+        dictid = adler32(dictid, dictionary, dictLength);
+        if (dictid != state->check)
             return Z_DATA_ERROR;
     }
 
-    /* copy dictionary to window */
-    if (updatewindow(strm, strm->avail_out)) {
+    /* copy dictionary to window using updatewindow(), which will amend the
+       existing dictionary if appropriate */
+    ret = updatewindow(strm, dictionary + dictLength, dictLength);
+    if (ret) {
         state->mode = MEM;
         return Z_MEM_ERROR;
     }
-    if (dictLength > state->wsize) {
-        zmemcpy(state->window, dictionary + dictLength - state->wsize,
-                state->wsize);
-        state->whave = state->wsize;
-    }
-    else {
-        zmemcpy(state->window + state->wsize - dictLength, dictionary,
-                dictLength);
-        state->whave = dictLength;
-    }
     state->havedict = 1;
     Tracev((stderr, "inflate:   dictionary set\n"));
     return Z_OK;
@@ -1321,7 +1353,7 @@ gz_headerp head;
  */
 local unsigned syncsearch(have, buf, len)
 unsigned FAR *have;
-unsigned char FAR *buf;
+const unsigned char FAR *buf;
 unsigned len;
 {
     unsigned got;
@@ -1433,8 +1465,8 @@ z_streamp source;
     }
 
     /* copy state */
-    zmemcpy(dest, source, sizeof(z_stream));
-    zmemcpy(copy, state, sizeof(struct inflate_state));
+    zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+    zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
     if (state->lencode >= state->codes &&
         state->lencode <= state->codes + ENOUGH - 1) {
         copy->lencode = copy->codes + (state->lencode - state->codes);
diff --git a/src/libz/inftrees.c b/src/libz/inftrees.c
index 11e9c52..44d89cf 100644
--- a/src/libz/inftrees.c
+++ b/src/libz/inftrees.c
@@ -1,5 +1,5 @@
 /* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-2010 Mark Adler
+ * Copyright (C) 1995-2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -9,7 +9,7 @@
 #define MAXBITS 15
 
 const char inflate_copyright[] =
-   " inflate 1.2.5 Copyright 1995-2010 Mark Adler ";
+   " inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
     static const unsigned short lext[31] = { /* Length codes 257..285 extra */
         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
-        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195};
+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
     static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -208,8 +208,8 @@ unsigned short FAR *work;
     mask = used - 1;            /* mask for comparing low */
 
     /* check available table space */
-    if ((type == LENS && used >= ENOUGH_LENS) ||
-        (type == DISTS && used >= ENOUGH_DISTS))
+    if ((type == LENS && used > ENOUGH_LENS) ||
+        (type == DISTS && used > ENOUGH_DISTS))
         return 1;
 
     /* process all codes and make table entries */
@@ -277,8 +277,8 @@ unsigned short FAR *work;
 
             /* check for enough space */
             used += 1U << curr;
-            if ((type == LENS && used >= ENOUGH_LENS) ||
-                (type == DISTS && used >= ENOUGH_DISTS))
+            if ((type == LENS && used > ENOUGH_LENS) ||
+                (type == DISTS && used > ENOUGH_DISTS))
                 return 1;
 
             /* point entry in root table to sub-table */
@@ -289,38 +289,14 @@ unsigned short FAR *work;
         }
     }
 
-    /*
-       Fill in rest of table for incomplete codes.  This loop is similar to the
-       loop above in incrementing huff for table indices.  It is assumed that
-       len is equal to curr + drop, so there is no loop needed to increment
-       through high index bits.  When the current sub-table is filled, the loop
-       drops back to the root table to fill in any remaining entries there.
-     */
-    here.op = (unsigned char)64;                /* invalid code marker */
-    here.bits = (unsigned char)(len - drop);
-    here.val = (unsigned short)0;
-    while (huff != 0) {
-        /* when done with sub-table, drop back to root table */
-        if (drop != 0 && (huff & mask) != low) {
-            drop = 0;
-            len = root;
-            next = *table;
-            here.bits = (unsigned char)len;
-        }
-
-        /* put invalid code marker in table */
-        next[huff >> drop] = here;
-
-        /* backwards increment the len-bit code huff */
-        incr = 1U << (len - 1);
-        while (huff & incr)
-            incr >>= 1;
-        if (incr != 0) {
-            huff &= incr - 1;
-            huff += incr;
-        }
-        else
-            huff = 0;
+    /* fill in remaining table entry if code is incomplete (guaranteed to have
+       at most one remaining entry, since if the code is incomplete, the
+       maximum code length that was allowed to get this far is one bit) */
+    if (huff != 0) {
+        here.op = (unsigned char)64;            /* invalid code marker */
+        here.bits = (unsigned char)(len - drop);
+        here.val = (unsigned short)0;
+        next[huff] = here;
     }
 
     /* set return parameters */
diff --git a/src/libz/trees.c b/src/libz/trees.c
index f747d5c..1fd7759 100644
--- a/src/libz/trees.c
+++ b/src/libz/trees.c
@@ -1,5 +1,5 @@
 /* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-2010 Jean-loup Gailly
+ * Copyright (C) 1995-2012 Jean-loup Gailly
  * detect_data_type() function provided freely by Cosmin Truta, 2006
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
@@ -30,7 +30,7 @@
  *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
  */
 
-/* @(#) $Id: trees.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 /* #define GEN_TREES_H */
 
@@ -74,11 +74,6 @@ local const uch bl_order[BL_CODES]
  * probability, to avoid transmitting the lengths for unused bit length codes.
  */
 
-#define Buf_size (8 * 2*sizeof(char))
-/* Number of bits used within bi_buf. (bi_buf might be implemented on
- * more than 16 bits on some systems.)
- */
-
 /* ===========================================================================
  * Local data. These are initialized only once.
  */
@@ -151,8 +146,8 @@ local void send_tree      OF((deflate_state *s, ct_data *tree, int max_code));
 local int  build_bl_tree  OF((deflate_state *s));
 local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
                               int blcodes));
-local void compress_block OF((deflate_state *s, ct_data *ltree,
-                              ct_data *dtree));
+local void compress_block OF((deflate_state *s, const ct_data *ltree,
+                              const ct_data *dtree));
 local int  detect_data_type OF((deflate_state *s));
 local unsigned bi_reverse OF((unsigned value, int length));
 local void bi_windup      OF((deflate_state *s));
@@ -399,7 +394,6 @@ void ZLIB_INTERNAL _tr_init(s)
 
     s->bi_buf = 0;
     s->bi_valid = 0;
-    s->last_eob_len = 8; /* enough lookahead for inflate */
 #ifdef DEBUG
     s->compressed_len = 0L;
     s->bits_sent = 0L;
@@ -883,15 +877,17 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
 }
 
 /* ===========================================================================
+ * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
+ */
+void ZLIB_INTERNAL _tr_flush_bits(s)
+    deflate_state *s;
+{
+    bi_flush(s);
+}
+
+/* ===========================================================================
  * Send one empty static block to give enough lookahead for inflate.
  * This takes 10 bits, of which 7 may remain in the bit buffer.
- * The current inflate code requires 9 bits of lookahead. If the
- * last two codes for the previous block (real code plus EOB) were coded
- * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
- * the last real code. In this case we send two empty static blocks instead
- * of one. (There are no problems if the previous block is stored or fixed.)
- * To simplify the code, we assume the worst case of last real code encoded
- * on one bit only.
  */
 void ZLIB_INTERNAL _tr_align(s)
     deflate_state *s;
@@ -902,20 +898,6 @@ void ZLIB_INTERNAL _tr_align(s)
     s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
 #endif
     bi_flush(s);
-    /* Of the 10 bits for the empty block, we have already sent
-     * (10 - bi_valid) bits. The lookahead for the last real code (before
-     * the EOB of the previous block) was thus at least one plus the length
-     * of the EOB plus what we have just sent of the empty static block.
-     */
-    if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
-        send_bits(s, STATIC_TREES<<1, 3);
-        send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
-        s->compressed_len += 10L;
-#endif
-        bi_flush(s);
-    }
-    s->last_eob_len = 7;
 }
 
 /* ===========================================================================
@@ -990,7 +972,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
     } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
 #endif
         send_bits(s, (STATIC_TREES<<1)+last, 3);
-        compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
+        compress_block(s, (const ct_data *)static_ltree,
+                       (const ct_data *)static_dtree);
 #ifdef DEBUG
         s->compressed_len += 3 + s->static_len;
 #endif
@@ -998,7 +981,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
         send_bits(s, (DYN_TREES<<1)+last, 3);
         send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
                        max_blindex+1);
-        compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
+        compress_block(s, (const ct_data *)s->dyn_ltree,
+                       (const ct_data *)s->dyn_dtree);
 #ifdef DEBUG
         s->compressed_len += 3 + s->opt_len;
 #endif
@@ -1075,8 +1059,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
  */
 local void compress_block(s, ltree, dtree)
     deflate_state *s;
-    ct_data *ltree; /* literal tree */
-    ct_data *dtree; /* distance tree */
+    const ct_data *ltree; /* literal tree */
+    const ct_data *dtree; /* distance tree */
 {
     unsigned dist;      /* distance of matched string */
     int lc;             /* match length or unmatched char (if dist == 0) */
@@ -1118,7 +1102,6 @@ local void compress_block(s, ltree, dtree)
     } while (lx < s->last_lit);
 
     send_code(s, END_BLOCK, ltree);
-    s->last_eob_len = ltree[END_BLOCK].Len;
 }
 
 /* ===========================================================================
@@ -1226,7 +1209,6 @@ local void copy_block(s, buf, len, header)
     int      header;  /* true if block header must be written */
 {
     bi_windup(s);        /* align on byte boundary */
-    s->last_eob_len = 8; /* enough lookahead for inflate */
 
     if (header) {
         put_short(s, (ush)len);
diff --git a/src/libz/uncompr.c b/src/libz/uncompr.c
index 88e5f55..242e949 100644
--- a/src/libz/uncompr.c
+++ b/src/libz/uncompr.c
@@ -3,7 +3,7 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $Id: uncompr.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #define ZLIB_INTERNAL
 #include "zlib.h"
@@ -30,7 +30,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
     z_stream stream;
     int err;
 
-    stream.next_in = (Bytef*)source;
+    stream.next_in = (z_const Bytef *)source;
     stream.avail_in = (uInt)sourceLen;
     /* Check for source > 64K on 16-bit machine: */
     if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
diff --git a/src/libz/zconf.h b/src/libz/zconf.h
index cc3f828..9987a77 100644
--- a/src/libz/zconf.h
+++ b/src/libz/zconf.h
@@ -1,9 +1,9 @@
 /* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2013 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $Id: zconf.h,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #ifndef ZCONF_H
 #define ZCONF_H
@@ -15,11 +15,13 @@
  * this permanently in zconf.h using "./configure --zprefix".
  */
 #ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */
+#  define Z_PREFIX_SET
 
 /* all linked symbols */
 #  define _dist_code            z__dist_code
 #  define _length_code          z__length_code
 #  define _tr_align             z__tr_align
+#  define _tr_flush_bits        z__tr_flush_bits
 #  define _tr_flush_block       z__tr_flush_block
 #  define _tr_init              z__tr_init
 #  define _tr_stored_block      z__tr_stored_block
@@ -27,9 +29,11 @@
 #  define adler32               z_adler32
 #  define adler32_combine       z_adler32_combine
 #  define adler32_combine64     z_adler32_combine64
-#  define compress              z_compress
-#  define compress2             z_compress2
-#  define compressBound         z_compressBound
+#  ifndef Z_SOLO
+#    define compress              z_compress
+#    define compress2             z_compress2
+#    define compressBound         z_compressBound
+#  endif
 #  define crc32                 z_crc32
 #  define crc32_combine         z_crc32_combine
 #  define crc32_combine64       z_crc32_combine64
@@ -40,44 +44,53 @@
 #  define deflateInit2_         z_deflateInit2_
 #  define deflateInit_          z_deflateInit_
 #  define deflateParams         z_deflateParams
+#  define deflatePending        z_deflatePending
 #  define deflatePrime          z_deflatePrime
 #  define deflateReset          z_deflateReset
+#  define deflateResetKeep      z_deflateResetKeep
 #  define deflateSetDictionary  z_deflateSetDictionary
 #  define deflateSetHeader      z_deflateSetHeader
 #  define deflateTune           z_deflateTune
 #  define deflate_copyright     z_deflate_copyright
 #  define get_crc_table         z_get_crc_table
-#  define gz_error              z_gz_error
-#  define gz_intmax             z_gz_intmax
-#  define gz_strwinerror        z_gz_strwinerror
-#  define gzbuffer              z_gzbuffer
-#  define gzclearerr            z_gzclearerr
-#  define gzclose               z_gzclose
-#  define gzclose_r             z_gzclose_r
-#  define gzclose_w             z_gzclose_w
-#  define gzdirect              z_gzdirect
-#  define gzdopen               z_gzdopen
-#  define gzeof                 z_gzeof
-#  define gzerror               z_gzerror
-#  define gzflush               z_gzflush
-#  define gzgetc                z_gzgetc
-#  define gzgets                z_gzgets
-#  define gzoffset              z_gzoffset
-#  define gzoffset64            z_gzoffset64
-#  define gzopen                z_gzopen
-#  define gzopen64              z_gzopen64
-#  define gzprintf              z_gzprintf
-#  define gzputc                z_gzputc
-#  define gzputs                z_gzputs
-#  define gzread                z_gzread
-#  define gzrewind              z_gzrewind
-#  define gzseek                z_gzseek
-#  define gzseek64              z_gzseek64
-#  define gzsetparams           z_gzsetparams
-#  define gztell                z_gztell
-#  define gztell64              z_gztell64
-#  define gzungetc              z_gzungetc
-#  define gzwrite               z_gzwrite
+#  ifndef Z_SOLO
+#    define gz_error              z_gz_error
+#    define gz_intmax             z_gz_intmax
+#    define gz_strwinerror        z_gz_strwinerror
+#    define gzbuffer              z_gzbuffer
+#    define gzclearerr            z_gzclearerr
+#    define gzclose               z_gzclose
+#    define gzclose_r             z_gzclose_r
+#    define gzclose_w             z_gzclose_w
+#    define gzdirect              z_gzdirect
+#    define gzdopen               z_gzdopen
+#    define gzeof                 z_gzeof
+#    define gzerror               z_gzerror
+#    define gzflush               z_gzflush
+#    define gzgetc                z_gzgetc
+#    define gzgetc_               z_gzgetc_
+#    define gzgets                z_gzgets
+#    define gzoffset              z_gzoffset
+#    define gzoffset64            z_gzoffset64
+#    define gzopen                z_gzopen
+#    define gzopen64              z_gzopen64
+#    ifdef _WIN32
+#      define gzopen_w              z_gzopen_w
+#    endif
+#    define gzprintf              z_gzprintf
+#    define gzvprintf             z_gzvprintf
+#    define gzputc                z_gzputc
+#    define gzputs                z_gzputs
+#    define gzread                z_gzread
+#    define gzrewind              z_gzrewind
+#    define gzseek                z_gzseek
+#    define gzseek64              z_gzseek64
+#    define gzsetparams           z_gzsetparams
+#    define gztell                z_gztell
+#    define gztell64              z_gztell64
+#    define gzungetc              z_gzungetc
+#    define gzwrite               z_gzwrite
+#  endif
 #  define inflate               z_inflate
 #  define inflateBack           z_inflateBack
 #  define inflateBackEnd        z_inflateBackEnd
@@ -92,16 +105,22 @@
 #  define inflateReset          z_inflateReset
 #  define inflateReset2         z_inflateReset2
 #  define inflateSetDictionary  z_inflateSetDictionary
+#  define inflateGetDictionary  z_inflateGetDictionary
 #  define inflateSync           z_inflateSync
 #  define inflateSyncPoint      z_inflateSyncPoint
 #  define inflateUndermine      z_inflateUndermine
+#  define inflateResetKeep      z_inflateResetKeep
 #  define inflate_copyright     z_inflate_copyright
 #  define inflate_fast          z_inflate_fast
 #  define inflate_table         z_inflate_table
-#  define uncompress            z_uncompress
+#  ifndef Z_SOLO
+#    define uncompress            z_uncompress
+#  endif
 #  define zError                z_zError
-#  define zcalloc               z_zcalloc
-#  define zcfree                z_zcfree
+#  ifndef Z_SOLO
+#    define zcalloc               z_zcalloc
+#    define zcfree                z_zcfree
+#  endif
 #  define zlibCompileFlags      z_zlibCompileFlags
 #  define zlibVersion           z_zlibVersion
 
@@ -111,7 +130,9 @@
 #  define alloc_func            z_alloc_func
 #  define charf                 z_charf
 #  define free_func             z_free_func
-#  define gzFile                z_gzFile
+#  ifndef Z_SOLO
+#    define gzFile                z_gzFile
+#  endif
 #  define gz_header             z_gz_header
 #  define gz_headerp            z_gz_headerp
 #  define in_func               z_in_func
@@ -197,6 +218,12 @@
 #  endif
 #endif
 
+#if defined(ZLIB_CONST) && !defined(z_const)
+#  define z_const const
+#else
+#  define z_const
+#endif
+
 /* Some Mac compilers merge all .h files incorrectly: */
 #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
 #  define NO_DUMMY_DECL
@@ -243,6 +270,14 @@
 #  endif
 #endif
 
+#ifndef Z_ARG /* function prototypes for stdarg */
+#  if defined(STDC) || defined(Z_HAVE_STDARG_H)
+#    define Z_ARG(args)  args
+#  else
+#    define Z_ARG(args)  ()
+#  endif
+#endif
+
 /* The following definitions for FAR are needed only for MSDOS mixed
  * model programming (small or medium model with some far allocations).
  * This was tested only with MSC; for other MSDOS compilers you may have
@@ -356,12 +391,47 @@ typedef uLong FAR uLongf;
    typedef Byte       *voidp;
 #endif
 
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
+#  include <limits.h>
+#  if (UINT_MAX == 0xffffffffUL)
+#    define Z_U4 unsigned
+#  elif (ULONG_MAX == 0xffffffffUL)
+#    define Z_U4 unsigned long
+#  elif (USHRT_MAX == 0xffffffffUL)
+#    define Z_U4 unsigned short
+#  endif
+#endif
+
+#ifdef Z_U4
+   typedef Z_U4 z_crc_t;
+#else
+   typedef unsigned long z_crc_t;
+#endif
+
 #ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
 #  define Z_HAVE_UNISTD_H
 #endif
 
+#ifdef HAVE_STDARG_H    /* may be set to #if 1 by ./configure */
+#  define Z_HAVE_STDARG_H
+#endif
+
 #ifdef STDC
-#  include <sys/types.h>    /* for off_t */
+#  ifndef Z_SOLO
+#    include <sys/types.h>      /* for off_t */
+#  endif
+#endif
+
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+#  ifndef Z_SOLO
+#    include <stdarg.h>         /* for va_list */
+#  endif
+#endif
+
+#ifdef _WIN32
+#  ifndef Z_SOLO
+#    include <stddef.h>         /* for wchar_t */
+#  endif
 #endif
 
 /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@@ -370,21 +440,38 @@ typedef uLong FAR uLongf;
  * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
  * equivalently requesting no 64-bit operations
  */
-#if -_LARGEFILE64_SOURCE - -1 == 1
+#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
 #  undef _LARGEFILE64_SOURCE
 #endif
 
-#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
-#  include <unistd.h>       /* for SEEK_* and off_t */
-#  ifdef VMS
-#    include <unixio.h>     /* for off_t */
-#  endif
-#  ifndef z_off_t
-#    define z_off_t off_t
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
+#  define Z_HAVE_UNISTD_H
+#endif
+#ifndef Z_SOLO
+#  if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
+#    include <unistd.h>         /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
+#    ifdef VMS
+#      include <unixio.h>       /* for off_t */
+#    endif
+#    ifndef z_off_t
+#      define z_off_t off_t
+#    endif
 #  endif
 #endif
 
-#ifndef SEEK_SET
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
+#  define Z_LFS64
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
+#  define Z_LARGE64
+#endif
+
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
+#  define Z_WANT64
+#endif
+
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
 #  define SEEK_SET        0       /* Seek from beginning of file.  */
 #  define SEEK_CUR        1       /* Seek from current position.  */
 #  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
@@ -394,18 +481,14 @@ typedef uLong FAR uLongf;
 #  define z_off_t long
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#if !defined(_WIN32) && defined(Z_LARGE64)
 #  define z_off64_t off64_t
 #else
-#  define z_off64_t z_off_t
-#endif
-
-#if defined(__OS400__)
-#  define NO_vsnprintf
-#endif
-
-#if defined(__MVS__)
-#  define NO_vsnprintf
+#  if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+#    define z_off64_t __int64
+#  else
+#    define z_off64_t z_off_t
+#  endif
 #endif
 
 /* MVS linker does not support external names larger than 8 bytes */
diff --git a/src/libz/zlib.h b/src/libz/zlib.h
index bfbba83..3e0c767 100644
--- a/src/libz/zlib.h
+++ b/src/libz/zlib.h
@@ -1,7 +1,7 @@
 /* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 1.2.5, April 19th, 2010
+  version 1.2.8, April 28th, 2013
 
-  Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
+  Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -24,8 +24,8 @@
 
 
   The data format used by the zlib library is described by RFCs (Request for
-  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
-  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+  Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
+  (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
 */
 
 #ifndef ZLIB_H
@@ -37,11 +37,11 @@
 extern "C" {
 #endif
 
-#define ZLIB_VERSION "1.2.5"
-#define ZLIB_VERNUM 0x1250
+#define ZLIB_VERSION "1.2.8"
+#define ZLIB_VERNUM 0x1280
 #define ZLIB_VER_MAJOR 1
 #define ZLIB_VER_MINOR 2
-#define ZLIB_VER_REVISION 5
+#define ZLIB_VER_REVISION 8
 #define ZLIB_VER_SUBREVISION 0
 
 /*
@@ -83,15 +83,15 @@ typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
 struct internal_state;
 
 typedef struct z_stream_s {
-    Bytef    *next_in;  /* next input byte */
+    z_const Bytef *next_in;     /* next input byte */
     uInt     avail_in;  /* number of bytes available at next_in */
-    uLong    total_in;  /* total nb of input bytes read so far */
+    uLong    total_in;  /* total number of input bytes read so far */
 
     Bytef    *next_out; /* next output byte should be put there */
     uInt     avail_out; /* remaining free space at next_out */
-    uLong    total_out; /* total nb of bytes output so far */
+    uLong    total_out; /* total number of bytes output so far */
 
-    char     *msg;      /* last error message, NULL if no error */
+    z_const char *msg;  /* last error message, NULL if no error */
     struct internal_state FAR *state; /* not visible by applications */
 
     alloc_func zalloc;  /* used to allocate the internal state */
@@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
 
     Z_FINISH can be used immediately after deflateInit if all the compression
   is to be done in a single step.  In this case, avail_out must be at least the
-  value returned by deflateBound (see below).  If deflate does not return
-  Z_STREAM_END, then it must be called again as described above.
+  value returned by deflateBound (see below).  Then deflate is guaranteed to
+  return Z_STREAM_END.  If not enough output space is provided, deflate will
+  not return Z_STREAM_END, and it must be called again as described above.
 
     deflate() sets strm->adler to the adler32 checksum of all input read
   so far (that is, total_in bytes).
@@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
   error.  However if all decompression is to be performed in a single step (a
   single call of inflate), the parameter flush should be set to Z_FINISH.  In
   this case all pending input is processed and all pending output is flushed;
-  avail_out must be large enough to hold all the uncompressed data.  (The size
-  of the uncompressed data may have been saved by the compressor for this
-  purpose.) The next operation on this stream must be inflateEnd to deallocate
-  the decompression state.  The use of Z_FINISH is never required, but can be
-  used to inform inflate that a faster approach may be used for the single
-  inflate() call.
+  avail_out must be large enough to hold all of the uncompressed data for the
+  operation to complete.  (The size of the uncompressed data may have been
+  saved by the compressor for this purpose.) The use of Z_FINISH is not
+  required to perform an inflation in one step.  However it may be used to
+  inform inflate that a faster approach can be used for the single inflate()
+  call.  Z_FINISH also informs inflate to not maintain a sliding window if the
+  stream completes, which reduces inflate's memory footprint.  If the stream
+  does not complete, either because not all of the stream is provided or not
+  enough output space is provided, then a sliding window will be allocated and
+  inflate() can be called again to continue the operation as if Z_NO_FLUSH had
+  been used.
 
      In this implementation, inflate() always flushes as much output as
   possible to the output buffer, and always uses the faster approach on the
-  first call.  So the only effect of the flush parameter in this implementation
-  is on the return value of inflate(), as noted below, or when it returns early
-  because Z_BLOCK or Z_TREES is used.
+  first call.  So the effects of the flush parameter in this implementation are
+  on the return value of inflate() as noted below, when inflate() returns early
+  when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
+  memory for a sliding window when Z_FINISH is used.
 
      If a preset dictionary is needed after this call (see inflateSetDictionary
-  below), inflate sets strm->adler to the adler32 checksum of the dictionary
+  below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
   chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
-  strm->adler to the adler32 checksum of all output produced so far (that is,
+  strm->adler to the Adler-32 checksum of all output produced so far (that is,
   total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
   below.  At the end of the stream, inflate() checks that its computed adler32
   checksum is equal to that saved by the compressor and returns Z_STREAM_END
@@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
   initializing with inflateInit2().  Any information contained in the gzip
   header is not retained, so applications that need that information should
   instead use raw inflate, see inflateInit2() below, or inflateBack() and
-  perform their own processing of the gzip header and trailer.
+  perform their own processing of the gzip header and trailer.  When processing
+  gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
+  producted so far.  The CRC-32 is checked against the gzip trailer.
 
     inflate() returns Z_OK if some progress has been made (more input processed
   or more output produced), Z_STREAM_END if the end of the compressed data has
@@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
                                              uInt  dictLength));
 /*
      Initializes the compression dictionary from the given byte sequence
-   without producing any compressed output.  This function must be called
-   immediately after deflateInit, deflateInit2 or deflateReset, before any call
-   of deflate.  The compressor and decompressor must use exactly the same
-   dictionary (see inflateSetDictionary).
+   without producing any compressed output.  When using the zlib format, this
+   function must be called immediately after deflateInit, deflateInit2 or
+   deflateReset, and before any call of deflate.  When doing raw deflate, this
+   function must be called either before any call of deflate, or immediately
+   after the completion of a deflate block, i.e. after all input has been
+   consumed and all output has been delivered when using any of the flush
+   options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH.  The
+   compressor and decompressor must use exactly the same dictionary (see
+   inflateSetDictionary).
 
      The dictionary should consist of strings (byte sequences) that are likely
    to be encountered later in the data to be compressed, with the most commonly
@@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
    parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
    inconsistent (for example if deflate has already been called for this stream
-   or if the compression method is bsort).  deflateSetDictionary does not
-   perform any compression: this will be done by deflate().
+   or if not at a block boundary for raw deflate).  deflateSetDictionary does
+   not perform any compression: this will be done by deflate().
 */
 
 ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
@@ -688,8 +702,28 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
    deflation of sourceLen bytes.  It must be called after deflateInit() or
    deflateInit2(), and after deflateSetHeader(), if used.  This would be used
    to allocate an output buffer for deflation in a single pass, and so would be
-   called before deflate().
-*/
+   called before deflate().  If that first deflate() call is provided the
+   sourceLen input bytes, an output buffer allocated to the size returned by
+   deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
+   to return Z_STREAM_END.  Note that it is possible for the compressed size to
+   be larger than the value returned by deflateBound() if flush options other
+   than Z_FINISH or Z_NO_FLUSH are used.
+*/
+
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
+                                       unsigned *pending,
+                                       int *bits));
+/*
+     deflatePending() returns the number of bytes and bits of output that have
+   been generated, but not yet provided in the available output.  The bytes not
+   provided would be due to the available output space having being consumed.
+   The number of bits of output not provided are between 0 and 7, where they
+   await more bits to join them in order to fill out a full byte.  If pending
+   or bits are Z_NULL, then those values are not set.
+
+     deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
+   stream state was inconsistent.
+ */
 
 ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
                                      int bits,
@@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
    than or equal to 16, and that many of the least significant bits of value
    will be inserted in the output.
 
-     deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent.
+     deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
+   room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
+   source stream state was inconsistent.
 */
 
 ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
@@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
    if that call returned Z_NEED_DICT.  The dictionary chosen by the compressor
    can be determined from the adler32 value returned by that call of inflate.
    The compressor and decompressor must use exactly the same dictionary (see
-   deflateSetDictionary).  For raw inflate, this function can be called
-   immediately after inflateInit2() or inflateReset() and before any call of
-   inflate() to set the dictionary.  The application must insure that the
-   dictionary that was used for compression is provided.
+   deflateSetDictionary).  For raw inflate, this function can be called at any
+   time to set the dictionary.  If the provided dictionary is smaller than the
+   window and there is already data in the window, then the provided dictionary
+   will amend what's there.  The application must insure that the dictionary
+   that was used for compression is provided.
 
      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
    parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
@@ -803,19 +839,38 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
    inflate().
 */
 
+ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
+                                             Bytef *dictionary,
+                                             uInt  *dictLength));
+/*
+     Returns the sliding dictionary being maintained by inflate.  dictLength is
+   set to the number of bytes in the dictionary, and that many bytes are copied
+   to dictionary.  dictionary must have enough space, where 32768 bytes is
+   always enough.  If inflateGetDictionary() is called with dictionary equal to
+   Z_NULL, then only the dictionary length is returned, and nothing is copied.
+   Similary, if dictLength is Z_NULL, then it is not set.
+
+     inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
+   stream state is inconsistent.
+*/
+
 ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
 /*
-     Skips invalid compressed data until a full flush point (see above the
-   description of deflate with Z_FULL_FLUSH) can be found, or until all
+     Skips invalid compressed data until a possible full flush point (see above
+   for the description of deflate with Z_FULL_FLUSH) can be found, or until all
    available input is skipped.  No output is provided.
 
-     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
-   if no more input was provided, Z_DATA_ERROR if no flush point has been
-   found, or Z_STREAM_ERROR if the stream structure was inconsistent.  In the
-   success case, the application may save the current current value of total_in
-   which indicates where valid compressed data was found.  In the error case,
-   the application may repeatedly call inflateSync, providing more input each
-   time, until success or end of the input data.
+     inflateSync searches for a 00 00 FF FF pattern in the compressed data.
+   All full flush points have this pattern, but not all occurrences of this
+   pattern are full flush points.
+
+     inflateSync returns Z_OK if a possible full flush point has been found,
+   Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
+   has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
+   In the success case, the application may save the current current value of
+   total_in which indicates where valid compressed data was found.  In the
+   error case, the application may repeatedly call inflateSync, providing more
+   input each time, until success or end of the input data.
 */
 
 ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
@@ -962,12 +1017,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
      See inflateBack() for the usage of these routines.
 
      inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
-   the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
+   the parameters are invalid, Z_MEM_ERROR if the internal state could not be
    allocated, or Z_VERSION_ERROR if the version of the library does not match
    the version of the header file.
 */
 
-typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
+typedef unsigned (*in_func) OF((void FAR *,
+                                z_const unsigned char FAR * FAR *));
 typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
 
 ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
@@ -975,11 +1031,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
                                     out_func out, void FAR *out_desc));
 /*
      inflateBack() does a raw inflate with a single call using a call-back
-   interface for input and output.  This is more efficient than inflate() for
-   file i/o applications in that it avoids copying between the output and the
-   sliding window by simply making the window itself the output buffer.  This
-   function trusts the application to not change the output buffer passed by
-   the output function, at least until inflateBack() returns.
+   interface for input and output.  This is potentially more efficient than
+   inflate() for file i/o applications, in that it avoids copying between the
+   output and the sliding window by simply making the window itself the output
+   buffer.  inflate() can be faster on modern CPUs when used with large
+   buffers.  inflateBack() trusts the application to not change the output
+   buffer passed by the output function, at least until inflateBack() returns.
 
      inflateBackInit() must be called first to allocate the internal state
    and to initialize the state with the user-provided window buffer.
@@ -1088,6 +1145,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
      27-31: 0 (reserved)
  */
 
+#ifndef Z_SOLO
 
                         /* utility functions */
 
@@ -1149,10 +1207,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
 
      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
    enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
+   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.  In
+   the case where there is not enough room, uncompress() will fill the output
+   buffer with the uncompressed data up to that point.
 */
 
-
                         /* gzip file access functions */
 
 /*
@@ -1162,7 +1221,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
    wrapper, documented in RFC 1952, wrapped around a deflate stream.
 */
 
-typedef voidp gzFile;       /* opaque gzip file descriptor */
+typedef struct gzFile_s *gzFile;    /* semi-opaque gzip file descriptor */
 
 /*
 ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
@@ -1172,13 +1231,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
    a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
    compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
    for fixed code compression as in "wb9F".  (See the description of
-   deflateInit2 for more information about the strategy parameter.) Also "a"
-   can be used instead of "w" to request that the gzip stream that will be
-   written be appended to the file.  "+" will result in an error, since reading
-   and writing to the same gzip file is not supported.
+   deflateInit2 for more information about the strategy parameter.)  'T' will
+   request transparent writing or appending with no compression and not using
+   the gzip format.
+
+     "a" can be used instead of "w" to request that the gzip stream that will
+   be written be appended to the file.  "+" will result in an error, since
+   reading and writing to the same gzip file is not supported.  The addition of
+   "x" when writing will create the file exclusively, which fails if the file
+   already exists.  On systems that support it, the addition of "e" when
+   reading or writing will set the flag to close the file on an execve() call.
+
+     These functions, as well as gzip, will read and decode a sequence of gzip
+   streams in a file.  The append function of gzopen() can be used to create
+   such a file.  (Also see gzflush() for another way to do this.)  When
+   appending, gzopen does not test whether the file begins with a gzip stream,
+   nor does it look for the end of the gzip streams to begin appending.  gzopen
+   will simply append a gzip stream to the existing file.
 
      gzopen can be used to read a file which is not in gzip format; in this
-   case gzread will directly read from the file without decompression.
+   case gzread will directly read from the file without decompression.  When
+   reading, this will be detected automatically by looking for the magic two-
+   byte gzip header.
 
      gzopen returns NULL if the file could not be opened, if there was
    insufficient memory to allocate the gzFile state, or if an invalid mode was
@@ -1197,7 +1271,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
    descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
    fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
    mode);.  The duplicated descriptor should be saved to avoid a leak, since
-   gzdopen does not close fd if it fails.
+   gzdopen does not close fd if it fails.  If you are using fileno() to get the
+   file descriptor from a FILE *, then you will have to use dup() to avoid
+   double-close()ing the file descriptor.  Both gzclose() and fclose() will
+   close the associated file descriptor, so they need to have different file
+   descriptors.
 
      gzdopen returns NULL if there was insufficient memory to allocate the
    gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
@@ -1235,14 +1313,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
 ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
 /*
      Reads the given number of uncompressed bytes from the compressed file.  If
-   the input file was not in gzip format, gzread copies the given number of
-   bytes into the buffer.
+   the input file is not in gzip format, gzread copies the given number of
+   bytes into the buffer directly from the file.
 
      After reaching the end of a gzip stream in the input, gzread will continue
-   to read, looking for another gzip stream, or failing that, reading the rest
-   of the input file directly without decompression.  The entire input file
-   will be read if gzread is called until it returns less than the requested
-   len.
+   to read, looking for another gzip stream.  Any number of gzip streams may be
+   concatenated in the input file, and will all be decompressed by gzread().
+   If something other than a gzip stream is encountered after a gzip stream,
+   that remaining trailing garbage is ignored (and no error is returned).
+
+     gzread can be used to read a gzip file that is being concurrently written.
+   Upon reaching the end of the input, gzread will return with the available
+   data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
+   gzclearerr can be used to clear the end of file indicator in order to permit
+   gzread to be tried again.  Z_OK indicates that a gzip stream was completed
+   on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
+   middle of a gzip stream.  Note that gzread does not return -1 in the event
+   of an incomplete gzip stream.  This error is deferred until gzclose(), which
+   will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
+   stream.  Alternatively, gzerror can be used before gzclose to detect this
+   case.
 
      gzread returns the number of uncompressed bytes actually read, less than
    len for end of file, or -1 for error.
@@ -1256,7 +1346,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
    error.
 */
 
-ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
 /*
      Converts, formats, and writes the arguments to the compressed file under
    control of the format string, as in fprintf.  gzprintf returns the number of
@@ -1301,7 +1391,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
 ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
 /*
      Reads one byte from the compressed file.  gzgetc returns this byte or -1
-   in case of end of file or error.
+   in case of end of file or error.  This is implemented as a macro for speed.
+   As such, it does not do all of the checking the other functions do.  I.e.
+   it does not check to see if file is NULL, nor whether the structure file
+   points to has been clobbered or not.
 */
 
 ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
@@ -1397,9 +1490,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
 ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
 /*
      Returns true (1) if file is being copied directly while reading, or false
-   (0) if file is a gzip stream being decompressed.  This state can change from
-   false to true while reading the input file if the end of a gzip stream is
-   reached, but is followed by data that is not another gzip stream.
+   (0) if file is a gzip stream being decompressed.
 
      If the input file is empty, gzdirect() will return true, since the input
    does not contain a gzip stream.
@@ -1408,6 +1499,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
    cause buffers to be allocated to allow reading the file to determine if it
    is a gzip file.  Therefore if gzbuffer() is used, it should be called before
    gzdirect().
+
+     When writing, gzdirect() returns true (1) if transparent writing was
+   requested ("wT" for the gzopen() mode), or false (0) otherwise.  (Note:
+   gzdirect() is not needed when writing.  Transparent writing must be
+   explicitly requested, so the application already knows the answer.  When
+   linking statically, using gzdirect() will include all of the zlib code for
+   gzip file reading and decompression, which may not be desired.)
 */
 
 ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
@@ -1419,7 +1517,8 @@ ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
    must not be called more than once on the same allocation.
 
      gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
-   file operation error, or Z_OK on success.
+   file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
+   last read ended in the middle of a gzip stream, or Z_OK on success.
 */
 
 ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
@@ -1457,6 +1556,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
    file that is being written concurrently.
 */
 
+#endif /* !Z_SOLO */
 
                         /* checksum functions */
 
@@ -1492,16 +1592,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
      Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
    and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
    each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
-   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
+   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.  Note
+   that the z_off_t type (like off_t) is a signed integer.  If len2 is
+   negative, the result has no meaning or utility.
 */
 
 ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
 /*
      Update a running CRC-32 with the bytes buf[0..len-1] and return the
    updated CRC-32.  If buf is Z_NULL, this function returns the required
-   initial value for the for the crc.  Pre- and post-conditioning (one's
-   complement) is performed within this function so it shouldn't be done by the
-   application.
+   initial value for the crc.  Pre- and post-conditioning (one's complement) is
+   performed within this function so it shouldn't be done by the application.
 
    Usage example:
 
@@ -1544,17 +1645,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
                                          const char *version,
                                          int stream_size));
 #define deflateInit(strm, level) \
-        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
+        deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
 #define inflateInit(strm) \
-        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
+        inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
 #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
-                      (strategy),           ZLIB_VERSION, sizeof(z_stream))
+                      (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
 #define inflateInit2(strm, windowBits) \
-        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+        inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+                      (int)sizeof(z_stream))
 #define inflateBackInit(strm, windowBits, window) \
         inflateBackInit_((strm), (windowBits), (window), \
-                                            ZLIB_VERSION, sizeof(z_stream))
+                      ZLIB_VERSION, (int)sizeof(z_stream))
+
+#ifndef Z_SOLO
+
+/* gzgetc() macro and its supporting function and exposed data structure.  Note
+ * that the real internal state is much larger than the exposed structure.
+ * This abbreviated structure exposes just enough for the gzgetc() macro.  The
+ * user should not mess with these exposed elements, since their names or
+ * behavior could change in the future, perhaps even capriciously.  They can
+ * only be used by the gzgetc() macro.  You have been warned.
+ */
+struct gzFile_s {
+    unsigned have;
+    unsigned char *next;
+    z_off64_t pos;
+};
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));  /* backward compatibility */
+#ifdef Z_PREFIX_SET
+#  undef z_gzgetc
+#  define z_gzgetc(g) \
+          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#else
+#  define gzgetc(g) \
+          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#endif
 
 /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
  * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
@@ -1562,7 +1688,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  * functions are changed to 64 bits) -- in case these are set on systems
  * without large file support, _LFS64_LARGEFILE must also be true
  */
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#ifdef Z_LARGE64
    ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
    ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
    ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
@@ -1571,14 +1697,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
    ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
 #endif
 
-#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
-#  define gzopen gzopen64
-#  define gzseek gzseek64
-#  define gztell gztell64
-#  define gzoffset gzoffset64
-#  define adler32_combine adler32_combine64
-#  define crc32_combine crc32_combine64
-#  ifdef _LARGEFILE64_SOURCE
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
+#  ifdef Z_PREFIX_SET
+#    define z_gzopen z_gzopen64
+#    define z_gzseek z_gzseek64
+#    define z_gztell z_gztell64
+#    define z_gzoffset z_gzoffset64
+#    define z_adler32_combine z_adler32_combine64
+#    define z_crc32_combine z_crc32_combine64
+#  else
+#    define gzopen gzopen64
+#    define gzseek gzseek64
+#    define gztell gztell64
+#    define gzoffset gzoffset64
+#    define adler32_combine adler32_combine64
+#    define crc32_combine crc32_combine64
+#  endif
+#  ifndef Z_LARGE64
      ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
      ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
      ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
@@ -1595,6 +1730,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
    ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
 #endif
 
+#else /* Z_SOLO */
+
+   ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+   ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+
+#endif /* !Z_SOLO */
+
 /* hack for buggy compilers */
 #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
     struct internal_state {int dummy;};
@@ -1603,8 +1745,21 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
 /* undocumented functions */
 ZEXTERN const char   * ZEXPORT zError           OF((int));
 ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp));
-ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table    OF((void));
 ZEXTERN int            ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int            ZEXPORT inflateResetKeep OF((z_streamp));
+ZEXTERN int            ZEXPORT deflateResetKeep OF((z_streamp));
+#if defined(_WIN32) && !defined(Z_SOLO)
+ZEXTERN gzFile         ZEXPORT gzopen_w OF((const wchar_t *path,
+                                            const char *mode));
+#endif
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+#  ifndef Z_SOLO
+ZEXTERN int            ZEXPORTVA gzvprintf Z_ARG((gzFile file,
+                                                  const char *format,
+                                                  va_list va));
+#  endif
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/src/libz/zutil.c b/src/libz/zutil.c
index 4d6b91c..23d2ebe 100644
--- a/src/libz/zutil.c
+++ b/src/libz/zutil.c
@@ -1,17 +1,20 @@
 /* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $Id: zutil.c,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #include "zutil.h"
+#ifndef Z_SOLO
+#  include "gzguts.h"
+#endif
 
 #ifndef NO_DUMMY_DECL
 struct internal_state      {int dummy;}; /* for buggy compilers */
 #endif
 
-const char * const z_errmsg[10] = {
+z_const char * const z_errmsg[10] = {
 "need dictionary",     /* Z_NEED_DICT       2  */
 "stream end",          /* Z_STREAM_END      1  */
 "",                    /* Z_OK              0  */
@@ -85,27 +88,27 @@ uLong ZEXPORT zlibCompileFlags()
 #ifdef FASTEST
     flags += 1L << 21;
 #endif
-#ifdef STDC
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
 #  ifdef NO_vsnprintf
-        flags += 1L << 25;
+    flags += 1L << 25;
 #    ifdef HAS_vsprintf_void
-        flags += 1L << 26;
+    flags += 1L << 26;
 #    endif
 #  else
 #    ifdef HAS_vsnprintf_void
-        flags += 1L << 26;
+    flags += 1L << 26;
 #    endif
 #  endif
 #else
-        flags += 1L << 24;
+    flags += 1L << 24;
 #  ifdef NO_snprintf
-        flags += 1L << 25;
+    flags += 1L << 25;
 #    ifdef HAS_sprintf_void
-        flags += 1L << 26;
+    flags += 1L << 26;
 #    endif
 #  else
 #    ifdef HAS_snprintf_void
-        flags += 1L << 26;
+    flags += 1L << 26;
 #    endif
 #  endif
 #endif
@@ -181,6 +184,7 @@ void ZLIB_INTERNAL zmemzero(dest, len)
 }
 #endif
 
+#ifndef Z_SOLO
 
 #ifdef SYS16BIT
 
@@ -316,3 +320,5 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
 }
 
 #endif /* MY_ZCALLOC */
+
+#endif /* !Z_SOLO */
diff --git a/src/libz/zutil.h b/src/libz/zutil.h
index 5dfdb5c..24ab06b 100644
--- a/src/libz/zutil.h
+++ b/src/libz/zutil.h
@@ -1,5 +1,5 @@
 /* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2013 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -8,12 +8,12 @@
    subject to change. Applications should only use zlib.h.
  */
 
-/* @(#) $Id: zutil.h,v 1.2 2010/06/30 04:58:25 gtkwave Exp $ */
+/* @(#) $Id$ */
 
 #ifndef ZUTIL_H
 #define ZUTIL_H
 
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
+#ifdef HAVE_HIDDEN
 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
 #else
 #  define ZLIB_INTERNAL
@@ -21,7 +21,7 @@
 
 #include "zlib.h"
 
-#ifdef STDC
+#if defined(STDC) && !defined(Z_SOLO)
 #  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
 #    include <stddef.h>
 #  endif
@@ -29,6 +29,10 @@
 #  include <stdlib.h>
 #endif
 
+#ifdef Z_SOLO
+   typedef long ptrdiff_t;  /* guess -- will be caught if guess is wrong */
+#endif
+
 #ifndef local
 #  define local static
 #endif
@@ -40,13 +44,13 @@ typedef unsigned short ush;
 typedef ush FAR ushf;
 typedef unsigned long  ulg;
 
-extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
+extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 /* (size given to avoid silly warnings with Visual C++) */
 
 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
 
 #define ERR_RETURN(strm,err) \
-  return (strm->msg = (char*)ERR_MSG(err), (err))
+  return (strm->msg = ERR_MSG(err), (err))
 /* To be used only when the state is known to be valid */
 
         /* common constants */
@@ -78,16 +82,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 
 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
 #  define OS_CODE  0x00
-#  if defined(__TURBOC__) || defined(__BORLANDC__)
-#    if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
-       /* Allow compilation with ANSI keywords only enabled */
-       void _Cdecl farfree( void *block );
-       void *_Cdecl farmalloc( unsigned long nbytes );
-#    else
-#      include <alloc.h>
+#  ifndef Z_SOLO
+#    if defined(__TURBOC__) || defined(__BORLANDC__)
+#      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+         /* Allow compilation with ANSI keywords only enabled */
+         void _Cdecl farfree( void *block );
+         void *_Cdecl farmalloc( unsigned long nbytes );
+#      else
+#        include <alloc.h>
+#      endif
+#    else /* MSC or DJGPP */
+#      include <malloc.h>
 #    endif
-#  else /* MSC or DJGPP */
-#    include <malloc.h>
 #  endif
 #endif
 
@@ -107,18 +113,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 
 #ifdef OS2
 #  define OS_CODE  0x06
-#  ifdef M_I86
+#  if defined(M_I86) && !defined(Z_SOLO)
 #    include <malloc.h>
 #  endif
 #endif
 
 #if defined(MACOS) || defined(TARGET_OS_MAC)
 #  define OS_CODE  0x07
-#  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-#    include <unix.h> /* for fdopen */
-#  else
-#    ifndef fdopen
-#      define fdopen(fd,mode) NULL /* No fdopen() */
+#  ifndef Z_SOLO
+#    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+#      include <unix.h> /* for fdopen */
+#    else
+#      ifndef fdopen
+#        define fdopen(fd,mode) NULL /* No fdopen() */
+#      endif
 #    endif
 #  endif
 #endif
@@ -153,14 +161,15 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  endif
 #endif
 
-#if defined(__BORLANDC__)
+#if defined(__BORLANDC__) && !defined(MSDOS)
   #pragma warn -8004
   #pragma warn -8008
   #pragma warn -8066
 #endif
 
 /* provide prototypes for these when building zlib without LFS */
-#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
+#if !defined(_WIN32) && \
+    (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
 #endif
@@ -177,42 +186,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 
          /* functions */
 
-#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
-#  ifndef HAVE_VSNPRINTF
-#    define HAVE_VSNPRINTF
-#  endif
-#endif
-#if defined(__CYGWIN__)
-#  ifndef HAVE_VSNPRINTF
-#    define HAVE_VSNPRINTF
-#  endif
-#endif
-#ifndef HAVE_VSNPRINTF
-#  ifdef MSDOS
-     /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
-        but for now we just assume it doesn't. */
-#    define NO_vsnprintf
-#  endif
-#  ifdef __TURBOC__
-#    define NO_vsnprintf
-#  endif
-#  ifdef WIN32
-     /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
-#    if !defined(vsnprintf) && !defined(NO_vsnprintf)
-#      if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
-#         define vsnprintf _vsnprintf
-#      endif
-#    endif
-#  endif
-#  ifdef __SASC
-#    define NO_vsnprintf
-#  endif
-#endif
-#ifdef VMS
-#  define NO_vsnprintf
-#endif
-
-#if defined(pyr)
+#if defined(pyr) || defined(Z_SOLO)
 #  define NO_MEMCPY
 #endif
 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
@@ -261,14 +235,19 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  define Tracecv(c,x)
 #endif
 
-
-voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
-                        unsigned size));
-void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
+#ifndef Z_SOLO
+   voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
+                                    unsigned size));
+   void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
+#endif
 
 #define ZALLOC(strm, items, size) \
            (*((strm)->zalloc))((strm)->opaque, (items), (size))
 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
 
+/* Reverse the bytes in a 32-bit value */
+#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
+                    (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
+
 #endif /* ZUTIL_H */
diff --git a/src/lxt.c b/src/lxt.c
index 54c7073..2a4d9ec 100644
--- a/src/lxt.c
+++ b/src/lxt.c
@@ -1,5 +1,5 @@
 /* 
- * Copyright (c) Tony Bybell 2001-2011.
+ * Copyright (c) Tony Bybell 2001-2013.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -183,7 +183,7 @@ inline static unsigned int get_64(offset) {
 
 #ifdef USE_X86_INLINE_ASM
 
-inline static unsigned int get_byte(offset) {
+inline static unsigned int get_byte(off_t offset) {
   return ((unsigned int)(*((unsigned char *) GLOBALS->mm_lxt_c_1+offset)));
 }
 
diff --git a/src/main.c b/src/main.c
index 4295d45..6fd5559 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) Tony Bybell 1999-2012.
+ * Copyright (c) Tony Bybell 1999-2013.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -370,7 +370,7 @@ if(dfile)
 		}
 #endif
 	}
-fileselbox_old("GTKWave: Select a dumpfile...",&GLOBALS->ftext_main_main_c_1,GTK_SIGNAL_FUNC(wave_get_filename_cleanup), GTK_SIGNAL_FUNC(wave_get_filename_cleanup), NULL);
+fileselbox_old("GTKWave: Select a dumpfile...",&GLOBALS->ftext_main_main_c_1,GTK_SIGNAL_FUNC(wave_get_filename_cleanup), GTK_SIGNAL_FUNC(wave_get_filename_cleanup), NULL, 0);
 gtk_main();
 
 return(GLOBALS->ftext_main_main_c_1);
diff --git a/src/menu.c b/src/menu.c
index 93088f2..0ec3e44 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -5426,8 +5426,6 @@ if(((typ == FST_MT_SOURCESTEM) || (typ == FST_MT_SOURCEISTEM)) && t_forced)
 static void
 menu_open_hierarchy_2a(gpointer null_data, guint callback_action, GtkWidget *widget, int typ)
 {
-Trptr t;
-int fix=0;
 if(GLOBALS->helpbox_is_active)
         {
 	if((typ == FST_MT_SOURCESTEM) || (typ == FST_MT_SOURCEISTEM))
diff --git a/src/signalwindow.c b/src/signalwindow.c
index 1e34792..b9339ed 100644
--- a/src/signalwindow.c
+++ b/src/signalwindow.c
@@ -1,5 +1,5 @@
 /* 
- * Copyright (c) Tony Bybell 1999-2012.
+ * Copyright (c) Tony Bybell 1999-2013.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -413,7 +413,7 @@ if(!GLOBALS || !GLOBALS->filter_entry || !event)
  */
 static gint keypress_local(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-GtkAdjustment *wadj, *hadj;
+GtkAdjustment *wadj;
 int num_traces_displayable;
 int target;
 int which;
@@ -527,6 +527,8 @@ if(GTK_WIDGET_HAS_FOCUS(GLOBALS->signalarea_event_box))
 		case GDK_Left:
 		case GDK_KP_Left:
 
+			service_left_edge(NULL, 0);
+			/*
 			hadj=GTK_ADJUSTMENT(GLOBALS->signal_hslider);
   
 			if(hadj->value < hadj->page_increment)
@@ -538,9 +540,10 @@ if(GTK_WIDGET_HAS_FOCUS(GLOBALS->signalarea_event_box))
 				hadj->value = hadj->value - hadj->page_increment;
 				}
 
-			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "changed");	/* force bar update */
-			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "value_changed"); /* force text update */
+			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "changed");
+			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "value_changed");
 			signalarea_configure_event(GLOBALS->signalarea, NULL);
+			*/
 
 			rc = TRUE;
 			break;
@@ -548,7 +551,8 @@ if(GTK_WIDGET_HAS_FOCUS(GLOBALS->signalarea_event_box))
 		case GDK_Right:
 		case GDK_KP_Right:
 
-			/* fill in left/right hscroll here */
+			service_right_edge(NULL, 0);
+			/*
 			hadj=GTK_ADJUSTMENT(GLOBALS->signal_hslider);
 
 			if( ((int) hadj->value + hadj->page_increment) >= hadj->upper)
@@ -560,9 +564,10 @@ if(GTK_WIDGET_HAS_FOCUS(GLOBALS->signalarea_event_box))
 				hadj->value = hadj->value + hadj->page_increment;
 				}
 
-			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "changed");	/* force bar update */
-			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "value_changed"); /* force text update */
+			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "changed");
+			gtk_signal_emit_by_name (GTK_OBJECT (hadj), "value_changed");
 			signalarea_configure_event(GLOBALS->signalarea, NULL);
+			*/
 
 			rc = TRUE;
 			break;
@@ -716,6 +721,66 @@ GdkEventMotion event[1];
 event[0].deviceid = GDK_CORE_POINTER;  
 #endif
 
+if(GLOBALS->button2_debounce_flag)
+	{
+	GLOBALS->button2_debounce_flag = 0;
+	}
+
+if((GLOBALS->dnd_state)||(GLOBALS->tree_dnd_begin)) /* drag scroll on DnD */
+	{
+	GtkAdjustment *wadj;
+	int num_traces_displayable;
+	int target;
+	int which;
+	int yscroll;
+
+	WAVE_GDK_GET_POINTER(GLOBALS->signalarea->window, &x, &y, &xi, &yi, &state);
+	WAVE_GDK_GET_POINTER_COPY;
+
+	if(y > GLOBALS->signalarea->allocation.height)
+		{
+                wadj=GTK_ADJUSTMENT(GLOBALS->wave_vslider);
+                num_traces_displayable=(GLOBALS->signalarea->allocation.height)/(GLOBALS->fontheight);
+                num_traces_displayable--;   /* for the time trace that is always there */
+                      
+               	if(num_traces_displayable<GLOBALS->traces.visible)
+			{
+			yscroll = 1;
+                        target=((int)wadj->value)+yscroll;  
+                        which=num_traces_displayable-1;
+
+                        if(target+which>=(GLOBALS->traces.visible-1)) target=GLOBALS->traces.visible-which-1;
+       			wadj->value=target;
+
+       			if(GLOBALS->cachedwhich_signalwindow_c_1==which) GLOBALS->cachedwhich_signalwindow_c_1=which-1; /* force update */
+
+       			gtk_signal_emit_by_name (GTK_OBJECT (wadj), "changed"); /* force bar update */
+       			gtk_signal_emit_by_name (GTK_OBJECT (wadj), "value_changed"); /* force text update */
+			}
+		}
+	else 
+	if(y < 0)
+		{
+                wadj=GTK_ADJUSTMENT(GLOBALS->wave_vslider);
+                num_traces_displayable=(GLOBALS->signalarea->allocation.height)/(GLOBALS->fontheight);
+                num_traces_displayable--;   /* for the time trace that is always there */
+                      
+               	if(num_traces_displayable<GLOBALS->traces.visible)
+			{
+			yscroll = 1;
+       			target=((int)wadj->value)-yscroll;
+       			if(target<0) target=0;
+       			wadj->value=target;
+                         
+			which=0;
+       			if(GLOBALS->cachedwhich_signalwindow_c_1==which) GLOBALS->cachedwhich_signalwindow_c_1=-1; /* force update */
+
+       			gtk_signal_emit_by_name (GTK_OBJECT (wadj), "changed"); /* force bar update */
+       			gtk_signal_emit_by_name (GTK_OBJECT (wadj), "value_changed"); /* force text update */
+			}
+		}
+	}
+
 if(in_main_iteration()) return(TRUE);
 
 if(GLOBALS->splash_is_loading)
diff --git a/src/strace.c b/src/strace.c
index 5718daf..537be1a 100644
--- a/src/strace.c
+++ b/src/strace.c
@@ -1,5 +1,5 @@
 /* 
- * Copyright (c) Tony Bybell 1999-2011.
+ * Copyright (c) Tony Bybell 1999-2013.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -39,64 +39,64 @@ static char *stype[WAVE_STYPE_COUNT]=
 
 static struct item_mark_string item_mark_start_strings[]=
 	{
-	   { "Start of Time"  },
-	   { "Named Marker A" },
-	   { "Named Marker B" },
-	   { "Named Marker C" },
-	   { "Named Marker D" },
-	   { "Named Marker E" },
-	   { "Named Marker F" },
-	   { "Named Marker G" },
-	   { "Named Marker H" },
-	   { "Named Marker I" },
-	   { "Named Marker J" },
-	   { "Named Marker K" },
-	   { "Named Marker L" },
-	   { "Named Marker M" },
-	   { "Named Marker N" },
-	   { "Named Marker O" },
-	   { "Named Marker P" },
-	   { "Named Marker Q" },
-	   { "Named Marker R" },
-	   { "Named Marker S" },
-	   { "Named Marker T" },
-	   { "Named Marker U" },
-	   { "Named Marker V" },
-	   { "Named Marker W" },
-	   { "Named Marker X" },
-	   { "Named Marker Y" },
-	   { "Named Marker Z" }
+	   { "Start of Time",  0 },
+	   { "Named Marker A", 0 },
+	   { "Named Marker B", 0 },
+	   { "Named Marker C", 0 },
+	   { "Named Marker D", 0 },
+	   { "Named Marker E", 0 },
+	   { "Named Marker F", 0 },
+	   { "Named Marker G", 0 },
+	   { "Named Marker H", 0 },
+	   { "Named Marker I", 0 },
+	   { "Named Marker J", 0 },
+	   { "Named Marker K", 0 },
+	   { "Named Marker L", 0 },
+	   { "Named Marker M", 0 },
+	   { "Named Marker N", 0 },
+	   { "Named Marker O", 0 },
+	   { "Named Marker P", 0 },
+	   { "Named Marker Q", 0 },
+	   { "Named Marker R", 0 },
+	   { "Named Marker S", 0 },
+	   { "Named Marker T", 0 },
+	   { "Named Marker U", 0 },
+	   { "Named Marker V", 0 },
+	   { "Named Marker W", 0 },
+	   { "Named Marker X", 0 },
+	   { "Named Marker Y", 0 },
+	   { "Named Marker Z", 0 }
 	};
 
 static struct item_mark_string item_mark_end_strings[]=
 	{
-	   { "End of Time"    },
-	   { "Named Marker A" },
-	   { "Named Marker B" },
-	   { "Named Marker C" },
-	   { "Named Marker D" },
-	   { "Named Marker E" },
-	   { "Named Marker F" },
-	   { "Named Marker G" },
-	   { "Named Marker H" },
-	   { "Named Marker I" },
-	   { "Named Marker J" },
-	   { "Named Marker K" },
-	   { "Named Marker L" },
-	   { "Named Marker M" },
-	   { "Named Marker N" },
-	   { "Named Marker O" },
-	   { "Named Marker P" },
-	   { "Named Marker Q" },
-	   { "Named Marker R" },
-	   { "Named Marker S" },
-	   { "Named Marker T" },
-	   { "Named Marker U" },
-	   { "Named Marker V" },
-	   { "Named Marker W" },
-	   { "Named Marker X" },
-	   { "Named Marker Y" },
-	   { "Named Marker Z" }
+	   { "End of Time",    0 },
+	   { "Named Marker A", 0 },
+	   { "Named Marker B", 0 },
+	   { "Named Marker C", 0 },
+	   { "Named Marker D", 0 },
+	   { "Named Marker E", 0 },
+	   { "Named Marker F", 0 },
+	   { "Named Marker G", 0 },
+	   { "Named Marker H", 0 },
+	   { "Named Marker I", 0 },
+	   { "Named Marker J", 0 },
+	   { "Named Marker K", 0 },
+	   { "Named Marker L", 0 },
+	   { "Named Marker M", 0 },
+	   { "Named Marker N", 0 },
+	   { "Named Marker O", 0 },
+	   { "Named Marker P", 0 },
+	   { "Named Marker Q", 0 },
+	   { "Named Marker R", 0 },
+	   { "Named Marker S", 0 },
+	   { "Named Marker T", 0 },
+	   { "Named Marker U", 0 },
+	   { "Named Marker V", 0 },
+	   { "Named Marker W", 0 },
+	   { "Named Marker X", 0 },
+	   { "Named Marker Y", 0 },
+	   { "Named Marker Z", 0 }
 	};
 
 
diff --git a/src/vcd_partial.c b/src/vcd_partial.c
index 4e5f6e4..bad416a 100644
--- a/src/vcd_partial.c
+++ b/src/vcd_partial.c
@@ -2478,6 +2478,10 @@ if(t->vector)
 					bts->nodes[i]->harray = NULL;
 					}
 				}
+				else
+				{
+				t->interactive_vector_needs_regeneration = 1;
+				}
 			}
 		}
 
@@ -2651,10 +2655,30 @@ if(GLOBALS->partial_vcd)
 gtkwave_main_iteration();
 }
 
+
+static void vcd_partial_regen_node_expansion(Trptr t)
+{
+if(!t->vector) 
+	{
+	if(t->n.nd && t->n.nd->expansion)
+		{
+		nptr np_ex = ExtractNodeSingleBit(t->n.nd->expansion->parent, t->n.nd->expansion->parentbit);
+
+		DeleteNode(t->n.nd);
+		t->n.nd = np_ex;
+		t->name_full = np_ex->nname;
+		t->name = (GLOBALS->hier_max_level) ? hier_extract(t->name_full, GLOBALS->hier_max_level) : t->name_full;
+		}
+	}
+
+}
+
 void vcd_partial_mark_and_sweep(int mandclear)
 {
 Trptr t;
 
+
+
 /* node */
 t = GLOBALS->traces.first; while(t) { if(!t->vector) regen_trace_mark(t, mandclear); t = t->t_next; }
 t = GLOBALS->traces.buffer; while(t) { if(!t->vector) regen_trace_mark(t, mandclear); t = t->t_next; }
@@ -2662,6 +2686,10 @@ t = GLOBALS->traces.buffer; while(t) { if(!t->vector) regen_trace_mark(t, mandcl
 t = GLOBALS->traces.first; while(t) { if(!t->vector) regen_trace_sweep(t); t = t->t_next; }
 t = GLOBALS->traces.buffer; while(t) { if(!t->vector) regen_trace_sweep(t); t = t->t_next; }
 
+/* node that is single bit extracted */
+t = GLOBALS->traces.first; while(t) { vcd_partial_regen_node_expansion(t); t = t->t_next; }
+t = GLOBALS->traces.buffer; while(t) { vcd_partial_regen_node_expansion(t); t = t->t_next; }
+
 /* vector */
 t = GLOBALS->traces.first; while(t) { if(t->vector) regen_trace_mark(t, mandclear); t = t->t_next; }
 t = GLOBALS->traces.buffer; while(t) { if(t->vector) regen_trace_mark(t, mandclear); t = t->t_next; }
diff --git a/src/wavewindow.c b/src/wavewindow.c
index 0abf467..e303fa3 100644
--- a/src/wavewindow.c
+++ b/src/wavewindow.c
@@ -1469,7 +1469,11 @@ if((event->button==1)||((event->button==3)&&(!GLOBALS->in_button_press_wavewindo
 else
 if(event->button==2)
 	{
-	button_motion_common(event->x,event->y,1,1);
+	if(!GLOBALS->button2_debounce_flag)
+		{
+		GLOBALS->button2_debounce_flag = 1; /* cleared by mouseover_timer() interrupt */
+		button_motion_common(event->x,event->y,1,1);
+		}
 	}
 
 return(TRUE);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-electronics/gtkwave.git



More information about the Pkg-electronics-commits mailing list